[patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject]

Jan Kratochvil
2013-05-21T07:58:12Z

On Fri, 19 Apr 2013 16:42:12 +0200, Tom Tromey wrote:
> --- a/gdb/python/py-utils.c
> +++ b/gdb/python/py-utils.c
[...]
> +int
> +gdb_pymodule_addobject (PyObject *module, const char *name, PyObject *object)
> +{
> + int result;
> +
> + Py_INCREF (object);
> + result = PyModule_AddObject (module, name, object);
> + if (result < 0)
> + Py_DECREF (object);
> + return result;
> +}

commit 62234c99e3a311c07838ebaea38198d7f4239d0c
Author: Tom Tromey <tromey@redhat.com>
Date: Mon May 20 20:36:18 2013 +0000

CentOS-6.4 x86_64

./python/py-utils.c: In function ‘gdb_pymodule_addobject’:
./python/py-utils.c:445: error: suggest explicit braces to avoid ambiguous ‘else’

python-devel-2.7.3-13.fc18.x86_64
/usr/include/python2.7/object.h
#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)

python-devel-2.6.6-36.el6.x86_64
/usr/include/python2.6/object.h
#define Py_DECREF(op) \
if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
--((PyObject*)(op))->ob_refcnt != 0) \
_Py_CHECK_REFCNT(op) \
else \
_Py_Dealloc((PyObject *)(op))

I will check it in today.

Regards,
Jan

gdb/
2013-05-21 Jan Kratochvil <jan.kratochvil@redhat.com>

Workaround Python 2.6.
* python/py-utils.c (gdb_pymodule_addobject): Wrap Py_DECREF into
a block.

diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index d87eb8c..23fcf3f 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -443,6 +443,9 @@ gdb_pymodule_addobject (PyObject *module, const char *name, PyObject *object)
Py_INCREF (object);
result = PyModule_AddObject (module, name, object);
if (result < 0)
- Py_DECREF (object);
+ {
+ /* Python 2.6 did not wrap Py_DECREF in do { } while (0);. */
+ Py_DECREF (object);
+ }
return result;
}