summaryrefslogtreecommitdiffstats
path: root/Python/_warnings.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-11-12 14:14:13 (GMT)
committerGitHub <noreply@github.com>2020-11-12 14:14:13 (GMT)
commitef75a625cdf8377d687a04948b4db9bc1917bf19 (patch)
treef9a979741790c9647b53e3f7c8f2c5fd66b6e56a /Python/_warnings.c
parentd19fa7a337d829e3dab3e9f919f5dcf09cf6f6ba (diff)
downloadcpython-ef75a625cdf8377d687a04948b4db9bc1917bf19.zip
cpython-ef75a625cdf8377d687a04948b4db9bc1917bf19.tar.gz
cpython-ef75a625cdf8377d687a04948b4db9bc1917bf19.tar.bz2
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.
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r--Python/_warnings.c30
1 files changed, 7 insertions, 23 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index e42b7c3..8d33fbe 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -114,37 +114,34 @@ init_filters(void)
}
/* Initialize the given warnings module state. */
-static int
-warnings_init_state(WarningsState *st)
+int
+_PyWarnings_InitState(PyThreadState *tstate)
{
+ WarningsState *st = &tstate->interp->warnings;
+
if (st->filters == NULL) {
st->filters = init_filters();
if (st->filters == NULL) {
- goto error;
+ return -1;
}
}
if (st->once_registry == NULL) {
st->once_registry = PyDict_New();
if (st->once_registry == NULL) {
- goto error;
+ return -1;
}
}
if (st->default_action == NULL) {
st->default_action = PyUnicode_FromString("default");
if (st->default_action == NULL) {
- goto error;
+ return -1;
}
}
st->filters_version = 0;
-
return 0;
-
-error:
- warnings_clear_state(st);
- return -1;
}
@@ -1367,16 +1364,6 @@ static struct PyModuleDef warningsmodule = {
};
-PyStatus
-_PyWarnings_InitState(PyThreadState *tstate)
-{
- if (warnings_init_state(&tstate->interp->warnings) < 0) {
- return _PyStatus_ERR("can't initialize warnings");
- }
- return _PyStatus_OK();
-}
-
-
PyMODINIT_FUNC
_PyWarnings_Init(void)
{
@@ -1391,9 +1378,6 @@ _PyWarnings_Init(void)
if (st == NULL) {
goto error;
}
- if (warnings_init_state(st) < 0) {
- goto error;
- }
if (PyModule_AddObjectRef(m, "filters", st->filters) < 0) {
goto error;