Skip to content

Commit 19b6f6d

Browse files
fix data race in ̌PyCode_Addr2Line
1 parent 7a3bca5 commit 19b6f6d

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Objects/codeobject.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,9 +1011,16 @@ PyCode_Addr2Line(PyCodeObject *co, int addrq)
10111011
if (addrq < 0) {
10121012
return co->co_firstlineno;
10131013
}
1014+
int lineno = -2; // -1 is a valid line number
1015+
Py_BEGIN_CRITICAL_SECTION(co);
10141016
if (co->_co_monitoring && co->_co_monitoring->lines) {
1015-
return _Py_Instrumentation_GetLine(co, addrq/sizeof(_Py_CODEUNIT));
1017+
lineno = _Py_Instrumentation_GetLine(co, addrq/sizeof(_Py_CODEUNIT));
1018+
}
1019+
Py_END_CRITICAL_SECTION();
1020+
if (lineno != -2) {
1021+
return lineno;
10161022
}
1023+
10171024
assert(addrq >= 0 && addrq < _PyCode_NBYTES(co));
10181025
PyCodeAddressRange bounds;
10191026
_PyCode_InitAddressRange(co, &bounds);

0 commit comments

Comments
 (0)