[PATCH 3/4] Use gdbpy_borrowed_ref when creating events

Tom Tromey <[email protected]>
Newsgroups gmane.comp.gdb.patches
Message-ID <20260808-python-safety-events-simple-v1-3-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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.