8000 gh-81057: Move the Remaining Import State Globals to _PyRuntimeState by ericsnowcurrently · Pull Request #99488 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-81057: Move the Remaining Import State Globals to _PyRuntimeState #99488

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 2 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
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
Add _PyRuntime.imports.find_and_load.
  • Loading branch information
ericsnowcurrently committed Nov 14, 2022
commit 7472eb440ae1a66b13e9fc8b5ebf90967dbf10fe
5 changes: 5 additions & 0 deletions Include/internal/pycore_import.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ struct _import_runtime_state {
unsigned long thread;
int level;
} lock;
struct {
int import_level;
_PyTime_t accumulated;
int header;
} find_and_load;
};


Expand Down
3 changes: 3 additions & 0 deletions Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ extern "C" {
.thread = PYTHREAD_INVALID_THREAD_ID, \
.level = 0, \
}, \
.find_and_load = { \
.header = 1, \
}, \
}, \
.global_objects = { \
.singletons = { \
Expand Down
9 changes: 6 additions & 3 deletions Python/import.c
Original file line number Diff line number Diff line change
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
3 changes: 0 additions & 3 deletions Tools/c-analyzer/cpython/globals-to-fix.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ Python/dtoa.c - p5s -
Python/fileutils.c - _Py_open_cloexec_works -
Python/fileutils.c - force_ascii -
Python/fileutils.c set_inheritable ioctl_works -
Python/import.c import_find_and_load header -

#-----------------------
# unlikely to change after init (or main thread)
Expand Down Expand Up @@ -430,8 +429,6 @@ Python/bootstrap_hash.c - urandom_cache -
Python/ceval_gil.c make_pending_calls busy -
Python/ceval.c _PyEval_SetProfile reentrant -
Python/ceval.c _PyEval_SetTrace reentrant -
Python/import.c import_find_and_load accumulated -
Python/import.c import_find_and_load import_level -
Python/modsupport.c - _Py_PackageContext -
Python/thread_pthread_stubs.h - py_tls_entries -
Python/pyfpe.c - PyFPE_counter -
Expand Down
0