Skip to content
Open
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
2 changes: 2 additions & 0 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ extern void _PyLineTable_InitAddressRange(
/** API for traversing the line number table. */
extern int _PyLineTable_NextAddressRange(PyCodeAddressRange *range);
extern int _PyLineTable_PreviousAddressRange(PyCodeAddressRange *range);
// This is used in dump_frame() in traceback.c without an attached tstate.
extern int _PyCode_Addr2LineNoTstate(PyCodeObject *co, int addr);

/** API for executors */
extern void _PyCode_Clear_Executors(PyCodeObject *code);
Expand Down
12 changes: 11 additions & 1 deletion Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
******************/

int
PyCode_Addr2Line(PyCodeObject *co, int addrq)
_PyCode_Addr2LineNoTstate(PyCodeObject *co, int addrq)
{
if (addrq < 0) {
return co->co_firstlineno;
Expand All @@ -1028,6 +1028,16 @@ PyCode_Addr2Line(PyCodeObject *co, int addrq)
return _PyCode_CheckLineNumber(addrq, &bounds);
}

int
PyCode_Addr2Line(PyCodeObject *co, int addrq)
{
int lineno;
Py_BEGIN_CRITICAL_SECTION(co);
lineno = _PyCode_Addr2LineNoTstate(co, addrq);
Py_END_CRITICAL_SECTION();
return lineno;
}

void
_PyLineTable_InitAddressRange(const char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range)
{
Expand Down
4 changes: 2 additions & 2 deletions Python/traceback.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,8 @@ dump_frame(int fd, _PyInterpreterFrame *frame)
} else {
PUTS(fd, "???");
}

int lineno = PyUnstable_InterpreterFrame_GetLine(frame);
int lasti = PyUnstable_InterpreterFrame_GetLasti(frame);
int lineno = _PyCode_Addr2LineNoTstate(code, lasti);
PUTS(fd, ", line ");
if (lineno >= 0) {
_Py_DumpDecimal(fd, (size_t)lineno);
Expand Down
Loading