Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
13 changes: 13 additions & 0 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@
#include <stdlib.h>
#include <stdbool.h> // 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 <pythread.h> /* Py_tss_t */
#include <string.h> /* strlen, memcpy */
Expand Down
Loading