From: <th...@us...> - 2009-08-04 00:06:26
|
Revision: 6628 http://jython.svn.sourceforge.net/jython/?rev=6628&view=rev Author: thobes Date: 2009-08-04 00:06:16 +0000 (Tue, 04 Aug 2009) Log Message: ----------- Imported patches by "Andrea" for issues 1412 and 1419, also for {PyList,PyTuple}.toArray(Object[]); as well as adding link to core javadoc. Modified Paths: -------------- trunk/jython/build.xml trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PyTuple.java trunk/jython/src/org/python/core/PythonTraceFunction.java Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2009-08-03 06:30:19 UTC (rev 6627) +++ trunk/jython/build.xml 2009-08-04 00:06:16 UTC (rev 6628) @@ -634,6 +634,7 @@ windowtitle="Jython API documentation" bottom="<a href='http://www.jython.org' target='_top'>Jython homepage</a>" > + <link href="http://java.sun.com/j2se/1.5.0/docs/api/" /> <classpath refid="javadoc.classpath" /> </javadoc> </target> Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2009-08-03 06:30:19 UTC (rev 6627) +++ trunk/jython/src/org/python/core/PyList.java 2009-08-04 00:06:16 UTC (rev 6628) @@ -17,6 +17,8 @@ import java.util.List; import java.util.ListIterator; +import java.lang.reflect.Array; + @ExposedType(name = "list", base = PyObject.class) public class PyList extends PySequenceList implements List { @@ -977,7 +979,7 @@ @Override public synchronized int indexOf(Object o) { - return list.indexOf(o); + return list.indexOf(Py.java2py(o)); } @Override @@ -1134,15 +1136,18 @@ @Override public synchronized Object[] toArray(Object[] a) { - Object copy[] = list.toArray(); - if (a.length < copy.length) { - a = copy; + int size = size(); + Class<?> type = a.getClass().getComponentType(); + if (a.length < size) { + a = (Object[])Array.newInstance(type, size); } - for (int i = 0; i < copy.length; i++) { - a[i] = ((PyObject) copy[i]).__tojava__(Object.class); + for (int i = 0; i < size; i++) { + a[i] = list.get(i).__tojava__(type); } - if (a.length > copy.length) { - a[copy.length] = null; + if (a.length > size) { + for (int i = size; i < a.length; i++) { + a[i] = null; + } } return a; } Modified: trunk/jython/src/org/python/core/PyTuple.java =================================================================== --- trunk/jython/src/org/python/core/PyTuple.java 2009-08-03 06:30:19 UTC (rev 6627) +++ trunk/jython/src/org/python/core/PyTuple.java 2009-08-04 00:06:16 UTC (rev 6628) @@ -7,6 +7,8 @@ import java.util.List; import java.util.ListIterator; +import java.lang.reflect.Array; + import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; import org.python.expose.ExposedType; @@ -494,7 +496,7 @@ @Override public int indexOf(Object o) { - return getList().indexOf(o); + return getList().indexOf(Py.java2py(o)); } @Override @@ -543,11 +545,12 @@ @Override public Object[] toArray(Object[] converted) { - if (converted.length != array.length) { - converted = new Object[array.length]; + Class<?> type = converted.getClass().getComponentType(); + if (converted.length < array.length) { + converted = (Object[])Array.newInstance(type, array.length); } for (int i = 0; i < array.length; i++) { - converted[i] = array[i].__tojava__(Object.class); + converted[i] = type.cast(array[i].__tojava__(type)); } if (array.length < converted.length) { for (int i = array.length; i < converted.length; i++) { Modified: trunk/jython/src/org/python/core/PythonTraceFunction.java =================================================================== --- trunk/jython/src/org/python/core/PythonTraceFunction.java 2009-08-03 06:30:19 UTC (rev 6627) +++ trunk/jython/src/org/python/core/PythonTraceFunction.java 2009-08-04 00:06:16 UTC (rev 6628) @@ -52,8 +52,9 @@ } public TraceFunction traceException(PyFrame frame, PyException exc) { - return safeCall(frame, - "exception", - new PyTuple(exc.type, exc.value, exc.traceback)); + // We must avoid passing a null to a PyTuple + PyObject safeTraceback = exc.traceback == null ? Py.None : exc.traceback; + return safeCall(frame, "exception", + new PyTuple(exc.type, exc.value, safeTraceback)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |