From: <cg...@us...> - 2007-08-05 21:10:06
|
Revision: 3394 http://jython.svn.sourceforge.net/jython/?rev=3394&view=rev Author: cgroves Date: 2007-08-05 14:10:04 -0700 (Sun, 05 Aug 2007) Log Message: ----------- Fall back to o.__rmul__(this) if this.__imul__(o) fails. list.setSize calls list.ensureCapacity, so there's no need to do it twice. Modified Paths: -------------- branches/2.3/src/org/python/core/PyList.java Modified: branches/2.3/src/org/python/core/PyList.java =================================================================== --- branches/2.3/src/org/python/core/PyList.java 2007-08-05 00:48:58 UTC (rev 3393) +++ branches/2.3/src/org/python/core/PyList.java 2007-08-05 21:10:04 UTC (rev 3394) @@ -913,7 +913,21 @@ } public PyObject __imul__(PyObject o) { - return list___imul__(o); + try { + return list___imul__(o); + } catch(PyException e) { + if(Py.matchException(e, Py.TypeError)) { + // We can't perform an in-place multiplication on o's type, so + // let o try to rmul this list. A new list will be created + // instead of modifying this one, but that's preferable to just + // blowing up on this operation. + PyObject result = o.__rmul__(this); + if(result != null) { + return result; + } + } + throw e; + } } final PyObject list___imul__(PyObject o) { @@ -923,13 +937,11 @@ int count = ((PyInteger)o.__int__()).getValue(); int newSize = l * count; - list.ensureCapacity(newSize); list.setSize(newSize); - //resize(l * count); PyObject[] array = getArray(); - for (int i=1; i<count; i++) { - System.arraycopy(array, 0, array, i*l, l); + for(int i = 1; i < count; i++) { + System.arraycopy(array, 0, array, i * l, l); } return this; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |