@@ -24,9 +24,6 @@ _Py_IDENTIFIER(ignore);
24
24
25
25
typedef struct _warnings_runtime_state WarningsState ;
26
26
27
- /* Forward declaration of the _warnings module definition. */
28
- static struct PyModuleDef warningsmodule ;
29
-
30
27
_Py_IDENTIFIER (__name__ );
31
28
32
29
/* Given a module object, get its per-module state. */
@@ -1353,52 +1350,45 @@ static PyMethodDef warnings_functions[] = {
1353
1350
};
1354
1351
1355
1352
1356
- static struct PyModuleDef warningsmodule = {
1357
- PyModuleDef_HEAD_INIT ,
1358
- MODULE_NAME , /* m_name */
1359
- warnings__doc__ , /* m_doc */
1360
- 0 , /* m_size */
1361
- warnings_functions , /* m_methods */
1362
- NULL , /* m_reload */
1363
- NULL , /* m_traverse */
1364
- NULL , /* m_clear */
1365
- NULL /* m_free */
1366
- };
1367
-
1368
-
1369
- PyMODINIT_FUNC
1370
- _PyWarnings_Init (void )
1353
+ static int
1354
+ warnings_module_exec (PyObject * module )
1371
1355
{
1372
- PyObject * m ;
1373
-
1374
- m = PyModule_Create (& warningsmodule );
1375
- if (m == NULL ) {
1376
- return NULL ;
1377
- }
1378
-
1379
1356
WarningsState * st = warnings_get_state ();
1380
1357
if (st == NULL ) {
1381
- goto error ;
1358
+ return -1 ;
1382
1359
}
1383
-
1384
- if (PyModule_AddObjectRef (m , "filters" , st -> filters ) < 0 ) {
1385
- goto error ;
1360
+ if (PyModule_AddObjectRef (module , "filters" , st -> filters ) < 0 ) {
1361
+ return -1 ;
1386
1362
}
1387
- if (PyModule_AddObjectRef (m , "_onceregistry" , st -> once_registry ) < 0 ) {
1388
- goto error ;
1363
+ if (PyModule_AddObjectRef (module , "_onceregistry" , st -> once_registry ) < 0 ) {
1364
+ return -1 ;
1389
1365
}
1390
- if (PyModule_AddObjectRef (m , "_defaultaction" , st -> default_action ) < 0 ) {
1391
- goto error ;
1366
+ if (PyModule_AddObjectRef (module , "_defaultaction" , st -> default_action ) < 0 ) {
1367
+ return -1 ;
1392
1368
}
1369
+ return 0 ;
1370
+ }
1393
1371
1394
- return m ;
1395
1372
1396
- error :
1397
- if (st != NULL ) {
1398
- warnings_clear_state (st );
1399
- }
1400
- Py_DECREF (m );
1401
- return NULL ;
1373
+ static PyModuleDef_Slot warnings_slots [] = {
1374
+ {Py_mod_exec , warnings_module_exec },
1375
+ {0 , NULL }
1376
+ };
1377
+
1378
+ static struct PyModuleDef warnings_module = {
1379
+ PyModuleDef_HEAD_INIT ,
1380
+ .m_name = MODULE_NAME ,
1381
+ .m_doc = warnings__doc__ ,
1382
+ .m_size = 0 ,
1383
+ .m_methods = warnings_functions ,
1384
+ .m_slots = warnings_slots ,
1385
+ };
1386
+
1387
+
1388
+ PyMODINIT_FUNC
1389
+ _PyWarnings_Init (void )
1390
+ {
1391
+ return PyModuleDef_Init (& warnings_module );
1402
1392
}
1403
1393
1404
1394
// We need this to ensure that warnings still work until late in finalization.
0 commit comments