From: <pj...@us...> - 2008-07-08 05:24:18
|
Revision: 4866 http://jython.svn.sourceforge.net/jython/?rev=4866&view=rev Author: pjenvey Date: 2008-07-07 22:24:17 -0700 (Mon, 07 Jul 2008) Log Message: ----------- o make StopIteration (and the like) a 'sink state' in iter and call-iter, to fix the test_iter test_sinkstate_* tests o workaround test_iter test_unpack_iter GC related issues Modified Paths: -------------- branches/asm/Lib/test/test_iter.py branches/asm/src/org/python/core/PyCallIter.java branches/asm/src/org/python/core/PySequenceIter.java Modified: branches/asm/Lib/test/test_iter.py =================================================================== --- branches/asm/Lib/test/test_iter.py 2008-07-08 05:20:37 UTC (rev 4865) +++ branches/asm/Lib/test/test_iter.py 2008-07-08 05:24:17 UTC (rev 4866) @@ -780,11 +780,16 @@ # Test reference count behavior - class C(object): + # XXX: Jython new style objects don't support __del__ yet + from test_weakref import extra_collect + #class C(object): + class C: count = 0 - def __new__(cls): + #def __new__(cls): + def __init__(self): + cls = C cls.count += 1 - return object.__new__(cls) + #return object.__new__(cls) def __del__(self): cls = self.__class__ assert cls.count > 0 @@ -792,6 +797,7 @@ x = C() self.assertEqual(C.count, 1) del x + extra_collect() self.assertEqual(C.count, 0) l = [C(), C(), C()] self.assertEqual(C.count, 3) @@ -800,6 +806,7 @@ except ValueError: pass del l + extra_collect() self.assertEqual(C.count, 0) Modified: branches/asm/src/org/python/core/PyCallIter.java =================================================================== --- branches/asm/src/org/python/core/PyCallIter.java 2008-07-08 05:20:37 UTC (rev 4865) +++ branches/asm/src/org/python/core/PyCallIter.java 2008-07-08 05:24:17 UTC (rev 4866) @@ -15,19 +15,25 @@ } public PyObject __iternext__() { - PyObject val = null; + if (callable == null) { + return null; + } + + PyObject result; try { - val = callable.__call__(); + result = callable.__call__(); } catch (PyException exc) { if (Py.matchException(exc, Py.StopIteration)) { + callable = null; stopException = exc; return null; } throw exc; } - if (val._eq(sentinel).__nonzero__()) { + if (result._eq(sentinel).__nonzero__()) { + callable = null; return null; } - return val; + return result; } } Modified: branches/asm/src/org/python/core/PySequenceIter.java =================================================================== --- branches/asm/src/org/python/core/PySequenceIter.java 2008-07-08 05:20:37 UTC (rev 4865) +++ branches/asm/src/org/python/core/PySequenceIter.java 2008-07-08 05:24:17 UTC (rev 4866) @@ -10,14 +10,24 @@ } public PyObject __iternext__() { + if (seq == null) { + return null; + } + + PyObject result; try { - return seq.__finditem__(idx++); + result = seq.__finditem__(idx++); } catch (PyException exc) { - if (Py.matchException(exc, Py.StopIteration)) + if (Py.matchException(exc, Py.StopIteration)) { + seq = null; return null; + } throw exc; } + if (result == null) { + seq = null; + } + return result; } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |