Skip to content

Commit bdd6358

Browse files
Isolate find_and_load.
1 parent b7a5dcf commit bdd6358

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

Include/internal/pycore_import.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ struct _import_runtime_state {
2121
This is initialized lazily in _PyImport_FixupExtensionObject().
2222
Modules are added there and looked up in _imp.find_extension(). */
2323
PyObject *extensions;
24-
struct {
25-
int import_level;
26-
_PyTime_t accumulated;
27-
int header;
28-
} find_and_load;
2924
/* Package context -- the full module name for package imports */
3025
const char * pkgcontext;
3126
};
@@ -68,6 +63,12 @@ struct _import_state {
6863
unsigned long thread;
6964
int level;
7065
} lock;
66+
/* diagnostic info in PyImport_ImportModuleLevelObject() */
67+
struct {
68+
int import_level;
69+
_PyTime_t accumulated;
70+
int header;
71+
} find_and_load;
7172
};
7273

7374
#ifdef HAVE_DLOPEN
@@ -91,6 +92,9 @@ struct _import_state {
9192
.thread = PYTHREAD_INVALID_THREAD_ID, \
9293
.level = 0, \
9394
}, \
95+
.find_and_load = { \
96+
.header = 1, \
97+
}, \
9498
}
9599

96100
extern void _PyImport_ClearCore(PyInterpreterState *interp);

Include/internal/pycore_runtime_init.h

-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ extern "C" {
3737
in accordance with the specification. */ \
3838
.autoTSSkey = Py_tss_NEEDS_INIT, \
3939
.parser = _parser_runtime_state_INIT, \
40-
.imports = { \
41-
.find_and_load = { \
42-
.header = 1, \
43-
}, \
44-
}, \
4540
.ceval = { \
4641
.perf = _PyEval_RUNTIME_PERF_INIT, \
4742
}, \

Python/import.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ static struct _inittab *inittab_copy = NULL;
5656
#define LAST_MODULE_INDEX _PyRuntime.imports.last_module_index
5757
#define EXTENSIONS _PyRuntime.imports.extensions
5858

59-
#define FIND_AND_LOAD _PyRuntime.imports.find_and_load
6059
#define PKGCONTEXT (_PyRuntime.imports.pkgcontext)
6160

6261

@@ -86,6 +85,9 @@ static struct _inittab *inittab_copy = NULL;
8685
#define IMPORT_LOCK_LEVEL(interp) \
8786
(interp)->imports.lock.level
8887

88+
#define FIND_AND_LOAD(interp) \
89+
(interp)->imports.find_and_load
90+
8991

9092
/*******************/
9193
/* the import lock */
@@ -2276,8 +2278,8 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
22762278
PyObject *mod = NULL;
22772279
PyInterpreterState *interp = tstate->interp;
22782280
int import_time = _PyInterpreterState_GetConfig(interp)->import_time;
2279-
#define import_level FIND_AND_LOAD.import_level
2280-
#define accumulated FIND_AND_LOAD.accumulated
2281+
#define import_level FIND_AND_LOAD(interp).import_level
2282+
#define accumulated FIND_AND_LOAD(interp).accumulated
22812283

22822284
_PyTime_t t1 = 0, accumulated_copy = accumulated;
22832285

@@ -2298,7 +2300,7 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name)
22982300
* _PyDict_GetItemIdWithError().
22992301
*/
23002302
if (import_time) {
2301-
#define header FIND_AND_LOAD.header
2303+
#define header FIND_AND_LOAD(interp).header
23022304
if (header) {
23032305
fputs("import time: self [us] | cumulative | imported package\n",
23042306
stderr);

0 commit comments

Comments
 (0)