10000 gh-81057: Move More Globals in Core Code to _PyRuntimeState by ericsnowcurrently · Pull Request #99516 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-81057: Move More Globals in Core Code to _PyRuntimeState #99516

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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 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
runtime.unicode_ids -> runtime.unicode_state.ids.
  • Loading branch information
ericsnowcurrently committed Nov 15, 2022
commit d04d9da11a13469743268b1c91ca0b533eb298cd
2 changes: 1 addition & 1 deletion Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ typedef struct pyruntimestate {
_Py_AuditHookEntry *audit_hook_head;

struct _Py_float_runtime_state float_state;
struct _Py_unicode_runtime_ids unicode_ids;
struct _Py_unicode_runtime_state unicode_state;

struct {
/* Used to set PyTypeObject.tp_version_tag */
Expand Down
4 changes: 4 additions & 0 deletions Include/internal/pycore_unicodeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ struct _Py_unicode_runtime_ids {
Py_ssize_t next_index;
};

struct _Py_unicode_runtime_state {
struct _Py_unicode_runtime_ids ids;
};

/* fs_codec.encoding is initialized to NULL.
Later, it is set to a non-NULL string by _PyUnicode_InitEncodings(). */
struct _Py_unicode_fs_codec {
Expand Down
2 changes: 1 addition & 1 deletion Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ _PyUnicode_FromId(_Py_Identifier *id)

Py_ssize_t index = _Py_atomic_size_get(&id->index);
if (index < 0) {
struct _Py_unicode_runtime_ids *rt_ids = &interp->runtime->unicode_ids;
struct _Py_unicode_runtime_ids *rt_ids = &interp->runtime->unicode_state.ids;

PyThread_acquire_lock(rt_ids->lock, WAIT_LOCK);
// Check again to detect concurrent access. Another thread can have
Expand Down
10 changes: 5 additions & 5 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ init_runtime(_PyRuntimeState *runtime,
// Set it to the ID of the main thread of the main interpreter.
runtime->main_thread = PyThread_get_thread_ident();

runtime->unicode_ids.next_index = unicode_next_index;
runtime->unicode_ids.lock = unicode_ids_mutex;
runtime->unicode_state.ids.next_index = unicode_next_index;
runtime->unicode_state.ids.lock = unicode_ids_mutex;

runtime->_initialized = 1;
}
Expand All @@ -154,7 +154,7 @@ _PyRuntimeState_Init(_PyRuntimeState *runtime)
_Py_AuditHookEntry *audit_hook_head = runtime->audit_hook_head;
// bpo-42882: Preserve next_index value if Py_Initialize()/Py_Finalize()
// is called multiple times.
Py_ssize_t unicode_next_index = runtime->unicode_ids.next_index;
Py_ssize_t unicode_next_index = runtime->unicode_state.ids.next_index;

PyThread_type_lock lock1, lock2, lock3, lock4;
if (alloc_for_runtime(&lock1, &lock2, &lock3, &lock4) != 0) {
Expand Down Expand Up @@ -186,7 +186,7 @@ _PyRuntimeState_Fini(_PyRuntimeState *runtime)

FREE_LOCK(runtime->interpreters.mutex);
FREE_LOCK(runtime->xidregistry.mutex);
FREE_LOCK(runtime->unicode_ids.lock);
FREE_LOCK(runtime->unicode_state.ids.lock);
FREE_LOCK(runtime->getargs.mutex);

#undef FREE_LOCK
Expand All @@ -209,7 +209,7 @@ _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime)

int reinit_interp = _PyThread_at_fork_reinit(&runtime->interpreters.mutex);
int reinit_xidregistry = _PyThread_at_fork_reinit(&runtime->xidregistry.mutex);
int reinit_unicode_ids = _PyThread_at_fork_reinit(&runtime->unicode_ids.lock);
int reinit_unicode_ids = _PyThread_at_fork_reinit(&runtime->unicode_state.ids.lock);
int reinit_getargs = _PyThread_at_fork_reinit(&runtime->getargs.mutex);

PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
Expand Down
0