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

Skip to content

Commit 2fb7029

Browse files
committed
SF Patch #871704: Py_SequenceFast can mask errors
(Contributed by Greg Chapman.) Since this only changes the error message, I doubt that it should be backported.
1 parent 44a9823 commit 2fb7029

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Objects/abstract.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,8 @@ PySequence_List(PyObject *v)
14961496
PyObject *
14971497
PySequence_Fast(PyObject *v, const char *m)
14981498
{
1499+
PyObject *it;
1500+
14991501
if (v == NULL)
15001502
return null_error();
15011503

@@ -1504,9 +1506,15 @@ PySequence_Fast(PyObject *v, const char *m)
15041506
return v;
15051507
}
15061508

1507-
v = PySequence_Tuple(v);
1508-
if (v == NULL && PyErr_ExceptionMatches(PyExc_TypeError))
1509-
return type_error(m);
1509+
it = PyObject_GetIter(v);
1510+
if (it == NULL) {
1511+
if (PyErr_ExceptionMatches(PyExc_TypeError))
1512+
return type_error(m);
1513+
return NULL;
1514+
}
1515+
1516+
v = PySequence_Tuple(it);
1517+
Py_DECREF(it);
15101518

15111519
return v;
15121520
}

0 commit comments

Comments
 (0)