summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorCollin Winter <collinw@gmail.com>2007-03-21 02:57:17 (GMT)
committerCollin Winter <collinw@gmail.com>2007-03-21 02:57:17 (GMT)
commit670e6921349dd408b6958a0c5d3b1486725f9beb (patch)
tree719d6b0e5348693a2d985dfabc5e9160f7f79108 /Python
parent450ee81b227b093eeb0b7a933fe6ddc6dc768d4a (diff)
downloadcpython-670e6921349dd408b6958a0c5d3b1486725f9beb.zip
cpython-670e6921349dd408b6958a0c5d3b1486725f9beb.tar.gz
cpython-670e6921349dd408b6958a0c5d3b1486725f9beb.tar.bz2
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c2
-rw-r--r--Python/pythonrun.c42
-rw-r--r--Python/sysmodule.c3
3 files changed, 20 insertions, 27 deletions
diff --git a/Python/import.c b/Python/import.c
index 33953c7..6d65703 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -361,7 +361,7 @@ PyImport_GetModuleDict(void)
/* List of names to clear in sys */
static char* sys_deletes[] = {
- "path", "argv", "ps1", "ps2", "exitfunc",
+ "path", "argv", "ps1", "ps2",
"exc_type", "exc_value", "exc_traceback",
"last_type", "last_value", "last_traceback",
"path_hooks", "path_importer_cache", "meta_path",
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index d60ca9e..31c8329 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -56,7 +56,7 @@ static PyObject *run_pyc_file(FILE *, const char *, PyObject *, PyObject *,
PyCompilerFlags *);
static void err_input(perrdetail *);
static void initsigs(void);
-static void call_sys_exitfunc(void);
+static void call_py_exitfuncs(void);
static void call_ll_exitfuncs(void);
extern void _PyUnicode_Init(void);
extern void _PyUnicode_Fini(void);
@@ -355,7 +355,7 @@ Py_Finalize(void)
* threads created thru it, so this also protects pending imports in
* the threads created via Threading.
*/
- call_sys_exitfunc();
+ call_py_exitfuncs();
initialized = 0;
/* Get current thread state and interpreter pointer */
@@ -1557,6 +1557,23 @@ Py_FatalError(const char *msg)
#include "pythread.h"
#endif
+static void (*pyexitfunc)(void) = NULL;
+/* For the atexit module. */
+void _Py_PyAtExit(void (*func)(void))
+{
+ pyexitfunc = func;
+}
+
+static void
+call_py_exitfuncs(void)
+{
+ if (pyexitfunc == NULL)
+ return;
+
+ (*pyexitfunc)();
+ PyErr_Clear();
+}
+
#define NEXITFUNCS 32
static void (*exitfuncs[NEXITFUNCS])(void);
static int nexitfuncs = 0;
@@ -1570,27 +1587,6 @@ int Py_AtExit(void (*func)(void))
}
static void
-call_sys_exitfunc(void)
-{
- PyObject *exitfunc = PySys_GetObject("exitfunc");
-
- if (exitfunc) {
- PyObject *res;
- Py_INCREF(exitfunc);
- PySys_SetObject("exitfunc", (PyObject *)NULL);
- res = PyEval_CallObject(exitfunc, (PyObject *)NULL);
- if (res == NULL) {
- if (!PyErr_ExceptionMatches(PyExc_SystemExit)) {
- PySys_WriteStderr("Error in sys.exitfunc:\n");
- }
- PyErr_Print();
- }
- Py_DECREF(exitfunc);
- }
-
-}
-
-static void
call_ll_exitfuncs(void)
{
while (nexitfuncs > 0)
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index c7d85933..d3c90bf 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -897,9 +897,6 @@ excepthook -- called to handle any uncaught exception other than SystemExit\n\
To customize printing in an interactive session or to install a custom\n\
top-level exception handler, assign other functions to replace these.\n\
\n\
-exitfunc -- if sys.exitfunc exists, this routine is called when Python exits\n\
- Assigning to sys.exitfunc is deprecated; use the atexit module instead.\n\
-\n\
stdin -- standard input file object; used by raw_input() and input()\n\
stdout -- standard output file object; used by print()\n\
stderr -- standard error object; used for error messages\n\