From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27242 invoked by alias); 13 Feb 2013 18:03:55 -0000 Received: (qmail 27232 invoked by uid 22791); 13 Feb 2013 18:03:54 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 13 Feb 2013 18:03:42 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1DI3evt021304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 13 Feb 2013 13:03:40 -0500 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1DI3dVe014291 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 13 Feb 2013 13:03:39 -0500 From: Tom Tromey To: Siva Chandra Cc: Doug Evans , gdb-patches Subject: Re: [RFC - Python Scripting] New method gdb.Architecture.disassemble References: <20753.38272.55066.651097@ruffy2.mtv.corp.google.com> <87txphmdt3.fsf@fleche.redhat.com> Date: Wed, 13 Feb 2013 18:03:00 -0000 In-Reply-To: (Siva Chandra's message of "Wed, 13 Feb 2013 06:37:46 -0800") Message-ID: <87r4kkks5g.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.92 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2013-02/txt/msg00323.txt.bz2 >>>>> "Siva" =3D=3D Siva Chandra writes: Siva> 1. docs.python.org says that PyList_Append sets an exception when it Siva> fails. It does not say so for PyList_New() and PyDict_New(). However, Siva> Tom commented that even these functions set exception on failure. In Siva> general, how do we know if a certain Python C API function sets an Siva> exception or not? The general rule in Python is that failures set the exception. I found some text in the manual, from http://docs.python.org/2/c-api/intro.html#exceptions All functions in the Python/C API can raise exceptions, unless an explicit claim is made otherwise in a function=E2=80=99s documentation= . In general, when a function encounters an error, it sets an exception, discards any object references that it owns, and returns an error indicator. If not documented otherwise, this indicator is either NULL or -1, depending on the function=E2=80=99s return type. A few function= s return a Boolean true/false result, with false indicating an error. Very few functions return no explicit error indicator or have an ambiguous return value, and require explicit testing for errors with PyErr_Occurred(). These exceptions are always explicitly documented. Siva> 2. One of Tom's suggestion was to use something like this: Siva> asm_code =3D=3D NULL ? unknown_str : asm_code Siva> I have modified my code accordingly, but the concern I have is that Siva> asm_code is of type 'char *', while unknown_str if of type 'const char Siva> *'. This means that the type of result of the above expression is Siva> dynamic! Though the code compiles with GCC, it that standard? It is. I'd have to dig through the standard to find the real language, but basically the type of the "?:" expression is the result of applying the appropriate kind of promotion to its arguments. Here the type is "const char *". Siva> + if (!result_list) There was a recent agreement to use "result =3D=3D NULL" for pointer types. I'm sorry if I didn't catch this last time around, I'm having a little difficulty adapting. Siva> + if (!insn_dict) Here too. Siva> + PyErr_SetString (PyExc_MemoryError, Siva> + _("Unable to add fields to instruction di= ct.")); I think you don't need this. Siva> +gdb_test "python arch.disassemble(0, 0)" ".*gdb\.MemoryError.*" "tes= t exception" I think this could use a line break somewhere. Tom