Fix build breakage with Python 2.4.
authorPedro Alves <palves@redhat.com>
Thu, 30 May 2013 08:56:56 +0000 (08:56 +0000)
committerPedro Alves <palves@redhat.com>
Thu, 30 May 2013 08:56:56 +0000 (08:56 +0000)
With Python 2.4, we see this build failure:

./python/python-internal.h: In function 'gdb_Py_DECREF':
./python/python-internal.h:179: warning: dereferencing 'void *' pointer
./python/python-internal.h:179: error: request for member 'ob_refcnt' in something not a structure or union

Python 2.4 forgets to cast 'op' to PyObject pointer on the ob_refcnt
accesses:

  #define Py_DECREF(op)                                   \
          if (_Py_DEC_REFTOTAL  _Py_REF_DEBUG_COMMA       \
              --(op)->ob_refcnt != 0)                     \
                  _Py_CHECK_REFCNT(op)                    \
          else                                            \
                  _Py_Dealloc((PyObject *)(op))

...

  #define _Py_CHECK_REFCNT(OP)                                    \
  {       if ((OP)->ob_refcnt < 0)                                \
                  _Py_NegativeRefcount(__FILE__, __LINE__,        \
                                       (PyObject *)(OP));         \
  }

Python 2.7:

  #define Py_DECREF(op)                                   \
      do {                                                \
          if (_Py_DEC_REFTOTAL  _Py_REF_DEBUG_COMMA       \
          --((PyObject*)(op))->ob_refcnt != 0)            \
              _Py_CHECK_REFCNT(op)                        \
          else                                            \
          _Py_Dealloc((PyObject *)(op));                  \
      } while (0)

...

  #define _Py_CHECK_REFCNT(OP)                                    \
  {       if (((PyObject*)OP)->ob_refcnt < 0)                             \
                  _Py_NegativeRefcount(__FILE__, __LINE__,        \
                                       (PyObject *)(OP));         \
  }

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

* python/python-internal.h (gdb_Py_DECREF): Cast OP to PyObject
pointer.

gdb/ChangeLog
gdb/python/python-internal.h

index 7c00a8e23a3a62a3359b3e03bc152e0028590e88..76e0d60d56c78743f6a0ff32dfdc6ca54a568d9d 100644 (file)
@@ -1,3 +1,8 @@
+2013-05-30  Pedro Alves  <palves@redhat.com>
+
+       * python/python-internal.h (gdb_Py_DECREF): Cast OP to PyObject
+       pointer.
+
 2013-05-30  Yao Qi  <yao@codesourcery.com>
 
        * remote.c (remote_check_symbols): Remove unused parameter
index f47d48a4195c3d1a2c7c9d43a9c3519b4b8027d6..d947be64b42d00e37f2350428177d36d508ade43 100644 (file)
@@ -176,7 +176,10 @@ typedef unsigned long gdb_py_ulongest;
 static inline void
 gdb_Py_DECREF (void *op) /* ARI: editCase function */
 {
-  Py_DECREF (op);
+  /* ... and Python 2.4 didn't cast OP to PyObject pointer on the
+     '(op)->ob_refcnt' references within the macro.  Cast it ourselves
+     too.  */
+  Py_DECREF ((PyObject *) op);
 }
 
 #undef Py_DECREF