Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 3/4] Use gdbpy_borrowed_ref when creating events
Date: Sat, 08 Aug 2026 15:47:27 -0600	[thread overview]
Message-ID: <20260808-python-safety-events-simple-v1-3-132aea40c801@tromey.com> (raw)
In-Reply-To: <20260808-python-safety-events-simple-v1-0-132aea40c801@tromey.com>

This changes create_thread_event_object and
create_breakpoint_event_object to accept gdbpy_borrowed_ref.  This
allows the removal of some calls to "get".
---
 gdb/python/py-bpevent.c       | 3 ++-
 gdb/python/py-continueevent.c | 2 +-
 gdb/python/py-event.h         | 2 +-
 gdb/python/py-inferior.c      | 3 +--
 gdb/python/py-stopevent.c     | 2 +-
 gdb/python/py-stopevent.h     | 7 ++++---
 gdb/python/py-threadevent.c   | 4 ++--
 7 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/gdb/python/py-bpevent.c b/gdb/python/py-bpevent.c
index 20a7745e4cc..2fcaac76c4e 100644
--- a/gdb/python/py-bpevent.c
+++ b/gdb/python/py-bpevent.c
@@ -24,7 +24,8 @@
 
 gdbpy_ref<>
 create_breakpoint_event_object (const gdbpy_ref<> &dict,
-				PyObject *breakpoint_list, PyObject *first_bp)
+				gdbpy_borrowed_ref<> breakpoint_list,
+				gdbpy_borrowed_ref<> first_bp)
 {
   gdbpy_ref<> breakpoint_event_obj
     = create_stop_event_object (&breakpoint_event_object_type, dict);
diff --git a/gdb/python/py-continueevent.c b/gdb/python/py-continueevent.c
index 06d4dabadd9..48c24cc710d 100644
--- a/gdb/python/py-continueevent.c
+++ b/gdb/python/py-continueevent.c
@@ -36,7 +36,7 @@ create_continue_event_object (ptid_t ptid)
     return nullptr;
 
   return create_thread_event_object (&continue_event_object_type,
-				     py_thr.get ());
+				     py_thr);
 }
 
 /* Callback function which notifies observers when a continue event occurs.
diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
index 2c724c9a084..100840318a5 100644
--- a/gdb/python/py-event.h
+++ b/gdb/python/py-event.h
@@ -74,7 +74,7 @@ extern gdbpy_ref<> create_event_object (PyTypeObject *py_type);
 extern gdbpy_ref<> py_get_event_thread (ptid_t ptid);
 
 extern gdbpy_ref<> create_thread_event_object (PyTypeObject *py_type,
-					       PyObject *thread);
+					       gdbpy_borrowed_ref<> thread);
 
 extern int emit_new_objfile_event (struct objfile *objfile);
 extern int emit_free_objfile_event (struct objfile *objfile);
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index ab3a95da1bf..dd2a3a0da24 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -333,8 +333,7 @@ add_thread_object (struct thread_info *tp)
     return;
 
   gdbpy_ref<> event = create_thread_event_object
-    (&new_thread_event_object_type,
-     (PyObject *) ins_result.first->second.get ());
+    (&new_thread_event_object_type, ins_result.first->second);
 
   if (event == NULL
       || evpy_emit_event (event, gdb_py_events.new_thread) < 0)
diff --git a/gdb/python/py-stopevent.c b/gdb/python/py-stopevent.c
index 3f07f8a29fb..cdb1ad3fc50 100644
--- a/gdb/python/py-stopevent.c
+++ b/gdb/python/py-stopevent.c
@@ -28,7 +28,7 @@ create_stop_event_object (PyTypeObject *py_type, const gdbpy_ref<> &dict)
   if (thread == nullptr)
     return nullptr;
 
-  gdbpy_ref<> result = create_thread_event_object (py_type, thread.get ());
+  gdbpy_ref<> result = create_thread_event_object (py_type, thread);
   if (result == nullptr)
     return nullptr;
 
diff --git a/gdb/python/py-stopevent.h b/gdb/python/py-stopevent.h
index f9a14fe00c1..7b36825019c 100644
--- a/gdb/python/py-stopevent.h
+++ b/gdb/python/py-stopevent.h
@@ -28,9 +28,10 @@ extern gdbpy_ref<> create_stop_event_object (PyTypeObject *py_type,
 extern int emit_stop_event (struct bpstat *bs,
 			    enum gdb_signal stop_signal);
 
-extern gdbpy_ref<> create_breakpoint_event_object (const gdbpy_ref<> &dict,
-						   PyObject *breakpoint_list,
-						   PyObject *first_bp);
+extern gdbpy_ref<> create_breakpoint_event_object
+     (const gdbpy_ref<> &dict,
+      gdbpy_borrowed_ref<> breakpoint_list,
+      gdbpy_borrowed_ref<> first_bp);
 
 extern gdbpy_ref<> create_signal_event_object (const gdbpy_ref<> &dict,
 					       enum gdb_signal stop_signal);
diff --git a/gdb/python/py-threadevent.c b/gdb/python/py-threadevent.c
index 9b0a963d0ba..a4a0c16dffc 100644
--- a/gdb/python/py-threadevent.c
+++ b/gdb/python/py-threadevent.c
@@ -37,7 +37,7 @@ py_get_event_thread (ptid_t ptid)
 }
 
 gdbpy_ref<>
-create_thread_event_object (PyTypeObject *py_type, PyObject *thread)
+create_thread_event_object (PyTypeObject *py_type, gdbpy_borrowed_ref<> thread)
 {
   gdb_assert (thread != NULL);
 
@@ -65,7 +65,7 @@ emit_thread_exit_event (thread_info * thread)
     return -1;
 
   auto inf_thr = create_thread_event_object (&thread_exited_event_object_type,
-				     py_thr.get ());
+					     py_thr);
   if (inf_thr == nullptr)
     return -1;
 

-- 
2.49.0


  parent reply	other threads:[~2026-08-08 21:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-08 21:47 [PATCH 0/4] Use gdbpy_borrowed_ref more + cast removal Tom Tromey
2026-08-08 21:47 ` [PATCH 1/4] Change evpy_emit_event to accept a gdbpy_opt_borrowed_ref Tom Tromey
2026-08-08 21:47 ` [PATCH 2/4] Change evpy_add_attribute to accept gdbpy_borrowed_ref Tom Tromey
2026-08-08 21:47 ` Tom Tromey [this message]
2026-08-08 21:47 ` [PATCH 4/4] Remove unneeded casts to PyObject* 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=20260808-python-safety-events-simple-v1-3-132aea40c801@tromey.com \
    --to=tom@tromey.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