Skip to content

Commit d5f97e7

Browse files
Add info.newcontext.
1 parent 427280f commit d5f97e7

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

Include/internal/pycore_importdl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct _Py_ext_module_loader_info {
2525
PyObject *name;
2626
PyObject *name_encoded;
2727
const char *hook_prefix;
28+
const char *newcontext;
2829
};
2930
extern void _Py_ext_module_loader_info_clear(
3031
struct _Py_ext_module_loader_info *info);

Python/importdl.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ _Py_ext_module_loader_info_init_from_spec(
128128
return -1;
129129
}
130130

131+
info.newcontext = PyUnicode_AsUTF8(info.name);
132+
if (info.newcontext == NULL) {
133+
_Py_ext_module_loader_info_clear(&info);
134+
return -1;
135+
}
136+
131137
info.path = PyObject_GetAttrString(spec, "origin");
132138
if (info.path == NULL) {
133139
_Py_ext_module_loader_info_clear(&info);
@@ -152,16 +158,11 @@ _PyImport_LoadDynamicModuleWithSpec(struct _Py_ext_module_loader_info *info,
152158
{
153159
PyObject *m = NULL;
154160
const char *name_buf = PyBytes_AS_STRING(info->name_encoded);
155-
const char *oldcontext, *newcontext;
161+
const char *oldcontext;
156162
dl_funcptr exportfunc;
157163
PyModInitFunction p0;
158164
PyModuleDef *def;
159165

160-
newcontext = PyUnicode_AsUTF8(info->name);
161-
if (newcontext == NULL) {
162-
goto error;
163-
}
164-
165166
#ifdef MS_WINDOWS
166167
exportfunc = _PyImport_FindSharedFuncptrWindows(
167168
info->hook_prefix, name_buf, info->path, fp);
@@ -191,7 +192,7 @@ _PyImport_LoadDynamicModuleWithSpec(struct _Py_ext_module_loader_info *info,
191192
p0 = (PyModInitFunction)exportfunc;
192193

193194
/* Package context is needed for single-phase init */
194-
oldcontext = _PyImport_SwapPackageContext(newcontext);
195+
oldcontext = _PyImport_SwapPackageContext(info->newcontext);
195196
m = p0();
196197
_PyImport_SwapPackageContext(oldcontext);
197198

0 commit comments

Comments
 (0)