summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-08-05 02:22:03 (GMT)
committerGuido van Rossum <guido@python.org>1997-08-05 02:22:03 (GMT)
commitcc283f56a79e85fc7163f455b2ab4e0c28e93ff5 (patch)
treefd8dea3f91c3fb6f141c4a923322c191d486eda9 /Python
parent085d269f1d91bcbe051ee423089230dd072d1cc4 (diff)
downloadcpython-cc283f56a79e85fc7163f455b2ab4e0c28e93ff5.zip
cpython-cc283f56a79e85fc7163f455b2ab4e0c28e93ff5.tar.gz
cpython-cc283f56a79e85fc7163f455b2ab4e0c28e93ff5.tar.bz2
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
functions.
Diffstat (limited to 'Python')
-rw-r--r--Python/pythonrun.c79
1 files changed, 43 insertions, 36 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index d0fe2fc..4d64114 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -69,6 +69,8 @@ static PyObject *run_pyc_file Py_PROTO((FILE *fp, char *filename,
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));
int Py_DebugFlag; /* Needed by parser.c */
int Py_VerboseFlag; /* Needed by import.c */
@@ -162,6 +164,8 @@ Py_Finalize()
PyInterpreterState *interp;
PyThreadState *tstate;
+ call_sys_exitfunc();
+
if (!initialized)
Py_FatalError("Py_Finalize: not initialized");
initialized = 0;
@@ -177,9 +181,38 @@ Py_Finalize()
finisigs();
_PyImport_Fini();
_PyBuiltin_Fini();
+ PyMethod_Fini();
+ PyFrame_Fini();
+ PyCFunction_Fini();
+ PyTuple_Fini();
PyString_Fini();
+ PyInt_Fini();
+ PyFloat_Fini();
+
+ /* XXX Still allocated:
+ - various static ad-hoc pointers to interned strings
+ - int and float free list blocks
+ - whatever various modules and libraries allocate
+ */
PyGrammar_RemoveAccelerators(&_PyParser_Grammar);
+
+ call_ll_exitfuncs();
+
+#ifdef COUNT_ALLOCS
+ dump_counts();
+#endif
+
+#ifdef Py_REF_DEBUG
+ fprintf(stderr, "[%ld refs]\n", _Py_RefTotal);
+#endif
+
+#ifdef Py_TRACE_REFS
+ if (_Py_AskYesNo("Print left references?")) {
+ _Py_PrintReferences(stderr);
+ }
+ _Py_ResetReferences();
+#endif /* Py_TRACE_REFS */
}
/* Create and initialize a new interpreter and thread, and return the
@@ -297,22 +330,6 @@ Py_GetProgramName()
return progname;
}
-/*
- 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
@@ -831,8 +848,8 @@ int Py_AtExit(func)
return 0;
}
-void
-Py_Cleanup()
+static void
+call_sys_exitfunc()
{
PyObject *exitfunc = PySys_GetObject("exitfunc");
@@ -849,9 +866,11 @@ Py_Cleanup()
}
Py_FlushLine();
+}
- Py_Finalize();
-
+static void
+call_ll_exitfuncs()
+{
while (nexitfuncs > 0)
(*exitfuncs[--nexitfuncs])();
@@ -867,21 +886,7 @@ void
Py_Exit(sts)
int sts;
{
- Py_Cleanup();
-
-#ifdef COUNT_ALLOCS
- dump_counts();
-#endif
-
-#ifdef Py_REF_DEBUG
- fprintf(stderr, "[%ld refs]\n", _Py_RefTotal);
-#endif
-
-#ifdef Py_TRACE_REFS
- if (_Py_AskYesNo("Print left references?")) {
- _Py_PrintReferences(stderr);
- }
-#endif /* Py_TRACE_REFS */
+ Py_Finalize();
#ifdef macintosh
PyMac_Exit(sts);
@@ -896,7 +901,9 @@ sighandler(sig)
int sig;
{
signal(sig, SIG_DFL); /* Don't catch recursive signals */
- Py_Cleanup(); /* Do essential clean-up */
+ /* Do essential exit processing only */
+ call_sys_exitfunc();
+ call_ll_exitfuncs();
#ifdef HAVE_KILL
kill(getpid(), sig); /* Pretend the signal killed us */
#else