Skip to content

Commit d8d0f02

Browse files
fix faulthandler
1 parent 90f0d46 commit d8d0f02

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

Include/internal/pycore_code.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ extern void _PyLineTable_InitAddressRange(
274274
/** API for traversing the line number table. */
275275
extern int _PyLineTable_NextAddressRange(PyCodeAddressRange *range);
276276
extern int _PyLineTable_PreviousAddressRange(PyCodeAddressRange *range);
277+
// This is used in dump_frame() in traceback.c without an attached tstate.
278+
extern int _PyCode_Addr2LineNoTstate(PyCodeObject *co, int addr);
277279

278280
/** API for executors */
279281
extern void _PyCode_Clear_Executors(PyCodeObject *code);

Objects/codeobject.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,20 +1005,13 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
10051005
* source location tracking (co_lines/co_positions)
10061006
******************/
10071007

1008-
int
1009-
PyCode_Addr2Line(PyCodeObject *co, int addrq)
1010-
{
1008+
int _PyCode_Addr2LineNoTstate(PyCodeObject *co, int addrq){
10111009
if (addrq < 0) {
10121010
return co->co_firstlineno;
10131011
}
1014-
int lineno = -2; // -1 is a valid line number
1015-
Py_BEGIN_CRITICAL_SECTION(co);
1012+
10161013
if (co->_co_monitoring && co->_co_monitoring->lines) {
1017-
lineno = _Py_Instrumentation_GetLine(co, addrq/sizeof(_Py_CODEUNIT));
1018-
}
1019-
Py_END_CRITICAL_SECTION();
1020-
if (lineno != -2) {
1021-
return lineno;
1014+
return _Py_Instrumentation_GetLine(co, addrq/sizeof(_Py_CODEUNIT));
10221015
}
10231016

10241017
assert(addrq >= 0 && addrq < _PyCode_NBYTES(co));
@@ -1027,6 +1020,16 @@ PyCode_Addr2Line(PyCodeObject *co, int addrq)
10271020
return _PyCode_CheckLineNumber(addrq, &bounds);
10281021
}
10291022

1023+
int
1024+
PyCode_Addr2Line(PyCodeObject *co, int addrq)
1025+
{
1026+
int lineno;
1027+
Py_BEGIN_CRITICAL_SECTION(co);
1028+
lineno = _PyCode_Addr2LineNoTstate(co, addrq);
1029+
Py_END_CRITICAL_SECTION();
1030+
return lineno;
1031+
}
1032+
10301033
void
10311034
_PyLineTable_InitAddressRange(const char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range)
10321035
{

Python/traceback.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,8 +993,8 @@ dump_frame(int fd, _PyInterpreterFrame *frame)
993993
} else {
994994
PUTS(fd, "???");
995995
}
996-
997-
int lineno = PyUnstable_InterpreterFrame_GetLine(frame);
996+
int lasti = PyUnstable_InterpreterFrame_GetLasti(frame);
997+
int lineno = _PyCode_Addr2LineNoTstate(code, lasti);
998998
PUTS(fd, ", line ");
999999
if (lineno >= 0) {
10001000
_Py_DumpDecimal(fd, (size_t)lineno);

0 commit comments

Comments
 (0)