diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-30 06:48:42 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-30 06:48:42 (GMT) |
commit | aa64c46ac9ff168d7730182d48665b0b51b4f69d (patch) | |
tree | fce292f7bbe0c540de322ec06e96ba0115221f9b /Python/errors.c | |
parent | d06c201e5bf74dd1ff227ab7bea73c8c790d234b (diff) | |
download | cpython-aa64c46ac9ff168d7730182d48665b0b51b4f69d.zip cpython-aa64c46ac9ff168d7730182d48665b0b51b4f69d.tar.gz cpython-aa64c46ac9ff168d7730182d48665b0b51b4f69d.tar.bz2 |
Issue #23781: Add private helper function _PyErr_ReplaceException() that
corresponds _PyErr_ChainExceptions() in Python 3 to help porting patches
from Python 3.
Diffstat (limited to 'Python/errors.c')
-rw-r--r-- | Python/errors.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Python/errors.c b/Python/errors.c index 64ba05d..00dfd3e 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -263,6 +263,26 @@ PyErr_Clear(void) PyErr_Restore(NULL, NULL, NULL); } +/* Restore previously fetched exception if an exception is not set, + otherwise drop previously fetched exception. + Like _PyErr_ChainExceptions() in Python 3, but doesn't set the context. + */ +void +_PyErr_ReplaceException(PyObject *exc, PyObject *val, PyObject *tb) +{ + if (exc == NULL) + return; + + if (PyErr_Occurred()) { + Py_DECREF(exc); + Py_XDECREF(val); + Py_XDECREF(tb); + } + else { + PyErr_Restore(exc, val, tb); + } +} + /* Convenience functions to set a type error exception and return 0 */ int |