diff options
author | Victor Stinner <vstinner@python.org> | 2020-01-27 21:37:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-27 21:37:05 (GMT) |
commit | a94c6b61aa5c09237b8105e5aee638cd54197b6f (patch) | |
tree | ed5a216fbd3bee7050dfec1b18fd029a57a1f887 /Objects/moduleobject.c | |
parent | 4a46adc7746930c4589ee483cad88d3f8504c045 (diff) | |
download | cpython-a94c6b61aa5c09237b8105e5aee638cd54197b6f.zip cpython-a94c6b61aa5c09237b8105e5aee638cd54197b6f.tar.gz cpython-a94c6b61aa5c09237b8105e5aee638cd54197b6f.tar.bz2 |
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.
Diffstat (limited to 'Objects/moduleobject.c')
-rw-r--r-- | Objects/moduleobject.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 03c7381..912c258 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -173,8 +173,11 @@ _add_methods_to_object(PyObject *module, PyObject *name, PyMethodDef *functions) PyObject * PyModule_Create2(struct PyModuleDef* module, int module_api_version) { - if (!_PyImport_IsInitialized(_PyInterpreterState_Get())) - Py_FatalError("Python import machinery not initialized"); + if (!_PyImport_IsInitialized(_PyInterpreterState_Get())) { + PyErr_SetString(PyExc_SystemError, + "Python import machinery not initialized"); + return NULL; + } return _PyModule_CreateInitialized(module, module_api_version); } |