mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Issue #24769: Interpreter now starts properly when dynamic loading
is disabled. Patch by Petr Viktorin.
This commit is contained in:
parent
7250d02b73
commit
1df0b35e3d
5 changed files with 80 additions and 26 deletions
|
@ -1943,6 +1943,34 @@ _imp_is_frozen_impl(PyModuleDef *module, PyObject *name)
|
|||
return PyBool_FromLong((long) (p == NULL ? 0 : p->size));
|
||||
}
|
||||
|
||||
/* Common implementation for _imp.exec_dynamic and _imp.exec_builtin */
|
||||
static int
|
||||
exec_builtin_or_dynamic(PyObject *mod) {
|
||||
PyModuleDef *def;
|
||||
void *state;
|
||||
|
||||
if (!PyModule_Check(mod)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
def = PyModule_GetDef(mod);
|
||||
if (def == NULL) {
|
||||
if (PyErr_Occurred()) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
state = PyModule_GetState(mod);
|
||||
if (PyErr_Occurred()) {
|
||||
return -1;
|
||||
}
|
||||
if (state) {
|
||||
/* Already initialized; skip reload */
|
||||
return 0;
|
||||
}
|
||||
return PyModule_ExecDef(mod, def);
|
||||
}
|
||||
|
||||
#ifdef HAVE_DYNAMIC_LOADING
|
||||
|
||||
/*[clinic input]
|
||||
|
@ -2014,34 +2042,28 @@ static int
|
|||
_imp_exec_dynamic_impl(PyModuleDef *module, PyObject *mod)
|
||||
/*[clinic end generated code: output=4b84f1301b22d4bd input=9fdbfcb250280d3a]*/
|
||||
{
|
||||
PyModuleDef *def;
|
||||
void *state;
|
||||
|
||||
if (!PyModule_Check(mod)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
def = PyModule_GetDef(mod);
|
||||
if (def == NULL) {
|
||||
if (PyErr_Occurred()) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
state = PyModule_GetState(mod);
|
||||
if (PyErr_Occurred()) {
|
||||
return -1;
|
||||
}
|
||||
if (state) {
|
||||
/* Already initialized; skip reload */
|
||||
return 0;
|
||||
}
|
||||
return PyModule_ExecDef(mod, def);
|
||||
return exec_builtin_or_dynamic(mod);
|
||||
}
|
||||
|
||||
|
||||
#endif /* HAVE_DYNAMIC_LOADING */
|
||||
|
||||
/*[clinic input]
|
||||
_imp.exec_builtin -> int
|
||||
|
||||
mod: object
|
||||
/
|
||||
|
||||
Initialize a built-in module.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
_imp_exec_builtin_impl(PyModuleDef *module, PyObject *mod)
|
||||
/*[clinic end generated code: output=215e99876a27e284 input=77ebec0c2a10ecca]*/
|
||||
{
|
||||
return exec_builtin_or_dynamic(mod);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
dump buffer
|
||||
[clinic start generated code]*/
|
||||
|
@ -2064,6 +2086,7 @@ static PyMethodDef imp_methods[] = {
|
|||
_IMP_IS_FROZEN_METHODDEF
|
||||
_IMP_CREATE_DYNAMIC_METHODDEF
|
||||
_IMP_EXEC_DYNAMIC_METHODDEF
|
||||
_IMP_EXEC_BUILTIN_METHODDEF
|
||||
_IMP__FIX_CO_FILENAME_METHODDEF
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue