[3.14] gh-138661: fix data race in PyCode_Addr2Line (GH-138664) (#138834)

gh-138661: fix data race in `PyCode_Addr2Line` (GH-138664)
(cherry picked from commit ea26f6da39)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
Miss Islington (bot) 2025-10-07 20:06:45 +02:00 committed by GitHub
parent 98d33bf19c
commit bfcd5f25a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 3 deletions

View file

@ -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;
@ -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)
{