diff options
author | Andrew Burgess <aburgess@redhat.com> | 2025-08-26 16:56:07 +0100 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2025-08-26 22:02:40 +0100 |
commit | f5493d6c96da9faf5f16d748cf6c899f0836b12d (patch) | |
tree | 4b7a62f90345b24f3169a5814aa3495f3e7bad50 | |
parent | 1cb99f1398127070de3ad4b354101f640316075c (diff) | |
download | binutils-f5493d6c96da9faf5f16d748cf6c899f0836b12d.zip binutils-f5493d6c96da9faf5f16d748cf6c899f0836b12d.tar.gz binutils-f5493d6c96da9faf5f16d748cf6c899f0836b12d.tar.bz2 |
gdb/python: return gdbpy_ref<> from gdbpy_create_ptid_object
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>
-rw-r--r-- | gdb/python/py-infevents.c | 2 | ||||
-rw-r--r-- | gdb/python/py-infthread.c | 10 | ||||
-rw-r--r-- | gdb/python/python-internal.h | 7 |
3 files changed, 12 insertions, 7 deletions
diff --git a/gdb/python/py-infevents.c b/gdb/python/py-infevents.c index e63ba52..f74fb01 100644 --- a/gdb/python/py-infevents.c +++ b/gdb/python/py-infevents.c @@ -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; diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c index d78c3a1..08533fe 100644 --- a/gdb/python/py-infthread.c +++ b/gdb/python/py-infthread.c @@ -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. diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 7f4237e..f61a175 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -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); |