]> granicus.if.org Git - python/commitdiff
SF Patch #871704: Py_SequenceFast can mask errors
authorRaymond Hettinger <python@rcn.com>
Sun, 11 Jan 2004 23:26:51 +0000 (23:26 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 11 Jan 2004 23:26:51 +0000 (23:26 +0000)
(Contributed by Greg Chapman.)

Since this only changes the error message, I doubt that it should be
backported.

Objects/abstract.c

index 342d9718798c2f02c1c015279413dc4cc54f5158..4ac92608ab91a128c3b8be97a9123178d54a1f14 100644 (file)
@@ -1496,6 +1496,8 @@ PySequence_List(PyObject *v)
 PyObject *
 PySequence_Fast(PyObject *v, const char *m)
 {
+       PyObject *it;
+
        if (v == NULL)
                return null_error();
 
@@ -1504,9 +1506,15 @@ PySequence_Fast(PyObject *v, const char *m)
                return v;
        }
 
-       v = PySequence_Tuple(v);
-       if (v == NULL && PyErr_ExceptionMatches(PyExc_TypeError))
-               return type_error(m);
+       it = PyObject_GetIter(v);
+       if (it == NULL) {
+               if (PyErr_ExceptionMatches(PyExc_TypeError))
+                       return type_error(m);
+               return NULL;
+       }
+
+       v = PySequence_Tuple(it);
+       Py_DECREF(it);
 
        return v;
 }