From b2afe2aae487ebf89897e22c01d9095944fd334f Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Thu, 12 Sep 2024 12:37:06 -0400 Subject: 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. --- Python/bytecodes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Python/bytecodes.c') diff --git a/Python/bytecodes.c b/Python/bytecodes.c index e8cf636656e..078f06d697c 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -3598,7 +3598,7 @@ dummy_func( op(_CREATE_INIT_FRAME, (self, init, args[oparg] -- init_frame: _PyInterpreterFrame *)) { _PyInterpreterFrame *shim = _PyFrame_PushTrampolineUnchecked( tstate, (PyCodeObject *)&_Py_InitCleanup, 1, frame); - assert(_PyCode_CODE((PyCodeObject *)shim->f_executable)[0].op.code == EXIT_INIT_CHECK); + assert(_PyCode_CODE(_PyFrame_GetCode(shim))[0].op.code == EXIT_INIT_CHECK); /* Push self onto stack of shim */ shim->localsplus[0] = PyStackRef_DUP(self); PyFunctionObject *init_func = (PyFunctionObject *)PyStackRef_AsPyObjectSteal(init); @@ -4798,7 +4798,7 @@ dummy_func( #endif _PyExecutorObject *executor; if (target->op.code == ENTER_EXECUTOR) { - PyCodeObject *code = (PyCodeObject *)frame->f_executable; + PyCodeObject *code = _PyFrame_GetCode(frame); executor = code->co_executors->executors[target->op.arg]; Py_INCREF(executor); } -- cgit v1.2.3