From f3504b2acb919c2cc84c14b8c9ea392e03f267b1 Mon Sep 17 00:00:00 2001 From: jamesclement1776 Date: Thu, 4 Dec 2025 13:52:45 -0600 Subject: [PATCH] Add implementations for missing eval and code helpers --- Objects/codeobject.c | 24 ++++++++++++++++++++++++ Python/ceval.c | 13 +++++++++++++ 2 files changed, 37 insertions(+) diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 975b587fe008f5..aee73ae09a2e36 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -1310,6 +1310,30 @@ PyCode_Addr2Line(PyCodeObject *co, int addrq) return _PyCode_CheckLineNumber(addrq, &bounds); } +int +_PyCode_SafeAddr2Line(PyCodeObject *co, int addrq) +{ + if (co == NULL) { + return -1; + } + /* + * dump_frame() may be called from signal handlers or other contexts where + * the code object could already be in the process of being torn down. + * Basic sanity checks help us avoid dereferencing obviously invalid + * objects while still providing a best-effort line number when possible. + */ + if (!Py_IS_TYPE(co, &PyCode_Type)) { + return -1; + } + if (Py_REFCNT(co) <= 0) { + return -1; + } + if (addrq < 0 || addrq >= _PyCode_NBYTES(co)) { + return -1; + } + return PyCode_Addr2Line(co, addrq); +} + void _PyLineTable_InitAddressRange(const char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range) { diff --git a/Python/ceval.c b/Python/ceval.c index 1175f0a5ffded7..c3b6fb89eeb0cc 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -52,6 +52,19 @@ #include #include // bool +bool +_PyEval_NoToolsForUnwind(PyThreadState *tstate) +{ + assert(tstate != NULL); + /* + * The generator fast-path in gen_close() only applies when we are sure + * that no tracing or profiling callbacks are going to observe the stack + * unwinding. In that situation we can skip some of the normal unwinding + * machinery. + */ + return !tstate->cframe->use_tracing; +} + /* ======================== Firmament2 source scope ======================== */ #include /* Py_tss_t */ #include /* strlen, memcpy */