@@ -1291,59 +1291,55 @@ static PyMethodDef module_methods[] = {
12911291 {NULL , NULL } /* sentinel */
12921292};
12931293
1294- static struct PyModuleDef module_def = {
1295- PyModuleDef_HEAD_INIT ,
1296- "faulthandler" ,
1297- module_doc ,
1298- 0 , /* non-negative size to be able to unload the module */
1299- module_methods ,
1300- NULL ,
1301- faulthandler_traverse ,
1302- NULL ,
1303- NULL
1304- };
1305-
1306- PyMODINIT_FUNC
1307- PyInit_faulthandler (void )
1308- {
1309- PyObject * m = PyModule_Create (& module_def );
1310- if (m == NULL )
1311- return NULL ;
1312-
1294+ static int
1295+ PyExec_faulthandler (PyObject * module ) {
13131296 /* Add constants for unit tests */
13141297#ifdef MS_WINDOWS
13151298 /* RaiseException() codes (prefixed by an underscore) */
1316- if (PyModule_AddIntConstant (m , "_EXCEPTION_ACCESS_VIOLATION" ,
1299+ if (PyModule_AddIntConstant (module , "_EXCEPTION_ACCESS_VIOLATION" ,
13171300 EXCEPTION_ACCESS_VIOLATION )) {
1318- goto error ;
1301+ return -1 ;
13191302 }
1320- if (PyModule_AddIntConstant (m , "_EXCEPTION_INT_DIVIDE_BY_ZERO" ,
1303+ if (PyModule_AddIntConstant (module , "_EXCEPTION_INT_DIVIDE_BY_ZERO" ,
13211304 EXCEPTION_INT_DIVIDE_BY_ZERO )) {
1322- goto error ;
1305+ return -1 ;
13231306 }
1324- if (PyModule_AddIntConstant (m , "_EXCEPTION_STACK_OVERFLOW" ,
1307+ if (PyModule_AddIntConstant (module , "_EXCEPTION_STACK_OVERFLOW" ,
13251308 EXCEPTION_STACK_OVERFLOW )) {
1326- goto error ;
1309+ return -1 ;
13271310 }
13281311
13291312 /* RaiseException() flags (prefixed by an underscore) */
1330- if (PyModule_AddIntConstant (m , "_EXCEPTION_NONCONTINUABLE" ,
1313+ if (PyModule_AddIntConstant (module , "_EXCEPTION_NONCONTINUABLE" ,
13311314 EXCEPTION_NONCONTINUABLE )) {
1332- goto error ;
1315+ return -1 ;
13331316 }
1334- if (PyModule_AddIntConstant (m , "_EXCEPTION_NONCONTINUABLE_EXCEPTION" ,
1317+ if (PyModule_AddIntConstant (module , "_EXCEPTION_NONCONTINUABLE_EXCEPTION" ,
13351318 EXCEPTION_NONCONTINUABLE_EXCEPTION )) {
1336- goto error ;
1319+ return -1 ;
13371320 }
13381321#endif
1322+ return 0 ;
1323+ }
13391324
1340- return m ;
1325+ static PyModuleDef_Slot faulthandler_slots [] = {
1326+ {Py_mod_exec , PyExec_faulthandler },
1327+ {0 , NULL }
1328+ };
13411329
1342- #ifdef MS_WINDOWS
1343- error :
1344- Py_DECREF (m );
1345- return NULL ;
1346- #endif
1330+ static struct PyModuleDef module_def = {
1331+ PyModuleDef_HEAD_INIT ,
1332+ .m_name = "faulthandler" ,
1333+ .m_doc = module_doc ,
1334+ .m_methods = module_methods ,
1335+ .m_traverse = faulthandler_traverse ,
1336+ .m_slots = faulthandler_slots
1337+ };
1338+
1339+ PyMODINIT_FUNC
1340+ PyInit_faulthandler (void )
1341+ {
1342+ return PyModuleDef_Init (& module_def );
13471343}
13481344
13491345static int
0 commit comments