Centralize workaround for Python 2.6's Py_DECREF.
authorPedro Alves <palves@redhat.com>
Tue, 21 May 2013 20:52:30 +0000 (20:52 +0000)
committerPedro Alves <palves@redhat.com>
Tue, 21 May 2013 20:52:30 +0000 (20:52 +0000)
Wrap/redefine Py_DECREF ourselves, avoiding the need for uses to care
about extra braces due to the fact that Python only started wrapping Py_DECREF
in 'do {} while (0)' after 2.6.

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

* python/py-utils.c (py_decref): Remove extra braces.
(gdb_pymodule_addobject): Remove extra braces.
* python-internal.h (gdb_Py_DECREF): New static inline function.
(Py_DECREF): Redefine as calling gdb_Py_DECREF.

gdb/ChangeLog
gdb/python/py-utils.c
gdb/python/python-internal.h

index c0ea04d14f8593da1e36c7f8dd9148284b7dce43..32c5558dc887e686bbd8b46a97ad77b6a95a27d3 100644 (file)
@@ -1,3 +1,10 @@
+2013-05-21  Pedro Alves  <palves@redhat.com>
+
+       * python/py-utils.c (py_decref): Remove extra braces.
+       (gdb_pymodule_addobject): Remove extra braces.
+       * python-internal.h (gdb_Py_DECREF): New static inline function.
+       (Py_DECREF): Redefine as calling gdb_Py_DECREF.
+
 2013-05-21  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
 
        * breakpoints.c (detach_breakpoints): Do not
index e78dee0b9f7b4cffb924c744b0d0b6bcba4146e6..80bacf766269264d56bd48b1ea412835d752e593 100644 (file)
@@ -31,12 +31,8 @@ py_decref (void *p)
 {
   PyObject *py = p;
 
-  /* Note that we need the extra braces in this 'if' to avoid a
-     warning from gcc.  */
   if (py)
-    {
-      Py_DECREF (py);
-    }
+    Py_DECREF (py);
 }
 
 /* Return a new cleanup which will decrement the Python object's
@@ -443,9 +439,6 @@ gdb_pymodule_addobject (PyObject *module, const char *name, PyObject *object)
   Py_INCREF (object);
   result = PyModule_AddObject (module, name, object);
   if (result < 0)
-    {
-      /* Python 2.6 did not wrap Py_DECREF in do { } while (0);.  */
-      Py_DECREF (object);
-    }
+    Py_DECREF (object);
   return result;
 }
index b01efa16e9d7cd2170295159ed02227cd266b71d..b5c34b62dd657b3f132a16ff7133a668471cb16a 100644 (file)
@@ -169,6 +169,18 @@ typedef unsigned long gdb_py_ulongest;
 
 #endif /* HAVE_LONG_LONG */
 
+/* Python 2.6 did not wrap Py_DECREF in 'do {...} while (0)', leading
+   to 'suggest explicit braces to avoid ambiguous ‘else’' gcc errors.
+   Wrap it ourselves, so that callers don't need to care.  */
+
+static inline void
+gdb_Py_DECREF (void *op)
+{
+  Py_DECREF (op);
+}
+
+#undef Py_DECREF
+#define Py_DECREF(op) gdb_Py_DECREF (op)
 
 /* In order to be able to parse symtab_and_line_to_sal_object function 
    a real symtab_and_line structure is needed.  */
This page took 0.043888 seconds and 4 git commands to generate.