py_decref: Don't check for NULL before calling Py_DECREF.
authorPedro Alves <palves@redhat.com>
Tue, 21 May 2013 20:53:21 +0000 (20:53 +0000)
committerPedro Alves <palves@redhat.com>
Tue, 21 May 2013 20:53:21 +0000 (20:53 +0000)
The only difference between Py_DECREF and Py_XDECREF is that the latter allows passing
in a NULL object, while the former prohibits it.  Given that, it's natural to expect
the same from py_decref vs py_xdecref.

gdb/
2013-05-21  Pedro Alves  <palves@redhat.com>

* python/py-prettyprint.c (apply_val_pretty_printer): Check
whether PRINTER is NULL before installing a Py_DECREF cleanup.
* python/py-utils.c (py_decref): Don't check for NULL before
calling Py_DECREF.

gdb/ChangeLog
gdb/python/py-prettyprint.c
gdb/python/py-utils.c

index 32c5558dc887e686bbd8b46a97ad77b6a95a27d3..24e5eb4f9221059acfb99fb5666d1af4273e4073 100644 (file)
@@ -1,3 +1,10 @@
+2013-05-21  Pedro Alves  <palves@redhat.com>
+
+       * python/py-prettyprint.c (apply_val_pretty_printer): Check
+       whether PRINTER is NULL before installing a Py_DECREF cleanup.
+       * python/py-utils.c (py_decref): Don't check for NULL before
+       calling Py_DECREF.
+
 2013-05-21  Pedro Alves  <palves@redhat.com>
 
        * python/py-utils.c (py_decref): Remove extra braces.
index 8c45cd6a6fa69d6001478f729e707ce056333956..8fa2f425f786738ffff9c4ffbbb2041621648816 100644 (file)
@@ -735,8 +735,12 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
   /* Find the constructor.  */
   printer = find_pretty_printer (val_obj);
   Py_DECREF (val_obj);
+
+  if (printer == NULL)
+    goto done;
+
   make_cleanup_py_decref (printer);
-  if (! printer || printer == Py_None)
+  if (printer == Py_None)
     goto done;
 
   /* If we are printing a map, we want some special formatting.  */
index 80bacf766269264d56bd48b1ea412835d752e593..7c7c5caee9b9f807bcbcaf7b7b984bec68f2d384 100644 (file)
@@ -31,8 +31,7 @@ py_decref (void *p)
 {
   PyObject *py = p;
 
-  if (py)
-    Py_DECREF (py);
+  Py_DECREF (py);
 }
 
 /* Return a new cleanup which will decrement the Python object's