8000 gh-117953: Add Internal struct _Py_ext_module_loader_info by ericsnowcurrently · Pull Request #118194 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-117953: Add Internal struct _Py_ext_module_loader_info #118194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Prev Previous commit
Next Next commit
Add info.newcontext.
  • Loading branch information
ericsnowcurrently committed Apr 24, 2024
commit d5f97e7e70b0c2f8298880d95da79b7b0e1995fa
1 change: 1 addition & 0 deletions Include/internal/pycore_importdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct _Py_ext_module_loader_info {
PyObject *name;
PyObject *name_encoded;
const char *hook_prefix;
const char *newcontext;
};
extern void _Py_ext_module_loader_info_clear(
struct _Py_ext_module_loader_info *info);
Expand Down
15 changes: 8 additions & 7 deletions Python/importdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ _Py_ext_module_loader_info_init_from_spec(
return -1;
}

info.newcontext = PyUnicode_AsUTF8(info.name);
if (info.newcontext == NULL) {
_Py_ext_module_loader_info_clear(&info);
return -1;
}

info.path = PyObject_GetAttrString(spec, "origin");
if (info.path == NULL) {
_Py_ext_module_loader_info_clear(&info);
Expand All @@ -152,16 +158,11 @@ _PyImport_LoadDynamicModuleWithSpec(struct _Py_ext_module_loader_info *info,
{
PyObject *m = NULL;
const char *name_buf = PyBytes_AS_STRING(info->name_encoded);
const char *oldcontext, *newcontext;
const char *oldcontext;
dl_funcptr exportfunc;
PyModInitFunction p0;
PyModuleDef *def;

newcontext = PyUnicode_AsUTF8(info->name);
if (newcontext == NULL) {
goto error;
}

#ifdef MS_WINDOWS
exportfunc = _PyImport_FindSharedFuncptrWindows(
info->hook_prefix, name_buf, info->path, fp);
Expand Down Expand Up @@ -191,7 +192,7 @@ _PyImport_LoadDynamicModuleWithSpec(struct _Py_ext_module_loader_info *info,
p0 = (PyModInitFunction)exportfunc;

/* Package context is needed for single-phase init */
oldcontext = _PyImport_SwapPackageContext(newcontext);
oldcontext = _PyImport_SwapPackageContext(info->newcontext);
m = p0();
_PyImport_SwapPackageContext(oldcontext);

Expand Down
0