mirror of
https://github.com/python/cpython.git
synced 2025-07-12 13:55:34 +00:00
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.
This commit is contained in:
parent
7ff20ac9c7
commit
3a44e1b9fb
1 changed files with 16 additions and 19 deletions
|
@ -69,7 +69,6 @@ static PyObject *run_pyc_file Py_PROTO((FILE *fp, char *filename,
|
|||
PyObject *globals, PyObject *locals));
|
||||
static void err_input Py_PROTO((perrdetail *));
|
||||
static void initsigs Py_PROTO((void));
|
||||
static void finisigs Py_PROTO((void));
|
||||
static void call_sys_exitfunc Py_PROTO((void));
|
||||
static void call_ll_exitfuncs Py_PROTO((void));
|
||||
|
||||
|
@ -78,6 +77,7 @@ int Py_VerboseFlag; /* Needed by import.c */
|
|||
int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
|
||||
int Py_NoSiteFlag; /* Suppress 'import site' */
|
||||
int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c */
|
||||
int Py_UsingLocale = 0; /* needed by compile.c, modified by localemodule */
|
||||
|
||||
static int initialized = 0;
|
||||
|
||||
|
@ -134,8 +134,8 @@ Py_Initialize()
|
|||
bimod = _PyBuiltin_Init_1();
|
||||
if (bimod == NULL)
|
||||
Py_FatalError("Py_Initialize: can't initialize __builtin__");
|
||||
interp->builtins = PyModule_GetDict(bimod);
|
||||
Py_INCREF(interp->builtins);
|
||||
Py_INCREF(bimod);
|
||||
interp->builtins = bimod;
|
||||
|
||||
sysmod = _PySys_Init();
|
||||
if (sysmod == NULL)
|
||||
|
@ -148,7 +148,7 @@ Py_Initialize()
|
|||
interp->modules);
|
||||
|
||||
/* phase 2 of builtins */
|
||||
_PyBuiltin_Init_2(interp->builtins);
|
||||
_PyBuiltin_Init_2(PyModule_GetDict(bimod));
|
||||
_PyImport_FixupExtension("__builtin__", "__builtin__");
|
||||
|
||||
_PyImport_Init();
|
||||
|
@ -186,21 +186,24 @@ Py_Finalize()
|
|||
return;
|
||||
initialized = 0;
|
||||
|
||||
/* We must call this before the current thread gets removed because
|
||||
it decrefs class instances, which in turn save and restore the
|
||||
current error state, which is a per thread data structure.
|
||||
*/
|
||||
_PyBuiltin_Fini_1();
|
||||
|
||||
/* Get current thread state and interpreter pointer */
|
||||
tstate = PyThreadState_Get();
|
||||
interp = tstate->interp;
|
||||
|
||||
/* Disable signal handling */
|
||||
PyOS_FiniInterrupts();
|
||||
|
||||
/* Destroy PyExc_MemoryErrorInst */
|
||||
_PyBuiltin_Fini_1();
|
||||
|
||||
/* Destroy all modules */
|
||||
PyImport_Cleanup();
|
||||
|
||||
/* Delete current thread
|
||||
PyInterpreterState_Clear(interp);
|
||||
PyThreadState_Swap(NULL);
|
||||
PyInterpreterState_Delete(interp);
|
||||
|
||||
finisigs();
|
||||
_PyImport_Fini();
|
||||
|
||||
/* Now we decref the exception classes. After this point nothing
|
||||
|
@ -284,8 +287,8 @@ Py_NewInterpreter()
|
|||
|
||||
bimod = _PyImport_FindExtension("__builtin__", "__builtin__");
|
||||
if (bimod != NULL) {
|
||||
interp->builtins = PyModule_GetDict(bimod);
|
||||
Py_INCREF(interp->builtins);
|
||||
Py_INCREF(bimod);
|
||||
interp->builtins = bimod;
|
||||
}
|
||||
sysmod = _PyImport_FindExtension("sys", "sys");
|
||||
if (bimod != NULL && sysmod != NULL) {
|
||||
|
@ -1102,12 +1105,6 @@ initsigs()
|
|||
PyOS_InitInterrupts(); /* May imply initsignal() */
|
||||
}
|
||||
|
||||
static void
|
||||
finisigs()
|
||||
{
|
||||
PyOS_FiniInterrupts(); /* May imply finisignal() */
|
||||
}
|
||||
|
||||
#ifdef Py_TRACE_REFS
|
||||
/* Ask a yes/no question */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue