From 0ae3ca3f5506dc256f706a84935698caa8cc8d05 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 21 Jan 2014 20:52:17 +0100 Subject: Issue #20024: Py_BuildValue() now saves/restores the current exception before building an item if the build of a previous item failed. --- Python/modsupport.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'Python/modsupport.c') diff --git a/Python/modsupport.c b/Python/modsupport.c index 428914f378..6c938ddd79 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -161,7 +161,17 @@ do_mktuple(const char **p_format, va_list *p_va, int endchar, int n, int flags) /* Note that we can't bail immediately on error as this will leak refcounts on any 'N' arguments. */ for (i = 0; i < n; i++) { - PyObject *w = do_mkvalue(p_format, p_va, flags); + PyObject *w; + + if (itemfailed) { + PyObject *exception, *value, *tb; + PyErr_Fetch(&exception, &value, &tb); + w = do_mkvalue(p_format, p_va, flags); + PyErr_Restore(exception, value, tb); + } + else { + w = do_mkvalue(p_format, p_va, flags); + } if (w == NULL) { itemfailed = 1; Py_INCREF(Py_None); -- cgit v1.2.1