gh-138661: fix data race in `PyCode_Addr2Line` (#138664) · python/cpython@ea26f6d · GitHub
Skip to content

Commit ea26f6d

Browse files
gh-138661: fix data race in PyCode_Addr2Line (#138664)
1 parent c3fca5d commit ea26f6d

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

Include/internal/pycore_code.h

Lines changed: 2 additions & 0 deletions

Objects/codeobject.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
10061006
******************/
10071007

10081008
int
1009-
PyCode_Addr2Line(PyCodeObject *co, int addrq)
1009+
_PyCode_Addr2LineNoTstate(PyCodeObject *co, int addrq)
10101010
{
10111011
if (addrq < 0) {
10121012
return co->co_firstlineno;
@@ -1020,6 +1020,16 @@ PyCode_Addr2Line(PyCodeObject *co, int addrq)
10201020
return _PyCode_CheckLineNumber(addrq, &bounds);
10211021
}
10221022

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+
10231033
void
10241034
_PyLineTable_InitAddressRange(const char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range)
10251035
{

Python/traceback.c

Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)