This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject]
- From: Pedro Alves <palves at redhat dot com>
- To: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- Cc: Tom Tromey <tromey at redhat dot com>, gdb-patches at sourceware dot org
- Date: Tue, 21 May 2013 17:23:54 +0100
- Subject: Re: [patch] Compilation regression with python-2.6 [Re: [PATCH 24/28] introduce gdb_pymodule_addobject]
- References: <87ehe638ww dot fsf at fleche dot redhat dot com> <8761ziy43f dot fsf at fleche dot redhat dot com> <20130521075803 dot GA404 at host2 dot jankratochvil dot net> <519B9B54 dot 9090907 at redhat dot com> <20130521161400 dot GA2763 at host2 dot jankratochvil dot net>
On 05/21/2013 05:14 PM, Jan Kratochvil wrote:
> On Tue, 21 May 2013 18:05:40 +0200, Pedro Alves wrote:
>> How about we handle this in a central place with something like:
>
> Fine with me although there is also Py_INCREF and not sure if also others.
Yeah. I guess we can handle those on an as needed basis.
Here's a complete patch, with ChangeLog.
I notice that py_decref could actually be using Py_XDECREF instead
of doing the explicit 'if (py)' check.
----
Subject: 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.
---
gdb/python/py-utils.c | 11 ++---------
gdb/python/python-internal.h | 12 ++++++++++++
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index e78dee0..80bacf7 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -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;
}
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index b01efa1..b5c34b6 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -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. */