aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2020-09-15 11:08:56 -0600
committerTom Tromey <tromey@adacore.com>2020-09-15 11:08:57 -0600
commit47f0e2ff7f0a4479c511f5d3ed4c8a962cb1f237 (patch)
tree62f0ecfdb041fc15083df188d26f10167efd907b /gdb/python
parent512116ce26a66338e1be1847cc8b014f4d4bbc13 (diff)
downloadgdb-47f0e2ff7f0a4479c511f5d3ed4c8a962cb1f237.zip
gdb-47f0e2ff7f0a4479c511f5d3ed4c8a962cb1f237.tar.gz
gdb-47f0e2ff7f0a4479c511f5d3ed4c8a962cb1f237.tar.bz2
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.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-breakpoint.c12
-rw-r--r--gdb/python/py-frame.c4
-rw-r--r--gdb/python/py-framefilter.c4
-rw-r--r--gdb/python/py-infthread.c19
-rw-r--r--gdb/python/py-record-btrace.c8
-rw-r--r--gdb/python/py-record.c2
-rw-r--r--gdb/python/py-symbol.c4
-rw-r--r--gdb/python/py-symtab.c2
-rw-r--r--gdb/python/py-type.c2
-rw-r--r--gdb/python/py-value.c2
-rw-r--r--gdb/python/python-internal.h1
11 files changed, 36 insertions, 24 deletions
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 11345ad..7369c91 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -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
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 0907055..24d4fae 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -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.
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 45bf51b..d0348b5 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -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;
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;
}
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index 762c0bc..15cd15b 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -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
diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c
index a6b08dc..3863408 100644
--- a/gdb/python/py-record.c
+++ b/gdb/python/py-record.c
@@ -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]. */
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index d683505..0adcb0b 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -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.
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index b0e7618..579662f 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -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 *
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index d487a39..951dac2 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -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
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index bb88bf3..6e29284 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -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)
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 2c4195f..36c1ab2 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -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