diff options
Diffstat (limited to 'gdb/python/py-infthread.c')
-rw-r--r-- | gdb/python/py-infthread.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c index 4f1f8d4..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,23 +361,14 @@ 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; - long lwp; - ULONGEST tid; - PyObject *ret; - - ret = PyTuple_New (3); - if (!ret) - return NULL; - - pid = ptid.pid (); - lwp = ptid.lwp (); - tid = ptid.tid (); + int pid = ptid.pid (); + long lwp = ptid.lwp (); + ULONGEST tid = ptid.tid (); gdbpy_ref<> pid_obj = gdb_py_object_from_longest (pid); if (pid_obj == nullptr) @@ -389,10 +380,14 @@ gdbpy_create_ptid_object (ptid_t ptid) if (tid_obj == nullptr) return nullptr; + gdbpy_ref<> ret (PyTuple_New (3)); + if (ret == nullptr) + return nullptr; + /* Note that these steal references, hence the use of 'release'. */ - PyTuple_SET_ITEM (ret, 0, pid_obj.release ()); - PyTuple_SET_ITEM (ret, 1, lwp_obj.release ()); - PyTuple_SET_ITEM (ret, 2, tid_obj.release ()); + PyTuple_SET_ITEM (ret.get (), 0, pid_obj.release ()); + PyTuple_SET_ITEM (ret.get (), 1, lwp_obj.release ()); + PyTuple_SET_ITEM (ret.get (), 2, tid_obj.release ()); return ret; } |