Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
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
31 changes: 7 additions & 24 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -4214,28 +4214,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 @@ -4247,17 +4239,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