[Python-checkins] python/dist/src/Python sysmodule.c,2.114,2.115
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Fri, 28 Feb 2003 19:20:44 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv29053/Python
Modified Files:
sysmodule.c
Log Message:
- New function sys.exc_clear() clears the current exception. This is
rarely needed, but can sometimes be useful to release objects
referenced by the traceback held in sys.exc_info()[2]. (SF patch
#693195.) Thanks to Kevin Jacobs!
Index: sysmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/sysmodule.c,v
retrieving revision 2.114
retrieving revision 2.115
diff -C2 -d -r2.114 -r2.115
*** sysmodule.c 19 Feb 2003 15:24:39 -0000 2.114
--- sysmodule.c 1 Mar 2003 03:20:41 -0000 2.115
***************
*** 133,137 ****
static PyObject *
! sys_exc_info(PyObject *self)
{
PyThreadState *tstate;
--- 133,137 ----
static PyObject *
! sys_exc_info(PyObject *self, PyObject *noargs)
{
PyThreadState *tstate;
***************
*** 148,153 ****
"exc_info() -> (type, value, traceback)\n\
\n\
! Return information about the exception that is currently being handled.\n\
! This should be called from inside an except clause only."
);
--- 148,184 ----
"exc_info() -> (type, value, traceback)\n\
\n\
! Return information about the most recent exception caught by an except\n\
! clause in the current stack frame or in an older stack frame."
! );
!
! static PyObject *
! sys_exc_clear(PyObject *self, PyObject *noargs)
! {
! PyThreadState *tstate = PyThreadState_Get();
! PyObject *tmp_type, *tmp_value, *tmp_tb;
! tmp_type = tstate->exc_type;
! tmp_value = tstate->exc_value;
! tmp_tb = tstate->exc_traceback;
! tstate->exc_type = NULL;
! tstate->exc_value = NULL;
! tstate->exc_traceback = NULL;
! Py_XDECREF(tmp_type);
! Py_XDECREF(tmp_value);
! Py_XDECREF(tmp_tb);
! /* For b/w compatibility */
! PySys_SetObject("exc_type", Py_None);
! PySys_SetObject("exc_value", Py_None);
! PySys_SetObject("exc_traceback", Py_None);
! Py_INCREF(Py_None);
! return Py_None;
! }
!
! PyDoc_STRVAR(exc_clear_doc,
! "exc_clear() -> None\n\
! \n\
! Clear global information on the current exception. Subsequent calls to\n\
! exc_info() will return (None,None,None) until another exception is raised\n\
! in the current thread or the execution stack returns to a frame where\n\
! another exception is being handled."
);
***************
*** 601,605 ****
callstats_doc},
{"displayhook", sys_displayhook, METH_O, displayhook_doc},
! {"exc_info", (PyCFunction)sys_exc_info, METH_NOARGS, exc_info_doc},
{"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
{"exit", sys_exit, METH_VARARGS, exit_doc},
--- 632,637 ----
callstats_doc},
{"displayhook", sys_displayhook, METH_O, displayhook_doc},
! {"exc_info", sys_exc_info, METH_NOARGS, exc_info_doc},
! {"exc_clear", sys_exc_clear, METH_NOARGS, exc_clear_doc},
{"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
{"exit", sys_exit, METH_VARARGS, exit_doc},
***************
*** 787,790 ****
--- 819,823 ----
excepthook() -- print an exception and its traceback to sys.stderr\n\
exc_info() -- return thread-safe information about the current exception\n\
+ exc_clear() -- clear the exception state for the current thread\n\
exit() -- exit the interpreter by raising SystemExit\n\
getdlopenflags() -- returns flags to be used for dlopen() calls\n\