@@ -1270,7 +1270,7 @@ finish_singlephase_extension(PyThreadState *tstate,
1270
1270
PyObject * name , PyObject * modules )
1271
1271
{
1272
1272
assert (mod != NULL && PyModule_Check (mod ));
1273
- assert (def == PyModule_GetDef (mod ));
1273
+ assert (def == _PyModule_GetDef (mod ));
1274
1274
1275
1275
if (_modules_by_index_set (tstate -> interp , def , mod ) < 0 ) {
1276
1276
return -1 ;
@@ -1395,6 +1395,7 @@ create_dynamic(PyThreadState *tstate, struct _Py_ext_module_loader_info *info,
1395
1395
PyObject * file , PyObject * spec )
1396
1396
{
1397
1397
PyObject * mod = NULL ;
1398
+ PyModuleDef * def = NULL ;
1398
1399
1399
1400
/* We would move this (and the fclose() below) into
1400
1401
* _PyImport_GetModInitFunc(), but it isn't clear if the intervening
@@ -1421,15 +1422,23 @@ create_dynamic(PyThreadState *tstate, struct _Py_ext_module_loader_info *info,
1421
1422
goto finally ;
1422
1423
}
1423
1424
1424
- if (res .module == NULL ) {
1425
- //assert(!is_singlephase(res.def));
1426
- mod = PyModule_FromDefAndSpec (res .def , spec );
1425
+ mod = res .module ;
1426
+ res .module = NULL ;
1427
+ def = res .def ;
1428
+ assert (def != NULL );
1429
+
1430
+ if (mod == NULL ) {
1431
+ //assert(!is_singlephase(def));
1432
+ mod = PyModule_FromDefAndSpec (def , spec );
1433
+ if (mod == NULL ) {
1434
+ goto finally ;
1435
+ }
1427
1436
}
1428
1437
else {
1429
- assert (is_singlephase (res . def ));
1438
+ assert (is_singlephase (def ));
1430
1439
assert (!is_core_module (tstate -> interp , info -> name , info -> filename ));
1431
1440
assert (!is_core_module (tstate -> interp , info -> name , info -> name ));
1432
- mod = Py_NewRef (res . module );
1441
+ mod = Py_NewRef (mod );
1433
1442
1434
1443
const char * name_buf = PyBytes_AS_STRING (info -> name_encoded );
1435
1444
if (_PyImport_CheckSubinterpIncompatibleExtensionAllowed (name_buf ) < 0 ) {
@@ -1445,20 +1454,20 @@ create_dynamic(PyThreadState *tstate, struct _Py_ext_module_loader_info *info,
1445
1454
struct singlephase_global_update singlephase = {0 };
1446
1455
// gh-88216: Extensions and def->m_base.m_copy can be updated
1447
1456
// when the extension module doesn't support sub-interpreters.
1448
- if (res . def -> m_size == -1 ) {
1457
+ if (def -> m_size == -1 ) {
1449
1458
singlephase .m_dict = PyModule_GetDict (mod );
1450
1459
assert (singlephase .m_dict != NULL );
1451
1460
}
1452
1461
if (update_global_state_for_extension (
1453
- tstate , info -> filename , info -> name , res . def , & singlephase ) < 0 )
1462
+ tstate , info -> filename , info -> name , def , & singlephase ) < 0 )
1454
1463
{
1455
1464
Py_CLEAR (mod );
1456
1465
goto finally ;
1457
1466
}
1458
1467
1459
1468
PyObject * modules = get_modules_dict (tstate , true);
1460
1469
if (finish_singlephase_extension (
1461
- tstate , mod , res . def , info -> name , modules ) < 0 )
1470
+ tstate , mod , def , info -> name , modules ) < 0 )
1462
1471
{
1463
1472
Py_CLEAR (mod );
1464
1473
goto finally ;
0 commit comments