diff options
author | Guido van Rossum <guido@python.org> | 1997-05-05 20:56:21 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-05-05 20:56:21 (GMT) |
commit | a027efa5bfa7911b5c4b522b6a0698749a6f2e4a (patch) | |
tree | 7027609cb66223aba0355957599aa7629fce7e53 /Python/pythonrun.c | |
parent | 73237c54b40c345813fa6b7831a32b10fa4671b5 (diff) | |
download | cpython-a027efa5bfa7911b5c4b522b6a0698749a6f2e4a.zip cpython-a027efa5bfa7911b5c4b522b6a0698749a6f2e4a.tar.gz cpython-a027efa5bfa7911b5c4b522b6a0698749a6f2e4a.tar.bz2 |
Massive changes for separate thread state management.
All per-thread globals are moved into a struct which is manipulated
separately.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 4d6b918..f08a2c4 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -77,17 +77,11 @@ int Py_VerboseFlag; /* Needed by import.c */ int Py_SuppressPrintingFlag; /* Needed by ceval.c */ int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ -/* Initialize all */ +/* Initialize the current interpreter; pass in the Python path. */ void -Py_Initialize() +Py_Setup() { - static int inited; - - if (inited) - return; - inited = 1; - PyImport_Init(); /* Modules '__builtin__' and 'sys' are initialized here, @@ -105,6 +99,46 @@ Py_Initialize() initmain(); } +/* Create and interpreter and thread state and initialize them; + if we already have an interpreter and thread, do nothing. + Fatal error if the creation fails. */ + +void +Py_Initialize() +{ + PyThreadState *tstate; + PyInterpreterState *interp; + if (PyThreadState_Get()) + return; + interp = PyInterpreterState_New(); + if (interp == NULL) + Py_FatalError("PyInterpreterState_New() failed"); + tstate = PyThreadState_New(interp); + if (tstate == NULL) + Py_FatalError("PyThreadState_New() failed"); + (void) PyThreadState_Swap(tstate); + + Py_Setup(); + + PySys_SetPath(Py_GetPath()); +} + +/* + Py_Initialize() + -- do everything, no-op on second call, call fatal on failure, set path + + #2 + -- create new interp+tstate & make it current, return NULL on failure, + make it current, do all setup, set path + + #3 + -- #2 without set path + + #4 + -- is there any point to #3 for caller-provided current interp+tstate? + +*/ + /* Create __main__ module */ static void |