Mercurial > cpython-lru_cache-weakref
diff Python/errors.c @ 76418:9fdec1354af4
Issue #14098: New functions PyErr_GetExcInfo and PyErr_SetExcInfo.
Patch by Stefan Behnel.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Thu, 19 Apr 2012 14:33:43 +0200 |
| parents | cb6811eb20ef |
| children | a281604a5c9a |
line wrap: on
line diff
--- a/Python/errors.c Thu Apr 19 22:22:37 2012 +1000 +++ b/Python/errors.c Thu Apr 19 14:33:43 2012 +0200 @@ -320,6 +320,39 @@ PyErr_Restore(NULL, NULL, NULL); } +void +PyErr_GetExcInfo(PyObject **p_type, PyObject **p_value, PyObject **p_traceback) +{ + PyThreadState *tstate = PyThreadState_GET(); + + *p_type = tstate->exc_type; + *p_value = tstate->exc_value; + *p_traceback = tstate->exc_traceback; + + Py_XINCREF(*p_type); + Py_XINCREF(*p_value); + Py_XINCREF(*p_traceback); +} + +void +PyErr_SetExcInfo(PyObject *p_type, PyObject *p_value, PyObject *p_traceback) +{ + PyObject *oldtype, *oldvalue, *oldtraceback; + PyThreadState *tstate = PyThreadState_GET(); + + oldtype = tstate->exc_type; + oldvalue = tstate->exc_value; + oldtraceback = tstate->exc_traceback; + + tstate->exc_type = p_type; + tstate->exc_value = p_value; + tstate->exc_traceback = p_traceback; + + Py_XDECREF(oldtype); + Py_XDECREF(oldvalue); + Py_XDECREF(oldtraceback); +} + /* Convenience functions to set a type error exception and return 0 */ int
