Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 08/10] Return gdbpy_ref<> from symtab_to_linetable_object
Date: Fri, 20 Feb 2026 14:03:54 -0700	[thread overview]
Message-ID: <20260220-python-safety-minor-v1-8-4c4b12e445af@adacore.com> (raw)
In-Reply-To: <20260220-python-safety-minor-v1-0-4c4b12e445af@adacore.com>

This changes symtab_to_linetable_object to return a gdbpy_ref<>,
using the type system to convey that a new reference is always
returned.
---
 gdb/python/py-linetable.c    | 4 ++--
 gdb/python/py-symtab.c       | 2 +-
 gdb/python/python-internal.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c
index 384ced68a32..2afa9b033e7 100644
--- a/gdb/python/py-linetable.c
+++ b/gdb/python/py-linetable.c
@@ -77,7 +77,7 @@ get_symtab (PyObject *linetable)
 /* Helper function to create a line table object that wraps a
    gdb.Symtab object.  */
 
-PyObject *
+gdbpy_ref<>
 symtab_to_linetable_object (PyObject *symtab)
 {
   linetable_object *ltable;
@@ -88,7 +88,7 @@ symtab_to_linetable_object (PyObject *symtab)
       ltable->symtab = symtab;
       Py_INCREF (symtab);
     }
-  return (PyObject *) ltable;
+  return gdbpy_ref<> (ltable);
 }
 
 /* Internal helper function to build a line table object from a line
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index 550f287a6ee..ed5abac1372 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -220,7 +220,7 @@ stpy_get_linetable (PyObject *self, PyObject *args)
 
   STPY_REQUIRE_VALID (self, symtab);
 
-  return symtab_to_linetable_object (self);
+  return symtab_to_linetable_object (self).release ();
 }
 
 static PyObject *
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 0b816db196f..85f7f1f4dd1 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -503,7 +503,7 @@ gdbpy_ref<> block_to_block_object (const struct block *block,
 gdbpy_ref<> value_to_value_object (struct value *v);
 gdbpy_ref<> type_to_type_object (struct type *);
 gdbpy_ref<> frame_info_to_frame_object (const frame_info_ptr &frame);
-PyObject *symtab_to_linetable_object (PyObject *symtab);
+gdbpy_ref<> symtab_to_linetable_object (PyObject *symtab);
 gdbpy_ref<> pspace_to_pspace_object (struct program_space *);
 PyObject *pspy_get_printers (PyObject *, void *);
 PyObject *pspy_get_frame_filters (PyObject *, void *);

-- 
2.53.0


  parent reply	other threads:[~2026-02-20 21:09 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
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 ` Tom Tromey [this message]
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=20260220-python-safety-minor-v1-8-4c4b12e445af@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /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