Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2d854c8

Browse files
committed
Issue #20024: Py_BuildValue() now saves/restores the current exception before
building an item if the build of a previous item failed.
1 parent 5116f78 commit 2d854c8

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

Python/modsupport.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,17 @@ do_mktuple(const char **p_format, va_list *p_va, int endchar, int n, int flags)
161161
/* Note that we can't bail immediately on error as this will leak
162162
refcounts on any 'N' arguments. */
163163
for (i = 0; i < n; i++) {
164-
PyObject *w = do_mkvalue(p_format, p_va, flags);
164+
PyObject *w;
165+
166+
if (itemfailed) {
167+
PyObject *exception, *value, *tb;
168+
PyErr_Fetch(&exception, &value, &tb);
169+
w = do_mkvalue(p_format, p_va, flags);
170+
PyErr_Restore(exception, value, tb);
171+
}
172+
else {
173+
w = do_mkvalue(p_format, p_va, flags);
174+
}
165175
if (w == NULL) {
166176
itemfailed = 1;
167177
Py_INCREF(Py_None);

0 commit comments

Comments
 (0)