From: <fwi...@us...> - 2009-04-10 02:22:12
|
Revision: 6195 http://jython.svn.sourceforge.net/jython/?rev=6195&view=rev Author: fwierzbicki Date: 2009-04-10 02:22:11 +0000 (Fri, 10 Apr 2009) Log Message: ----------- Throw exception on mutate during sort. Modified Paths: -------------- branches/newlist/src/org/python/core/PyComparator.java branches/newlist/src/org/python/core/PyList.java Modified: branches/newlist/src/org/python/core/PyComparator.java =================================================================== --- branches/newlist/src/org/python/core/PyComparator.java 2009-04-10 01:09:14 UTC (rev 6194) +++ branches/newlist/src/org/python/core/PyComparator.java 2009-04-10 02:22:11 UTC (rev 6195) @@ -4,11 +4,13 @@ public class PyComparator implements Comparator<PyObject> { - protected PyObject cmp = null; - protected PyObject key = null; + protected PyList list; + protected PyObject cmp; + protected PyObject key; protected boolean reverse = false; - PyComparator(PyObject cmp, PyObject key, boolean reverse) { + PyComparator(PyList list, PyObject cmp, PyObject key, boolean reverse) { + this.list = list; this.cmp = cmp; this.key = key; this.reverse = reverse; @@ -32,6 +34,9 @@ if (reverse) { return -result; } + if (this.list.gListAllocatedStatus >= 0) { + throw Py.ValueError("list modified during sort"); + } return result; } Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-10 01:09:14 UTC (rev 6194) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-10 02:22:11 UTC (rev 6195) @@ -680,12 +680,11 @@ sort(Py.None, Py.None, Py.False); } - public void sort(PyObject cmp, PyObject key, PyObject reverse) { - //System.out.println("sorting with " + cmp + ":" + key + ":" + reverse); - //MergeState ms = new MergeState(this, cmp, key, reverse.__nonzero__()); - //ms.sort(); - PyComparator c = new PyComparator(cmp, key, reverse.__nonzero__()); + public synchronized void sort(PyObject cmp, PyObject key, PyObject reverse) { + gListAllocatedStatus = -1; + PyComparator c = new PyComparator(this, cmp, key, reverse.__nonzero__()); Collections.sort(list, c); + gListAllocatedStatus = __len__(); } public int hashCode() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |