diff options
author | Sam Gross <colesbury@gmail.com> | 2024-09-12 16:37:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-12 16:37:06 (GMT) |
commit | b2afe2aae487ebf89897e22c01d9095944fd334f (patch) | |
tree | 3ffa3ebfe3c69cd21968ce76d8d7cb2f325ff6d3 /Python/tracemalloc.c | |
parent | 4ed7d1d6acc22807bfb5983c98fd59f7cb5061db (diff) | |
download | cpython-b2afe2aae487ebf89897e22c01d9095944fd334f.zip cpython-b2afe2aae487ebf89897e22c01d9095944fd334f.tar.gz cpython-b2afe2aae487ebf89897e22c01d9095944fd334f.tar.bz2 |
gh-123923: Defer refcounting for `f_executable` in `_PyInterpreterFrame` (#123924)
Use a `_PyStackRef` and defer the reference to `f_executable` when
possible. This avoids some reference count contention in the common case
of executing the same code object from multiple threads concurrently in
the free-threaded build.
Diffstat (limited to 'Python/tracemalloc.c')
-rw-r--r-- | Python/tracemalloc.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Python/tracemalloc.c b/Python/tracemalloc.c index e58b60d..f661d69 100644 --- a/Python/tracemalloc.c +++ b/Python/tracemalloc.c @@ -250,7 +250,7 @@ hashtable_compare_traceback(const void *key1, const void *key2) static void tracemalloc_get_frame(_PyInterpreterFrame *pyframe, frame_t *frame) { - assert(PyCode_Check(pyframe->f_executable)); + assert(PyStackRef_CodeCheck(pyframe->f_executable)); frame->filename = &_Py_STR(anon_unknown); int lineno = PyUnstable_InterpreterFrame_GetLine(pyframe); if (lineno < 0) { @@ -258,7 +258,7 @@ tracemalloc_get_frame(_PyInterpreterFrame *pyframe, frame_t *frame) } frame->lineno = (unsigned int)lineno; - PyObject *filename = filename = ((PyCodeObject *)pyframe->f_executable)->co_filename; + PyObject *filename = filename = _PyFrame_GetCode(pyframe)->co_filename; if (filename == NULL) { #ifdef TRACE_DEBUG |