diff options
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pylifecycle.c | 16 | ||||
-rw-r--r-- | Python/pystate.c | 85 |
2 files changed, 54 insertions, 47 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 36fcf61..9eeac9d 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -48,8 +48,6 @@ _Py_IDENTIFIER(threading); extern "C" { #endif -extern wchar_t *Py_GetPath(void); - extern grammar _PyParser_Grammar; /* From graminit.c */ /* Forward */ @@ -842,6 +840,11 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config) /* Now finish configuring the main interpreter */ interp->config = *config; + /* GetPath may initialize state that _PySys_EndInit locks + in, and so has to be called first. */ + /* TODO: Call Py_GetPath() in Py_ReadConfig, rather than here */ + wchar_t *sys_path = _Py_GetPathWithConfig(&interp->core_config); + if (interp->core_config._disable_importlib) { /* Special mode for freeze_importlib: run with no import system * @@ -857,10 +860,7 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config) return _Py_INIT_ERR("can't initialize time"); /* Finish setting up the sys module and import system */ - /* GetPath may initialize state that _PySys_EndInit locks - in, and so has to be called first. */ - /* TODO: Call Py_GetPath() in Py_ReadConfig, rather than here */ - PySys_SetPath(Py_GetPath()); + PySys_SetPath(sys_path); if (_PySys_EndInit(interp->sysdict) < 0) return _Py_INIT_ERR("can't finish initializing sys"); @@ -1301,6 +1301,8 @@ new_interpreter(PyThreadState **tstate_p) /* XXX The following is lax in error checking */ + wchar_t *sys_path = _Py_GetPathWithConfig(&interp->core_config); + PyObject *modules = PyDict_New(); if (modules == NULL) { return _Py_INIT_ERR("can't make modules dictionary"); @@ -1314,7 +1316,7 @@ new_interpreter(PyThreadState **tstate_p) goto handle_error; Py_INCREF(interp->sysdict); PyDict_SetItemString(interp->sysdict, "modules", modules); - PySys_SetPath(Py_GetPath()); + PySys_SetPath(sys_path); _PySys_EndInit(interp->sysdict); } diff --git a/Python/pystate.c b/Python/pystate.c index 807ac4e..f6fbb4d 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; } |