gh-81057: Move the Remaining Import State Globals to _PyRuntimeState by ericsnowcurrently · Pull Request #99488 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions Include/internal/pycore_import.h
10 changes: 10 additions & 0 deletions Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ extern "C" {
.types = { \
.next_version_tag = 1, \
}, \
.imports = { \
.lock = { \
.mutex = NULL, \
.thread = PYTHREAD_INVALID_THREAD_ID, \
.level = 0, \
}, \
.find_and_load = { \
.header = 1, \
}, \
}, \
.global_objects = { \
.singletons = { \
.small_ints = _Py_small_ints_INIT, \
Expand Down
15 changes: 9 additions & 6 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ _PyImportZip_Init(PyThreadState *tstate)
in different threads to return with a partially loaded module.
These calls are serialized by the global interpreter lock. */

static PyThread_type_lock import_lock = NULL;
static unsigned long import_lock_thread = PYTHREAD_INVALID_THREAD_ID;
static int import_lock_level = 0;
#define import_lock _PyRuntime.imports.lock.mutex
#define import_lock_thread _PyRuntime.imports.lock.thread
#define import_lock_level _PyRuntime.imports.lock.level

void
_PyImport_AcquireLock(void)
Expand Down Expand Up @@ -1759,8 +1759,8 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
PyObject *mod = NULL;
PyInterpreterState *interp = tstate->interp;
int import_time = _PyInterpreterState_GetConfig(interp)->import_time;
static int import_level;
static _PyTime_t accumulated;
#define import_level _PyRuntime.imports.find_and_load.import_level
#define accumulated _PyRuntime.imports.find_and_load.accumulated

_PyTime_t t1 = 0, accumulated_copy = accumulated;

Expand All @@ -1781,12 +1781,13 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
* _PyDict_GetItemIdWithError().
*/
if (import_time) {
static int header = 1;
#define header _PyRuntime.imports.find_and_load.header
if (header) {
fputs("import time: self [us] | cumulative | imported package\n",
stderr);
header = 0;
}
#undef header

import_level++;
t1 = _PyTime_GetPerfCounter();
Expand Down Expand Up @@ -1816,6 +1817,8 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
}

return mod;
#undef import_level
#undef accumulated
}

PyObject *
Expand Down
6 changes: 0 additions & 6 deletions Tools/c-analyzer/cpython/globals-to-fix.tsv