Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 5405:b7871ca930ad legacy-trunk
Massive changes for separate thread state management.
All per-thread globals are moved into a struct which is manipulated
separately.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 05 May 1997 20:56:21 +0000 |
| parents | 07ed52e200db |
| children | 596380a567d2 |
comparison
equal
deleted
inserted
replaced
| 5404:3780cce14f7d | 5405:b7871ca930ad |
|---|---|
| 75 int Py_DebugFlag; /* Needed by parser.c */ | 75 int Py_DebugFlag; /* Needed by parser.c */ |
| 76 int Py_VerboseFlag; /* Needed by import.c */ | 76 int Py_VerboseFlag; /* Needed by import.c */ |
| 77 int Py_SuppressPrintingFlag; /* Needed by ceval.c */ | 77 int Py_SuppressPrintingFlag; /* Needed by ceval.c */ |
| 78 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ | 78 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ |
| 79 | 79 |
| 80 /* Initialize all */ | 80 /* Initialize the current interpreter; pass in the Python path. */ |
| 81 | 81 |
| 82 void | 82 void |
| 83 Py_Initialize() | 83 Py_Setup() |
| 84 { | 84 { |
| 85 static int inited; | |
| 86 | |
| 87 if (inited) | |
| 88 return; | |
| 89 inited = 1; | |
| 90 | |
| 91 PyImport_Init(); | 85 PyImport_Init(); |
| 92 | 86 |
| 93 /* Modules '__builtin__' and 'sys' are initialized here, | 87 /* Modules '__builtin__' and 'sys' are initialized here, |
| 94 they are needed by random bits of the interpreter. | 88 they are needed by random bits of the interpreter. |
| 95 All other modules are optional and are initialized | 89 All other modules are optional and are initialized |
| 102 | 96 |
| 103 initsigs(); /* Signal handling stuff, including initintr() */ | 97 initsigs(); /* Signal handling stuff, including initintr() */ |
| 104 | 98 |
| 105 initmain(); | 99 initmain(); |
| 106 } | 100 } |
| 101 | |
| 102 /* Create and interpreter and thread state and initialize them; | |
| 103 if we already have an interpreter and thread, do nothing. | |
| 104 Fatal error if the creation fails. */ | |
| 105 | |
| 106 void | |
| 107 Py_Initialize() | |
| 108 { | |
| 109 PyThreadState *tstate; | |
| 110 PyInterpreterState *interp; | |
| 111 if (PyThreadState_Get()) | |
| 112 return; | |
| 113 interp = PyInterpreterState_New(); | |
| 114 if (interp == NULL) | |
| 115 Py_FatalError("PyInterpreterState_New() failed"); | |
| 116 tstate = PyThreadState_New(interp); | |
| 117 if (tstate == NULL) | |
| 118 Py_FatalError("PyThreadState_New() failed"); | |
| 119 (void) PyThreadState_Swap(tstate); | |
| 120 | |
| 121 Py_Setup(); | |
| 122 | |
| 123 PySys_SetPath(Py_GetPath()); | |
| 124 } | |
| 125 | |
| 126 /* | |
| 127 Py_Initialize() | |
| 128 -- do everything, no-op on second call, call fatal on failure, set path | |
| 129 | |
| 130 #2 | |
| 131 -- create new interp+tstate & make it current, return NULL on failure, | |
| 132 make it current, do all setup, set path | |
| 133 | |
| 134 #3 | |
| 135 -- #2 without set path | |
| 136 | |
| 137 #4 | |
| 138 -- is there any point to #3 for caller-provided current interp+tstate? | |
| 139 | |
| 140 */ | |
| 107 | 141 |
| 108 /* Create __main__ module */ | 142 /* Create __main__ module */ |
| 109 | 143 |
| 110 static void | 144 static void |
| 111 initmain() | 145 initmain() |
