mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-27 20:14:06 +08:00
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 <tromey@adacore.com> * 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.
This commit is contained in:
parent
512116ce26
commit
47f0e2ff7f
@ -1,3 +1,29 @@
|
||||
2020-09-15 Tom Tromey <tromey@adacore.com>
|
||||
|
||||
* 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.
|
||||
|
||||
2020-09-15 Tom Tromey <tromey@adacore.com>
|
||||
|
||||
* python/python.c (gdbpy_parameter_value): Use
|
||||
|
@ -552,7 +552,7 @@ bppy_get_type (PyObject *self, void *closure)
|
||||
|
||||
BPPY_REQUIRE_VALID (self_bp);
|
||||
|
||||
return PyInt_FromLong (self_bp->bp->type);
|
||||
return gdb_py_object_from_longest (self_bp->bp->type).release ();
|
||||
}
|
||||
|
||||
/* Python function to get the visibility of the breakpoint. */
|
||||
@ -613,7 +613,7 @@ bppy_get_number (PyObject *self, void *closure)
|
||||
|
||||
BPPY_REQUIRE_VALID (self_bp);
|
||||
|
||||
return PyInt_FromLong (self_bp->number);
|
||||
return gdb_py_object_from_longest (self_bp->number).release ();
|
||||
}
|
||||
|
||||
/* Python function to get the breakpoint's thread ID. */
|
||||
@ -627,7 +627,7 @@ bppy_get_thread (PyObject *self, void *closure)
|
||||
if (self_bp->bp->thread == -1)
|
||||
Py_RETURN_NONE;
|
||||
|
||||
return PyInt_FromLong (self_bp->bp->thread);
|
||||
return gdb_py_object_from_longest (self_bp->bp->thread).release ();
|
||||
}
|
||||
|
||||
/* Python function to get the breakpoint's task ID (in Ada). */
|
||||
@ -641,7 +641,7 @@ bppy_get_task (PyObject *self, void *closure)
|
||||
if (self_bp->bp->task == 0)
|
||||
Py_RETURN_NONE;
|
||||
|
||||
return PyInt_FromLong (self_bp->bp->task);
|
||||
return gdb_py_object_from_longest (self_bp->bp->task).release ();
|
||||
}
|
||||
|
||||
/* Python function to get the breakpoint's hit count. */
|
||||
@ -652,7 +652,7 @@ bppy_get_hit_count (PyObject *self, void *closure)
|
||||
|
||||
BPPY_REQUIRE_VALID (self_bp);
|
||||
|
||||
return PyInt_FromLong (self_bp->bp->hit_count);
|
||||
return gdb_py_object_from_longest (self_bp->bp->hit_count).release ();
|
||||
}
|
||||
|
||||
/* Python function to get the breakpoint's ignore count. */
|
||||
@ -663,7 +663,7 @@ bppy_get_ignore_count (PyObject *self, void *closure)
|
||||
|
||||
BPPY_REQUIRE_VALID (self_bp);
|
||||
|
||||
return PyInt_FromLong (self_bp->bp->ignore_count);
|
||||
return gdb_py_object_from_longest (self_bp->bp->ignore_count).release ();
|
||||
}
|
||||
|
||||
/* Internal function to validate the Python parameters/keywords
|
||||
|
@ -165,7 +165,7 @@ frapy_type (PyObject *self, PyObject *args)
|
||||
GDB_PY_HANDLE_EXCEPTION (except);
|
||||
}
|
||||
|
||||
return PyInt_FromLong (type);
|
||||
return gdb_py_object_from_longest (type).release ();
|
||||
}
|
||||
|
||||
/* Implementation of gdb.Frame.architecture (self) -> gdb.Architecture.
|
||||
@ -209,7 +209,7 @@ frapy_unwind_stop_reason (PyObject *self, PyObject *args)
|
||||
|
||||
stop_reason = get_frame_unwind_stop_reason (frame);
|
||||
|
||||
return PyInt_FromLong (stop_reason);
|
||||
return gdb_py_object_from_longest (stop_reason).release ();
|
||||
}
|
||||
|
||||
/* Implementation of gdb.Frame.pc (self) -> Long.
|
||||
|
@ -1098,11 +1098,11 @@ bootstrap_python_frame_filters (struct frame_info *frame,
|
||||
if (sort_func == NULL)
|
||||
return NULL;
|
||||
|
||||
gdbpy_ref<> py_frame_low (PyInt_FromLong (frame_low));
|
||||
gdbpy_ref<> py_frame_low = gdb_py_object_from_longest (frame_low);
|
||||
if (py_frame_low == NULL)
|
||||
return NULL;
|
||||
|
||||
gdbpy_ref<> py_frame_high (PyInt_FromLong (frame_high));
|
||||
gdbpy_ref<> py_frame_high = gdb_py_object_from_longest (frame_high);
|
||||
if (py_frame_high == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -246,7 +246,7 @@ recpy_bt_insn_size (PyObject *self, void *closure)
|
||||
if (insn == NULL)
|
||||
return NULL;
|
||||
|
||||
return PyInt_FromLong (insn->size);
|
||||
return gdb_py_object_from_longest (insn->size).release ();
|
||||
}
|
||||
|
||||
/* Implementation of RecordInstruction.is_speculative [bool] for btrace.
|
||||
@ -342,7 +342,8 @@ recpy_bt_func_level (PyObject *self, void *closure)
|
||||
return NULL;
|
||||
|
||||
tinfo = ((recpy_element_object *) self)->thread;
|
||||
return PyInt_FromLong (tinfo->btrace.level + func->level);
|
||||
return gdb_py_object_from_longest (tinfo->btrace.level
|
||||
+ func->level).release ();
|
||||
}
|
||||
|
||||
/* Implementation of RecordFunctionSegment.symbol [gdb.Symbol] for btrace.
|
||||
@ -566,7 +567,8 @@ btpy_list_count (PyObject *self, PyObject *value)
|
||||
{
|
||||
/* We know that if an element is in the list, it is so exactly one time,
|
||||
enabling us to reuse the "is element of" check. */
|
||||
return PyInt_FromLong (btpy_list_contains (self, value));
|
||||
return gdb_py_object_from_longest (btpy_list_contains (self,
|
||||
value)).release ();
|
||||
}
|
||||
|
||||
/* Python rich compare function to allow for equality and inequality checks
|
||||
|
@ -464,7 +464,7 @@ recpy_gap_reason_code (PyObject *self, void *closure)
|
||||
{
|
||||
const recpy_gap_object * const obj = (const recpy_gap_object *) self;
|
||||
|
||||
return PyInt_FromLong (obj->reason_code);
|
||||
return gdb_py_object_from_longest (obj->reason_code).release ();
|
||||
}
|
||||
|
||||
/* Implementation of RecordGap.error_string [str]. */
|
||||
|
@ -131,7 +131,7 @@ sympy_get_addr_class (PyObject *self, void *closure)
|
||||
|
||||
SYMPY_REQUIRE_VALID (self, symbol);
|
||||
|
||||
return PyInt_FromLong (SYMBOL_CLASS (symbol));
|
||||
return gdb_py_object_from_longest (SYMBOL_CLASS (symbol)).release ();
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
@ -221,7 +221,7 @@ sympy_line (PyObject *self, void *closure)
|
||||
|
||||
SYMPY_REQUIRE_VALID (self, symbol);
|
||||
|
||||
return PyInt_FromLong (SYMBOL_LINE (symbol));
|
||||
return gdb_py_object_from_longest (SYMBOL_LINE (symbol)).release ();
|
||||
}
|
||||
|
||||
/* Implementation of gdb.Symbol.is_valid (self) -> Boolean.
|
||||
|
@ -290,7 +290,7 @@ salpy_get_line (PyObject *self, void *closure)
|
||||
|
||||
SALPY_REQUIRE_VALID (self, sal);
|
||||
|
||||
return PyInt_FromLong (sal->line);
|
||||
return gdb_py_object_from_longest (sal->line).release ();
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -157,7 +157,7 @@ typy_get_code (PyObject *self, void *closure)
|
||||
{
|
||||
struct type *type = ((type_object *) self)->type;
|
||||
|
||||
return PyInt_FromLong (type->code ());
|
||||
return gdb_py_object_from_longest (type->code ()).release ();
|
||||
}
|
||||
|
||||
/* Helper function for typy_fields which converts a single field to a
|
||||
|
@ -1860,7 +1860,7 @@ convert_value_from_python (PyObject *obj)
|
||||
if (PyErr_ExceptionMatches (PyExc_OverflowError))
|
||||
{
|
||||
gdbpy_err_fetch fetched_error;
|
||||
gdbpy_ref<> zero (PyInt_FromLong (0));
|
||||
gdbpy_ref<> zero = gdb_py_object_from_longest (0);
|
||||
|
||||
/* Check whether obj is positive. */
|
||||
if (PyObject_RichCompareBool (obj, zero.get (), Py_GT) > 0)
|
||||
|
@ -96,7 +96,6 @@
|
||||
#define Py_TPFLAGS_CHECKTYPES 0
|
||||
|
||||
#define PyInt_Check PyLong_Check
|
||||
#define PyInt_FromLong PyLong_FromLong
|
||||
#define PyInt_AsLong PyLong_AsLong
|
||||
#define PyInt_AsSsize_t PyLong_AsSsize_t
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user