From 47f0e2ff7f0a4479c511f5d3ed4c8a962cb1f237 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 15 Sep 2020 11:08:56 -0600 Subject: Don't use PyInt_FromLong Avoid the use of PyInt_FromLong, preferring gdb_py_object_from_longest instead. I found found another spot that was incorrectly handling errors (see gdbpy_create_ptid_object) while writing this patch; it is fixed here. gdb/ChangeLog 2020-09-15 Tom Tromey * python/python-internal.h (PyInt_FromLong): Remove define. * python/py-value.c (convert_value_from_python): Use gdb_py_object_from_longest. * python/py-type.c (typy_get_code): Use gdb_py_object_from_longest. * python/py-symtab.c (salpy_get_line): Use gdb_py_object_from_longest. * python/py-symbol.c (sympy_get_addr_class, sympy_line): Use gdb_py_object_from_longest. * python/py-record.c (recpy_gap_reason_code): Use gdb_py_object_from_longest. * python/py-record-btrace.c (recpy_bt_insn_size) (recpy_bt_func_level, btpy_list_count): Use gdb_py_object_from_longest. * python/py-infthread.c (gdbpy_create_ptid_object): Use gdb_py_object_from_longest. Fix error handling. * python/py-framefilter.c (bootstrap_python_frame_filters): Use gdb_py_object_from_longest. * python/py-frame.c (frapy_type, frapy_unwind_stop_reason): Use gdb_py_object_from_longest. * python/py-breakpoint.c (bppy_get_type, bppy_get_number) (bppy_get_thread, bppy_get_task, bppy_get_hit_count) (bppy_get_ignore_count): Use gdb_py_object_from_longest. --- gdb/python/py-infthread.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'gdb/python/py-infthread.c') diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c index 669b6d8..fec7bca 100644 --- a/gdb/python/py-infthread.c +++ b/gdb/python/py-infthread.c @@ -307,10 +307,21 @@ gdbpy_create_ptid_object (ptid_t ptid) lwp = ptid.lwp (); tid = ptid.tid (); - PyTuple_SET_ITEM (ret, 0, PyInt_FromLong (pid)); - PyTuple_SET_ITEM (ret, 1, PyInt_FromLong (lwp)); - PyTuple_SET_ITEM (ret, 2, PyInt_FromLong (tid)); - + gdbpy_ref<> pid_obj = gdb_py_object_from_longest (pid); + if (pid_obj == nullptr) + return nullptr; + gdbpy_ref<> lwp_obj = gdb_py_object_from_longest (lwp); + if (lwp_obj == nullptr) + return nullptr; + gdbpy_ref<> tid_obj = gdb_py_object_from_longest (tid); + if (tid_obj == 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 ()); + return ret; } -- cgit v1.1