mirror of
https://github.com/python/cpython.git
synced 2025-11-01 14:11:41 +00:00
gh-117953: Add Internal struct _Py_ext_module_loader_info (gh-118194)
This helps with a later change that splits up _PyImport_LoadDynamicModuleWithSpec().
This commit is contained in:
parent
9b280ab0ab
commit
5865fa5f9b
3 changed files with 180 additions and 94 deletions
|
|
@ -14,10 +14,38 @@ extern "C" {
|
||||||
|
|
||||||
extern const char *_PyImport_DynLoadFiletab[];
|
extern const char *_PyImport_DynLoadFiletab[];
|
||||||
|
|
||||||
extern PyObject *_PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *);
|
|
||||||
|
|
||||||
typedef PyObject *(*PyModInitFunction)(void);
|
typedef PyObject *(*PyModInitFunction)(void);
|
||||||
|
|
||||||
|
struct _Py_ext_module_loader_info {
|
||||||
|
PyObject *filename;
|
||||||
|
#ifndef MS_WINDOWS
|
||||||
|
PyObject *filename_encoded;
|
||||||
|
#endif
|
||||||
|
PyObject *name;
|
||||||
|
PyObject *name_encoded;
|
||||||
|
/* path is always a borrowed ref of name or filename,
|
||||||
|
* depending on if it's builtin or not. */
|
||||||
|
PyObject *path;
|
||||||
|
const char *hook_prefix;
|
||||||
|
const char *newcontext;
|
||||||
|
};
|
||||||
|
extern void _Py_ext_module_loader_info_clear(
|
||||||
|
struct _Py_ext_module_loader_info *info);
|
||||||
|
extern int _Py_ext_module_loader_info_init(
|
||||||
|
struct _Py_ext_module_loader_info *info,
|
||||||
|
PyObject *name,
|
||||||
|
PyObject *filename);
|
||||||
|
extern int _Py_ext_module_loader_info_init_from_spec(
|
||||||
|
struct _Py_ext_module_loader_info *info,
|
||||||
|
PyObject *spec);
|
||||||
|
|
||||||
|
extern PyObject *_PyImport_LoadDynamicModuleWithSpec(
|
||||||
|
struct _Py_ext_module_loader_info *info,
|
||||||
|
PyObject *spec,
|
||||||
|
FILE *fp);
|
||||||
|
|
||||||
|
|
||||||
/* Max length of module suffix searched for -- accommodates "module.slb" */
|
/* Max length of module suffix searched for -- accommodates "module.slb" */
|
||||||
#define MAXSUFFIXSIZE 12
|
#define MAXSUFFIXSIZE 12
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1328,11 +1328,11 @@ _PyImport_FixupExtensionObject(PyObject *mod, PyObject *name,
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
import_find_extension(PyThreadState *tstate, PyObject *name,
|
import_find_extension(PyThreadState *tstate,
|
||||||
PyObject *path)
|
struct _Py_ext_module_loader_info *info)
|
||||||
{
|
{
|
||||||
/* Only single-phase init modules will be in the cache. */
|
/* Only single-phase init modules will be in the cache. */
|
||||||
PyModuleDef *def = _extensions_cache_get(path, name);
|
PyModuleDef *def = _extensions_cache_get(info->path, info->name);
|
||||||
if (def == NULL) {
|
if (def == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -1340,7 +1340,7 @@ import_find_extension(PyThreadState *tstate, PyObject *name,
|
||||||
/* It may have been successfully imported previously
|
/* It may have been successfully imported previously
|
||||||
in an interpreter that allows legacy modules
|
in an interpreter that allows legacy modules
|
||||||
but is not allowed in the current interpreter. */
|
but is not allowed in the current interpreter. */
|
||||||
const char *name_buf = PyUnicode_AsUTF8(name);
|
const char *name_buf = PyUnicode_AsUTF8(info->name);
|
||||||
assert(name_buf != NULL);
|
assert(name_buf != NULL);
|
||||||
if (_PyImport_CheckSubinterpIncompatibleExtensionAllowed(name_buf) < 0) {
|
if (_PyImport_CheckSubinterpIncompatibleExtensionAllowed(name_buf) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -1355,12 +1355,13 @@ import_find_extension(PyThreadState *tstate, PyObject *name,
|
||||||
if (m_copy == NULL) {
|
if (m_copy == NULL) {
|
||||||
/* It might be a core module (e.g. sys & builtins),
|
/* It might be a core module (e.g. sys & builtins),
|
||||||
for which we don't set m_copy. */
|
for which we don't set m_copy. */
|
||||||
m_copy = get_core_module_dict(tstate->interp, name, path);
|
m_copy = get_core_module_dict(
|
||||||
|
tstate->interp, info->name, info->path);
|
||||||
if (m_copy == NULL) {
|
if (m_copy == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mod = import_add_module(tstate, name);
|
mod = import_add_module(tstate, info->name);
|
||||||
if (mod == NULL) {
|
if (mod == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -1378,15 +1379,16 @@ import_find_extension(PyThreadState *tstate, PyObject *name,
|
||||||
if (def->m_base.m_init == NULL)
|
if (def->m_base.m_init == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
mod = def->m_base.m_init();
|
mod = def->m_base.m_init();
|
||||||
if (mod == NULL)
|
if (mod == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
if (PyObject_SetItem(modules, name, mod) == -1) {
|
}
|
||||||
|
if (PyObject_SetItem(modules, info->name, mod) == -1) {
|
||||||
Py_DECREF(mod);
|
Py_DECREF(mod);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_modules_by_index_set(tstate->interp, def, mod) < 0) {
|
if (_modules_by_index_set(tstate->interp, def, mod) < 0) {
|
||||||
PyMapping_DelItem(modules, name);
|
PyMapping_DelItem(modules, info->name);
|
||||||
Py_DECREF(mod);
|
Py_DECREF(mod);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -1394,7 +1396,7 @@ import_find_extension(PyThreadState *tstate, PyObject *name,
|
||||||
int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose;
|
int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose;
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
PySys_FormatStderr("import %U # previously loaded (%R)\n",
|
PySys_FormatStderr("import %U # previously loaded (%R)\n",
|
||||||
name, path);
|
info->name, info->path);
|
||||||
}
|
}
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
@ -1505,44 +1507,56 @@ static PyObject*
|
||||||
create_builtin(PyThreadState *tstate, PyObject *name, PyObject *spec)
|
create_builtin(PyThreadState *tstate, PyObject *name, PyObject *spec)
|
||||||
{
|
{
|
||||||
PyModuleDef *def = NULL;
|
PyModuleDef *def = NULL;
|
||||||
PyObject *mod = import_find_extension(tstate, name, name);
|
|
||||||
|
struct _Py_ext_module_loader_info info;
|
||||||
|
if (_Py_ext_module_loader_info_init(&info, name, NULL) < 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject *mod = import_find_extension(tstate, &info);
|
||||||
if (mod || _PyErr_Occurred(tstate)) {
|
if (mod || _PyErr_Occurred(tstate)) {
|
||||||
return mod;
|
goto finally;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct _inittab *found = NULL;
|
struct _inittab *found = NULL;
|
||||||
for (struct _inittab *p = INITTAB; p->name != NULL; p++) {
|
for (struct _inittab *p = INITTAB; p->name != NULL; p++) {
|
||||||
if (_PyUnicode_EqualToASCIIString(name, p->name)) {
|
if (_PyUnicode_EqualToASCIIString(info.name, p->name)) {
|
||||||
found = p;
|
found = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found == NULL) {
|
if (found == NULL) {
|
||||||
// not found
|
// not found
|
||||||
Py_RETURN_NONE;
|
mod = Py_NewRef(Py_None);
|
||||||
|
goto finally;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyModInitFunction p0 = (PyModInitFunction)found->initfunc;
|
PyModInitFunction p0 = (PyModInitFunction)found->initfunc;
|
||||||
if (p0 == NULL) {
|
if (p0 == NULL) {
|
||||||
/* Cannot re-init internal module ("sys" or "builtins") */
|
/* Cannot re-init internal module ("sys" or "builtins") */
|
||||||
assert(is_core_module(tstate->interp, name, name));
|
assert(is_core_module(tstate->interp, info.name, info.path));
|
||||||
return import_add_module(tstate, name);
|
mod = import_add_module(tstate, info.name);
|
||||||
|
goto finally;
|
||||||
}
|
}
|
||||||
|
|
||||||
mod = p0();
|
mod = p0();
|
||||||
if (mod == NULL) {
|
if (mod == NULL) {
|
||||||
return NULL;
|
goto finally;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PyObject_TypeCheck(mod, &PyModuleDef_Type)) {
|
if (PyObject_TypeCheck(mod, &PyModuleDef_Type)) {
|
||||||
def = (PyModuleDef*)mod;
|
def = (PyModuleDef*)mod;
|
||||||
assert(!is_singlephase(def));
|
assert(!is_singlephase(def));
|
||||||
return PyModule_FromDefAndSpec(def, spec);
|
mod = PyModule_FromDefAndSpec(def, spec);
|
||||||
|
if (mod == NULL) {
|
||||||
|
goto finally;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(PyModule_Check(mod));
|
assert(PyModule_Check(mod));
|
||||||
def = PyModule_GetDef(mod);
|
def = PyModule_GetDef(mod);
|
||||||
if (def == NULL) {
|
if (def == NULL) {
|
||||||
return NULL;
|
Py_CLEAR(mod);
|
||||||
|
goto finally;
|
||||||
}
|
}
|
||||||
assert(is_singlephase(def));
|
assert(is_singlephase(def));
|
||||||
|
|
||||||
|
|
@ -1553,23 +1567,30 @@ create_builtin(PyThreadState *tstate, PyObject *name, PyObject *spec)
|
||||||
// gh-88216: Extensions and def->m_base.m_copy can be updated
|
// gh-88216: Extensions and def->m_base.m_copy can be updated
|
||||||
// when the extension module doesn't support sub-interpreters.
|
// when the extension module doesn't support sub-interpreters.
|
||||||
if (def->m_size == -1
|
if (def->m_size == -1
|
||||||
&& !is_core_module(tstate->interp, name, name))
|
&& !is_core_module(tstate->interp, info.name, info.path))
|
||||||
{
|
{
|
||||||
singlephase.m_dict = PyModule_GetDict(mod);
|
singlephase.m_dict = PyModule_GetDict(mod);
|
||||||
assert(singlephase.m_dict != NULL);
|
assert(singlephase.m_dict != NULL);
|
||||||
}
|
}
|
||||||
if (update_global_state_for_extension(
|
if (update_global_state_for_extension(
|
||||||
tstate, name, name, def, &singlephase) < 0)
|
tstate, info.name, info.path, def, &singlephase) < 0)
|
||||||
{
|
{
|
||||||
return NULL;
|
Py_CLEAR(mod);
|
||||||
|
goto finally;
|
||||||
}
|
}
|
||||||
PyObject *modules = get_modules_dict(tstate, true);
|
PyObject *modules = get_modules_dict(tstate, true);
|
||||||
if (finish_singlephase_extension(tstate, mod, def, name, modules) < 0) {
|
if (finish_singlephase_extension(
|
||||||
return NULL;
|
tstate, mod, def, info.name, modules) < 0)
|
||||||
|
{
|
||||||
|
Py_CLEAR(mod);
|
||||||
|
goto finally;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
finally:
|
||||||
|
_Py_ext_module_loader_info_clear(&info);
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************/
|
/*****************************/
|
||||||
|
|
@ -3878,28 +3899,22 @@ static PyObject *
|
||||||
_imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
|
_imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
|
||||||
/*[clinic end generated code: output=83249b827a4fde77 input=c31b954f4cf4e09d]*/
|
/*[clinic end generated code: output=83249b827a4fde77 input=c31b954f4cf4e09d]*/
|
||||||
{
|
{
|
||||||
PyObject *mod, *name, *filename;
|
PyObject *mod = NULL;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
name = PyObject_GetAttrString(spec, "name");
|
struct _Py_ext_module_loader_info info;
|
||||||
if (name == NULL) {
|
if (_Py_ext_module_loader_info_init_from_spec(&info, spec) < 0) {
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
filename = PyObject_GetAttrString(spec, "origin");
|
|
||||||
if (filename == NULL) {
|
|
||||||
Py_DECREF(name);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyThreadState *tstate = _PyThreadState_GET();
|
PyThreadState *tstate = _PyThreadState_GET();
|
||||||
mod = import_find_extension(tstate, name, filename);
|
mod = import_find_extension(tstate, &info);
|
||||||
if (mod != NULL || _PyErr_Occurred(tstate)) {
|
if (mod != NULL || _PyErr_Occurred(tstate)) {
|
||||||
assert(mod == NULL || !_PyErr_Occurred(tstate));
|
assert(mod == NULL || !_PyErr_Occurred(tstate));
|
||||||
goto finally;
|
goto finally;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PySys_Audit("import", "OOOOO", name, filename,
|
if (PySys_Audit("import", "OOOOO", info.name, info.filename,
|
||||||
Py_None, Py_None, Py_None) < 0)
|
Py_None, Py_None, Py_None) < 0)
|
||||||
{
|
{
|
||||||
goto finally;
|
goto finally;
|
||||||
|
|
@ -3911,7 +3926,7 @@ _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
|
||||||
* _PyImport_GetModInitFunc(), but it isn't clear if the intervening
|
* _PyImport_GetModInitFunc(), but it isn't clear if the intervening
|
||||||
* code relies on fp still being open. */
|
* code relies on fp still being open. */
|
||||||
if (file != NULL) {
|
if (file != NULL) {
|
||||||
fp = _Py_fopen_obj(filename, "r");
|
fp = _Py_fopen_obj(info.filename, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
goto finally;
|
goto finally;
|
||||||
}
|
}
|
||||||
|
|
@ -3920,7 +3935,7 @@ _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
|
||||||
fp = NULL;
|
fp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mod = _PyImport_LoadDynamicModuleWithSpec(spec, fp);
|
mod = _PyImport_LoadDynamicModuleWithSpec(&info, spec, fp);
|
||||||
|
|
||||||
// XXX Shouldn't this happen in the error cases too.
|
// XXX Shouldn't this happen in the error cases too.
|
||||||
if (fp) {
|
if (fp) {
|
||||||
|
|
@ -3928,8 +3943,7 @@ _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
|
||||||
}
|
}
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
Py_DECREF(name);
|
_Py_ext_module_loader_info_clear(&info);
|
||||||
Py_DECREF(filename);
|
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,57 +93,108 @@ get_encoded_name(PyObject *name, const char **hook_prefix) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *
|
void
|
||||||
_PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
|
_Py_ext_module_loader_info_clear(struct _Py_ext_module_loader_info *info)
|
||||||
{
|
{
|
||||||
|
Py_CLEAR(info->filename);
|
||||||
#ifndef MS_WINDOWS
|
#ifndef MS_WINDOWS
|
||||||
PyObject *filename_bytes = NULL;
|
Py_CLEAR(info->filename_encoded);
|
||||||
const char *filename_buf;
|
|
||||||
#endif
|
#endif
|
||||||
PyObject *name_unicode = NULL, *name = NULL, *filename = NULL, *m = NULL;
|
Py_CLEAR(info->name);
|
||||||
const char *name_buf, *hook_prefix;
|
Py_CLEAR(info->name_encoded);
|
||||||
const char *oldcontext, *newcontext;
|
|
||||||
dl_funcptr exportfunc;
|
|
||||||
PyModuleDef *def;
|
|
||||||
PyModInitFunction p0;
|
|
||||||
|
|
||||||
name_unicode = PyObject_GetAttrString(spec, "name");
|
|
||||||
if (name_unicode == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
if (!PyUnicode_Check(name_unicode)) {
|
|
||||||
|
int
|
||||||
|
_Py_ext_module_loader_info_init(struct _Py_ext_module_loader_info *p_info,
|
||||||
|
PyObject *name, PyObject *filename)
|
||||||
|
{
|
||||||
|
struct _Py_ext_module_loader_info info = {0};
|
||||||
|
|
||||||
|
assert(name != NULL);
|
||||||
|
if (!PyUnicode_Check(name)) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"spec.name must be a string");
|
"module name must be a string");
|
||||||
goto error;
|
_Py_ext_module_loader_info_clear(&info);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
newcontext = PyUnicode_AsUTF8(name_unicode);
|
info.name = Py_NewRef(name);
|
||||||
if (newcontext == NULL) {
|
|
||||||
goto error;
|
info.name_encoded = get_encoded_name(info.name, &info.hook_prefix);
|
||||||
|
if (info.name_encoded == NULL) {
|
||||||
|
_Py_ext_module_loader_info_clear(&info);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = get_encoded_name(name_unicode, &hook_prefix);
|
info.newcontext = PyUnicode_AsUTF8(info.name);
|
||||||
|
if (info.newcontext == NULL) {
|
||||||
|
_Py_ext_module_loader_info_clear(&info);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filename != NULL) {
|
||||||
|
if (!PyUnicode_Check(filename)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
"module filename must be a string");
|
||||||
|
_Py_ext_module_loader_info_clear(&info);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
info.filename = Py_NewRef(filename);
|
||||||
|
|
||||||
|
#ifndef MS_WINDOWS
|
||||||
|
info.filename_encoded = PyUnicode_EncodeFSDefault(info.filename);
|
||||||
|
if (info.filename_encoded == NULL) {
|
||||||
|
_Py_ext_module_loader_info_clear(&info);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
info.path = info.filename;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
info.path = info.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
*p_info = info;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
_Py_ext_module_loader_info_init_from_spec(
|
||||||
|
struct _Py_ext_module_loader_info *p_info,
|
||||||
|
PyObject *spec)
|
||||||
|
{
|
||||||
|
PyObject *name = PyObject_GetAttrString(spec, "name");
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
goto error;
|
return -1;
|
||||||
}
|
}
|
||||||
name_buf = PyBytes_AS_STRING(name);
|
PyObject *filename = PyObject_GetAttrString(spec, "origin");
|
||||||
|
|
||||||
filename = PyObject_GetAttrString(spec, "origin");
|
|
||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
goto error;
|
return -1;
|
||||||
}
|
}
|
||||||
|
return _Py_ext_module_loader_info_init(p_info, name, filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
_PyImport_LoadDynamicModuleWithSpec(struct _Py_ext_module_loader_info *info,
|
||||||
|
PyObject *spec, FILE *fp)
|
||||||
|
{
|
||||||
|
PyObject *m = NULL;
|
||||||
|
const char *name_buf = PyBytes_AS_STRING(info->name_encoded);
|
||||||
|
const char *oldcontext;
|
||||||
|
dl_funcptr exportfunc;
|
||||||
|
PyModInitFunction p0;
|
||||||
|
PyModuleDef *def;
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
exportfunc = _PyImport_FindSharedFuncptrWindows(
|
exportfunc = _PyImport_FindSharedFuncptrWindows(
|
||||||
hook_prefix, name_buf, filename, fp);
|
info->hook_prefix, name_buf, info->filename, fp);
|
||||||
#else
|
#else
|
||||||
filename_bytes = PyUnicode_EncodeFSDefault(filename);
|
{
|
||||||
if (filename_bytes == NULL) {
|
const char *path_buf = PyBytes_AS_STRING(info->filename_encoded);
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
filename_buf = PyBytes_AS_STRING(filename_bytes);
|
|
||||||
exportfunc = _PyImport_FindSharedFuncptr(
|
exportfunc = _PyImport_FindSharedFuncptr(
|
||||||
hook_prefix, name_buf, filename_buf, fp);
|
info->hook_prefix, name_buf, path_buf, fp);
|
||||||
Py_DECREF(filename_bytes);
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (exportfunc == NULL) {
|
if (exportfunc == NULL) {
|
||||||
|
|
@ -152,19 +203,19 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
|
||||||
msg = PyUnicode_FromFormat(
|
msg = PyUnicode_FromFormat(
|
||||||
"dynamic module does not define "
|
"dynamic module does not define "
|
||||||
"module export function (%s_%s)",
|
"module export function (%s_%s)",
|
||||||
hook_prefix, name_buf);
|
info->hook_prefix, name_buf);
|
||||||
if (msg == NULL)
|
if (msg != NULL) {
|
||||||
goto error;
|
PyErr_SetImportError(msg, info->name, info->filename);
|
||||||
PyErr_SetImportError(msg, name_unicode, filename);
|
|
||||||
Py_DECREF(msg);
|
Py_DECREF(msg);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
p0 = (PyModInitFunction)exportfunc;
|
p0 = (PyModInitFunction)exportfunc;
|
||||||
|
|
||||||
/* Package context is needed for single-phase init */
|
/* Package context is needed for single-phase init */
|
||||||
oldcontext = _PyImport_SwapPackageContext(newcontext);
|
oldcontext = _PyImport_SwapPackageContext(info->newcontext);
|
||||||
m = p0();
|
m = p0();
|
||||||
_PyImport_SwapPackageContext(oldcontext);
|
_PyImport_SwapPackageContext(oldcontext);
|
||||||
|
|
||||||
|
|
@ -195,9 +246,6 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (PyObject_TypeCheck(m, &PyModuleDef_Type)) {
|
if (PyObject_TypeCheck(m, &PyModuleDef_Type)) {
|
||||||
Py_DECREF(name_unicode);
|
|
||||||
Py_DECREF(name);
|
|
||||||
Py_DECREF(filename);
|
|
||||||
return PyModule_FromDefAndSpec((PyModuleDef*)m, spec);
|
return PyModule_FromDefAndSpec((PyModuleDef*)m, spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,7 +255,7 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hook_prefix == nonascii_prefix) {
|
if (info->hook_prefix == nonascii_prefix) {
|
||||||
/* don't allow legacy init for non-ASCII module names */
|
/* don't allow legacy init for non-ASCII module names */
|
||||||
PyErr_Format(
|
PyErr_Format(
|
||||||
PyExc_SystemError,
|
PyExc_SystemError,
|
||||||
|
|
@ -227,24 +275,20 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
|
||||||
def->m_base.m_init = p0;
|
def->m_base.m_init = p0;
|
||||||
|
|
||||||
/* Remember the filename as the __file__ attribute */
|
/* Remember the filename as the __file__ attribute */
|
||||||
if (PyModule_AddObjectRef(m, "__file__", filename) < 0) {
|
if (PyModule_AddObjectRef(m, "__file__", info->filename) < 0) {
|
||||||
PyErr_Clear(); /* Not important enough to report */
|
PyErr_Clear(); /* Not important enough to report */
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *modules = PyImport_GetModuleDict();
|
PyObject *modules = PyImport_GetModuleDict();
|
||||||
if (_PyImport_FixupExtensionObject(m, name_unicode, filename, modules) < 0)
|
if (_PyImport_FixupExtensionObject(
|
||||||
|
m, info->name, info->filename, modules) < 0)
|
||||||
|
{
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
Py_DECREF(name_unicode);
|
|
||||||
Py_DECREF(name);
|
|
||||||
Py_DECREF(filename);
|
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
Py_DECREF(name_unicode);
|
|
||||||
Py_XDECREF(name);
|
|
||||||
Py_XDECREF(filename);
|
|
||||||
Py_XDECREF(m);
|
Py_XDECREF(m);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue