@@ -3243,75 +3243,56 @@ create_managed_dict_type(void)
3243
3243
return PyType_FromSpec (& ManagedDict_spec );
3244
3244
}
3245
3245
3246
- static struct PyModuleDef _testcapimodule = {
3247
- PyModuleDef_HEAD_INIT ,
3248
- .m_name = "_testcapi" ,
3249
- .m_size = sizeof (testcapistate_t ),
3250
- .m_methods = TestMethods ,
3251
- };
3252
-
3253
- /* Per PEP 489, this module will not be converted to multi-phase initialization
3254
- */
3255
-
3256
- PyMODINIT_FUNC
3257
- PyInit__testcapi (void )
3246
+ static int
3247
+ _testcapi_exec (PyObject * m )
3258
3248
{
3259
- PyObject * m ;
3260
-
3261
- m = PyModule_Create (& _testcapimodule );
3262
- if (m == NULL )
3263
- return NULL ;
3264
- #ifdef Py_GIL_DISABLED
3265
- PyUnstable_Module_SetGIL (m , Py_MOD_GIL_NOT_USED );
3266
- #endif
3267
-
3268
3249
Py_SET_TYPE (& _HashInheritanceTester_Type , & PyType_Type );
3269
3250
if (PyType_Ready (& _HashInheritanceTester_Type ) < 0 ) {
3270
- return NULL ;
3251
+ return -1 ;
3271
3252
}
3272
3253
if (PyType_Ready (& matmulType ) < 0 )
3273
- return NULL ;
3254
+ return -1 ;
3274
3255
Py_INCREF (& matmulType );
3275
3256
PyModule_AddObject (m , "matmulType" , (PyObject * )& matmulType );
3276
3257
if (PyType_Ready (& ipowType ) < 0 ) {
3277
- return NULL ;
3258
+ return -1 ;
3278
3259
}
3279
3260
Py_INCREF (& ipowType );
3280
3261
PyModule_AddObject (m , "ipowType" , (PyObject * )& ipowType );
3281
3262
3282
3263
if (PyType_Ready (& awaitType ) < 0 )
3283
- return NULL ;
3264
+ return -1 ;
3284
3265
Py_INCREF (& awaitType );
3285
3266
PyModule_AddObject (m , "awaitType" , (PyObject * )& awaitType );
3286
3267
3287
3268
MyList_Type .tp_base = & PyList_Type ;
3288
3269
if (PyType_Ready (& MyList_Type ) < 0 )
3289
- return NULL ;
3270
+ return -1 ;
3290
3271
Py_INCREF (& MyList_Type );
3291
3272
PyModule_AddObject (m , "MyList" , (PyObject * )& MyList_Type );
3292
3273
3293
3274
if (PyType_Ready (& GenericAlias_Type ) < 0 )
3294
- return NULL ;
3275
+ return -1 ;
3295
3276
Py_INCREF (& GenericAlias_Type );
3296
3277
PyModule_AddObject (m , "GenericAlias" , (PyObject * )& GenericAlias_Type );
3297
3278
3298
3279
if (PyType_Ready (& Generic_Type ) < 0 )
3299
- return NULL ;
3280
+ return -1 ;
3300
3281
Py_INCREF (& Generic_Type );
3301
3282
PyModule_AddObject (m , "Generic" , (PyObject * )& Generic_Type );
3302
3283
3303
3284
if (PyType_Ready (& MethInstance_Type ) < 0 )
3304
- return NULL ;
3285
+ return -1 ;
3305
3286
Py_INCREF (& MethInstance_Type );
3306
3287
PyModule_AddObject (m , "MethInstance" , (PyObject * )& MethInstance_Type );
3307
3288
3308
3289
if (PyType_Ready (& MethClass_Type ) < 0 )
3309
- return NULL ;
3290
+ return -1 ;
3310
3291
Py_INCREF (& MethClass_Type );
3311
3292
PyModule_AddObject (m , "MethClass" , (PyObject * )& MethClass_Type );
3312
3293
3313
3294
if (PyType_Ready (& MethStatic_Type ) < 0 )
3314
- return NULL ;
3295
+ return -1 ;
3315
3296
Py_INCREF (& MethStatic_Type );
3316
3297
PyModule_AddObject (m , "MethStatic" , (PyObject * )& MethStatic_Type );
3317
3298
@@ -3354,159 +3335,179 @@ PyInit__testcapi(void)
3354
3335
PyModule_AddObject (m , "UINT64_MAX" , PyLong_FromUInt64 (UINT64_MAX ));
3355
3336
3356
3337
if (PyModule_AddIntMacro (m , Py_single_input )) {
3357
- return NULL ;
3338
+ return -1 ;
3358
3339
}
3359
3340
if (PyModule_AddIntMacro (m , Py_file_input )) {
3360
- return NULL ;
3341
+ return -1 ;
3361
3342
}
3362
3343
if (PyModule_AddIntMacro (m , Py_eval_input )) {
3363
- return NULL ;
3344
+ return -1 ;
3364
3345
}
3365
3346
3366
3347
testcapistate_t * state = get_testcapi_state (m );
3367
3348
state -> error = PyErr_NewException ("_testcapi.error" , NULL , NULL );
3368
3349
PyModule_AddObject (m , "error" , state -> error );
3369
3350
3370
3351
if (PyType_Ready (& ContainerNoGC_type ) < 0 ) {
3371
- return NULL ;
3352
+ return -1 ;
3372
3353
}
3373
3354
Py_INCREF (& ContainerNoGC_type );
3374
3355
if (PyModule_AddObject (m , "ContainerNoGC" ,
3375
3356
(PyObject * ) & ContainerNoGC_type ) < 0 )
3376
- return NULL ;
3357
+ return -1 ;
3377
3358
3378
3359
PyObject * manual_heap_type = create_manual_heap_type ();
3379
3360
if (manual_heap_type == NULL ) {
3380
- return NULL ;
3361
+ return -1 ;
3381
3362
}
3382
3363
if (PyModule_Add (m , "ManualHeapType" , manual_heap_type ) < 0 ) {
3383
- return NULL ;
3364
+ return -1 ;
3384
3365
}
3385
3366
3386
3367
PyObject * managed_dict_type = create_managed_dict_type ();
3387
3368
if (managed_dict_type == NULL ) {
3388
- return NULL ;
3369
+ return -1 ;
3389
3370
}
3390
3371
if (PyModule_Add (m , "ManagedDictType" , managed_dict_type ) < 0 ) {
3391
- return NULL ;
3372
+ return -1 ;
3392
3373
}
3393
3374
3394
3375
/* Include tests from the _testcapi/ directory */
3395
3376
if (_PyTestCapi_Init_Vectorcall (m ) < 0 ) {
3396
- return NULL ;
3377
+ return -1 ;
3397
3378
}
3398
3379
if (_PyTestCapi_Init_Heaptype (m ) < 0 ) {
3399
- return NULL ;
3380
+ return -1 ;
3400
3381
}
3401
3382
if (_PyTestCapi_Init_Abstract (m ) < 0 ) {
3402
- return NULL ;
3383
+ return -1 ;
3403
3384
}
3404
3385
if (_PyTestCapi_Init_Bytes (m ) < 0 ) {
3405
- return NULL ;
3386
+ return -1 ;
3406
3387
}
3407
3388
if (_PyTestCapi_Init_Unicode (m ) < 0 ) {
3408
- return NULL ;
3389
+ return -1 ;
3409
3390
}
3410
3391
if (_PyTestCapi_Init_GetArgs (m ) < 0 ) {
3411
- return NULL ;
3392
+ return -1 ;
3412
3393
}
3413
3394
if (_PyTestCapi_Init_DateTime (m ) < 0 ) {
3414
- return NULL ;
3395
+ return -1 ;
3415
3396
}
3416
3397
if (_PyTestCapi_Init_Docstring (m ) < 0 ) {
3417
- return NULL ;
3398
+ return -1 ;
3418
3399
}
3419
3400
if (_PyTestCapi_Init_Mem (m ) < 0 ) {
3420
- return NULL ;
3401
+ return -1 ;
3421
3402
}
3422
3403
if (_PyTestCapi_Init_Watchers (m ) < 0 ) {
3423
- return NULL ;
3404
+ return -1 ;
3424
3405
}
3425
3406
if (_PyTestCapi_Init_Long (m ) < 0 ) {
3426
- return NULL ;
3407
+ return -1 ;
3427
3408
}
3428
3409
if (_PyTestCapi_Init_Float (m ) < 0 ) {
3429
- return NULL ;
3410
+ return -1 ;
3430
3411
}
3431
3412
if (_PyTestCapi_Init_Complex (m ) < 0 ) {
3432
- return NULL ;
3413
+ return -1 ;
3433
3414
}
3434
3415
if (_PyTestCapi_Init_Numbers (m ) < 0 ) {
3435
- return NULL ;
3416
+ return -1 ;
3436
3417
}
3437
3418
if (_PyTestCapi_Init_Dict (m ) < 0 ) {
3438
- return NULL ;
3419
+ return -1 ;
3439
3420
}
3440
3421
if (_PyTestCapi_Init_Set (m ) < 0 ) {
3441
- return NULL ;
3422
+ return -1 ;
3442
3423
}
3443
3424
if (_PyTestCapi_Init_List (m ) < 0 ) {
3444
- return NULL ;
3425
+ return -1 ;
3445
3426
}
3446
3427
if (_PyTestCapi_Init_Tuple (m ) < 0 ) {
3447
- return NULL ;
3428
+ return -1 ;
3448
3429
}
3449
3430
if (_PyTestCapi_Init_Structmember (m ) < 0 ) {
3450
- return NULL ;
3431
+ return -1 ;
3451
3432
}
3452
3433
if (_PyTestCapi_Init_Exceptions (m ) < 0 ) {
3453
- return NULL ;
3434
+ return -1 ;
3454
3435
}
3455
3436
if (_PyTestCapi_Init_Code (m ) < 0 ) {
3456
- return NULL ;
3437
+ return -1 ;
3457
3438
}
3458
3439
if (_PyTestCapi_Init_Buffer (m ) < 0 ) {
3459
- return NULL ;
3440
+ return -1 ;
3460
3441
}
3461
3442
if (_PyTestCapi_Init_File (m ) < 0 ) {
3462
- return NULL ;
3443
+ return -1 ;
3463
3444
}
3464
3445
if (_PyTestCapi_Init_Codec (m ) < 0 ) {
3465
- return NULL ;
3446
+ return -1 ;
3466
3447
}
3467
3448
if (_PyTestCapi_Init_Immortal (m ) < 0 ) {
3468
- return NULL ;
3449
+ return -1 ;
3469
3450
}
3470
3451
if (_PyTestCapi_Init_GC (m ) < 0 ) {
3471
- return NULL ;
3452
+ return -1 ;
3472
3453
}
3473
3454
if (_PyTestCapi_Init_PyAtomic (m ) < 0 ) {
3474
- return NULL ;
3455
+ return -1 ;
3475
3456
}
3476
3457
if (_PyTestCapi_Init_Run (m ) < 0 ) {
3477
- return NULL ;
3458
+ return -1 ;
3478
3459
}
3479
3460
if (_PyTestCapi_Init_Hash (m ) < 0 ) {
3480
- return NULL ;
3461
+ return -1 ;
3481
3462
}
3482
3463
if (_PyTestCapi_Init_Time (m ) < 0 ) {
3483
- return NULL ;
3464
+ return -1 ;
3484
3465
}
3485
3466
if (_PyTestCapi_Init_Modsupport (m ) < 0 ) {
3486
- return NULL ;
3467
+ return -1 ;
3487
3468
}
3488
3469
if (_PyTestCapi_Init_Monitoring (m ) < 0 ) {
3489
- return NULL ;
3470
+ return -1 ;
3490
3471
}
3491
3472
if (_PyTestCapi_Init_Object (m ) < 0 ) {
3492
- return NULL ;
3473
+ return -1 ;
3493
3474
}
3494
3475
if (_PyTestCapi_Init_Config (m ) < 0 ) {
3495
- return NULL ;
3476
+ return -1 ;
3496
3477
}
3497
3478
if (_PyTestCapi_Init_Import (m ) < 0 ) {
3498
- return NULL ;
3479
+ return -1 ;
3499
3480
}
3500
3481
if (_PyTestCapi_Init_Frame (m ) < 0 ) {
3501
- return NULL ;
3482
+ return -1 ;
3502
3483
}
3503
3484
if (_PyTestCapi_Init_Type (m ) < 0 ) {
3504
- return NULL ;
3485
+ return -1 ;
3505
3486
}
3506
3487
if (_PyTestCapi_Init_Function (m ) < 0 ) {
3507
- return NULL ;
3488
+ return -1 ;
3508
3489
}
3509
3490
3510
- PyState_AddModule (m , & _testcapimodule );
3511
- return m ;
3491
+ return 0 ;
3492
+ }
3493
+
3494
+ static PyModuleDef_Slot _testcapi_slots [] = {
3495
+ {Py_mod_exec , _testcapi_exec },
3496
+ {Py_mod_gil , Py_MOD_GIL_NOT_USED },
3497
+ {Py_mod_multiple_interpreters , Py_MOD_PER_INTERPRETER_GIL_SUPPORTED },
3498
+ {0 , NULL },
3499
+ };
3500
+
3501
+ static struct PyModuleDef _testcapimodule = {
3502
+ PyModuleDef_HEAD_INIT ,
3503
+ .m_name = "_testcapi" ,
3504
+ .m_size = sizeof (testcapistate_t ),
3505
+ .m_methods = TestMethods ,
3506
+ .m_slots = _testcapi_slots
3507
+ };
3508
+
3509
+ PyMODINIT_FUNC
3510
+ PyInit__testcapi (void )
3511
+ {
3512
+ return PyModuleDef_Init (& _testcapimodule );
3512
3513
}
0 commit comments