mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-42260: Initialize time and warnings earlier at startup (GH-23249)
* Call _PyTime_Init() and _PyWarnings_InitState() earlier during the Python initialization. * Inline _PyImportHooks_Init() into _PySys_InitCore(). * The _warnings initialization function no longer call _PyWarnings_InitState() to prevent resetting filters_version to 0. * _PyWarnings_InitState() now returns an int and no longer clear the state in case of error (it's done anyway at Python exit). * Rework init_importlib(), fix refleaks on errors.
This commit is contained in:
parent
d19fa7a337
commit
ef75a625cd
7 changed files with 68 additions and 133 deletions
|
@ -51,43 +51,6 @@ module _imp
|
|||
|
||||
/* Initialize things */
|
||||
|
||||
PyStatus
|
||||
_PyImportHooks_Init(PyThreadState *tstate)
|
||||
{
|
||||
PyObject *v, *path_hooks = NULL;
|
||||
int err = 0;
|
||||
|
||||
/* adding sys.path_hooks and sys.path_importer_cache */
|
||||
v = PyList_New(0);
|
||||
if (v == NULL)
|
||||
goto error;
|
||||
err = PySys_SetObject("meta_path", v);
|
||||
Py_DECREF(v);
|
||||
if (err)
|
||||
goto error;
|
||||
v = PyDict_New();
|
||||
if (v == NULL)
|
||||
goto error;
|
||||
err = PySys_SetObject("path_importer_cache", v);
|
||||
Py_DECREF(v);
|
||||
if (err)
|
||||
goto error;
|
||||
path_hooks = PyList_New(0);
|
||||
if (path_hooks == NULL)
|
||||
goto error;
|
||||
err = PySys_SetObject("path_hooks", path_hooks);
|
||||
if (err) {
|
||||
goto error;
|
||||
}
|
||||
Py_DECREF(path_hooks);
|
||||
return _PyStatus_OK();
|
||||
|
||||
error:
|
||||
_PyErr_Print(tstate);
|
||||
return _PyStatus_ERR("initializing sys.meta_path, sys.path_hooks, "
|
||||
"or path_importer_cache failed");
|
||||
}
|
||||
|
||||
PyStatus
|
||||
_PyImportZip_Init(PyThreadState *tstate)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue