diff options
author | Dong-hee Na <donghee.na92@gmail.com> | 2020-07-03 16:36:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-03 16:36:47 (GMT) |
commit | c0b214bc08f0da89e5b2e4b8cc9f07783833d6b8 (patch) | |
tree | cea7de4362e4a4c0062cf4bf73b9b2372c20cbaa | |
parent | 3549ca313a6103a3adb281ef3a849298b7d7f72c (diff) | |
download | cpython-c0b214bc08f0da89e5b2e4b8cc9f07783833d6b8.zip cpython-c0b214bc08f0da89e5b2e4b8cc9f07783833d6b8.tar.gz cpython-c0b214bc08f0da89e5b2e4b8cc9f07783833d6b8.tar.bz2 |
bpo-1635741: Port faulthandler module to multiphase initialization (GH-21294)
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2020-07-03-23-10-02.bpo-1635741.F5coWe.rst | 1 | ||||
-rw-r--r-- | Modules/faulthandler.c | 66 |
2 files changed, 32 insertions, 35 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-07-03-23-10-02.bpo-1635741.F5coWe.rst b/Misc/NEWS.d/next/Core and Builtins/2020-07-03-23-10-02.bpo-1635741.F5coWe.rst new file mode 100644 index 0000000..927c8e5 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-07-03-23-10-02.bpo-1635741.F5coWe.rst @@ -0,0 +1 @@ +Port :mod:`faulthandler` to multiphase initialization. diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index e7a2850..67fe1ca 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -1291,59 +1291,55 @@ static PyMethodDef module_methods[] = { {NULL, NULL} /* sentinel */ }; -static struct PyModuleDef module_def = { - PyModuleDef_HEAD_INIT, - "faulthandler", - module_doc, - 0, /* non-negative size to be able to unload the module */ - module_methods, - NULL, - faulthandler_traverse, - NULL, - NULL -}; - -PyMODINIT_FUNC -PyInit_faulthandler(void) -{ - PyObject *m = PyModule_Create(&module_def); - if (m == NULL) - return NULL; - +static int +PyExec_faulthandler(PyObject *module) { /* Add constants for unit tests */ #ifdef MS_WINDOWS /* RaiseException() codes (prefixed by an underscore) */ - if (PyModule_AddIntConstant(m, "_EXCEPTION_ACCESS_VIOLATION", + if (PyModule_AddIntConstant(module, "_EXCEPTION_ACCESS_VIOLATION", EXCEPTION_ACCESS_VIOLATION)) { - goto error; + return -1; } - if (PyModule_AddIntConstant(m, "_EXCEPTION_INT_DIVIDE_BY_ZERO", + if (PyModule_AddIntConstant(module, "_EXCEPTION_INT_DIVIDE_BY_ZERO", EXCEPTION_INT_DIVIDE_BY_ZERO)) { - goto error; + return -1; } - if (PyModule_AddIntConstant(m, "_EXCEPTION_STACK_OVERFLOW", + if (PyModule_AddIntConstant(module, "_EXCEPTION_STACK_OVERFLOW", EXCEPTION_STACK_OVERFLOW)) { - goto error; + return -1; } /* RaiseException() flags (prefixed by an underscore) */ - if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE", + if (PyModule_AddIntConstant(module, "_EXCEPTION_NONCONTINUABLE", EXCEPTION_NONCONTINUABLE)) { - goto error; + return -1; } - if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE_EXCEPTION", + if (PyModule_AddIntConstant(module, "_EXCEPTION_NONCONTINUABLE_EXCEPTION", EXCEPTION_NONCONTINUABLE_EXCEPTION)) { - goto error; + return -1; } #endif + return 0; +} - return m; +static PyModuleDef_Slot faulthandler_slots[] = { + {Py_mod_exec, PyExec_faulthandler}, + {0, NULL} +}; -#ifdef MS_WINDOWS -error: - Py_DECREF(m); - return NULL; -#endif +static struct PyModuleDef module_def = { + PyModuleDef_HEAD_INIT, + .m_name = "faulthandler", + .m_doc = module_doc, + .m_methods = module_methods, + .m_traverse = faulthandler_traverse, + .m_slots = faulthandler_slots +}; + +PyMODINIT_FUNC +PyInit_faulthandler(void) +{ + return PyModuleDef_Init(&module_def); } static int |