Skip to content

Commit 8b4e216

Browse files
Make sure __file__ is set before m_copy gets populated.
1 parent 5627ad9 commit 8b4e216

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

Python/import.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3848,12 +3848,6 @@ _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
38483848
}
38493849

38503850
mod = _PyImport_LoadDynamicModuleWithSpec(spec, fp);
3851-
if (mod != NULL) {
3852-
/* Remember the filename as the __file__ attribute */
3853-
if (PyModule_AddObjectRef(mod, "__file__", filename) < 0) {
3854-
PyErr_Clear(); /* Not important enough to report */
3855-
}
3856-
}
38573851

38583852
// XXX Shouldn't this happen in the error cases too.
38593853
if (fp) {

Python/importdl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
226226
}
227227
def->m_base.m_init = p0;
228228

229+
/* Remember the filename as the __file__ attribute */
230+
if (PyModule_AddObjectRef(m, "__file__", filename) < 0) {
231+
PyErr_Clear(); /* Not important enough to report */
232+
}
233+
229234
PyObject *modules = PyImport_GetModuleDict();
230235
if (_PyImport_FixupExtensionObject(m, name_unicode, filename, modules) < 0)
231236
goto error;

0 commit comments

Comments
 (0)