Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-28994: Chain exceptions rather than dropping the old exception.
  • Loading branch information
serhiy-storchaka committed Nov 6, 2017
commit 09668664af1fe3f828c20ffd859d3a7c08b0527f
18 changes: 11 additions & 7 deletions Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,14 +924,17 @@ void _ctypes_extend_error(PyObject *exc_class, const char *fmt, ...)
va_list vargs;
PyObject *tp, *v, *tb, *s, *cls_str, *msg_str;

PyErr_Fetch(&tp, &v, &tb);
assert(tp != NULL);
PyErr_NormalizeException(&tp, &v, &tb);

va_start(vargs, fmt);
s = PyUnicode_FromFormatV(fmt, vargs);
va_end(vargs);
if (!s)
return;
if (s == NULL) {
goto error;
}

PyErr_Fetch(&tp, &v, &tb);
PyErr_NormalizeException(&tp, &v, &tb);
cls_str = PyObject_Str(tp);
if (cls_str) {
PyUnicode_AppendAndDel(&s, cls_str);
Expand All @@ -950,10 +953,11 @@ void _ctypes_extend_error(PyObject *exc_class, const char *fmt, ...)
if (s == NULL)
goto error;
PyErr_SetObject(exc_class, s);
Py_DECREF(s);
return;

error:
Py_XDECREF(tp);
Py_XDECREF(v);
Py_XDECREF(tb);
_PyErr_ChainExceptions(tp, v, tb);
Py_XDECREF(s);
}

Expand Down
16 changes: 5 additions & 11 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,11 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc, int closing)
/* Pop the exception before issuing a warning. */
PyErr_Fetch(&exc, &val, &tb);

if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
"generator '%.50S' raised StopIteration",
gen->gi_qualname)) {
/* Warning was converted to an error. */
Py_XDECREF(exc);
Py_XDECREF(val);
Py_XDECREF(tb);
}
else {
PyErr_Restore(exc, val, tb);
}
(void)PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
"generator '%.50S' raised StopIteration",
gen->gi_qualname);
/* Warning can be converted to an error. */
_PyErr_ChainExceptions(exc, val, tb);
}
}
else if (PyAsyncGen_CheckExact(gen) && !result &&
Expand Down
31 changes: 7 additions & 24 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -4224,28 +4224,20 @@ call_exc_trace(Py_tracefunc func, PyObject *self,
PyThreadState *tstate, PyFrameObject *f)
{
PyObject *type, *value, *traceback, *orig_traceback, *arg;
int err;
PyErr_Fetch(&type, &value, &orig_traceback);
assert(type != NULL);
if (value == NULL) {
value = Py_None;
Py_INCREF(value);
}
PyErr_NormalizeException(&type, &value, &orig_traceback);
traceback = (orig_traceback != NULL) ? orig_traceback : Py_None;
arg = PyTuple_Pack(3, type, value, traceback);
if (arg == NULL) {
PyErr_Restore(type, value, orig_traceback);
return;
}
err = call_trace(func, self, tstate, f, PyTrace_EXCEPTION, arg);
Py_DECREF(arg);
if (err == 0)
PyErr_Restore(type, value, orig_traceback);
else {
Py_XDECREF(type);
Py_XDECREF(value);
Py_XDECREF(orig_traceback);
if (arg != NULL) {
(void)call_trace(func, self, tstate, f, PyTrace_EXCEPTION, arg);
Py_DECREF(arg);
}
_PyErr_ChainExceptions(type, value, orig_traceback);
}

static int
Expand All @@ -4257,17 +4249,8 @@ call_trace_protected(Py_tracefunc func, PyObject *obj,
int err;
PyErr_Fetch(&type, &value, &traceback);
err = call_trace(func, obj, tstate, frame, what, arg);
if (err == 0)
{
PyErr_Restore(type, value, traceback);
return 0;
}
else {
Py_XDECREF(type);
Py_XDECREF(value);
Py_XDECREF(traceback);
return -1;
}
_PyErr_ChainExceptions(type, value, traceback);
return err;
}

static int
Expand Down
4 changes: 1 addition & 3 deletions Python/traceback.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,7 @@ PyTraceBack_Print(PyObject *v, PyObject *f)
limit = PyTraceBack_LIMIT;
}
else {
Py_XDECREF(exc_type);
Py_XDECREF(exc_value);
Py_XDECREF(exc_tb);
_PyErr_ChainExceptions(exc_type, exc_value, exc_tb);
return 0;
}
}
Expand Down