From ef5aa9af7c7e493402ac62009e4400aed7c3d54e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 20 Nov 2019 00:38:03 +0100 Subject: bpo-38858: Reorganize pycore_init_types() (GH-17265) * Call _PyLong_Init() and _PyExc_Init() earlier * new_interpreter() reuses pycore_init_types() --- Python/pylifecycle.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index add7519..1bfc7c1 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -565,19 +565,15 @@ pycore_init_types(void) return status; } + if (!_PyLong_Init()) { + return _PyStatus_ERR("can't init longs"); + } + status = _PyUnicode_Init(); if (_PyStatus_EXCEPTION(status)) { return status; } - if (_PyStructSequence_Init() < 0) { - return _PyStatus_ERR("can't initialize structseq"); - } - - if (!_PyLong_Init()) { - return _PyStatus_ERR("can't init longs"); - } - status = _PyExc_Init(); if (_PyStatus_EXCEPTION(status)) { return status; @@ -587,8 +583,8 @@ pycore_init_types(void) return _PyStatus_ERR("can't init float"); } - if (!_PyContext_Init()) { - return _PyStatus_ERR("can't init context"); + if (_PyStructSequence_Init() < 0) { + return _PyStatus_ERR("can't initialize structseq"); } status = _PyErr_Init(); @@ -596,6 +592,10 @@ pycore_init_types(void) return status; } + if (!_PyContext_Init()) { + return _PyStatus_ERR("can't init context"); + } + return _PyStatus_OK(); } @@ -1447,16 +1447,7 @@ new_interpreter(PyThreadState **tstate_p) } config = &interp->config; - status = _PyExc_Init(); - if (_PyStatus_EXCEPTION(status)) { - return status; - } - - status = _PyErr_Init(); - if (_PyStatus_EXCEPTION(status)) { - return status; - } - + status = pycore_init_types(); /* XXX The following is lax in error checking */ PyObject *modules = PyDict_New(); -- cgit v0.12