From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5284 invoked by alias); 19 Apr 2013 14:31:41 -0000 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 Received: (qmail 5271 invoked by uid 89); 19 Apr 2013 14:31:40 -0000 X-Spam-SWARE-Status: No, score=-6.8 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 19 Apr 2013 14:31:40 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3JEVc51013047 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 19 Apr 2013 10:31:39 -0400 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3JEVaVO002670 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 19 Apr 2013 10:31:37 -0400 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 08/28] use CPYCHECKER_SETS_EXCEPTION References: <87ehe638ww.fsf@fleche.redhat.com> Date: Fri, 19 Apr 2013 14:40:00 -0000 In-Reply-To: <87ehe638ww.fsf@fleche.redhat.com> (Tom Tromey's message of "Fri, 19 Apr 2013 08:13:51 -0600") Message-ID: <8738um1tiv.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-04/txt/msg00591.txt.bz2 The checker defines an attribute that can be used to indicate that a function sets the Python exception. This patch introduces a new macro for this attribute and changes gdb to use it. I also changed gdbpy_convert_exception to return 'void'. This is friendlier to the checker, which didn't recognize our current convention; but also turns out to clean up the code a little. * python/py-arch.c (archpy_disassemble): Update. * python/py-type.c (typy_get_composite, typy_lookup_typename) (typy_lookup_type): Use GDB_PY_HANDLE_EXCEPTION. * python/py-utils.c (gdbpy_convert_exception): Return 'void'. * python/python-internal.h (CPYCHECKER_SETS_EXCEPTION): New macro. (GDB_PY_HANDLE_EXCEPTION): Update. (gdbpy_convert_exception): Update. Use CPYCHECKER_SETS_EXCEPTION. --- gdb/python/py-arch.c | 3 ++- gdb/python/py-type.c | 20 +++----------------- gdb/python/py-utils.c | 6 +++--- gdb/python/python-internal.h | 22 ++++++++++++++++------ 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c index 7eb6eea..146a642 100644 --- a/gdb/python/py-arch.c +++ b/gdb/python/py-arch.c @@ -200,7 +200,8 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw) Py_DECREF (result_list); ui_file_delete (memfile); - return gdbpy_convert_exception (except); + gdbpy_convert_exception (except); + return NULL; } as = ui_file_xstrdup (memfile, NULL); diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 7cc89ca..b289a89 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -443,13 +443,7 @@ typy_get_composite (struct type *type) { CHECK_TYPEDEF (type); } - /* Don't use GDB_PY_HANDLE_EXCEPTION here because that returns - a (NULL) pointer of the wrong type. */ - if (except.reason < 0) - { - gdbpy_convert_exception (except); - return NULL; - } + GDB_PY_HANDLE_EXCEPTION (except); if (TYPE_CODE (type) != TYPE_CODE_PTR && TYPE_CODE (type) != TYPE_CODE_REF) @@ -732,11 +726,7 @@ typy_lookup_typename (const char *type_name, const struct block *block) type = lookup_typename (python_language, python_gdbarch, type_name, block, 0); } - if (except.reason < 0) - { - gdbpy_convert_exception (except); - return NULL; - } + GDB_PY_HANDLE_EXCEPTION (except); return type; } @@ -785,11 +775,7 @@ typy_lookup_type (struct demangle_component *demangled, break; } } - if (except.reason < 0) - { - gdbpy_convert_exception (except); - return NULL; - } + GDB_PY_HANDLE_EXCEPTION (except); } /* If we have a type from the switch statement above, just return diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index b280c8c..4cd35a0 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -272,9 +272,9 @@ gdbpy_exception_to_string (PyObject *ptype, PyObject *pvalue) /* Convert a GDB exception to the appropriate Python exception. - This sets the Python error indicator, and returns NULL. */ + This sets the Python error indicator. */ -PyObject * +void gdbpy_convert_exception (struct gdb_exception exception) { PyObject *exc_class; @@ -286,7 +286,7 @@ gdbpy_convert_exception (struct gdb_exception exception) else exc_class = gdbpy_gdb_error; - return PyErr_Format (exc_class, "%s", exception.message); + PyErr_Format (exc_class, "%s", exception.message); } /* Converts OBJ to a CORE_ADDR value. diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 8eb1774..57fcc74 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -41,6 +41,12 @@ #define CPYCHECKER_STEALS_REFERENCE_TO_ARG(n) #endif +#ifdef WITH_CPYCHECKER_SETS_EXCEPTION_ATTRIBUTE +#define CPYCHECKER_SETS_EXCEPTION __attribute__ ((cpychecker_sets_exception)) +#else +#define CPYCHECKER_SETS_EXCEPTION +#endif + #include /* Python 2.4 doesn't include stdint.h soon enough to get {u,}intptr_t @@ -343,11 +349,14 @@ extern const struct language_defn *python_language; /* Use this after a TRY_EXCEPT to throw the appropriate Python exception. */ -#define GDB_PY_HANDLE_EXCEPTION(Exception) \ - do { \ - if (Exception.reason < 0) \ - return gdbpy_convert_exception (Exception); \ - } while (0) +#define GDB_PY_HANDLE_EXCEPTION(Exception) \ + do { \ + if (Exception.reason < 0) \ + { \ + gdbpy_convert_exception (Exception); \ + return NULL; \ + } \ + } while (0) /* Use this after a TRY_EXCEPT to throw the appropriate Python exception. This macro is for use inside setter functions. */ @@ -405,7 +414,8 @@ extern PyObject *gdbpy_gdb_error; extern PyObject *gdbpy_gdb_memory_error; extern PyObject *gdbpy_gdberror_exc; -extern PyObject *gdbpy_convert_exception (struct gdb_exception); +extern void gdbpy_convert_exception (struct gdb_exception) + CPYCHECKER_SETS_EXCEPTION; int get_addr_from_python (PyObject *obj, CORE_ADDR *addr); -- 1.8.1.4 Tom