mirror of https://github.com/python/cpython
bpo-1635741: Port faulthandler module to multiphase initialization (GH-21294)
This commit is contained in:
parent
3549ca313a
commit
c0b214bc08
|
@ -0,0 +1 @@
|
||||||
|
Port :mod:`faulthandler` to multiphase initialization.
|
|
@ -1291,59 +1291,55 @@ static PyMethodDef module_methods[] = {
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
PyExec_faulthandler(PyObject *module) {
|
||||||
|
/* Add constants for unit tests */
|
||||||
|
#ifdef MS_WINDOWS
|
||||||
|
/* RaiseException() codes (prefixed by an underscore) */
|
||||||
|
if (PyModule_AddIntConstant(module, "_EXCEPTION_ACCESS_VIOLATION",
|
||||||
|
EXCEPTION_ACCESS_VIOLATION)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (PyModule_AddIntConstant(module, "_EXCEPTION_INT_DIVIDE_BY_ZERO",
|
||||||
|
EXCEPTION_INT_DIVIDE_BY_ZERO)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (PyModule_AddIntConstant(module, "_EXCEPTION_STACK_OVERFLOW",
|
||||||
|
EXCEPTION_STACK_OVERFLOW)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* RaiseException() flags (prefixed by an underscore) */
|
||||||
|
if (PyModule_AddIntConstant(module, "_EXCEPTION_NONCONTINUABLE",
|
||||||
|
EXCEPTION_NONCONTINUABLE)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (PyModule_AddIntConstant(module, "_EXCEPTION_NONCONTINUABLE_EXCEPTION",
|
||||||
|
EXCEPTION_NONCONTINUABLE_EXCEPTION)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyModuleDef_Slot faulthandler_slots[] = {
|
||||||
|
{Py_mod_exec, PyExec_faulthandler},
|
||||||
|
{0, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
static struct PyModuleDef module_def = {
|
static struct PyModuleDef module_def = {
|
||||||
PyModuleDef_HEAD_INIT,
|
PyModuleDef_HEAD_INIT,
|
||||||
"faulthandler",
|
.m_name = "faulthandler",
|
||||||
module_doc,
|
.m_doc = module_doc,
|
||||||
0, /* non-negative size to be able to unload the module */
|
.m_methods = module_methods,
|
||||||
module_methods,
|
.m_traverse = faulthandler_traverse,
|
||||||
NULL,
|
.m_slots = faulthandler_slots
|
||||||
faulthandler_traverse,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PyMODINIT_FUNC
|
PyMODINIT_FUNC
|
||||||
PyInit_faulthandler(void)
|
PyInit_faulthandler(void)
|
||||||
{
|
{
|
||||||
PyObject *m = PyModule_Create(&module_def);
|
return PyModuleDef_Init(&module_def);
|
||||||
if (m == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
/* Add constants for unit tests */
|
|
||||||
#ifdef MS_WINDOWS
|
|
||||||
/* RaiseException() codes (prefixed by an underscore) */
|
|
||||||
if (PyModule_AddIntConstant(m, "_EXCEPTION_ACCESS_VIOLATION",
|
|
||||||
EXCEPTION_ACCESS_VIOLATION)) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (PyModule_AddIntConstant(m, "_EXCEPTION_INT_DIVIDE_BY_ZERO",
|
|
||||||
EXCEPTION_INT_DIVIDE_BY_ZERO)) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (PyModule_AddIntConstant(m, "_EXCEPTION_STACK_OVERFLOW",
|
|
||||||
EXCEPTION_STACK_OVERFLOW)) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* RaiseException() flags (prefixed by an underscore) */
|
|
||||||
if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE",
|
|
||||||
EXCEPTION_NONCONTINUABLE)) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (PyModule_AddIntConstant(m, "_EXCEPTION_NONCONTINUABLE_EXCEPTION",
|
|
||||||
EXCEPTION_NONCONTINUABLE_EXCEPTION)) {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return m;
|
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
|
||||||
error:
|
|
||||||
Py_DECREF(m);
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
Loading…
Reference in New Issue