]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/python: return gdbpy_ref<> from gdbpy_create_ptid_object
authorAndrew Burgess <aburgess@redhat.com>
Tue, 26 Aug 2025 15:56:07 +0000 (16:56 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Tue, 26 Aug 2025 21:02:40 +0000 (22:02 +0100)
Update gdbpy_create_ptid_object (python/py-infthread.c) to return a
gdbpy_ref<> rather than a 'PyObject *'.  This reduces the chances that
a caller will leak an object, though no such memory leaks are fixed in
this commit, this is just a code improvement patch.

There should be no user visible changes after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/python/py-infevents.c
gdb/python/py-infthread.c
gdb/python/python-internal.h

index e63ba52623fd52e96a19bd979c928245866546ab..f74fb017edc570f3b39eda208861a2b27d6a13db 100644 (file)
@@ -40,7 +40,7 @@ create_inferior_call_event_object (inferior_call_kind flag, ptid_t ptid,
       gdb_assert_not_reached ("invalid inferior_call_kind");
     }
 
-  gdbpy_ref<> ptid_obj (gdbpy_create_ptid_object (ptid));
+  gdbpy_ref<> ptid_obj = gdbpy_create_ptid_object (ptid);
   if (ptid_obj == NULL)
     return NULL;
 
index d78c3a15b8739c63f86d323b5c02a0bf492a535d..08533fe2923ff9f84948c3954849fedd7bb9471d 100644 (file)
@@ -190,7 +190,7 @@ thpy_get_ptid (PyObject *self, void *closure)
 
   THPY_REQUIRE_VALID (thread_obj);
 
-  return gdbpy_create_ptid_object (thread_obj->thread->ptid);
+  return gdbpy_create_ptid_object (thread_obj->thread->ptid).release ();
 }
 
 /* Implement gdb.InferiorThread.ptid_string attribute.  */
@@ -361,9 +361,9 @@ thpy_repr (PyObject *self)
                               target_pid_to_str (thr->ptid).c_str ());
 }
 
-/* Return a reference to a new Python object representing a ptid_t.
-   The object is a tuple containing (pid, lwp, tid). */
-PyObject *
+/* See python-internal.h.  */
+
+gdbpy_ref<>
 gdbpy_create_ptid_object (ptid_t ptid)
 {
   int pid = ptid.pid ();
@@ -389,7 +389,7 @@ gdbpy_create_ptid_object (ptid_t ptid)
   PyTuple_SET_ITEM (ret.get (), 1, lwp_obj.release ());
   PyTuple_SET_ITEM (ret.get (), 2, tid_obj.release ());
 
-  return ret.release ();
+  return ret;
 }
 
 /* Implementation of gdb.selected_thread () -> gdb.InferiorThread.
index 7f4237eecc2171b90d19e144e2002e58a9fa2a40..f61a1753ac40988745a1530370325b9a80e27d54 100644 (file)
@@ -503,7 +503,12 @@ PyObject *gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
                                           const char *encoding,
                                           struct type *type);
 PyObject *gdbpy_inferiors (PyObject *unused, PyObject *unused2);
-PyObject *gdbpy_create_ptid_object (ptid_t ptid);
+
+/* Return a reference to a new Python Tuple object representing a ptid_t.
+   The object is a tuple containing (pid, lwp, tid).  */
+
+extern gdbpy_ref<> gdbpy_create_ptid_object (ptid_t ptid);
+
 PyObject *gdbpy_selected_thread (PyObject *self, PyObject *args);
 PyObject *gdbpy_selected_inferior (PyObject *self, PyObject *args);
 PyObject *gdbpy_string_to_argv (PyObject *self, PyObject *args);