Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Vrany <jan.vrany@labware.com>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@labware.com>
Subject: [RFC 9/9] gdb/python: convert gdb.Symtab_and_line to use gdbpy_registry
Date: Mon, 27 Jan 2025 10:44:35 +0000	[thread overview]
Message-ID: <20250127104435.823519-10-jan.vrany@labware.com> (raw)
In-Reply-To: <20250127104435.823519-1-jan.vrany@labware.com>

This commit converts gdb.Symtab_and_line to use gdbpy_registry for
lifecycle management.
---
 gdb/python/py-symtab.c | 47 ++++++++++--------------------------------
 1 file changed, 11 insertions(+), 36 deletions(-)

diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index 417ad68a155..8749380ed2c 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -65,30 +65,19 @@ struct sal_object {
    data.  All access to obj->sal should be gated by
    SALPY_REQUIRE_VALID which will raise an exception on invalid symbol
    table and line objects.  */
-struct salpy_deleter
+struct salpy_invalidator
 {
   void operator() (sal_object *obj)
   {
-    gdbpy_enter enter_py;
-
-    while (obj)
-      {
-	sal_object *next = obj->next;
-
-	obj->next = nullptr;
-	obj->prev = nullptr;
-	xfree (obj->sal);
-	obj->sal = nullptr;
-
-	obj = next;
-      }
+    xfree (obj->sal);
+    obj->sal = nullptr;
   }
 };
 
 extern PyTypeObject sal_object_type
     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("sal_object");
-static const registry<objfile>::key<sal_object, salpy_deleter>
-     salpy_objfile_data_key;
+static const gdbpy_registry<gdbpy_tracking_registry_storage<sal_object, symtab_and_line, &sal_object::sal, salpy_invalidator>>
+     salpy_registry;
 
 /* Require a valid symbol table and line object.  All access to
    sal_object->sal should be gated by this call.  */
@@ -322,15 +311,9 @@ salpy_dealloc (PyObject *self)
 {
   sal_object *self_sal = (sal_object *) self;
 
-  if (self_sal->prev)
-    self_sal->prev->next = self_sal->next;
-  else if (self_sal->sal != nullptr && self_sal->sal->symtab != nullptr)
-    salpy_objfile_data_key.set
-      (self_sal->sal->symtab->compunit ()->objfile (),
-       self_sal->next);
-
-  if (self_sal->next)
-    self_sal->next->prev = self_sal->prev;
+  if (self_sal->sal != nullptr && self_sal->sal->symtab != nullptr)
+    salpy_registry.remove (self_sal->sal->symtab->compunit ()->objfile (),
+			   self_sal);
 
   xfree (self_sal->sal);
   Py_TYPE (self)->tp_free (self);
@@ -347,22 +330,14 @@ set_sal (sal_object *sal_obj, struct symtab_and_line sal)
   sal_obj->sal = ((struct symtab_and_line *)
 		  xmemdup (&sal, sizeof (struct symtab_and_line),
 			   sizeof (struct symtab_and_line)));
-  sal_obj->prev = NULL;
+  sal_obj->prev = nullptr;
+  sal_obj->next = nullptr;
 
   /* If the SAL does not have a symtab, we do not add it to the
      objfile cleanup observer linked list.  */
   symtab *symtab = sal_obj->sal->symtab;
   if (symtab != nullptr)
-    {
-      sal_obj->next
-	= salpy_objfile_data_key.get (symtab->compunit ()->objfile ());
-      if (sal_obj->next)
-	sal_obj->next->prev = sal_obj;
-
-      salpy_objfile_data_key.set (symtab->compunit ()->objfile (), sal_obj);
-    }
-  else
-    sal_obj->next = NULL;
+    salpy_registry.add (symtab->compunit ()->objfile (), sal_obj);
 }
 
 /* Given a symtab, and a symtab_object that has previously been
-- 
2.45.2


  parent reply	other threads:[~2025-01-27 10:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-27 10:44 [RFC 0/9] Attempt to unify Python object's lifecycle Jan Vrany
2025-01-27 10:44 ` [RFC 1/9] gdb/python: preserve identity for gdb.Symtab objects Jan Vrany
2025-01-27 10:44 ` [RFC 2/9] gdb/python: preserve identity for gdb.Symbol objects Jan Vrany
2025-02-20 19:22   ` Tom Tromey
2025-01-27 10:44 ` [RFC 3/9] gdb/python: do not hold on gdb.Symtab object from gdb.Symtab_and_line Jan Vrany
2025-01-27 10:44 ` [RFC 4/9] gdb/python: preserve identity for gdb.Type objects Jan Vrany
2025-01-27 10:44 ` [RFC 5/9] gdb/python: introduce gdbpy_registry Jan Vrany
2025-02-20 19:28   ` Tom Tromey
2025-01-27 10:44 ` [RFC 6/9] gdb/python: convert gdb.Symbol to use gdbpy_registry Jan Vrany
2025-01-27 10:44 ` [RFC 7/9] gdb/python: convert gdb.Type " Jan Vrany
2025-01-27 10:44 ` [RFC 8/9] gdb/python: convert gdb.Symtab " Jan Vrany
2025-01-27 10:44 ` Jan Vrany [this message]
2025-02-18 11:15 ` [PING] Re: [RFC 0/9] Attempt to unify Python object's lifecycle Jan Vraný
2025-02-19 21:00 ` Simon Marchi
2025-02-20 17:50   ` Jan Vraný
2025-02-20 19:18 ` Tom Tromey

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=20250127104435.823519-10-jan.vrany@labware.com \
    --to=jan.vrany@labware.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