Centralize workaround for Python 2.6's Py_DECREF.

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.
This commit is contained in:
Pedro Alves
2013-05-21 20:52:30 +00:00
parent 52c935b6f5
commit 1915daebe6
3 changed files with 21 additions and 9 deletions

View 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;
}