* python/py-cmd.c (cmdpy_completer): Use explicit decref.
authorTom Tromey <tromey@redhat.com>
Mon, 20 May 2013 20:34:49 +0000 (20:34 +0000)
committerTom Tromey <tromey@redhat.com>
Mon, 20 May 2013 20:34:49 +0000 (20:34 +0000)
* 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/ChangeLog
gdb/python/py-cmd.c
gdb/python/py-param.c
gdb/python/python.c

index ed139fde35f253b7150a0b4b94f85d10c19c8268..d7471f6327a7d5b566a501bb9406cb0ff6db9484 100644 (file)
@@ -1,3 +1,11 @@
+2013-05-20  Tom Tromey  <tromey@redhat.com>
+
+       * 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.
+
 2013-05-20  Tom Tromey  <tromey@redhat.com>
 
        * python/py-evts.c (gdbpy_initialize_py_events): Don't
index ba765e098a738184740f0fa2972edc106d363494..22eff253b76e5a0537b54d672c285dfceef5e06f 100644 (file)
@@ -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;
index fbd9a7706f4882a8adc2c5e9ecb303bc45c9c128..a81ab66127d3b53df7c81fd94eb1f8d13bd24a59 100644 (file)
@@ -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;
index 605efc04ae9c7b5e3136d0bbc7622d2f0391616c..d8b0de639a0ffe510ddd7cc98bb3827688328ee2 100644 (file)
@@ -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;
 }