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.
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);
}