Skip to content

Commit b2ffe6e

Browse files
Merge pull request #10 from jamesclement1776/codex/fix-undefined-references-in-build
Add missing unwind helper implementations
2 parents 9e7729a + f3504b2 commit b2ffe6e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Objects/codeobject.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,30 @@ PyCode_Addr2Line(PyCodeObject *co, int addrq)
13101310
return _PyCode_CheckLineNumber(addrq, &bounds);
13111311
}
13121312

1313+
int
1314+
_PyCode_SafeAddr2Line(PyCodeObject *co, int addrq)
1315+
{
1316+
if (co == NULL) {
1317+
return -1;
1318+
}
1319+
/*
1320+
* dump_frame() may be called from signal handlers or other contexts where
1321+
* the code object could already be in the process of being torn down.
1322+
* Basic sanity checks help us avoid dereferencing obviously invalid
1323+
* objects while still providing a best-effort line number when possible.
1324+
*/
1325+
if (!Py_IS_TYPE(co, &PyCode_Type)) {
1326+
return -1;
1327+
}
1328+
if (Py_REFCNT(co) <= 0) {
1329+
return -1;
1330+
}
1331+
if (addrq < 0 || addrq >= _PyCode_NBYTES(co)) {
1332+
return -1;
1333+
}
1334+
return PyCode_Addr2Line(co, addrq);
1335+
}
1336+
13131337
void
13141338
_PyLineTable_InitAddressRange(const char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range)
13151339
{

Python/ceval.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@
5252
#include <stdlib.h>
5353
#include <stdbool.h> // bool
5454

55+
bool
56+
_PyEval_NoToolsForUnwind(PyThreadState *tstate)
57+
{
58+
assert(tstate != NULL);
59+
/*
60+
* The generator fast-path in gen_close() only applies when we are sure
61+
* that no tracing or profiling callbacks are going to observe the stack
62+
* unwinding. In that situation we can skip some of the normal unwinding
63+
* machinery.
64+
*/
65+
return !tstate->cframe->use_tracing;
66+
}
67+
5568
/* ======================== Firmament2 source scope ======================== */
5669
#include <pythread.h> /* Py_tss_t */
5770
#include <string.h> /* strlen, memcpy */

0 commit comments

Comments
 (0)