summaryrefslogtreecommitdiff
path: root/Python/pystate.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-11-23 00:12:09 +0100
committerGitHub <noreply@github.com>2017-11-23 00:12:09 +0100
commitd4341109746aa15e1909e63b30b93b6133ffe401 (patch)
tree8982cc677ace3953484d4e4e34c8b154d0b9fb35 /Python/pystate.c
parent82656276caf4cb889193572d2d14dbc5f3d2bdff (diff)
downloadcpython-git-d4341109746aa15e1909e63b30b93b6133ffe401.tar.gz
bpo-32030: Add _PyCoreConfig.module_search_path_env (#4504)
Changes: * Py_Main() initializes _PyCoreConfig.module_search_path_env from the PYTHONPATH environment variable. * PyInterpreterState_New() now initializes core_config and config fields * Compute sys.path a little bit ealier in _Py_InitializeMainInterpreter() and new_interpreter() * Add _Py_GetPathWithConfig() private function.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c85
1 files changed, 45 insertions, 40 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 807ac4eb9d..f6fbb4d041 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -106,55 +106,60 @@ PyInterpreterState_New(void)
PyInterpreterState *interp = (PyInterpreterState *)
PyMem_RawMalloc(sizeof(PyInterpreterState));
- if (interp != 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->importlib = NULL;
- interp->import_func = NULL;
- interp->eval_frame = _PyEval_EvalFrameDefault;
- interp->co_extra_user_count = 0;
+ if (interp == NULL) {
+ return 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;
+ interp->dlopenflags = RTLD_NOW;
#else
- interp->dlopenflags = RTLD_LAZY;
+ interp->dlopenflags = RTLD_LAZY;
#endif
#endif
#ifdef HAVE_FORK
- interp->before_forkers = NULL;
- interp->after_forkers_parent = NULL;
- interp->after_forkers_child = NULL;
+ interp->before_forkers = NULL;
+ interp->after_forkers_parent = NULL;
+ interp->after_forkers_child = NULL;
#endif
- HEAD_LOCK();
- interp->next = _PyRuntime.interpreters.head;
- if (_PyRuntime.interpreters.main == NULL) {
- _PyRuntime.interpreters.main = interp;
- }
- _PyRuntime.interpreters.head = interp;
- if (_PyRuntime.interpreters.next_id < 0) {
- /* overflow or Py_Initialize() not called! */
- PyErr_SetString(PyExc_RuntimeError,
- "failed to get an interpreter ID");
- interp = NULL;
- } else {
- interp->id = _PyRuntime.interpreters.next_id;
- _PyRuntime.interpreters.next_id += 1;
- }
- HEAD_UNLOCK();
+ HEAD_LOCK();
+ interp->next = _PyRuntime.interpreters.head;
+ if (_PyRuntime.interpreters.main == NULL) {
+ _PyRuntime.interpreters.main = interp;
+ }
+ _PyRuntime.interpreters.head = interp;
+ if (_PyRuntime.interpreters.next_id < 0) {
+ /* overflow or Py_Initialize() not called! */
+ PyErr_SetString(PyExc_RuntimeError,
+ "failed to get an interpreter ID");
+ interp = NULL;
+ } else {
+ interp->id = _PyRuntime.interpreters.next_id;
+ _PyRuntime.interpreters.next_id += 1;
}
+ HEAD_UNLOCK();
return interp;
}