unpack_iterable(): Add a missing DECREF in an error case. Reported by

Armin Rigo (SF bug #488477).  Added a testcase to test_unpack_iter()
in test_iter.py.
This commit is contained in:
Guido van Rossum 2001-12-03 19:33:25 +00:00
parent 2009aa66b4
commit bb8f59a371
2 changed files with 24 additions and 0 deletions

View File

@ -747,6 +747,29 @@ class TestCase(unittest.TestCase):
(a, b), (c,) = IteratingSequenceClass(2), {42: 24}
self.assertEqual((a, b, c), (0, 1, 42))
# Test reference count behavior
class C(object):
count = 0
def __new__(cls):
cls.count += 1
return object.__new__(cls)
def __del__(self):
cls = self.__class__
assert cls.count > 0
cls.count -= 1
x = C()
self.assertEqual(C.count, 1)
del x
self.assertEqual(C.count, 0)
l = [C(), C(), C()]
self.assertEqual(C.count, 3)
try:
a, b = iter(l)
except ValueError:
pass
del l
self.assertEqual(C.count, 0)
def test_main():
run_unittest(TestCase)

View File

@ -2796,6 +2796,7 @@ unpack_iterable(PyObject *v, int argcnt, PyObject **sp)
Py_DECREF(it);
return 1;
}
Py_DECREF(w);
PyErr_SetString(PyExc_ValueError, "too many values to unpack");
/* fall through */
Error: