summaryrefslogtreecommitdiffstats
path: root/Python/importdl.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/importdl.c')
-rw-r--r--Python/importdl.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/Python/importdl.c b/Python/importdl.c
index 91fa06f..6dafb45 100644
--- a/Python/importdl.c
+++ b/Python/importdl.c
@@ -99,7 +99,7 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
#endif
PyObject *name_unicode = NULL, *name = NULL, *path = NULL, *m = NULL;
const char *name_buf, *hook_prefix;
- const char *oldcontext;
+ const char *oldcontext, *newcontext;
dl_funcptr exportfunc;
PyModuleDef *def;
PyModInitFunction p0;
@@ -113,6 +113,10 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
"spec.name must be a string");
goto error;
}
+ newcontext = PyUnicode_AsUTF8(name_unicode);
+ if (newcontext == NULL) {
+ goto error;
+ }
name = get_encoded_name(name_unicode, &hook_prefix);
if (name == NULL) {
@@ -160,16 +164,9 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
p0 = (PyModInitFunction)exportfunc;
/* Package context is needed for single-phase init */
-#define _Py_PackageContext (_PyRuntime.imports.pkgcontext)
- oldcontext = _Py_PackageContext;
- _Py_PackageContext = PyUnicode_AsUTF8(name_unicode);
- if (_Py_PackageContext == NULL) {
- _Py_PackageContext = oldcontext;
- goto error;
- }
+ oldcontext = _PyImport_SwapPackageContext(newcontext);
m = _PyImport_InitFunc_TrampolineCall(p0);
- _Py_PackageContext = oldcontext;
-#undef _Py_PackageContext
+ _PyImport_SwapPackageContext(oldcontext);
if (m == NULL) {
if (!PyErr_Occurred()) {