summaryrefslogtreecommitdiff
path: root/Python/pystate.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2019-03-08 22:47:07 -0700
committerGitHub <noreply@github.com>2019-03-08 22:47:07 -0700
commit5be45a6105d656c551adeee7770afdc3b806fbb5 (patch)
tree94cadf53fd4024b66375474529dbb8b97cbac549 /Python/pystate.c
parent7bda9de5504382931822baecba7f85028031c2cd (diff)
downloadcpython-git-5be45a6105d656c551adeee7770afdc3b806fbb5.tar.gz
bpo-33608: Minor cleanup related to pending calls. (gh-12247)
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c63
1 files changed, 28 insertions, 35 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 49497b7c37..ec8dba8ee5 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -60,6 +60,8 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime)
return _Py_INIT_ERR("Can't initialize threads for cross-interpreter data registry");
}
+ // runtime->main_thread is set in PyEval_InitThreads().
+
return _Py_INIT_OK();
}
@@ -133,28 +135,12 @@ PyInterpreterState_New(void)
return NULL;
}
+ memset(interp, 0, sizeof(*interp));
interp->id_refcount = -1;
- interp->id_mutex = NULL;
- interp->modules = NULL;
- interp->modules_by_index = NULL;
- interp->sysdict = NULL;
- interp->builtins = NULL;
- interp->builtins_copy = NULL;
- interp->tstate_head = NULL;
interp->check_interval = 100;
- interp->num_threads = 0;
- interp->pythread_stacksize = 0;
- interp->codec_search_path = NULL;
- interp->codec_search_cache = NULL;
- interp->codec_error_registry = NULL;
- interp->codecs_initialized = 0;
- interp->fscodec_initialized = 0;
interp->core_config = _PyCoreConfig_INIT;
interp->config = _PyMainInterpreterConfig_INIT;
- interp->importlib = NULL;
- interp->import_func = NULL;
interp->eval_frame = _PyEval_EvalFrameDefault;
- interp->co_extra_user_count = 0;
#ifdef HAVE_DLOPEN
#if HAVE_DECL_RTLD_NOW
interp->dlopenflags = RTLD_NOW;
@@ -162,13 +148,6 @@ PyInterpreterState_New(void)
interp->dlopenflags = RTLD_LAZY;
#endif
#endif
-#ifdef HAVE_FORK
- interp->before_forkers = NULL;
- interp->after_forkers_parent = NULL;
- interp->after_forkers_child = NULL;
-#endif
- interp->pyexitfunc = NULL;
- interp->pyexitmodule = NULL;
HEAD_LOCK();
if (_PyRuntime.interpreters.next_id < 0) {
@@ -223,6 +202,9 @@ PyInterpreterState_Clear(PyInterpreterState *interp)
Py_CLEAR(interp->after_forkers_parent);
Py_CLEAR(interp->after_forkers_child);
#endif
+ // XXX Once we have one allocator per interpreter (i.e.
+ // per-interpreter GC) we must ensure that all of the interpreter's
+ // objects have been cleaned up at the point.
}
@@ -334,28 +316,39 @@ PyInterpreterState_GetID(PyInterpreterState *interp)
}
-PyInterpreterState *
-_PyInterpreterState_LookUpID(PY_INT64_T requested_id)
+static PyInterpreterState *
+interp_look_up_id(PY_INT64_T requested_id)
{
- if (requested_id < 0)
- goto error;
-
PyInterpreterState *interp = PyInterpreterState_Head();
while (interp != NULL) {
PY_INT64_T id = PyInterpreterState_GetID(interp);
- if (id < 0)
+ if (id < 0) {
return NULL;
- if (requested_id == id)
+ }
+ if (requested_id == id) {
return interp;
+ }
interp = PyInterpreterState_Next(interp);
}
-
-error:
- PyErr_Format(PyExc_RuntimeError,
- "unrecognized interpreter ID %lld", requested_id);
return NULL;
}
+PyInterpreterState *
+_PyInterpreterState_LookUpID(PY_INT64_T requested_id)
+{
+ PyInterpreterState *interp = NULL;
+ if (requested_id >= 0) {
+ HEAD_LOCK();
+ interp = interp_look_up_id(requested_id);
+ HEAD_UNLOCK();
+ }
+ if (interp == NULL && !PyErr_Occurred()) {
+ PyErr_Format(PyExc_RuntimeError,
+ "unrecognized interpreter ID %lld", requested_id);
+ }
+ return interp;
+}
+
int
_PyInterpreterState_IDInitref(PyInterpreterState *interp)