Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5874d8e

Browse filesBrowse files
Check the module returned by import_find_extension() to ensure single-phase init.
1 parent a9c7ad6 commit 5874d8e
Copy full SHA for 5874d8e

File tree

Expand file treeCollapse file tree

1 file changed

+14
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-6
lines changed

‎Python/import.c

Copy file name to clipboardExpand all lines: Python/import.c
+14-6Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,12 @@ create_builtin(PyThreadState *tstate, PyObject *name, PyObject *spec)
15571557
}
15581558

15591559
PyObject *mod = import_find_extension(tstate, &info);
1560-
if (mod || _PyErr_Occurred(tstate)) {
1560+
if (mod != NULL) {
1561+
assert(!_PyErr_Occurred(tstate));
1562+
assert(is_singlephase(_PyModule_GetDef(mod)));
1563+
goto finally;
1564+
}
1565+
else if (_PyErr_Occurred(tstate)) {
15611566
goto finally;
15621567
}
15631568

@@ -3943,20 +3948,23 @@ _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
39433948
/*[clinic end generated code: output=83249b827a4fde77 input=c31b954f4cf4e09d]*/
39443949
{
39453950
PyObject *mod = NULL;
3951+
PyThreadState *tstate = _PyThreadState_GET();
39463952

39473953
struct _Py_ext_module_loader_info info;
39483954
if (_Py_ext_module_loader_info_init_from_spec(&info, spec) < 0) {
39493955
return NULL;
39503956
}
39513957

3952-
PyThreadState *tstate = _PyThreadState_GET();
39533958
mod = import_find_extension(tstate, &info);
3954-
if (mod != NULL || _PyErr_Occurred(tstate)) {
3955-
assert(mod == NULL || !_PyErr_Occurred(tstate));
3959+
if (mod != NULL) {
3960+
assert(!_PyErr_Occurred(tstate));
3961+
assert(is_singlephase(_PyModule_GetDef(mod)));
39563962
goto finally;
39573963
}
3958-
3959-
/* Is multi-phase init or this is the first time being loaded. */
3964+
else if (_PyErr_Occurred(tstate)) {
3965+
goto finally;
3966+
}
3967+
/* Otherwise it must be multi-phase init or the first time it's loaded. */
39603968

39613969
if (PySys_Audit("import", "OOOOO", info.name, info.filename,
39623970
Py_None, Py_None, Py_None) < 0)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.