Skip to content

Commit ef5aa9a

Browse files
authored
bpo-38858: Reorganize pycore_init_types() (GH-17265)
* Call _PyLong_Init() and _PyExc_Init() earlier * new_interpreter() reuses pycore_init_types()
1 parent ac22354 commit ef5aa9a

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

‎Python/pylifecycle.c‎

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -565,19 +565,15 @@ pycore_init_types(void)
565565
return status;
566566
}
567567

568+
if (!_PyLong_Init()) {
569+
return _PyStatus_ERR("can't init longs");
570+
}
571+
568572
status = _PyUnicode_Init();
569573
if (_PyStatus_EXCEPTION(status)) {
570574
return status;
571575
}
572576

573-
if (_PyStructSequence_Init() < 0) {
574-
return _PyStatus_ERR("can't initialize structseq");
575-
}
576-
577-
if (!_PyLong_Init()) {
578-
return _PyStatus_ERR("can't init longs");
579-
}
580-
581577
status = _PyExc_Init();
582578
if (_PyStatus_EXCEPTION(status)) {
583579
return status;
@@ -587,15 +583,19 @@ pycore_init_types(void)
587583
return _PyStatus_ERR("can't init float");
588584
}
589585

590-
if (!_PyContext_Init()) {
591-
return _PyStatus_ERR("can't init context");
586+
if (_PyStructSequence_Init() < 0) {
587+
return _PyStatus_ERR("can't initialize structseq");
592588
}
593589

594590
status = _PyErr_Init();
595591
if (_PyStatus_EXCEPTION(status)) {
596592
return status;
597593
}
598594

595+
if (!_PyContext_Init()) {
596+
return _PyStatus_ERR("can't init context");
597+
}
598+
599599
return _PyStatus_OK();
600600
}
601601

@@ -1447,16 +1447,7 @@ new_interpreter(PyThreadState **tstate_p)
14471447
}
14481448
config = &interp->config;
14491449

1450-
status = _PyExc_Init();
1451-
if (_PyStatus_EXCEPTION(status)) {
1452-
return status;
1453-
}
1454-
1455-
status = _PyErr_Init();
1456-
if (_PyStatus_EXCEPTION(status)) {
1457-
return status;
1458-
}
1459-
1450+
status = pycore_init_types();
14601451

14611452
/* XXX The following is lax in error checking */
14621453
PyObject *modules = PyDict_New();

0 commit comments

Comments
 (0)