8000 gh-100227: Make the Global Interned Dict Safe for Isolated Interpreters by ericsnowcurrently · Pull Request #102925 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-100227: Make the Global Interned Dict Safe for Isolated Interpreters #102925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Add acquire_global_objects_lock() and release_global_objects_lock().
  • Loading branch information
ericsnowcurrently committed Mar 22, 2023
commit 6216207cfa3410a20bed9161bb9f067ded8f97fe
21 changes: 18 additions & 3 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,22 @@ unbind_global_objects_state(_PyRuntimeState *runtime)
#endif
}

static inline void
acquire_global_objects_lock(_PyRuntimeState *runtime)
{
/* For now we can rely on the GIL, so we don't actually
acquire a global lock here. */
assert(current_fast_get(runtime) != NULL);
}

static inline void
release_global_objects_lock(_PyRuntimeState *runtime)
{
/* For now we can rely on the GIL, so we don't actually
release a global lock here. */
assert(current_fast_get(runtime) != NULL);
}

PyObject *
_Py_AddToGlobalDict(PyObject *dict, PyObject *key, PyObject *value)
{
Expand All @@ -623,7 +639,7 @@ _Py_AddToGlobalDict(PyObject *dict, PyObject *key, PyObject *value)
starting at this point and ending before we return.
Note that the operations in this function are very fucused
and we should not expect any reentrancy. */
// For now we rely on the GIL.
acquire_global_objects_lock(runtime);

/* Swap to the main interpreter, if necessary. */
PyThreadState *oldts = NULL;
Expand Down Expand Up @@ -659,8 +675,7 @@ _Py_AddToGlobalDict(PyObject *dict, PyObject *key, PyObject *value)
unbind_global_objects_state(runtime);
}

// This is where we would release the global lock,
// if we weren't relying on the GIL.
release_global_objects_lock(runtime);

// XXX Immortalize the key and value.

Expand Down
0