From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 02/10] Return gdbpy_ref<> from symbol_to_symbol_object
Date: Fri, 20 Feb 2026 21:28:38 -0500 [thread overview]
Message-ID: <b3961aea-f4b3-4f71-8ac4-5b6d448a2be8@simark.ca> (raw)
In-Reply-To: <20260220-python-safety-minor-v1-2-4c4b12e445af@adacore.com>
On 2026-02-20 16:03, Tom Tromey wrote:
> @@ -622,9 +614,10 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
>
> if (symbol != nullptr)
> {
> - PyObject *sym_obj = symbol_to_symbol_object (symbol);
> + gdbpy_ref<> sym_obj = symbol_to_symbol_object (symbol);
> if (sym_obj == nullptr
> - || PyList_Append (return_list.get (), sym_obj) == -1)
> + || PyList_Append (return_list.get (),
> + sym_obj.get ()) == -1)
I asked Claude to review your comments, and it said:
Bonus finding: The gdbpy_lookup_static_symbols function in
py-symbol.c had a pre-existing reference leak — the old code passed
the raw PyObject * from symbol_to_symbol_object directly to
PyList_Append (which does its own incref) without decrementing. The
new code stores it in a gdbpy_ref<> and passes .get(), fixing the
leak.
It seems true. It's really hard to remember which functions steal
references and which functions get their own new reference. Good job on
your part to call .get() here and not .release(). I wish we had a C++
layer around the Python API to make that clear through the type
system...
Simon
next prev parent reply other threads:[~2026-02-21 2:29 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-20 21:03 [PATCH 00/10] Mildly better refcount safety for Python Tom Tromey
2026-02-20 21:03 ` [PATCH 01/10] Return gdbpy_ref<> from symtab_and_line_to_sal_object Tom Tromey
2026-02-21 1:58 ` Simon Marchi
2026-02-21 2:13 ` Simon Marchi
2026-02-21 22:33 ` Tom Tromey
2026-02-23 12:28 ` Tom Tromey
2026-02-20 21:03 ` [PATCH 02/10] Return gdbpy_ref<> from symbol_to_symbol_object Tom Tromey
2026-02-21 2:28 ` Simon Marchi [this message]
2026-02-21 22:35 ` Tom Tromey
2026-02-20 21:03 ` [PATCH 03/10] Return gdbpy_ref<> from symtab_to_symtab_object Tom Tromey
2026-02-20 21:03 ` [PATCH 04/10] Return gdbpy_ref<> from block_to_block_object Tom Tromey
2026-02-20 21:03 ` [PATCH 05/10] Return gdbpy_ref<> from value_to_value_object Tom Tromey
2026-02-20 21:03 ` [PATCH 06/10] Return gdbpy_ref<> from type_to_type_object Tom Tromey
2026-02-20 21:03 ` [PATCH 07/10] Return gdbpy_ref<> from frame_info_to_frame_object Tom Tromey
2026-02-20 21:03 ` [PATCH 08/10] Return gdbpy_ref<> from symtab_to_linetable_object Tom Tromey
2026-02-20 21:03 ` [PATCH 09/10] Return gdbpy_ref<> from gdbarch_to_arch_object Tom Tromey
2026-02-20 21:03 ` [PATCH 10/10] Return gdbpy_ref<> from gdbpy_registry::lookup Tom Tromey
2026-02-21 2:31 ` [PATCH 00/10] Mildly better refcount safety for Python Simon Marchi
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=b3961aea-f4b3-4f71-8ac4-5b6d448a2be8@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=tromey@adacore.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