Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 6547:724382af5339 legacy-trunk
Two independent changes (alas):
- The interp->builtins variable (and hence, __main__.__builtins__) is
once again initialized to the built-in *module* instead of its
dictionary.
- The finalization order is once again changed. Signals are finalized
relatively early, because (1) it DECREF's the signal handlers, and if
a signal handler happens to be a bound method, deleting it could cause
problems when there's no current thread around, and (2) we don't want
to risk executing signal handlers during finalization.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 03 Nov 1997 21:58:47 +0000 |
| parents | 1afcac7658e5 |
| children | b331cd47e0bc |
comparison
equal
deleted
inserted
replaced
| 6546:c915c94ebb6b | 6547:724382af5339 |
|---|---|
| 67 PyObject *globals, PyObject *locals)); | 67 PyObject *globals, PyObject *locals)); |
| 68 static PyObject *run_pyc_file Py_PROTO((FILE *fp, char *filename, | 68 static PyObject *run_pyc_file Py_PROTO((FILE *fp, char *filename, |
| 69 PyObject *globals, PyObject *locals)); | 69 PyObject *globals, PyObject *locals)); |
| 70 static void err_input Py_PROTO((perrdetail *)); | 70 static void err_input Py_PROTO((perrdetail *)); |
| 71 static void initsigs Py_PROTO((void)); | 71 static void initsigs Py_PROTO((void)); |
| 72 static void finisigs Py_PROTO((void)); | |
| 73 static void call_sys_exitfunc Py_PROTO((void)); | 72 static void call_sys_exitfunc Py_PROTO((void)); |
| 74 static void call_ll_exitfuncs Py_PROTO((void)); | 73 static void call_ll_exitfuncs Py_PROTO((void)); |
| 75 | 74 |
| 76 int Py_DebugFlag; /* Needed by parser.c */ | 75 int Py_DebugFlag; /* Needed by parser.c */ |
| 77 int Py_VerboseFlag; /* Needed by import.c */ | 76 int Py_VerboseFlag; /* Needed by import.c */ |
| 78 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ | 77 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ |
| 79 int Py_NoSiteFlag; /* Suppress 'import site' */ | 78 int Py_NoSiteFlag; /* Suppress 'import site' */ |
| 80 int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c */ | 79 int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c */ |
| 80 int Py_UsingLocale = 0; /* needed by compile.c, modified by localemodule */ | |
| 81 | 81 |
| 82 static int initialized = 0; | 82 static int initialized = 0; |
| 83 | 83 |
| 84 /* API to access the initialized flag -- useful for eroteric use */ | 84 /* API to access the initialized flag -- useful for eroteric use */ |
| 85 | 85 |
| 132 Py_FatalError("Py_Initialize: can't make modules dictionary"); | 132 Py_FatalError("Py_Initialize: can't make modules dictionary"); |
| 133 | 133 |
| 134 bimod = _PyBuiltin_Init_1(); | 134 bimod = _PyBuiltin_Init_1(); |
| 135 if (bimod == NULL) | 135 if (bimod == NULL) |
| 136 Py_FatalError("Py_Initialize: can't initialize __builtin__"); | 136 Py_FatalError("Py_Initialize: can't initialize __builtin__"); |
| 137 interp->builtins = PyModule_GetDict(bimod); | 137 Py_INCREF(bimod); |
| 138 Py_INCREF(interp->builtins); | 138 interp->builtins = bimod; |
| 139 | 139 |
| 140 sysmod = _PySys_Init(); | 140 sysmod = _PySys_Init(); |
| 141 if (sysmod == NULL) | 141 if (sysmod == NULL) |
| 142 Py_FatalError("Py_Initialize: can't initialize sys"); | 142 Py_FatalError("Py_Initialize: can't initialize sys"); |
| 143 interp->sysdict = PyModule_GetDict(sysmod); | 143 interp->sysdict = PyModule_GetDict(sysmod); |
| 146 PySys_SetPath(Py_GetPath()); | 146 PySys_SetPath(Py_GetPath()); |
| 147 PyDict_SetItemString(interp->sysdict, "modules", | 147 PyDict_SetItemString(interp->sysdict, "modules", |
| 148 interp->modules); | 148 interp->modules); |
| 149 | 149 |
| 150 /* phase 2 of builtins */ | 150 /* phase 2 of builtins */ |
| 151 _PyBuiltin_Init_2(interp->builtins); | 151 _PyBuiltin_Init_2(PyModule_GetDict(bimod)); |
| 152 _PyImport_FixupExtension("__builtin__", "__builtin__"); | 152 _PyImport_FixupExtension("__builtin__", "__builtin__"); |
| 153 | 153 |
| 154 _PyImport_Init(); | 154 _PyImport_Init(); |
| 155 | 155 |
| 156 initsigs(); /* Signal handling stuff, including initintr() */ | 156 initsigs(); /* Signal handling stuff, including initintr() */ |
| 184 | 184 |
| 185 if (!initialized) | 185 if (!initialized) |
| 186 return; | 186 return; |
| 187 initialized = 0; | 187 initialized = 0; |
| 188 | 188 |
| 189 /* We must call this before the current thread gets removed because | 189 /* Get current thread state and interpreter pointer */ |
| 190 it decrefs class instances, which in turn save and restore the | |
| 191 current error state, which is a per thread data structure. | |
| 192 */ | |
| 193 _PyBuiltin_Fini_1(); | |
| 194 | |
| 195 tstate = PyThreadState_Get(); | 190 tstate = PyThreadState_Get(); |
| 196 interp = tstate->interp; | 191 interp = tstate->interp; |
| 197 | 192 |
| 193 /* Disable signal handling */ | |
| 194 PyOS_FiniInterrupts(); | |
| 195 | |
| 196 /* Destroy PyExc_MemoryErrorInst */ | |
| 197 _PyBuiltin_Fini_1(); | |
| 198 | |
| 199 /* Destroy all modules */ | |
| 198 PyImport_Cleanup(); | 200 PyImport_Cleanup(); |
| 201 | |
| 202 /* Delete current thread | |
| 199 PyInterpreterState_Clear(interp); | 203 PyInterpreterState_Clear(interp); |
| 200 PyThreadState_Swap(NULL); | 204 PyThreadState_Swap(NULL); |
| 201 PyInterpreterState_Delete(interp); | 205 PyInterpreterState_Delete(interp); |
| 202 | 206 |
| 203 finisigs(); | |
| 204 _PyImport_Fini(); | 207 _PyImport_Fini(); |
| 205 | 208 |
| 206 /* Now we decref the exception classes. After this point nothing | 209 /* Now we decref the exception classes. After this point nothing |
| 207 can raise an exception. That's okay, because each Fini() method | 210 can raise an exception. That's okay, because each Fini() method |
| 208 below has been checked to make sure no exceptions are ever | 211 below has been checked to make sure no exceptions are ever |
| 282 | 285 |
| 283 interp->modules = PyDict_New(); | 286 interp->modules = PyDict_New(); |
| 284 | 287 |
| 285 bimod = _PyImport_FindExtension("__builtin__", "__builtin__"); | 288 bimod = _PyImport_FindExtension("__builtin__", "__builtin__"); |
| 286 if (bimod != NULL) { | 289 if (bimod != NULL) { |
| 287 interp->builtins = PyModule_GetDict(bimod); | 290 Py_INCREF(bimod); |
| 288 Py_INCREF(interp->builtins); | 291 interp->builtins = bimod; |
| 289 } | 292 } |
| 290 sysmod = _PyImport_FindExtension("sys", "sys"); | 293 sysmod = _PyImport_FindExtension("sys", "sys"); |
| 291 if (bimod != NULL && sysmod != NULL) { | 294 if (bimod != NULL && sysmod != NULL) { |
| 292 interp->sysdict = PyModule_GetDict(sysmod); | 295 interp->sysdict = PyModule_GetDict(sysmod); |
| 293 Py_INCREF(interp->sysdict); | 296 Py_INCREF(interp->sysdict); |
| 1100 #endif | 1103 #endif |
| 1101 #endif /* HAVE_SIGNAL_H */ | 1104 #endif /* HAVE_SIGNAL_H */ |
| 1102 PyOS_InitInterrupts(); /* May imply initsignal() */ | 1105 PyOS_InitInterrupts(); /* May imply initsignal() */ |
| 1103 } | 1106 } |
| 1104 | 1107 |
| 1105 static void | |
| 1106 finisigs() | |
| 1107 { | |
| 1108 PyOS_FiniInterrupts(); /* May imply finisignal() */ | |
| 1109 } | |
| 1110 | |
| 1111 #ifdef Py_TRACE_REFS | 1108 #ifdef Py_TRACE_REFS |
| 1112 /* Ask a yes/no question */ | 1109 /* Ask a yes/no question */ |
| 1113 | 1110 |
| 1114 int | 1111 int |
| 1115 _Py_AskYesNo(prompt) | 1112 _Py_AskYesNo(prompt) |
