Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 23/28] use explicit decrefs rather than cleanups in some cases
Date: Fri, 19 Apr 2013 17:15:00 -0000	[thread overview]
Message-ID: <87a9ouy447.fsf@fleche.redhat.com> (raw)
In-Reply-To: <87ehe638ww.fsf@fleche.redhat.com> (Tom Tromey's message of "Fri,	19 Apr 2013 08:13:51 -0600")

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



  parent reply	other threads:[~2013-04-19 14:41 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-19 14:32 [0/27] RFC: fix reports from the CPython checker Tom Tromey
2013-04-19 14:32 ` Eli Zaretskii
2013-04-19 18:08   ` Tom Tromey
2013-04-19 14:34 ` Tom Tromey
2013-04-19 14:36 ` [PATCH 01/28] introduce CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF and use it Tom Tromey
2013-05-15 15:57   ` Pedro Alves
2013-05-20 20:08     ` Tom Tromey
2013-05-21  0:20       ` Pedro Alves
2013-04-19 14:36 ` [0/27] RFC: fix reports from the CPython checker Tom Tromey
2013-04-19 14:36 ` [PATCH 03/28] PyObject_GetAttrString returns a new ref Tom Tromey
2013-04-19 14:37 ` [PATCH 04/28] add missing decref in before_prompt_hook Tom Tromey
2013-04-19 14:38 ` [PATCH 06/28] fix py-evtregistry.c refcount bug Tom Tromey
2013-04-23  0:23   ` Tom Tromey
2013-04-19 14:38 ` [PATCH 05/28] py-cmd.c error-checking bug fix Tom Tromey
2013-05-15 16:01   ` Pedro Alves
2013-05-15 16:20     ` Tom Tromey
2013-05-15 16:29       ` Pedro Alves
2013-04-19 14:39 ` [PATCH 07/28] remove unused declaration Tom Tromey
2013-04-19 14:40 ` [PATCH 08/28] use CPYCHECKER_SETS_EXCEPTION Tom Tromey
2013-04-19 14:41 ` [PATCH 09/28] introduce and use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION Tom Tromey
2013-04-19 14:41 ` [PATCH 11/28] use iterator protocol and avoid refcount bugs Tom Tromey
2013-04-19 14:41 ` [PATCH 10/28] add decref to cmdpy_init Tom Tromey
2013-04-19 14:42 ` [PATCH 12/28] add decref in evpy_emit_event Tom Tromey
2013-04-19 14:43 ` [PATCH 14/28] add gdb_assert_not_reached Tom Tromey
2013-04-19 14:43 ` [PATCH 13/28] fix get_addr_from_python Tom Tromey
2013-04-19 14:43 ` [PATCH 15/28] fix bug in gdbpy_initialize_event_generic Tom Tromey
2013-04-19 14:44 ` [PATCH 16/28] reference count in bpfinishpy_out_of_scope Tom Tromey
2013-04-19 14:47 ` [PATCH 17/28] convert python init functions to do error-checking Tom Tromey
2013-04-19 15:40 ` [PATCH 18/28] check gdb_python_initialized everywhere Tom Tromey
2013-04-23  1:09   ` Tom Tromey
2013-05-07 17:57     ` Doug Evans
2013-05-07 18:06       ` Tom Tromey
2013-05-07 18:06       ` Doug Evans
2013-05-07 18:13         ` Tom Tromey
2013-05-15 16:43         ` Pedro Alves
2013-05-15 17:39           ` Remove my name from a couple tests (Re: [PATCH 18/28] check gdb_python_initialized everywhere) Pedro Alves
2013-05-21  8:22     ` new FAIL python-selftest.exp in gdbserver mode [Re: [PATCH 18/28] check gdb_python_initialized everywhere] Jan Kratochvil
2013-06-17 16:59       ` RFC: fix python-selftest.exp failure (Was: new FAIL python-selftest.exp in gdbserver mode [Re: [PATCH 18/28] check gdb_python_initialized everywhere]) Tom Tromey
2013-06-17 17:10         ` Jan Kratochvil
2013-06-18 14:25           ` RFC: fix python-selftest.exp failure Tom Tromey
2013-04-19 16:20 ` [PATCH 19/28] add missing decref in py-param.c Tom Tromey
2013-04-19 16:34 ` [PATCH 20/28] make set_sal follow negative result convention Tom Tromey
2013-04-19 16:44 ` [PATCH 21/28] fix refcounting in gdbpy_run_events Tom Tromey
2013-04-19 16:55 ` [PATCH 22/28] remove erroneous incref from gdbpy_initialize_py_events Tom Tromey
2013-04-19 17:15 ` Tom Tromey [this message]
2013-04-19 17:46 ` [PATCH 24/28] introduce gdb_pymodule_addobject Tom Tromey
2013-05-21  7:58   ` [patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject] Jan Kratochvil
2013-05-21 13:30     ` Tom Tromey
2013-05-21 15:02       ` [commit] " Jan Kratochvil
2013-05-21 16:05     ` Pedro Alves
2013-05-21 16:14       ` Jan Kratochvil
2013-05-21 16:24         ` Pedro Alves
2013-05-21 16:36           ` Tom Tromey
2013-05-21 16:48             ` Pedro Alves
2013-05-21 17:32               ` Tom Tromey
2013-05-21 20:56                 ` [COMMIT] py_decref: Don't check for NULL before calling Py_DECREF. (was: Re: [patch] Compilation regression with python-2.6) Pedro Alves
2013-05-21 20:55           ` [COMMIT] Centralize workaround for Python 2.6's Py_DECREF. (Re: " Pedro Alves
2013-06-03 12:50   ` Python 2.4 compile failure (Re: [PATCH 24/28] introduce gdb_pymodule_addobject) Ulrich Weigand
2013-06-03 16:06     ` Tom Tromey
2013-06-03 16:54       ` Ulrich Weigand
2013-06-05 17:31       ` Tom Tromey
2013-04-19 17:49 ` [PATCH 25/28] some py-frame.c changes to make the checker work better Tom Tromey
2013-04-19 17:50 ` [PATCH 26/28] fix refcount bug in typy_fields Tom Tromey
2013-04-19 17:52 ` [PATCH 27/28] rearrange for some clarity in valpy_get_dynamic_type Tom Tromey
2013-04-19 17:59 ` [PATCH 28/28] fix refcount bug in search_pp_list Tom Tromey
2013-05-20 20:06 ` [0/27] RFC: fix reports from the CPython checker Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a9ouy447.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox