diff options
Diffstat (limited to 'Python/errors.c')
-rw-r--r-- | Python/errors.c | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/Python/errors.c b/Python/errors.c index e170c9d..ce77858 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -499,6 +499,38 @@ _PyErr_GetExcInfo(PyThreadState *tstate, Py_XINCREF(*p_traceback); } +PyObject* +_PyErr_GetHandledException(PyThreadState *tstate) +{ + _PyErr_StackItem *exc_info = _PyErr_GetTopmostException(tstate); + PyObject *exc = exc_info->exc_value; + if (exc == NULL || exc == Py_None) { + return NULL; + } + return Py_NewRef(exc); +} + +PyObject* +PyErr_GetHandledException(void) +{ + PyThreadState *tstate = _PyThreadState_GET(); + return _PyErr_GetHandledException(tstate); +} + +void +_PyErr_SetHandledException(PyThreadState *tstate, PyObject *exc) +{ + PyObject *oldexc = tstate->exc_info->exc_value; + tstate->exc_info->exc_value = Py_XNewRef(exc); + Py_XDECREF(oldexc); +} + +void +PyErr_SetHandledException(PyObject *exc) +{ + PyThreadState *tstate = _PyThreadState_GET(); + _PyErr_SetHandledException(tstate, exc); +} void PyErr_GetExcInfo(PyObject **p_type, PyObject **p_value, PyObject **p_traceback) @@ -510,17 +542,10 @@ PyErr_GetExcInfo(PyObject **p_type, PyObject **p_value, PyObject **p_traceback) void PyErr_SetExcInfo(PyObject *type, PyObject *value, PyObject *traceback) { - PyThreadState *tstate = _PyThreadState_GET(); - - PyObject *oldvalue = tstate->exc_info->exc_value; - - tstate->exc_info->exc_value = value; - + PyErr_SetHandledException(value); /* These args are no longer used, but we still need to steal a ref */ Py_XDECREF(type); Py_XDECREF(traceback); - - Py_XDECREF(oldvalue); } |