mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-38631: Avoid Py_FatalError() in PyModule_Create2() (GH-18212)
If PyModule_Create2() is called when the Python import machinery is not initialized, it now raises a SystemError and returns NULL, instead of calling Py_FatalError() which aborts the process. The caller must be prepared to handle NULL anyway.
This commit is contained in:
parent
4a46adc774
commit
a94c6b61aa
1 changed files with 5 additions and 2 deletions
|
@ -173,8 +173,11 @@ _add_methods_to_object(PyObject *module, PyObject *name, PyMethodDef *functions)
|
||||||
PyObject *
|
PyObject *
|
||||||
PyModule_Create2(struct PyModuleDef* module, int module_api_version)
|
PyModule_Create2(struct PyModuleDef* module, int module_api_version)
|
||||||
{
|
{
|
||||||
if (!_PyImport_IsInitialized(_PyInterpreterState_Get()))
|
if (!_PyImport_IsInitialized(_PyInterpreterState_Get())) {
|
||||||
Py_FatalError("Python import machinery not initialized");
|
PyErr_SetString(PyExc_SystemError,
|
||||||
|
"Python import machinery not initialized");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return _PyModule_CreateInitialized(module, module_api_version);
|
return _PyModule_CreateInitialized(module, module_api_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue