Skip to content

bpo-1635741: Port faulthandler module to multiphase initialization #21294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Port :mod:`faulthandler` to multiphase initialization.
66 changes: 31 additions & 35 deletions Modules/faulthandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down