From: <zy...@us...> - 2009-04-11 07:03:00
|
Revision: 6217 http://jython.svn.sourceforge.net/jython/?rev=6217&view=rev Author: zyasoft Date: 2009-04-11 07:02:56 +0000 (Sat, 11 Apr 2009) Log Message: ----------- Fixed PyTuple#index, #toArray Modified Paths: -------------- branches/newlist/src/org/python/core/PyList.java branches/newlist/src/org/python/core/PyTuple.java Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-11 05:58:57 UTC (rev 6216) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-11 07:02:56 UTC (rev 6217) @@ -11,6 +11,7 @@ import java.util.Collection; import java.util.Collections; +import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -510,12 +511,18 @@ // Follow Python 2.3+ behavior int validStop = boundToSequence(stop); int validStart = boundToSequence(start); - int i = 0; - for (PyObject item : list.subList(validStart, validStop)) { - if (item.equals(o)) { - return i; + int i = validStart; + if (validStart <= validStop) { + try { + for (PyObject item : list.subList(validStart, validStop)) { + if (item.equals(o)) { + return i; + } + i++; + } + } catch (ConcurrentModificationException ex) { + throw Py.ValueError(message); } - i++; } throw Py.ValueError(message); } Modified: branches/newlist/src/org/python/core/PyTuple.java =================================================================== --- branches/newlist/src/org/python/core/PyTuple.java 2009-04-11 05:58:57 UTC (rev 6216) +++ branches/newlist/src/org/python/core/PyTuple.java 2009-04-11 07:02:56 UTC (rev 6217) @@ -541,12 +541,26 @@ @Override public Object[] toArray() { - return array; + Object[] converted = new Object[array.length]; + for (int i = 0; i < array.length; i++) { + converted[i] = array[i].__tojava__(Object.class); + } + return converted; } @Override - public Object[] toArray(Object[] a) { - System.arraycopy(array, 0, a, 0, array.length); - return a; + public Object[] toArray(Object[] converted) { + if (converted.length != array.length) { + converted = new Object[array.length]; + } + for (int i = 0; i < array.length; i++) { + converted[i] = array[i].__tojava__(Object.class); + } + if (array.length < converted.length) { + for (int i = array.length; i < converted.length; i++) { + converted[i] = null; + } + } + return converted; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |