From: Tom de Vries <tdevries@suse.de>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 0/2] [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE}
Date: Wed, 13 May 2026 18:42:10 +0200 [thread overview]
Message-ID: <792efae2-943f-4c03-8477-a899b69f70ab@suse.de> (raw)
In-Reply-To: <8733zvmksq.fsf@tromey.com>
On 5/13/26 4:44 PM, Tom Tromey wrote:
> Tom> The only point of it seems to be to increase the reference count on the
> Tom> Py_None object for older python versions.
>
> Tom> ISTM unnecessary to increase the reference count for each Py_RETURN_NONE use.
>
> I mentioned this in the bug, but for the record on the list, I think
> this patch will not work for versions of Python before the immortality
> changes.
>
Hi Tom,
thank you for review comments.
I can confirm that this is the case. I ran into a test failures with
python 3.6, and managed to fix some of them by making gdbpy_ref aware of
None/True/False:
...
diff --git a/gdb/python/py-ref.h b/gdb/python/py-ref.h
index dc0b14814af..b2eb2811408 100644
--- a/gdb/python/py-ref.h
+++ b/gdb/python/py-ref.h
@@ -27,11 +27,19 @@ struct gdbpy_ref_policy
{
static void incref (PyObject *ptr)
{
+ if (ptr == Py_None
+ || ptr == Py_True
+ || ptr == Py_False)
+ return;
Py_INCREF (ptr);
}
static void decref (PyObject *ptr)
{
+ if (ptr == Py_None
+ || ptr == Py_True
+ || ptr == Py_False)
+ return;
Py_DECREF (ptr);
}
};
...
but a few test-cases still failed, AFAIU because of using Py_DECREF on
None/True/False.
I could have tried to fix this by replacing Py_DECREF et al by
gdb-specific overrides that handle None/True/False in the appropriate
way, but that would be way beyond the scope of what I was trying to achieve.
So instead, I've written a v2 that wraps Py_RETURN_{NONE,FALSE,TRUE} in
functions that return gdbpy_ref, and used those instead (
https://sourceware.org/pipermail/gdb-patches/2026-May/227374.html ).
Please let me know what you think about this approach.
Thanks,
- Tom
> In particular if a gdb method returns a new reference, it means the
> caller is free to decref the reference. However this series changes gdb
> to assume that the decref will not happen for certain objects.
>
> thanks,
> Tom
prev parent reply other threads:[~2026-05-13 16:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 16:34 Tom de Vries
2026-05-12 16:34 ` [PATCH 1/2] [gdb/python] Add init_py_immortals Tom de Vries
2026-05-12 16:34 ` [PATCH 2/2] [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE} Tom de Vries
2026-05-13 14:44 ` [PATCH 0/2] " Tom Tromey
2026-05-13 16:42 ` Tom de Vries [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=792efae2-943f-4c03-8477-a899b69f70ab@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox