From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20260 invoked by alias); 19 Apr 2013 14:41:48 -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 20251 invoked by uid 89); 19 Apr 2013 14:41:48 -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:41:47 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3JEfk5d013754 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 19 Apr 2013 10:41:46 -0400 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3JEfifZ001303 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 19 Apr 2013 10:41:45 -0400 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 23/28] use explicit decrefs rather than cleanups in some cases References: <87ehe638ww.fsf@fleche.redhat.com> Date: Fri, 19 Apr 2013 17:15: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: <87a9ouy447.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/msg00607.txt.bz2 The checker doesn't understand cleanups, and probably never will. However, in a few places, I think we use cleanups where explicit decref calls are just as clean. So, this patch changes those spots and silences the checker. There are other spots using decref cleanups that can't readily be changed. For example, the pretty-printing code calls into parts of gdb that can throw, and so cleanups must be used. * python/py-cmd.c (cmdpy_completer): Use explicit decref. * python/py-param.c (get_set_value, get_show_value): Use explicit decrefs. * python/python.c (start_type_printers, apply_type_printers): Use explicit decrefs. --- gdb/python/py-cmd.c | 2 +- gdb/python/py-param.c | 11 +++++------ gdb/python/python.c | 17 +++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c index ba765e0..22eff25 100644 --- a/gdb/python/py-cmd.c +++ b/gdb/python/py-cmd.c @@ -244,7 +244,6 @@ cmdpy_completer (struct cmd_list_element *command, PyErr_Clear (); goto done; } - make_cleanup_py_decref (resultobj); result = NULL; if (PyInt_Check (resultobj)) @@ -300,6 +299,7 @@ cmdpy_completer (struct cmd_list_element *command, done: + Py_XDECREF (resultobj); do_cleanups (cleanup); return result; diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c index fbd9a77..a81ab66 100644 --- a/gdb/python/py-param.c +++ b/gdb/python/py-param.c @@ -374,8 +374,6 @@ get_set_value (char *args, int from_tty, if (! set_doc_func) goto error; - make_cleanup_py_decref (set_doc_func); - if (PyObject_HasAttr (obj, set_doc_func)) { set_doc_string = call_doc_function (obj, set_doc_func, NULL); @@ -393,10 +391,12 @@ get_set_value (char *args, int from_tty, make_cleanup (xfree, set_doc_string); fprintf_filtered (gdb_stdout, "%s\n", set_doc_string); + Py_XDECREF (set_doc_func); do_cleanups (cleanup); return; error: + Py_XDECREF (set_doc_func); gdbpy_print_stack (); do_cleanups (cleanup); return; @@ -422,8 +422,6 @@ get_show_value (struct ui_file *file, int from_tty, if (! show_doc_func) goto error; - make_cleanup_py_decref (show_doc_func); - if (PyObject_HasAttr (obj, show_doc_func)) { PyObject *val_obj = PyString_FromString (value); @@ -431,9 +429,8 @@ get_show_value (struct ui_file *file, int from_tty, if (! val_obj) goto error; - make_cleanup_py_decref (val_obj); - show_doc_string = call_doc_function (obj, show_doc_func, val_obj); + Py_DECREF (val_obj); if (! show_doc_string) goto error; @@ -451,10 +448,12 @@ get_show_value (struct ui_file *file, int from_tty, fprintf_filtered (file, "%s %s\n", show_doc_string, value); } + Py_XDECREF (show_doc_func); do_cleanups (cleanup); return; error: + Py_XDECREF (show_doc_func); gdbpy_print_stack (); do_cleanups (cleanup); return; diff --git a/gdb/python/python.c b/gdb/python/python.c index de21cdb..ab84bad 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1232,7 +1232,7 @@ void * start_type_printers (void) { struct cleanup *cleanups; - PyObject *type_module, *func, *result_obj = NULL; + PyObject *type_module, *func = NULL, *result_obj = NULL; if (!gdb_python_initialized) return NULL; @@ -1245,7 +1245,6 @@ start_type_printers (void) gdbpy_print_stack (); goto done; } - make_cleanup_py_decref (type_module); func = PyObject_GetAttrString (type_module, "get_type_recognizers"); if (func == NULL) @@ -1253,13 +1252,14 @@ start_type_printers (void) gdbpy_print_stack (); goto done; } - make_cleanup_py_decref (func); result_obj = PyObject_CallFunctionObjArgs (func, (char *) NULL); if (result_obj == NULL) gdbpy_print_stack (); done: + Py_XDECREF (type_module); + Py_XDECREF (func); do_cleanups (cleanups); return result_obj; } @@ -1276,7 +1276,8 @@ char * apply_type_printers (void *printers, struct type *type) { struct cleanup *cleanups; - PyObject *type_obj, *type_module, *func, *result_obj; + PyObject *type_obj, *type_module = NULL, *func = NULL; + PyObject *result_obj = NULL; PyObject *printers_obj = printers; char *result = NULL; @@ -1294,7 +1295,6 @@ apply_type_printers (void *printers, struct type *type) gdbpy_print_stack (); goto done; } - make_cleanup_py_decref (type_obj); type_module = PyImport_ImportModule ("gdb.types"); if (type_module == NULL) @@ -1302,7 +1302,6 @@ apply_type_printers (void *printers, struct type *type) gdbpy_print_stack (); goto done; } - make_cleanup_py_decref (type_module); func = PyObject_GetAttrString (type_module, "apply_type_recognizers"); if (func == NULL) @@ -1310,7 +1309,6 @@ apply_type_printers (void *printers, struct type *type) gdbpy_print_stack (); goto done; } - make_cleanup_py_decref (func); result_obj = PyObject_CallFunctionObjArgs (func, printers_obj, type_obj, (char *) NULL); @@ -1319,7 +1317,6 @@ apply_type_printers (void *printers, struct type *type) gdbpy_print_stack (); goto done; } - make_cleanup_py_decref (result_obj); if (result_obj != Py_None) { @@ -1329,6 +1326,10 @@ apply_type_printers (void *printers, struct type *type) } done: + Py_XDECREF (type_obj); + Py_XDECREF (type_module); + Py_XDECREF (func); + Py_XDECREF (result_obj); do_cleanups (cleanups); return result; } -- 1.8.1.4