Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Free-threading: Re-add lock for intern_constants
  • Loading branch information
encukou committed Jul 24, 2024
commit 9bca4c69d133ada11fa6c963fa3f5a8dc5d1e04e
11 changes: 10 additions & 1 deletion Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ intern_names(PyObject *tuple)

Conceptually: return a new tuple.
(If no changes are needed, return a new ref to the argument.)

In the free-threaded build this needs a lock.
*/
static PyObject *
intern_constants(PyObject *tuple)
Expand Down Expand Up @@ -686,11 +688,18 @@ _PyCode_New(struct _PyCodeConstructor *con)
if (!names_interned) {
goto finally;
}
#ifdef Py_GIL_DISABLED
PyInterpreterState *interp = _PyInterpreterState_GET();
struct _py_code_state *state = &interp->code_state;
PyMutex_Lock(&state->mutex);
#endif
consts_interned = intern_constants(con->consts);
if (!consts_interned) {
goto finally;
}
localsplusnames_interned = intern_constants(con->localsplusnames);
#ifdef Py_GIL_DISABLED
PyMutex_Unlock(&state->mutex);
#endif
localsplusnames_interned = intern_names(con->localsplusnames);
if (!localsplusnames_interned) {
goto finally;
Expand Down