aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2025-03-10 14:06:56 +0000
committerGitHub <noreply@github.com>2025-03-10 14:06:56 +0000
commit2bef8ea8ea045d20394f0daec7a5c5b1046a4e22 (patch)
treeeb4ee444fd0d58b788304c46839807475ea133ac /Python/ceval.c
parent7cc99a54b755cc7cc0b3680fde7834cf612d4fbc (diff)
downloadcpython-2bef8ea8ea045d20394f0daec7a5c5b1046a4e22.tar.gz
cpython-2bef8ea8ea045d20394f0daec7a5c5b1046a4e22.zip
GH-127705: Use `_PyStackRef`s in the default build. (GH-127875)
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c58
1 files changed, 38 insertions, 20 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 0a3b3051373..a702d296e22 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -134,35 +134,54 @@
#ifdef Py_DEBUG
static void
+dump_item(_PyStackRef item)
+{
+ if (PyStackRef_IsNull(item)) {
+ printf("<NULL>");
+ return;
+ }
+ PyObject *obj = PyStackRef_AsPyObjectBorrow(item);
+ if (obj == NULL) {
+ printf("<nil>");
+ return;
+ }
+ if (
+ obj == Py_None
+ || PyBool_Check(obj)
+ || PyLong_CheckExact(obj)
+ || PyFloat_CheckExact(obj)
+ || PyUnicode_CheckExact(obj)
+ ) {
+ if (PyObject_Print(obj, stdout, 0) == 0) {
+ return;
+ }
+ PyErr_Clear();
+ }
+ // Don't call __repr__(), it might recurse into the interpreter.
+ printf("<%s at %p>", Py_TYPE(obj)->tp_name, (void *)obj);
+}
+
+static void
dump_stack(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer)
{
_PyFrame_SetStackPointer(frame, stack_pointer);
+ _PyStackRef *locals_base = _PyFrame_GetLocalsArray(frame);
_PyStackRef *stack_base = _PyFrame_Stackbase(frame);
PyObject *exc = PyErr_GetRaisedException();
+ printf(" locals=[");
+ for (_PyStackRef *ptr = locals_base; ptr < stack_base; ptr++) {
+ if (ptr != locals_base) {
+ printf(", ");
+ }
+ dump_item(*ptr);
+ }
+ printf("]\n");
printf(" stack=[");
for (_PyStackRef *ptr = stack_base; ptr < stack_pointer; ptr++) {
if (ptr != stack_base) {
printf(", ");
}
- PyObject *obj = PyStackRef_AsPyObjectBorrow(*ptr);
- if (obj == NULL) {
- printf("<nil>");
- continue;
- }
- if (
- obj == Py_None
- || PyBool_Check(obj)
- || PyLong_CheckExact(obj)
- || PyFloat_CheckExact(obj)
- || PyUnicode_CheckExact(obj)
- ) {
- if (PyObject_Print(obj, stdout, 0) == 0) {
- continue;
- }
- PyErr_Clear();
- }
- // Don't call __repr__(), it might recurse into the interpreter.
- printf("<%s at %p>", Py_TYPE(obj)->tp_name, PyStackRef_AsPyObjectBorrow(*ptr));
+ dump_item(*ptr);
}
printf("]\n");
fflush(stdout);
@@ -1390,7 +1409,6 @@ initialize_locals(PyThreadState *tstate, PyFunctionObject *func,
{
PyCodeObject *co = (PyCodeObject*)func->func_code;
const Py_ssize_t total_args = co->co_argcount + co->co_kwonlyargcount;
-
/* Create a dictionary for keyword parameters (**kwags) */
PyObject *kwdict;
Py_ssize_t i;