This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[COMMIT] py_decref: Don't check for NULL before calling Py_DECREF. (was: Re: [patch] Compilation regression with python-2.6)
- From: Pedro Alves <palves at redhat dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: Jan Kratochvil <jan dot kratochvil at redhat dot com>, gdb-patches at sourceware dot org
- Date: Tue, 21 May 2013 21:56:24 +0100
- Subject: [COMMIT] py_decref: Don't check for NULL before calling Py_DECREF. (was: Re: [patch] Compilation regression with python-2.6)
- 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> <519B9F9A dot 9070600 at redhat dot com> <877gisl275 dot fsf at fleche dot redhat dot com> <519BA558 dot 4030100 at redhat dot com> <87txlwjl1p dot fsf at fleche dot redhat dot com>
On 05/21/2013 06:32 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>
> Pedro> If you think this is not good, then I'll just file a PR.
>
> It is totally fine. Please check it in.
Thanks. Done.
---------
Subject: py_decref: Don't check for NULL before calling Py_DECREF.
The only difference between Py_DECREF and Py_XDECREF is that the latter allows passing
in a NULL object, while the former prohibits it. Given that, it's natural to expect
the same from py_decref vs py_xdecref.
gdb/
2013-05-21 Pedro Alves <palves@redhat.com>
* python/py-prettyprint.c (apply_val_pretty_printer): Check
whether PRINTER is NULL before installing a Py_DECREF cleanup.
* python/py-utils.c (py_decref): Don't check for NULL before
calling Py_DECREF.
---
gdb/python/py-prettyprint.c | 6 +++++-
gdb/python/py-utils.c | 3 +--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index 8c45cd6..8fa2f42 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -735,8 +735,12 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
/* Find the constructor. */
printer = find_pretty_printer (val_obj);
Py_DECREF (val_obj);
+
+ if (printer == NULL)
+ goto done;
+
make_cleanup_py_decref (printer);
- if (! printer || printer == Py_None)
+ if (printer == Py_None)
goto done;
/* If we are printing a map, we want some special formatting. */
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index 80bacf7..7c7c5ca 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -31,8 +31,7 @@ py_decref (void *p)
{
PyObject *py = p;
- if (py)
- Py_DECREF (py);
+ Py_DECREF (py);
}
/* Return a new cleanup which will decrement the Python object's