Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2c29fe

Browse files
We already know the def is okay.
1 parent 5874d8e commit c2c29fe

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

Python/import.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ finish_singlephase_extension(PyThreadState *tstate,
12701270
PyObject *name, PyObject *modules)
12711271
{
12721272
assert(mod != NULL && PyModule_Check(mod));
1273-
assert(def == PyModule_GetDef(mod));
1273+
assert(def == _PyModule_GetDef(mod));
12741274

12751275
if (_modules_by_index_set(tstate->interp, def, mod) < 0) {
12761276
return -1;
@@ -1395,6 +1395,7 @@ create_dynamic(PyThreadState *tstate, struct _Py_ext_module_loader_info *info,
13951395
PyObject *file, PyObject *spec)
13961396
{
13971397
PyObject *mod = NULL;
1398+
PyModuleDef *def = NULL;
13981399

13991400
/* We would move this (and the fclose() below) into
14001401
* _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,
14211422
goto finally;
14221423
}
14231424

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+
}
14271436
}
14281437
else {
1429-
assert(is_singlephase(res.def));
1438+
assert(is_singlephase(def));
14301439
assert(!is_core_module(tstate->interp, info->name, info->filename));
14311440
assert(!is_core_module(tstate->interp, info->name, info->name));
1432-
mod = Py_NewRef(res.module);
1441+
mod = Py_NewRef(mod);
14331442

14341443
const char *name_buf = PyBytes_AS_STRING(info->name_encoded);
14351444
if (_PyImport_CheckSubinterpIncompatibleExtensionAllowed(name_buf) < 0) {
@@ -1445,20 +1454,20 @@ create_dynamic(PyThreadState *tstate, struct _Py_ext_module_loader_info *info,
14451454
struct singlephase_global_update singlephase = {0};
14461455
// gh-88216: Extensions and def->m_base.m_copy can be updated
14471456
// when the extension module doesn't support sub-interpreters.
1448-
if (res.def->m_size == -1) {
1457+
if (def->m_size == -1) {
14491458
singlephase.m_dict = PyModule_GetDict(mod);
14501459
assert(singlephase.m_dict != NULL);
14511460
}
14521461
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)
14541463
{
14551464
Py_CLEAR(mod);
14561465
goto finally;
14571466
}
14581467

14591468
PyObject *modules = get_modules_dict(tstate, true);
14601469
if (finish_singlephase_extension(
1461-
tstate, mod, res.def, info->name, modules) < 0)
1470+
tstate, mod, def, info->name, modules) < 0)
14621471
{
14631472
Py_CLEAR(mod);
14641473
goto finally;

0 commit comments

Comments
 (0)