You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <fwi...@us...> - 2009-04-28 17:31:20
|
Revision: 6267 http://jython.svn.sourceforge.net/jython/?rev=6267&view=rev Author: fwierzbicki Date: 2009-04-28 17:31:19 +0000 (Tue, 28 Apr 2009) Log Message: ----------- b4 readme Modified Paths: -------------- trunk/jython/README.txt Modified: trunk/jython/README.txt =================================================================== --- trunk/jython/README.txt 2009-04-27 05:00:40 UTC (rev 6266) +++ trunk/jython/README.txt 2009-04-28 17:31:19 UTC (rev 6267) @@ -1,11 +1,13 @@ -Welcome to Jython 2.5b3 +Welcome to Jython 2.5b4 ======================= -This is the forth beta of the 2.5 version of Jython. It contains a couple of -bug fixes since the 2.5b2 release a couple of days ago. The bug that prompted -another release was a corner case on Windows that caused Jython to not start. -This beta contains all of the new features for the eventual 2.5 release and -represents a feature freeze. +This is the fifth beta of the 2.5 version of Jython. It contains a new +implementation of List and Tuple, as well as a patch which helps Jython run in +an envrironment without file write access (specifically for use on Google App +Engine) There are also a number of smaller bug fixes. This beta contains all +of the new features for the eventual 2.5 release continues the feature freeze. +We are very close, once this beta has been tested in the wild for a bit and we +close a few more high priority bugs, we will start release candidates. The release was compiled on Mac OS X with JDK 5 and requires JDK 5 to run. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-04-27 05:00:44
|
Revision: 6266 http://jython.svn.sourceforge.net/jython/?rev=6266&view=rev Author: cgroves Date: 2009-04-27 05:00:40 +0000 (Mon, 27 Apr 2009) Log Message: ----------- Climb all the way up the stack of superclasses to find methods with respectJavaAccessibility is false. Fixes issue1285. This is going to lead to some weirdness if a superclass defines a method with more restrictive types than a subclass, but ignoring Java accessibility is always going to lead to weirdness, and we already try to steer people away from this flag. Modified Paths: -------------- trunk/jython/Lib/test/test_java_visibility.py trunk/jython/src/org/python/core/PyJavaType.java Added Paths: ----------- trunk/jython/Lib/test/call_overridden_method.py trunk/jython/tests/java/org/python/tests/RespectJavaAccessibility.java Added: trunk/jython/Lib/test/call_overridden_method.py =================================================================== --- trunk/jython/Lib/test/call_overridden_method.py (rev 0) +++ trunk/jython/Lib/test/call_overridden_method.py 2009-04-27 05:00:40 UTC (rev 6266) @@ -0,0 +1,14 @@ +from org.python.tests.RespectJavaAccessibility import Banana, Pear + +p = Pear() +b = Banana() +assert b.amethod() == 'Banana.amethod()' +assert p.amethod() == 'Banana.amethod()' +assert b.amethod(1,2) == 'Banana.amethod(x,y)' +assert p.amethod(1,2) == 'Pear.amethod(x,y)' +assert b.privBanana() == 'Banana.privBanana()' +assert p.privPear() == 'Pear.privPear()' +assert b.protMethod() == 'Banana.protMethod()' +assert p.protMethod() == 'Banana.protMethod()' +assert b.protMethod(1,2) == 'Banana.protMethod(x,y)' +assert p.protMethod(1,2) == 'Pear.protMethod(x,y)' Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2009-04-27 00:56:29 UTC (rev 6265) +++ trunk/jython/Lib/test/test_java_visibility.py 2009-04-27 05:00:40 UTC (rev 6266) @@ -228,6 +228,9 @@ def test_protected_class(self): self.run_accessibility_script("access_protected_class.py", TypeError) + def test_overriding(self): + self.run_accessibility_script("call_overridden_method.py") + class ClassloaderTest(unittest.TestCase): def test_loading_classes_without_import(self): cl = test_support.make_jar_classloader("../callbacker_test.jar") Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-04-27 00:56:29 UTC (rev 6265) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-04-27 05:00:40 UTC (rev 6266) @@ -229,10 +229,15 @@ // returns just the public methods methods = forClass.getMethods(); } else { - methods = forClass.getDeclaredMethods(); - for (Method method : methods) { - method.setAccessible(true); + // Grab all methods on this class and all of its superclasses and make them accessible + List<Method> allMethods = Generic.list(); + for(Class<?> c = forClass; c != null; c = c.getSuperclass()) { + for (Method meth : c.getDeclaredMethods()) { + allMethods.add(meth); + meth.setAccessible(true); + } } + methods = allMethods.toArray(new Method[allMethods.size()]); } boolean isInAwt = name.startsWith("java.awt.") && name.indexOf('.', 9) == -1; Added: trunk/jython/tests/java/org/python/tests/RespectJavaAccessibility.java =================================================================== --- trunk/jython/tests/java/org/python/tests/RespectJavaAccessibility.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/RespectJavaAccessibility.java 2009-04-27 05:00:40 UTC (rev 6266) @@ -0,0 +1,42 @@ +package org.python.tests; + +public class RespectJavaAccessibility { + + public static class Banana { + + public String amethod() { + return "Banana.amethod()"; + } + + public String amethod(int x, int y) { + return "Banana.amethod(x,y)"; + } + + protected String protMethod() { + return "Banana.protMethod()"; + } + + protected String protMethod(int x, int y) { + return "Banana.protMethod(x,y)"; + } + + private String privBanana() { + return "Banana.privBanana()"; + } + } + + public static class Pear extends Banana { + + public String amethod(int x, int y) { + return "Pear.amethod(x,y)"; + } + + protected String protMethod(int x, int y) { + return "Pear.protMethod(x,y)"; + } + + private String privPear() { + return "Pear.privPear()"; + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-04-27 00:56:40
|
Revision: 6265 http://jython.svn.sourceforge.net/jython/?rev=6265&view=rev Author: cgroves Date: 2009-04-27 00:56:29 +0000 (Mon, 27 Apr 2009) Log Message: ----------- Naming collision clarification Modified Paths: -------------- trunk/jython/Lib/test/test_java_visibility.py Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2009-04-27 00:56:11 UTC (rev 6264) +++ trunk/jython/Lib/test/test_java_visibility.py 2009-04-27 00:56:29 UTC (rev 6265) @@ -19,21 +19,21 @@ "Calling a Java class with package protected constructors should raise a TypeError") def test_protected_from_python_subclass(self): - class SubVisible(Visible): + class PySubVisible(Visible): def __init__(self, publicValue=None): if publicValue is not None: Visible.__init__(self, publicValue) else: Visible.__init__(self) - class SubSubVisible(SubVisible): + class SubPySubVisible(PySubVisible): pass # TODO - protectedStaticMethod, protectedStaticField, StaticInner, and protectedField should # be here - for cls in SubVisible, SubSubVisible: + for cls in PySubVisible, SubPySubVisible: s = cls() self.assertEquals(Results.PROTECTED_METHOD, s.protectedMethod(0)) self.assertEquals(Results.OVERLOADED_PROTECTED_METHOD, s.protectedMethod('foo')) - self.assertEquals(Results.UNUSED, SubVisible(Results.UNUSED).visibleField) + self.assertEquals(Results.UNUSED, PySubVisible(Results.UNUSED).visibleField) self.assertRaises(TypeError, OnlySubclassable, "Calling a Java class with protected constructors should raise a TypeError") class SubSubclassable(OnlySubclassable): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-04-27 00:56:17
|
Revision: 6264 http://jython.svn.sourceforge.net/jython/?rev=6264&view=rev Author: cgroves Date: 2009-04-27 00:56:11 +0000 (Mon, 27 Apr 2009) Log Message: ----------- Whoops, forgot the test for issue1297. Modified Paths: -------------- trunk/jython/Lib/test/test_java_subclasses.py Added Paths: ----------- trunk/jython/tests/java/org/python/tests/OwnMethodCaller.java Modified: trunk/jython/Lib/test/test_java_subclasses.py =================================================================== --- trunk/jython/Lib/test/test_java_subclasses.py 2009-04-27 00:53:26 UTC (rev 6263) +++ trunk/jython/Lib/test/test_java_subclasses.py 2009-04-27 00:56:11 UTC (rev 6264) @@ -12,7 +12,7 @@ from java.awt import Color, Component, Dimension, Rectangle from javax.swing.table import AbstractTableModel -from org.python.tests import BeanInterface, Callbacker, Coercions +from org.python.tests import BeanInterface, Callbacker, Coercions, OwnMethodCaller class InterfaceTest(unittest.TestCase): def test_java_calling_python_interface_implementation(self): @@ -211,7 +211,20 @@ aa.name self.assertEquals("getName", output.pop()) + def test_python_subclass_of_python_subclass_of_java_class_overriding(self): + '''Test for http://bugs.jython.org/issue1297. + Checks that getValue on SecondSubclass is overriden correctly when called from Java.''' + class FirstSubclass(OwnMethodCaller): + pass + + class SecondSubclass(FirstSubclass): + def getValue(self): + return 10 + + self.assertEquals(10, SecondSubclass().callGetValue()) + + """ public abstract class Abstract { public Abstract() { Added: trunk/jython/tests/java/org/python/tests/OwnMethodCaller.java =================================================================== --- trunk/jython/tests/java/org/python/tests/OwnMethodCaller.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/OwnMethodCaller.java 2009-04-27 00:56:11 UTC (rev 6264) @@ -0,0 +1,12 @@ +package org.python.tests; + +public class OwnMethodCaller { + + public int getValue() { + return 7; + } + + public int callGetValue() { + return getValue(); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-04-27 00:53:30
|
Revision: 6263 http://jython.svn.sourceforge.net/jython/?rev=6263&view=rev Author: cgroves Date: 2009-04-27 00:53:26 +0000 (Mon, 27 Apr 2009) Log Message: ----------- Add the proxy type for a python subclass of a python subclass of a java class before the proxy type for its superclass. This exposes any Java methods overriden in the most derived subclass. Fixes issue1297. Modified Paths: -------------- trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-04-25 18:45:51 UTC (rev 6262) +++ trunk/jython/src/org/python/core/PyType.java 2009-04-27 00:53:26 UTC (rev 6263) @@ -267,7 +267,7 @@ } } } - + if (wantDict) { createDictSlot(); } @@ -596,6 +596,7 @@ // non-proxy types go straight into our lookup cleanedBases.add(base); } else { + if (!(base instanceof PyJavaType)) { // python subclasses of proxy types need to be added as a base so their // version of methods will show up @@ -875,10 +876,21 @@ PyObject candidate = toMerge[i].getCandidate(); for (MROMergeState mergee : toMerge) { - if(mergee.unmergedContains(candidate)) { + if (mergee.pastnextContains(candidate)) { continue scan; } } + if (!(this instanceof PyJavaType) && candidate instanceof PyJavaType + && candidate.javaProxy != null + && PyProxy.class.isAssignableFrom(((Class<?>)candidate.javaProxy)) + && candidate.javaProxy != javaProxy) { + // If this is a subclass of a Python class that subclasses a Java class, slip the + // proxy for this class in before the proxy class in the superclass' mro. + // This exposes the methods from the proxy generated for this class in addition to + // those generated for the superclass while allowing methods from the superclass to + // remain visible from the proxies. + mro.add(PyType.fromClass(((Class<?>)javaProxy))); + } mro.add(candidate); for (MROMergeState element : toMerge) { element.noteMerged(candidate); @@ -893,7 +905,6 @@ return mro.toArray(new PyObject[mro.size()]); } - /** * Must either throw an exception, or bring the merges in <code>toMerge</code> to completion by * finishing filling in <code>mro</code>. @@ -1616,7 +1627,7 @@ /** * Returns true if candidate is in the items past this state's next item to be merged. */ - public boolean unmergedContains(PyObject candidate) { + public boolean pastnextContains(PyObject candidate) { for (int i = next + 1; i < mro.length; i++) { if (mro[i] == candidate) { return true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-25 18:46:17
|
Revision: 6262 http://jython.svn.sourceforge.net/jython/?rev=6262&view=rev Author: pjenvey Date: 2009-04-25 18:45:51 +0000 (Sat, 25 Apr 2009) Log Message: ----------- refactor Modified Paths: -------------- trunk/jython/src/org/python/core/PySystemState.java Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2009-04-24 12:45:27 UTC (rev 6261) +++ trunk/jython/src/org/python/core/PySystemState.java 2009-04-25 18:45:51 UTC (rev 6262) @@ -12,7 +12,6 @@ import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; import java.security.AccessControlException; -import java.util.Iterator; import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; @@ -626,9 +625,7 @@ FileInputStream fp = new FileInputStream(file); try { fileProperties.load(fp); - Iterator<Object> iterator = fileProperties.keySet().iterator(); - while (iterator.hasNext()) { - Object key = iterator.next(); + for (Object key : fileProperties.keySet()) { if (!registry.containsKey(key)) { registry.put(key, fileProperties.get(key)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2009-04-24 12:45:29
|
Revision: 6261 http://jython.svn.sourceforge.net/jython/?rev=6261&view=rev Author: otmarhumbel Date: 2009-04-24 12:45:27 +0000 (Fri, 24 Apr 2009) Log Message: ----------- adjust oracle jdbc imports according to http://forums.oracle.com/forums/ann.jspa?annID=201 Modified Paths: -------------- trunk/jython/src/com/ziclix/python/sql/handler/OracleDataHandler.java Modified: trunk/jython/src/com/ziclix/python/sql/handler/OracleDataHandler.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/handler/OracleDataHandler.java 2009-04-24 08:35:48 UTC (rev 6260) +++ trunk/jython/src/com/ziclix/python/sql/handler/OracleDataHandler.java 2009-04-24 12:45:27 UTC (rev 6261) @@ -11,8 +11,8 @@ import com.ziclix.python.sql.DataHandler; import com.ziclix.python.sql.FilterDataHandler; import com.ziclix.python.sql.zxJDBC; -import oracle.jdbc.driver.OracleResultSet; -import oracle.jdbc.driver.OracleTypes; +import oracle.jdbc.OracleResultSet; +import oracle.jdbc.OracleTypes; import oracle.sql.BLOB; import oracle.sql.ROWID; import org.python.core.Py; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2009-04-24 08:35:55
|
Revision: 6260 http://jython.svn.sourceforge.net/jython/?rev=6260&view=rev Author: otmarhumbel Date: 2009-04-24 08:35:48 +0000 (Fri, 24 Apr 2009) Log Message: ----------- enable overriding registry file entries with system properties (makes test_java_visibility pass again) Modified Paths: -------------- trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/util/PythonInterpreter.java Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2009-04-24 05:16:57 UTC (rev 6259) +++ trunk/jython/src/org/python/core/PySystemState.java 2009-04-24 08:35:48 UTC (rev 6260) @@ -12,6 +12,7 @@ import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; import java.security.AccessControlException; +import java.util.Iterator; import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; @@ -618,11 +619,20 @@ private static void addRegistryFile(File file) { if (file.exists()) { if (!file.isDirectory()) { - registry = new Properties(registry); + // pre (e.g. system) properties should override the registry, + // therefore only add missing properties from this registry file + Properties fileProperties = new Properties(); try { FileInputStream fp = new FileInputStream(file); try { - registry.load(fp); + fileProperties.load(fp); + Iterator<Object> iterator = fileProperties.keySet().iterator(); + while (iterator.hasNext()) { + Object key = iterator.next(); + if (!registry.containsKey(key)) { + registry.put(key, fileProperties.get(key)); + } + } } finally { fp.close(); } Modified: trunk/jython/src/org/python/util/PythonInterpreter.java =================================================================== --- trunk/jython/src/org/python/util/PythonInterpreter.java 2009-04-24 05:16:57 UTC (rev 6259) +++ trunk/jython/src/org/python/util/PythonInterpreter.java 2009-04-24 08:35:48 UTC (rev 6260) @@ -36,6 +36,7 @@ * * @param preProperties * A set of properties. Typically System.getProperties() is used. + * PreProperties override properties from the registry file. * @param postProperties * An other set of properties. Values like python.home, python.path and all other * values from the registry files can be added to this property set. PostProperties This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-24 05:17:15
|
Revision: 6259 http://jython.svn.sourceforge.net/jython/?rev=6259&view=rev Author: pjenvey Date: 2009-04-24 05:16:57 +0000 (Fri, 24 Apr 2009) Log Message: ----------- default to -Xmx512m Modified Paths: -------------- trunk/jython/build.xml trunk/jython/src/shell/jython trunk/jython/src/shell/jython.bat Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2009-04-23 07:45:20 UTC (rev 6258) +++ trunk/jython/build.xml 2009-04-24 05:16:57 UTC (rev 6259) @@ -170,9 +170,6 @@ <pathelement path="${compile.dir}" /> <pathelement path="${cpptasks.jar.dir}" /> </path> - <!-- 64 bit Java 6 needs roughly 96m for regrtest on most platforms, but Apple's needs - more --> - <property name="regrtest.Xmx" value="-Xmx160m" /> <property name="jython.dev.jar" value="jython-dev.jar" /> <property name="jython.deploy.jar" value="jython.jar" /> </target> @@ -834,7 +831,6 @@ <target name="regrtest" depends="developer-build,regrtest-unix,regrtest-windows"/> <target name="regrtest-unix" if="os.family.unix"> <exec executable="${dist.dir}/bin/jython"> - <arg value="-J${regrtest.Xmx}"/> <arg value="${dist.dir}/Lib/test/regrtest.py"/> <!-- Only run the tests that are expected to work on Jython --> <arg value="--expected"/> @@ -844,7 +840,6 @@ </target> <target name="regrtest-windows" if="os.family.windows"> <exec executable="${dist.dir}/bin/jython.bat"> - <arg value="-J${regrtest.Xmx}"/> <arg value="${dist.dir}/Lib/test/regrtest.py"/> <!-- Only run the tests that are expected to work on Jython --> <arg value="--expected"/> Modified: trunk/jython/src/shell/jython =================================================================== --- trunk/jython/src/shell/jython 2009-04-23 07:45:20 UTC (rev 6258) +++ trunk/jython/src/shell/jython 2009-04-24 05:16:57 UTC (rev 6259) @@ -96,6 +96,10 @@ # ----- Execute the requested command ----------------------------------------- +if [ -z "$JAVA_MEM" ] ; then + JAVA_MEM=-Xmx512m +fi + if [ -z "$JAVA_STACK" ]; then # 32 bit Java 6 needs the stack increased to at least 512k for # test_cpickle to pass, but we don't want to shrink 64 bit Java's @@ -110,8 +114,18 @@ # Stuff after '-J' in this argument goes to JVM -J*) val=${1:2} - if [ "${val:0:4}" = "-Xss" ] ; then + if [ "${val:0:4}" = "-Xmx" ]; then + JAVA_MEM=$val + elif [ "${val:0:4}" = "-Xss" ]; then JAVA_STACK=$val + elif [ "${val}" = "" ]; then + $JAVA_CMD -help + echo "(Prepend -J in front of these options when using 'jython' command)" + exit + elif [ "${val}" = "-X" ]; then + $JAVA_CMD -X + echo "(Prepend -J in front of these options when using 'jython' command)" + exit else java_args=("${java_args[@]}" "${1:2}") fi @@ -187,7 +201,7 @@ # Put the python_args back into the position arguments $1, $2 etc set -- "${python_args[@]}" -JAVA_OPTS="$JAVA_OPTS $JAVA_STACK" +JAVA_OPTS="$JAVA_OPTS $JAVA_MEM $JAVA_STACK" if $cygwin; then JAVA_HOME=`cygpath --mixed "$JAVA_HOME"` Modified: trunk/jython/src/shell/jython.bat =================================================================== --- trunk/jython/src/shell/jython.bat 2009-04-23 07:45:20 UTC (rev 6258) +++ trunk/jython/src/shell/jython.bat 2009-04-24 05:16:57 UTC (rev 6259) @@ -76,6 +76,7 @@ rem ----- Execute the requested command ---------------------------------------- :run +set _JAVA_MEM=-Xmx512m set _JAVA_STACK=-Xss512k rem Escape any quotes. Use _S for ', _D for ", and _U to escape _ itself. @@ -152,14 +153,14 @@ :jvmArg set _VAL=%_CMP:~2% -if "%_VAL:~0,4%" == "-Xss" ( +if "%_VAL:~0,4%" == "-Xmx" ( + set _JAVA_MEM=%_VAL% +) else if "%_VAL:~0,4%" == "-Xss" ( set _JAVA_STACK=%_VAL% - echo %_VAL% - goto nextArg +) else ( + set _JAVA_OPTS=%_JAVA_OPTS% %_VAL% ) -set _JAVA_OPTS=%_JAVA_OPTS% %_VAL% - :nextArg set _CMP= goto scanArgs @@ -172,7 +173,7 @@ set CLASSPATH=%_CP:"=% ) ) -set _FULL_CMD=%_JAVA_CMD% %_JAVA_OPTS% %_JAVA_STACK% %_BOOT_CP% -Dpython.home=%_JYTHON_HOME% -Dpython.executable="%~f0" -classpath "%CLASSPATH%" org.python.util.jython %_JYTHON_OPTS% %_JYTHON_ARGS% %_ARGS% +set _FULL_CMD=%_JAVA_CMD% %_JAVA_OPTS% %_JAVA_MEM% %_JAVA_STACK% %_BOOT_CP% -Dpython.home=%_JYTHON_HOME% -Dpython.executable="%~f0" -classpath "%CLASSPATH%" org.python.util.jython %_JYTHON_OPTS% %_JYTHON_ARGS% %_ARGS% if defined _PRINT ( echo %_FULL_CMD% ) else ( @@ -190,6 +191,7 @@ set _FULL_CMD= set _JAVA_CMD= set _JAVA_OPTS= +set _JAVA_MEM= set _JAVA_STACK= set _JYTHON_HOME= set _JYTHON_OPTS= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-23 07:45:29
|
Revision: 6258 http://jython.svn.sourceforge.net/jython/?rev=6258&view=rev Author: pjenvey Date: 2009-04-23 07:45:20 +0000 (Thu, 23 Apr 2009) Log Message: ----------- omit the -h usage from an invalid -c argument (as -m does) consequently this fixes test_cmd_line blocking on Windows. subprocess w/ stderr=PIPE seems to have issues there Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2009-04-23 07:38:49 UTC (rev 6257) +++ trunk/jython/src/org/python/util/jython.java 2009-04-23 07:45:20 UTC (rev 6258) @@ -126,7 +126,7 @@ System.err.println("Jython " + Version.PY_VERSION); System.exit(0); } - if (!opts.runModule) { + if (!opts.runCommand && !opts.runModule) { System.err.println(usage); } @@ -339,7 +339,7 @@ { public String filename; public boolean jar, interactive, notice; - public boolean runModule; + public boolean runCommand, runModule; public boolean fixInteractive; public boolean help, version; public String[] argv; @@ -409,6 +409,7 @@ Options.importSite = false; } else if (arg.equals("-c")) { + runCommand = true; if (arg.length() > 2) { command = arg.substring(2); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-04-23 07:38:55
|
Revision: 6257 http://jython.svn.sourceforge.net/jython/?rev=6257&view=rev Author: zyasoft Date: 2009-04-23 07:38:49 +0000 (Thu, 23 Apr 2009) Log Message: ----------- Fixed PyList#toArray(Object[]), which in turn fixes initializing a Vector from a list on Java 5. This change resolves the test_java_list_delegate. Also fixed PyList#iterator, resolving #1323 (still need to put in a test). Modified Paths: -------------- trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PyTuple.java Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2009-04-23 05:46:39 UTC (rev 6256) +++ trunk/jython/src/org/python/core/PyList.java 2009-04-23 07:38:49 UTC (rev 6257) @@ -772,8 +772,10 @@ @Override public boolean containsAll(Collection c) { - if (c instanceof PySequenceList) { - return list.containsAll(c); + if (c instanceof PyList) { + return list.containsAll(((PyList) c).list); + } else if (c instanceof PyTuple) { + return list.containsAll(((PyTuple) c).getList()); } else { return list.containsAll(new PyList(c)); } @@ -783,8 +785,9 @@ public boolean equals(Object o) { if (o instanceof PyList) { return (((PyList) o).list.equals(list)); - } else if (o instanceof List) { // XXX copied from PyList, but... - return o.equals(this); // XXX shouldn't this compare using py2java? + } else if (o instanceof List && !(o instanceof PyTuple)) { + List oList = (List) o; + return oList.equals(list); } return false; } @@ -813,7 +816,23 @@ @Override public Iterator iterator() { - return list.iterator(); + return new Iterator() { + + private final Iterator<PyObject> iter = list.iterator(); + + public boolean hasNext() { + return iter.hasNext(); + } + + public Object next() { + return iter.next().__tojava__(Object.class); + } + + public void remove() { + iter.remove(); + } + }; + } @Override @@ -945,14 +964,14 @@ @Override public Object[] toArray(Object[] a) { Object copy[] = list.toArray(); - if (a.length != copy.length) { + if (a.length < copy.length) { a = copy; } for (int i = 0; i < copy.length; i++) { a[i] = ((PyObject) copy[i]).__tojava__(Object.class); } - for (int i = copy.length; i < a.length; i++) { - a[i] = null; + if (a.length > copy.length) { + a[copy.length] = null; } return a; } Modified: trunk/jython/src/org/python/core/PyTuple.java =================================================================== --- trunk/jython/src/org/python/core/PyTuple.java 2009-04-23 05:46:39 UTC (rev 6256) +++ trunk/jython/src/org/python/core/PyTuple.java 2009-04-23 07:38:49 UTC (rev 6257) @@ -460,7 +460,13 @@ @Override public boolean containsAll(Collection c) { - return getList().containsAll(new PyList(c)); + if (c instanceof PyList) { + return getList().containsAll(((PyList)c).list); + } else if (c instanceof PyTuple) { + return getList().containsAll(((PyTuple)c).getList()); + } else { + return getList().containsAll(new PyList(c)); + } } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-23 05:47:00
|
Revision: 6256 http://jython.svn.sourceforge.net/jython/?rev=6256&view=rev Author: pjenvey Date: 2009-04-23 05:46:39 +0000 (Thu, 23 Apr 2009) Log Message: ----------- fix test___all__ on windows Modified Paths: -------------- trunk/jython/Lib/os.py Modified: trunk/jython/Lib/os.py =================================================================== --- trunk/jython/Lib/os.py 2009-04-22 23:45:41 UTC (rev 6255) +++ trunk/jython/Lib/os.py 2009-04-23 05:46:39 UTC (rev 6256) @@ -30,15 +30,13 @@ 'O_RDWR', 'O_SYNC', 'O_TRUNC', 'O_WRONLY', 'R_OK', 'SEEK_CUR', 'SEEK_END', 'SEEK_SET', 'W_OK', 'X_OK', '_exit', 'access', 'altsep', 'chdir', 'chmod', 'close', 'curdir', 'defpath', - 'environ', 'error', 'fdopen', 'getcwd', 'getcwdu', 'getegid', - 'getenv','geteuid', 'getgid', 'getlogin', 'getlogin', 'getpgrp', - 'getpid', 'getppid', 'getuid', 'isatty', 'linesep', 'listdir', - 'lseek', 'lstat', 'makedirs', 'mkdir', 'name', 'open', 'pardir', - 'path', 'pathsep', 'popen', 'popen2', 'popen3', 'popen4', - 'putenv', 'read', 'remove', 'removedirs', 'rename', 'renames', - 'rmdir', 'sep', 'setpgrp', 'setsid', 'stat', 'stat_result', - 'strerror', 'system', 'unlink', 'unsetenv', 'utime', 'walk', - 'write']) + 'environ', 'error', 'fdopen', 'getcwd', 'getcwdu', 'getenv', + 'getpid', 'isatty', 'linesep', 'listdir', 'lseek', 'lstat', + 'makedirs', 'mkdir', 'name', 'open', 'pardir', 'path', + 'pathsep', 'popen', 'popen2', 'popen3', 'popen4', 'putenv', + 'read', 'remove', 'removedirs', 'rename', 'renames', 'rmdir', + 'sep', 'stat', 'stat_result', 'strerror', 'system', 'unlink', + 'unsetenv', 'utime', 'walk', 'write']) import errno import jarray @@ -1050,6 +1048,10 @@ raise OSError(status[0], strerror(status[0])) return res_pid, status[0] + __all__.extend(['link', 'symlink', 'readlink', 'getegid', 'geteuid', + 'getgid', 'getlogin', 'getpgrp', 'getppid', 'getuid', + 'setpgrp', 'setsid', 'kill', 'wait', 'waitpid']) + def getpid(): """getpid() -> pid This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-22 23:46:07
|
Revision: 6255 http://jython.svn.sourceforge.net/jython/?rev=6255&view=rev Author: pjenvey Date: 2009-04-22 23:45:41 +0000 (Wed, 22 Apr 2009) Log Message: ----------- keywordMangling option is long gone Modified Paths: -------------- trunk/jython/registry Modified: trunk/jython/registry =================================================================== --- trunk/jython/registry 2009-04-22 22:15:16 UTC (rev 6254) +++ trunk/jython/registry 2009-04-22 23:45:41 UTC (rev 6255) @@ -30,10 +30,6 @@ # this option is set from the command line. #python.verbose = message -# Setting this to true will support old 1.0 style keyword+"_" names -# This isn't needed any more due to improvements in the parser -python.deprecated.keywordMangling = false - # Setting this to the name of different console class, new console # features can be enabled. Readline support is such an example #python.console=org.python.util.JLineConsole This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2009-04-22 22:15:23
|
Revision: 6254 http://jython.svn.sourceforge.net/jython/?rev=6254&view=rev Author: otmarhumbel Date: 2009-04-22 22:15:16 +0000 (Wed, 22 Apr 2009) Log Message: ----------- do not default to jline until it is stable enough (see http://bugs.jython.org/issue1293) Modified Paths: -------------- trunk/jython/registry Modified: trunk/jython/registry =================================================================== --- trunk/jython/registry 2009-04-22 21:13:26 UTC (rev 6253) +++ trunk/jython/registry 2009-04-22 22:15:16 UTC (rev 6254) @@ -36,7 +36,8 @@ # Setting this to the name of different console class, new console # features can be enabled. Readline support is such an example -python.console=org.python.util.JLineConsole +#python.console=org.python.util.JLineConsole +#python.console=org.python.util.ReadlineConsole #python.console.readlinelib=JavaReadline # Setting this to a valid codec name will cause the console to use a This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2009-04-22 21:13:36
|
Revision: 6253 http://jython.svn.sourceforge.net/jython/?rev=6253&view=rev Author: otmarhumbel Date: 2009-04-22 21:13:26 +0000 (Wed, 22 Apr 2009) Log Message: ----------- developer-build: copy the registry file to the local dist directory Modified Paths: -------------- trunk/jython/build.xml Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2009-04-22 03:03:00 UTC (rev 6252) +++ trunk/jython/build.xml 2009-04-22 21:13:26 UTC (rev 6253) @@ -632,7 +632,7 @@ <target name="copy-full" depends="copy-lib, copy-license" if="full-build"> <echo>copy misc files from ${jython.base.dir}</echo> - <copy todir="${dist.dir}" preservelastmodified="true"> + <copy todir="${dist.dir}" preservelastmodified="true" overwrite="true"> <fileset dir="${jython.base.dir}" includes="ACKNOWLEDGMENTS, build.xml, build.Lib.include.properties, NEWS, LICENSE.txt, README.txt, registry" /> @@ -692,14 +692,16 @@ </fileset> </copy> + <!-- copy the shell scripts and make them executable --> <copy todir="${dist.dir}/bin"> <fileset dir="${source.dir}/shell"/> </copy> - <chmod perm="ugo+rx"> <fileset dir="${dist.dir}/bin" /> </chmod> + <!-- copy the registry --> + <copy todir="${dist.dir}" file="${jython.base.dir}/registry" preservelastmodified="true" overwrite="true" /> </target> <target name="copy-cpythonlib"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-04-22 03:03:10
|
Revision: 6252 http://jython.svn.sourceforge.net/jython/?rev=6252&view=rev Author: fwierzbicki Date: 2009-04-22 03:03:00 +0000 (Wed, 22 Apr 2009) Log Message: ----------- Applied patch from http://bugs.jython.org/issue1188: Patch against trunk to handle SecurityExceptions. This should make it much easier to run Jython in GAE! Thanks to James Robinson for the patch! Modified Paths: -------------- trunk/jython/ACKNOWLEDGMENTS trunk/jython/NEWS trunk/jython/src/org/python/core/BytecodeLoader.java trunk/jython/src/org/python/core/PyTraceback.java trunk/jython/src/org/python/core/SyspathJavaLoader.java trunk/jython/src/org/python/core/imp.java trunk/jython/src/org/python/core/packagecache/PathPackageManager.java trunk/jython/src/org/python/modules/zipimport/zipimporter.java Modified: trunk/jython/ACKNOWLEDGMENTS =================================================================== --- trunk/jython/ACKNOWLEDGMENTS 2009-04-22 02:23:54 UTC (rev 6251) +++ trunk/jython/ACKNOWLEDGMENTS 2009-04-22 03:03:00 UTC (rev 6252) @@ -82,6 +82,7 @@ Sean McGrath Clark Updike Leonardo Soto + James Robinson Local Variables: mode: indented-text Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-04-22 02:23:54 UTC (rev 6251) +++ trunk/jython/NEWS 2009-04-22 03:03:00 UTC (rev 6252) @@ -2,6 +2,7 @@ Jython 2.5.0 rc 1 Bugs fixed (new numbering due to move to Roundup) + - [ 1188 ] Patch against trunk to handle SecurityExceptions - [ 1271 ] Bean property accessors in derived class overide methods in base class - [ 1264 ] 'is not' test exhibits incorrect behaviour when wrapping Java objects - [ 1295 ] Setting a write-only bean property causes a NPE Modified: trunk/jython/src/org/python/core/BytecodeLoader.java =================================================================== --- trunk/jython/src/org/python/core/BytecodeLoader.java 2009-04-22 02:23:54 UTC (rev 6251) +++ trunk/jython/src/org/python/core/BytecodeLoader.java 2009-04-22 03:03:00 UTC (rev 6252) @@ -1,7 +1,8 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; -import java.security.SecureClassLoader; +import java.net.URL; +import java.net.URLClassLoader; import java.util.List; import org.objectweb.asm.ClassReader; @@ -30,7 +31,8 @@ if (cur != null) { loader.addParent(cur); } - } catch (SecurityException e) {} + } catch (SecurityException e) { + } } return loader.loadClassFromBytes(name, data); } @@ -71,11 +73,12 @@ } } - public static class Loader extends SecureClassLoader { + public static class Loader extends URLClassLoader { private List<ClassLoader> parents = Generic.list(); public Loader() { + super(new URL[0]); parents.add(imp.getSyspathJavaLoader()); } @@ -115,7 +118,6 @@ } Class<?> c = defineClass(name, data, 0, data.length, getClass().getProtectionDomain()); resolveClass(c); - Compiler.compileClass(c); return c; } } Modified: trunk/jython/src/org/python/core/PyTraceback.java =================================================================== --- trunk/jython/src/org/python/core/PyTraceback.java 2009-04-22 02:23:54 UTC (rev 6251) +++ trunk/jython/src/org/python/core/PyTraceback.java 2009-04-22 03:03:00 UTC (rev 6252) @@ -50,9 +50,13 @@ */ private String getLine(String filename, int lineno) { RelativeFile file = new RelativeFile(filename); - if (!file.isFile() || !file.canRead()) { - // XXX: We should run through sys.path until the filename is found - return null; + try { + if (!file.isFile() || !file.canRead()) { + // XXX: We should run through sys.path until the filename is found + return null; + } + } catch (SecurityException e) { + return null; // If we don't have read access to the file, return null } PyFile pyFile; Modified: trunk/jython/src/org/python/core/SyspathJavaLoader.java =================================================================== --- trunk/jython/src/org/python/core/SyspathJavaLoader.java 2009-04-22 02:23:54 UTC (rev 6251) +++ trunk/jython/src/org/python/core/SyspathJavaLoader.java 2009-04-22 03:03:00 UTC (rev 6252) @@ -105,13 +105,16 @@ // Search the sys.path for a .class file matching the named class. try { return Class.forName(name); - } catch(ClassNotFoundException e) {} + } catch(ClassNotFoundException e) { + } // The current class loader may be null (e.g., when Jython is loaded // from the boot classpath); try the system class loader. try { return Class.forName(name, true, ClassLoader.getSystemClassLoader()); - } catch(ClassNotFoundException e) {} + } catch(ClassNotFoundException e) { + } catch (SecurityException se) { + } Class<?> c = findLoadedClass(name); if(c != null) { @@ -143,11 +146,13 @@ if (file == null) { continue; } - size = (int)file.length(); try { + size = (int)file.length(); fis = new FileInputStream(file); } catch (FileNotFoundException e) { continue; + } catch(SecurityException e) { + continue; } } try { @@ -163,7 +168,8 @@ } finally { try { fis.close(); - } catch (IOException e) {} + } catch (IOException e) { + } } } Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2009-04-22 02:23:54 UTC (rev 6251) +++ trunk/jython/src/org/python/core/imp.java 2009-04-22 03:03:00 UTC (rev 6252) @@ -214,6 +214,10 @@ } FileOutputStream fop = null; try { + SecurityManager man = System.getSecurityManager(); + if (man != null) { + man.checkWrite(compiledFilename); + } fop = new FileOutputStream(compiledFilename); fop.write(compiledSource); fop.close(); @@ -223,6 +227,11 @@ Py.writeDebug(IMPORT_LOG, "Unable to write to source cache file '" + compiledFilename + "' due to " + exc); return null; + } catch(SecurityException exc) { + // If we can't write the cache file, just log and continue + Py.writeDebug(IMPORT_LOG, "Unable to write to source cache file '" + + compiledFilename + "' due to " + exc); + return null; } finally { if(fop != null) { try { @@ -463,8 +472,12 @@ File sourceFile = new File(dir, sourceName); File compiledFile = new File(dir, compiledName); - boolean pkg = dir.isDirectory() && caseok(dir, name) && (sourceFile.isFile() + boolean pkg = false; + try { + pkg = dir.isDirectory() && caseok(dir, name) && (sourceFile.isFile() || compiledFile.isFile()); + } catch (SecurityException e) { + } if (!pkg) { Py.writeDebug(IMPORT_LOG, "trying source " + dir.getPath()); sourceName = name + ".py"; @@ -479,28 +492,33 @@ m.__dict__.__setitem__("__path__", new PyList(new PyObject[] {filename})); } - if (sourceFile.isFile() && caseok(sourceFile, sourceName)) { - long pyTime = sourceFile.lastModified(); - if (compiledFile.isFile() && caseok(compiledFile, compiledName)) { - Py.writeDebug(IMPORT_LOG, "trying precompiled " + compiledFile.getPath()); - long classTime = compiledFile.lastModified(); - if (classTime >= pyTime) { - PyObject ret = createFromPyClass(modName, makeStream(compiledFile), true, - displaySourceName, displayCompiledName, pyTime); - if (ret != null) { - return ret; + try { + if (sourceFile.isFile() && caseok(sourceFile, sourceName)) { + long pyTime = sourceFile.lastModified(); + if (compiledFile.isFile() && caseok(compiledFile, compiledName)) { + Py.writeDebug(IMPORT_LOG, "trying precompiled " + compiledFile.getPath()); + long classTime = compiledFile.lastModified(); + if (classTime >= pyTime) { + PyObject ret = createFromPyClass(modName, makeStream(compiledFile), true, + displaySourceName, displayCompiledName, pyTime); + if (ret != null) { + return ret; + } } + return createFromSource(modName, makeStream(sourceFile), displaySourceName, + compiledFile.getPath()); } + return createFromSource(modName, makeStream(sourceFile), displaySourceName, + compiledFile.getPath(), pyTime); } - return createFromSource(modName, makeStream(sourceFile), displaySourceName, - compiledFile.getPath(), pyTime); - } - // If no source, try loading precompiled - Py.writeDebug(IMPORT_LOG, "trying precompiled with no source " + compiledFile.getPath()); - if (compiledFile.isFile() && caseok(compiledFile, compiledName)) { - return createFromPyClass(modName, makeStream(compiledFile), true, displaySourceName, - displayCompiledName); + // If no source, try loading precompiled + Py.writeDebug(IMPORT_LOG, "trying precompiled with no source " + compiledFile.getPath()); + if (compiledFile.isFile() && caseok(compiledFile, compiledName)) { + return createFromPyClass(modName, makeStream(compiledFile), true, displaySourceName, + displayCompiledName); + } + } catch (SecurityException e) { } return null; } Modified: trunk/jython/src/org/python/core/packagecache/PathPackageManager.java =================================================================== --- trunk/jython/src/org/python/core/packagecache/PathPackageManager.java 2009-04-22 02:23:54 UTC (rev 6251) +++ trunk/jython/src/org/python/core/packagecache/PathPackageManager.java 2009-04-22 03:03:00 UTC (rev 6252) @@ -41,20 +41,24 @@ String dir = path.pyget(i).__str__().toString(); File f = new RelativeFile(dir, child); - if (f.isDirectory() && imp.caseok(f, name)) { - /* - * Figure out if we have a directory a mixture of python and - * java or just an empty directory (which means Java) or a - * directory with only Python source (which means Python). - */ - PackageExistsFileFilter m = new PackageExistsFileFilter(); - f.listFiles(m); - boolean exists = m.packageExists(); - if (exists) { - Py.writeComment("import", "java package as '" - + f.getAbsolutePath() + "'"); + try { + if (f.isDirectory() && imp.caseok(f, name)) { + /* + * Figure out if we have a directory a mixture of python and + * java or just an empty directory (which means Java) or a + * directory with only Python source (which means Python). + */ + PackageExistsFileFilter m = new PackageExistsFileFilter(); + f.listFiles(m); + boolean exists = m.packageExists(); + if (exists) { + Py.writeComment("import", "java package as '" + + f.getAbsolutePath() + "'"); + } + return exists; } - return exists; + } catch (SecurityException se) { + return false; } } return false; Modified: trunk/jython/src/org/python/modules/zipimport/zipimporter.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2009-04-22 02:23:54 UTC (rev 6251) +++ trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2009-04-22 03:03:00 UTC (rev 6252) @@ -91,11 +91,12 @@ prefix = ""; while (true) { File fullPathFile = new File(sys.getPath(pathFile.getPath())); - if (fullPathFile.exists()) { - if (fullPathFile.isFile()) { - archive = pathFile.getPath(); - } - break; + try { + if (fullPathFile.isFile()) { + archive = pathFile.getPath(); + break; + } + } catch (SecurityException se) { } // back up one path element This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-04-22 02:24:12
|
Revision: 6251 http://jython.svn.sourceforge.net/jython/?rev=6251&view=rev Author: fwierzbicki Date: 2009-04-22 02:23:54 +0000 (Wed, 22 Apr 2009) Log Message: ----------- add -S since site.py involves writing to the filesystem. Modified Paths: -------------- trunk/jython/tests/policy/run.sh Modified: trunk/jython/tests/policy/run.sh =================================================================== --- trunk/jython/tests/policy/run.sh 2009-04-22 01:47:20 UTC (rev 6250) +++ trunk/jython/tests/policy/run.sh 2009-04-22 02:23:54 UTC (rev 6251) @@ -1 +1 @@ -java -Djava.security.manager -Djava.security.policy=nowrite.policy -classpath ../../dist/jython.jar org.python.util.jython -Dpython.home=../../dist -Dpython.cachedir.skip=true $@ +java -Djava.security.manager -Djava.security.policy=nowrite.policy -classpath ../../dist/jython.jar org.python.util.jython -S -Dpython.home=../../dist -Dpython.cachedir.skip=true $@ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-04-22 01:47:24
|
Revision: 6250 http://jython.svn.sourceforge.net/jython/?rev=6250&view=rev Author: fwierzbicki Date: 2009-04-22 01:47:20 +0000 (Wed, 22 Apr 2009) Log Message: ----------- Factored out calls like: imp.load("os").__getattr__("isatty").__call__(Py.java2py(fd)).__nonzero__(); into FileUtil#isatty and added a fallback to do a simple isatty check modeled after jna-posix JavaPOSIX#isatty. This allows jython to run without Lib/ which was broken. Modified Paths: -------------- trunk/jython/src/org/python/core/io/FileIO.java trunk/jython/src/org/python/core/io/StreamIO.java trunk/jython/src/org/python/core/util/FileUtil.java trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/core/io/FileIO.java =================================================================== --- trunk/jython/src/org/python/core/io/FileIO.java 2009-04-21 03:13:55 UTC (rev 6249) +++ trunk/jython/src/org/python/core/io/FileIO.java 2009-04-22 01:47:20 UTC (rev 6250) @@ -15,6 +15,7 @@ import com.kenai.constantine.platform.Errno; import org.python.core.imp; import org.python.core.Py; +import org.python.core.util.FileUtil; import org.python.core.util.RelativeFile; /** @@ -181,7 +182,7 @@ return false; } try { - return imp.load("os").invoke("isatty", Py.java2py(file.getFD())).__nonzero__(); + return FileUtil.isatty(file.getFD()); } catch (IOException e) { return false; } Modified: trunk/jython/src/org/python/core/io/StreamIO.java =================================================================== --- trunk/jython/src/org/python/core/io/StreamIO.java 2009-04-21 03:13:55 UTC (rev 6249) +++ trunk/jython/src/org/python/core/io/StreamIO.java 2009-04-22 01:47:20 UTC (rev 6250) @@ -18,6 +18,7 @@ import org.python.core.Py; import org.python.core.imp; +import org.python.core.util.FileUtil; /** * Raw I/O implementation for simple streams. @@ -217,7 +218,7 @@ return false; } - return imp.load("os").__getattr__("isatty").__call__(Py.java2py(fd)).__nonzero__(); + return FileUtil.isatty(fd); } /** {@inheritDoc} */ Modified: trunk/jython/src/org/python/core/util/FileUtil.java =================================================================== --- trunk/jython/src/org/python/core/util/FileUtil.java 2009-04-21 03:13:55 UTC (rev 6249) +++ trunk/jython/src/org/python/core/util/FileUtil.java 2009-04-22 01:47:20 UTC (rev 6250) @@ -2,10 +2,14 @@ package org.python.core.util; import java.io.ByteArrayOutputStream; +import java.io.FileDescriptor; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import org.python.core.imp; +import org.python.core.Py; +import org.python.core.PyException; import org.python.core.PyFile; /** @@ -60,4 +64,18 @@ } return out.toByteArray(); } + + public static boolean isatty(FileDescriptor fd) { + boolean atty = false; + try { + atty = imp.load("os").__getattr__("isatty").__call__(Py.java2py(fd)).__nonzero__(); + } catch (PyException e) { + //Weak isatty check copied from jna-posix JavaPOSIX class + return (fd == FileDescriptor.in + || fd == FileDescriptor.out + || fd == FileDescriptor.err); + } + return atty; + } + } Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2009-04-21 03:13:55 UTC (rev 6249) +++ trunk/jython/src/org/python/util/jython.java 2009-04-22 01:47:20 UTC (rev 6250) @@ -24,6 +24,7 @@ import org.python.core.PyStringMap; import org.python.core.PySystemState; import org.python.core.imp; +import org.python.core.util.FileUtil; import org.python.core.util.RelativeFile; import org.python.modules._systemrestart; import org.python.modules.thread.thread; @@ -220,7 +221,7 @@ } catch (java.io.FileNotFoundException e) { throw Py.IOError(e); } - if (imp.load("os").__getattr__("isatty").__call__(Py.java2py(file.getFD())).__nonzero__()) { + if (FileUtil.isatty(file.getFD())) { opts.interactive = true; interp.interact(null, new PyFile(file)); System.exit(0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-21 03:14:09
|
Revision: 6249 http://jython.svn.sourceforge.net/jython/?rev=6249&view=rev Author: pjenvey Date: 2009-04-21 03:13:55 +0000 (Tue, 21 Apr 2009) Log Message: ----------- recycle numerics in some obvious places Modified Paths: -------------- trunk/jython/src/org/python/core/PyComplex.java trunk/jython/src/org/python/core/PyFloat.java trunk/jython/src/org/python/core/PyInteger.java trunk/jython/src/org/python/core/PyLong.java Modified: trunk/jython/src/org/python/core/PyComplex.java =================================================================== --- trunk/jython/src/org/python/core/PyComplex.java 2009-04-21 02:37:28 UTC (rev 6248) +++ trunk/jython/src/org/python/core/PyComplex.java 2009-04-21 03:13:55 UTC (rev 6249) @@ -639,6 +639,9 @@ @ExposedMethod(doc = BuiltinDocs.complex___pos___doc) final PyObject complex___pos__() { + if (getType() == TYPE) { + return this; + } return new PyComplex(real, imag); } Modified: trunk/jython/src/org/python/core/PyFloat.java =================================================================== --- trunk/jython/src/org/python/core/PyFloat.java 2009-04-21 02:37:28 UTC (rev 6248) +++ trunk/jython/src/org/python/core/PyFloat.java 2009-04-21 03:13:55 UTC (rev 6249) @@ -560,7 +560,7 @@ @ExposedMethod(doc = BuiltinDocs.float___pos___doc) final PyObject float___pos__() { - return Py.newFloat(value); + return float___float__(); } public PyObject __invert__() { @@ -573,10 +573,10 @@ @ExposedMethod(doc = BuiltinDocs.float___abs___doc) final PyObject float___abs__() { - if (value >= 0) - return Py.newFloat(value); - else - return __neg__(); + if (value < 0) { + return float___neg__(); + } + return float___float__(); } public PyObject __int__() { @@ -606,6 +606,9 @@ @ExposedMethod(doc = BuiltinDocs.float___float___doc) final PyFloat float___float__() { + if (getType() == TYPE) { + return this; + } return Py.newFloat(value); } public PyComplex __complex__() { Modified: trunk/jython/src/org/python/core/PyInteger.java =================================================================== --- trunk/jython/src/org/python/core/PyInteger.java 2009-04-21 02:37:28 UTC (rev 6248) +++ trunk/jython/src/org/python/core/PyInteger.java 2009-04-21 03:13:55 UTC (rev 6249) @@ -722,7 +722,7 @@ @ExposedMethod(doc = BuiltinDocs.int___pos___doc) final PyObject int___pos__() { - return Py.newInteger(getValue()); + return int___int__(); } public PyObject __abs__() { @@ -731,10 +731,10 @@ @ExposedMethod(doc = BuiltinDocs.int___abs___doc) final PyObject int___abs__() { - if (getValue() >= 0) - return Py.newInteger(getValue()); - else - return __neg__(); + if (getValue() < 0) { + return int___neg__(); + } + return int___int__(); } public PyObject __invert__() { @@ -752,6 +752,9 @@ @ExposedMethod(doc = BuiltinDocs.int___int___doc) final PyInteger int___int__() { + if (getType() == TYPE) { + return this; + } return Py.newInteger(getValue()); } Modified: trunk/jython/src/org/python/core/PyLong.java =================================================================== --- trunk/jython/src/org/python/core/PyLong.java 2009-04-21 02:37:28 UTC (rev 6248) +++ trunk/jython/src/org/python/core/PyLong.java 2009-04-21 03:13:55 UTC (rev 6249) @@ -741,7 +741,7 @@ @ExposedMethod(doc = BuiltinDocs.long___pos___doc) final PyObject long___pos__() { - return Py.newLong(value); + return long___long__(); } public PyObject __abs__() { @@ -750,7 +750,10 @@ @ExposedMethod(doc = BuiltinDocs.long___abs___doc) final PyObject long___abs__() { - return Py.newLong(value.abs()); + if (value.signum() == -1) { + return long___neg__(); + } + return long___long__(); } public PyObject __invert__() { @@ -771,7 +774,7 @@ if (value.compareTo(PyInteger.maxInt) <= 0 && value.compareTo(PyInteger.minInt) >= 0) { return Py.newInteger(value.intValue()); } - return Py.newLong(value); + return long___long__(); } @@ -781,6 +784,9 @@ @ExposedMethod(doc = BuiltinDocs.long___long___doc) final PyObject long___long__() { + if (getType() == TYPE) { + return this; + } return Py.newLong(value); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-04-21 02:37:32
|
Revision: 6248 http://jython.svn.sourceforge.net/jython/?rev=6248&view=rev Author: zyasoft Date: 2009-04-21 02:37:28 +0000 (Tue, 21 Apr 2009) Log Message: ----------- Fixes #1317 - PyTuple#equals should only compare if the other obj is a List, but not a PyList, so as to balance both the Java and Python semantics. Modified Paths: -------------- trunk/jython/Lib/test/test_list_jy.py trunk/jython/src/org/python/core/PyTuple.java Modified: trunk/jython/Lib/test/test_list_jy.py =================================================================== --- trunk/jython/Lib/test/test_list_jy.py 2009-04-20 17:47:43 UTC (rev 6247) +++ trunk/jython/Lib/test/test_list_jy.py 2009-04-21 02:37:28 UTC (rev 6248) @@ -41,6 +41,9 @@ self.assertEquals(glmt.silly, "spam") glmt['my-key'] self.assertEquals(glmt.silly, "eggs") + + def test_tuple_equality(self): + self.assertEqual([(1,), [1]].count([1]), 1) # http://bugs.jython.org/issue1317 def test_main(): test.test_support.run_unittest(ListTestCase) Modified: trunk/jython/src/org/python/core/PyTuple.java =================================================================== --- trunk/jython/src/org/python/core/PyTuple.java 2009-04-20 17:47:43 UTC (rev 6247) +++ trunk/jython/src/org/python/core/PyTuple.java 2009-04-21 02:37:28 UTC (rev 6248) @@ -467,7 +467,7 @@ public boolean equals(Object o) { if (o instanceof PyTuple) { return Arrays.equals(array, ((PyTuple) o).array); - } else if (o instanceof List) { + } else if (o instanceof List && !(o instanceof PyList)) { return o.equals(this); } return false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2009-04-20 17:48:00
|
Revision: 6247 http://jython.svn.sourceforge.net/jython/?rev=6247&view=rev Author: otmarhumbel Date: 2009-04-20 17:47:43 +0000 (Mon, 20 Apr 2009) Log Message: ----------- throw a meaningful exception instead of a NullPointerException if version.properties cannot be loaded Modified Paths: -------------- trunk/jython/src/org/python/Version.java Modified: trunk/jython/src/org/python/Version.java =================================================================== --- trunk/jython/src/org/python/Version.java 2009-04-19 20:59:54 UTC (rev 6246) +++ trunk/jython/src/org/python/Version.java 2009-04-20 17:47:43 UTC (rev 6247) @@ -1,8 +1,8 @@ /* Copyright (c) Jython Developers */ package org.python; +import java.io.IOException; import java.io.InputStream; -import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.EnumSet; @@ -86,31 +86,39 @@ * Load the version information from the properties file. */ private static void loadProperties() { - InputStream in = Version.class.getResourceAsStream("/org/python/version.properties"); - Properties properties = new Properties(); - try { - properties.load(in); - } catch (IOException ioe) { - System.err.println("There was a problem loading version.properties:"); - ioe.printStackTrace(); - } finally { + boolean loaded = false; + final String versionProperties = "/org/python/version.properties"; + InputStream in = Version.class.getResourceAsStream(versionProperties); + if (in != null) { try { - in.close(); + Properties properties = new Properties(); + properties.load(in); + loaded = true; + PY_VERSION = properties.getProperty("jython.version"); + PY_MAJOR_VERSION = Integer.valueOf(properties.getProperty("jython.major_version")); + PY_MINOR_VERSION = Integer.valueOf(properties.getProperty("jython.minor_version")); + PY_MICRO_VERSION = Integer.valueOf(properties.getProperty("jython.micro_version")); + PY_RELEASE_LEVEL = Integer.valueOf(properties.getProperty("jython.release_level")); + PY_RELEASE_SERIAL = Integer.valueOf(properties.getProperty("jython.release_serial")); + DATE = properties.getProperty("jython.build.date"); + TIME = properties.getProperty("jython.build.time"); + SVN_REVISION = properties.getProperty("jython.build.svn_revision"); } catch (IOException ioe) { - // ok + System.err.println("There was a problem loading ".concat(versionProperties) + .concat(":")); + ioe.printStackTrace(); + } finally { + try { + in.close(); + } catch (IOException ioe) { + // ok + } } } - - PY_VERSION = properties.getProperty("jython.version"); - PY_MAJOR_VERSION = Integer.valueOf(properties.getProperty("jython.major_version")); - PY_MINOR_VERSION = Integer.valueOf(properties.getProperty("jython.minor_version")); - PY_MICRO_VERSION = Integer.valueOf(properties.getProperty("jython.micro_version")); - PY_RELEASE_LEVEL = Integer.valueOf(properties.getProperty("jython.release_level")); - PY_RELEASE_SERIAL = Integer.valueOf(properties.getProperty("jython.release_serial")); - - DATE = properties.getProperty("jython.build.date"); - TIME = properties.getProperty("jython.build.time"); - SVN_REVISION = properties.getProperty("jython.build.svn_revision"); + if (!loaded) { + // fail with a meaningful exception (cannot use Py exceptions here) + throw new RuntimeException("unable to load ".concat(versionProperties)); + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-19 21:00:15
|
Revision: 6246 http://jython.svn.sourceforge.net/jython/?rev=6246&view=rev Author: pjenvey Date: 2009-04-19 20:59:54 +0000 (Sun, 19 Apr 2009) Log Message: ----------- small cleanup Modified Paths: -------------- trunk/jython/src/org/python/core/PyTuple.java Modified: trunk/jython/src/org/python/core/PyTuple.java =================================================================== --- trunk/jython/src/org/python/core/PyTuple.java 2009-04-19 00:01:40 UTC (rev 6245) +++ trunk/jython/src/org/python/core/PyTuple.java 2009-04-19 20:59:54 UTC (rev 6246) @@ -3,7 +3,6 @@ import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -20,7 +19,11 @@ public class PyTuple extends PySequenceList implements List { public static final PyType TYPE = PyType.fromClass(PyTuple.class); + private final PyObject[] array; + + private volatile List<PyObject> cachedList = null; + private static final PyTuple EMPTY_TUPLE = new PyTuple(); public PyTuple() { @@ -59,7 +62,6 @@ private static PyTuple fromArrayNoCopy(PyObject[] elements) { return new PyTuple(elements, false); } - private volatile List<PyObject> cachedList = null; List<PyObject> getList() { if (cachedList == null) { @@ -70,8 +72,8 @@ @ExposedNew final static PyObject tuple_new(PyNewWrapper new_, boolean init, PyType subtype, - PyObject[] args, String[] keywords) { - ArgParser ap = new ArgParser("newtuple", args, keywords, new String[]{"sequence"}, 0); + PyObject[] args, String[] keywords) { + ArgParser ap = new ArgParser("tuple", args, keywords, new String[] {"sequence"}, 0); PyObject S = ap.getPyObject(0, null); if (new_.for_type == subtype) { if (S == null) { @@ -115,10 +117,8 @@ System.arraycopy(array, start, newArray, 0, stop - start); return fromArrayNoCopy(newArray); } - int j = 0; - for (int i = start; j < n; i += step) { + for (int i = start, j = 0; j < n; i += step, j++) { newArray[j] = array[i]; - j++; } return fromArrayNoCopy(newArray); } @@ -329,7 +329,6 @@ } else if (fromIndex > toIndex) { throw new IllegalArgumentException(); } - System.err.println("subList" + fromIndex + "," + toIndex); PyObject elements[] = new PyObject[toIndex - fromIndex]; for (int i = 0, j = fromIndex; i < elements.length; i++, j++) { elements[i] = array[j]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-04-19 00:01:42
|
Revision: 6245 http://jython.svn.sourceforge.net/jython/?rev=6245&view=rev Author: zyasoft Date: 2009-04-19 00:01:40 +0000 (Sun, 19 Apr 2009) Log Message: ----------- Cleanup. Removed Paths: ------------- trunk/jython/src/templates/newtuple.derived Deleted: trunk/jython/src/templates/newtuple.derived =================================================================== --- trunk/jython/src/templates/newtuple.derived 2009-04-19 00:01:11 UTC (rev 6244) +++ trunk/jython/src/templates/newtuple.derived 2009-04-19 00:01:40 UTC (rev 6245) @@ -1,4 +0,0 @@ -base_class: PyNewTuple -want_dict: true -ctr: PyObject[] elements -incl: object This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-04-19 00:01:14
|
Revision: 6244 http://jython.svn.sourceforge.net/jython/?rev=6244&view=rev Author: zyasoft Date: 2009-04-19 00:01:11 +0000 (Sun, 19 Apr 2009) Log Message: ----------- Merged revisions 6168,6176,6186,6190-6192,6195-6197,6199-6202,6215-6217,6222-6223,6227-6228,6231,6237-6240 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/branches/newlist Replaces PyList with a java.util.List and PyTuple with PyObject[] backed representations, respectively. Modified Paths: -------------- trunk/jython/Lib/test/test_javalist.py trunk/jython/src/org/python/core/JavaImportHelper.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PySequenceList.java trunk/jython/src/org/python/core/PyTuple.java trunk/jython/src/org/python/core/packagecache/PackageManager.java trunk/jython/src/templates/README.txt Added Paths: ----------- trunk/jython/src/org/python/core/PyComparator.java trunk/jython/src/templates/newtuple.derived Removed Paths: ------------- trunk/jython/src/org/python/core/PyObjectArray.java trunk/jython/src/org/python/core/PyObjectList.java Property Changed: ---------------- trunk/jython/ Property changes on: trunk/jython ___________________________________________________________________ Modified: svnmerge-integrated - /branches/modjy:1-6074 /branches/pbcvm:1-6045 /branches/newlist:1-6160 + /branches/modjy:1-6074 /branches/pbcvm:1-6045 /branches/newlist:1-6243 Modified: trunk/jython/Lib/test/test_javalist.py =================================================================== --- trunk/jython/Lib/test/test_javalist.py 2009-04-18 23:32:59 UTC (rev 6243) +++ trunk/jython/Lib/test/test_javalist.py 2009-04-19 00:01:11 UTC (rev 6244) @@ -1,4 +1,3 @@ -from test_support import * from javatests import ListTest class PyListTest(ListTest): Modified: trunk/jython/src/org/python/core/JavaImportHelper.java =================================================================== --- trunk/jython/src/org/python/core/JavaImportHelper.java 2009-04-18 23:32:59 UTC (rev 6243) +++ trunk/jython/src/org/python/core/JavaImportHelper.java 2009-04-19 00:01:11 UTC (rev 6244) @@ -120,6 +120,9 @@ Iterator iterator = ((PyTuple) fromlist).iterator(); while (iterator.hasNext()) { Object obj = iterator.next(); + if (obj instanceof PyString) { + obj = ((PyString)obj).string; + } if (obj instanceof String) { String fromName = (String) obj; if (!"*".equals(fromName)) { Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2009-04-18 23:32:59 UTC (rev 6243) +++ trunk/jython/src/org/python/core/Py.java 2009-04-19 00:01:11 UTC (rev 6244) @@ -21,6 +21,8 @@ import org.python.antlr.base.mod; import com.kenai.constantine.platform.Errno; +import java.util.ArrayList; +import java.util.List; import org.python.compiler.Module; import org.python.core.adapter.ClassicPyObjectAdapter; import org.python.core.adapter.ExtensiblePyObjectAdapter; @@ -1932,13 +1934,12 @@ } catch (PyException exc) { } - PyObjectArray objs = new PyObjectArray(n); + List<PyObject> objs = new ArrayList<PyObject>(n); for (PyObject item : o.asIterable()) { objs.add(item); } - // Cut back if guess was too large. - objs.trimToSize(); - return (PyObject[]) objs.getArray(); + PyObject dest[] = new PyObject[0]; + return (objs.toArray(dest)); } } /** @deprecated */ Copied: trunk/jython/src/org/python/core/PyComparator.java (from rev 6202, branches/newlist/src/org/python/core/PyComparator.java) =================================================================== --- trunk/jython/src/org/python/core/PyComparator.java (rev 0) +++ trunk/jython/src/org/python/core/PyComparator.java 2009-04-19 00:01:11 UTC (rev 6244) @@ -0,0 +1,53 @@ +package org.python.core; + +import java.util.Comparator; + +public class PyComparator implements Comparator<PyObject> { + + protected PyList list; + protected PyObject cmp; + protected PyObject key; + protected boolean reverse = false; + + PyComparator(PyList list, PyObject cmp, PyObject key, boolean reverse) { + this.list = list; + this.cmp = cmp; + this.key = key; + this.reverse = reverse; + } + + // First cut at an implementation. FIXME: In CPython key is supposed to + // make things fast, accessing each element once. For this first cut I am + // cheating and calling the key function on every pass to get something + // that works right away. + public int compare(PyObject o1, PyObject o2) { + int result; + if (key != null && key != Py.None) { + o1 = key.__call__(o1); + o2 = key.__call__(o2); + } + if (cmp != null && cmp != Py.None) { + result = cmp.__call__(o1, o2).asInt(); + } else { + result = o1._cmp(o2); + } + if (reverse) { + return -result; + } + if (this.list.gListAllocatedStatus >= 0) { + throw Py.ValueError("list modified during sort"); + } + return result; + } + + public boolean equals(Object o) { + if(o == this) { + return true; + } + + if (o instanceof PyComparator) { + return key.equals(((PyComparator)o).key) && cmp.equals(((PyComparator)o).cmp); + } + return false; + } +} Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2009-04-18 23:32:59 UTC (rev 6243) +++ trunk/jython/src/org/python/core/PyList.java 2009-04-19 00:01:11 UTC (rev 6244) @@ -1,38 +1,59 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - +import java.util.ArrayList; +import java.util.Arrays; import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; import org.python.expose.ExposedType; import org.python.expose.MethodType; import org.python.util.Generic; -/** - * A builtin python list. - */ +import java.util.Collection; +import java.util.Collections; +import java.util.ConcurrentModificationException; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + @ExposedType(name = "list", base = PyObject.class) -public class PyList extends PySequenceList { +public class PyList extends PySequenceList implements List { public static final PyType TYPE = PyType.fromClass(PyList.class); + protected final List<PyObject> list; public PyList() { - this(TYPE, Py.EmptyObjects); + this(TYPE); } public PyList(PyType type) { super(type); + list = Generic.list(); } + private PyList(List list, boolean convert) { + super(TYPE); + if (!convert) { + this.list = list; + } else { + this.list = Generic.list(); + for (Object o : list) { + add(o); + } + } + } + public PyList(PyType type, PyObject[] elements) { - super(type, elements); + super(type); + list = new ArrayList<PyObject>(Arrays.asList(elements)); } public PyList(PyType type, Collection c) { - super(type, c); + super(type); + list = new ArrayList<PyObject>(c.size()); + for (Object o : c) { + add(o); + } } public PyList(PyObject[] elements) { @@ -40,23 +61,28 @@ } public PyList(Collection c) { - super(TYPE, c); + this(TYPE, c); } public PyList(PyObject o) { this(TYPE); for (PyObject item : o.asIterable()) { - append(item); + list.add(item); } } + public static PyList fromList(List<PyObject> list) { + return new PyList(list, false); + } + private static List<PyObject> listify(Iterator<PyObject> iter) { - List<PyObject> list = Generic.list(); - while (iter.hasNext()) { + List<PyObject> list = Generic.list(); + while (iter.hasNext()) { list.add(iter.next()); - } - return list; + } + return list; } + public PyList(Iterator<PyObject> iter) { this(TYPE, listify(iter)); } @@ -64,15 +90,16 @@ @ExposedNew @ExposedMethod(doc = BuiltinDocs.list___init___doc) final void list___init__(PyObject[] args, String[] kwds) { - ArgParser ap = new ArgParser("list", args, kwds, new String[] {"sequence"}, 0); + ArgParser ap = new ArgParser("list", args, kwds, new String[]{"sequence"}, 0); PyObject seq = ap.getPyObject(0, null); clear(); - if(seq == null) { + if (seq == null) { return; } - if(seq instanceof PySequenceList) { - PySequenceList p = (PySequenceList)seq.__getslice__(Py.None, Py.None, Py.One); - this.list = p.list; + if (seq instanceof PyList) { + list.addAll(((PyList) seq).list); // don't convert + } else if (seq instanceof PyTuple) { + list.addAll(((PyTuple) seq).getList()); } else { for (PyObject item : seq.asIterable()) { append(item); @@ -80,6 +107,7 @@ } } + @Override public int __len__() { return list___len__(); } @@ -89,105 +117,92 @@ return size(); } - protected PyObject getslice(int start, int stop, int step) { - if(step > 0 && stop < start) { - stop = start; - } - int n = sliceLength(start, stop, step); - PyObject[] newList = new PyObject[n]; - PyObject[] array = getArray(); - if(step == 1) { - System.arraycopy(array, start, newList, 0, stop - start); - return new PyList(newList); - } - int j = 0; - for(int i = start; j < n; i += step) { - newList[j] = array[i]; - j++; - } - return new PyList(newList); - } - + @Override protected void del(int i) { remove(i); } + @Override protected void delRange(int start, int stop) { remove(start, stop); } + @Override protected void setslice(int start, int stop, int step, PyObject value) { - if(stop < start) { + if (stop < start) { stop = start; } - if(value instanceof PySequence) { - PySequence sequence = (PySequence) value; - setslicePySequence(start, stop, step, sequence); - } else if(value instanceof List) { - List list = (List)value.__tojava__(List.class); - if(list != null && list != Py.NoConversion) { - setsliceList(start, stop, step, list); + if (value instanceof PyList) { + if (value == this) { // copy + value = new PyList((PySequence) value); } + setslicePyList(start, stop, step, (PyList) value); + } else if (value instanceof PySequence) { + setsliceIterator(start, stop, step, value.asIterable().iterator()); + } else if (value != null && !(value instanceof List)) { + value = new PyList(value); + setsliceIterator(start, stop, step, value.asIterable().iterator()); } else { - setsliceIterable(start, stop, step, value); + List valueList = (List) value.__tojava__(List.class); + if (valueList != null && valueList != Py.NoConversion) { + setsliceList(start, stop, step, valueList); + } } } - protected void setslicePySequence(int start, int stop, int step, PySequence value) { - if(step == 1) { - PyObject[] otherArray; - PyObject[] array = getArray(); + protected void setsliceList(int start, int stop, int step, List value) { + int n = sliceLength(start, stop, step); + if (list instanceof ArrayList) { + ((ArrayList) list).ensureCapacity(start + n); + } + ListIterator src = value.listIterator(); + for (int j = start; src.hasNext(); j += step) { + set(j, src.next()); + } + } - int n = value.__len__(); - if (value instanceof PySequenceList) { - otherArray = ((PySequenceList)value).getArray(); - } else { - otherArray = Py.unpackSequence(value, value.__len__()); + protected void setsliceIterator(int start, int stop, int step, Iterator<PyObject> iter) { + if (step == 1) { + List<PyObject> insertion = new ArrayList<PyObject>(); + if (iter != null) { + while (iter.hasNext()) { + insertion.add(iter.next()); + } } - if (otherArray == array) { - otherArray = otherArray.clone(); - } - list.replaceSubArray(start, stop, otherArray, 0, n); - } else if(step != 0) { - if(value == this) { - PyList newseq = new PyList(); - PyObject iter = value.__iter__(); - for(PyObject item = null; (item = iter.__iternext__()) != null;) { - newseq.append(item); + list.subList(start, stop).clear(); + list.addAll(start, insertion); + } else { + int size = list.size(); + for (int j = start; iter.hasNext(); j += step) { + PyObject item = iter.next(); + if (j >= size) { + list.add(item); + } else { + list.set(j, item); } - value = newseq; } - int n = value.__len__(); - for (int i = 0, j = start; i < n; i++, j += step) { - list.pyset(j, value.pyget(i)); - } } } - protected void setsliceList(int start, int stop, int step, List value) { - if(step != 1) { - throw Py.TypeError("setslice with java.util.List and step != 1 not supported yet"); - } - int n = value.size(); - list.ensureCapacity(start + n); - for(int i = 0; i < n; i++) { - list.add(i + start, value.get(i)); - } - } - - protected void setsliceIterable(int start, int stop, int step, PyObject value) { - PyObject[] seq; - try { - seq = Py.make_array(value); - } catch (PyException pye) { - if (Py.matchException(pye, Py.TypeError)) { - throw Py.TypeError("can only assign an iterable"); + protected void setslicePyList(int start, int stop, int step, PyList other) { + if (step == 1) { + list.subList(start, stop).clear(); + list.addAll(start, other.list); + } else { + int size = list.size(); + Iterator<PyObject> iter = other.list.listIterator(); + for (int j = start; iter.hasNext(); j += step) { + PyObject item = iter.next(); + if (j >= size) { + list.add(item); + } else { + list.set(j, item); + } } - throw pye; } - setslicePySequence(start, stop, step, new PyList(seq)); } + @Override protected PyObject repeat(int count) { if (count < 0) { count = 0; @@ -198,12 +213,11 @@ throw Py.MemoryError(""); } - PyObject[] array = getArray(); - PyObject[] newArray = new PyObject[newSize]; - for(int i = 0; i < count; i++) { - System.arraycopy(array, 0, newArray, i * size, size); + PyList newList = new PyList(); + for (int i = 0; i < count; i++) { + newList.addAll(list); } - return new PyList(newArray); + return newList; } @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___ne___doc) @@ -236,6 +250,7 @@ return seq___ge__(o); } + @Override public PyObject __imul__(PyObject o) { return list___imul__(o); } @@ -262,12 +277,14 @@ } int newSize = size * count; - list.setSize(newSize); - PyObject[] array = getArray(); + if (list instanceof ArrayList) { + ((ArrayList) list).ensureCapacity(newSize); + } + List oldList = new ArrayList<PyObject>(list); for (int i = 1; i < count; i++) { - System.arraycopy(array, 0, array, i * size, size); + list.addAll(oldList); } - gListAllocatedStatus = __len__(); + gListAllocatedStatus = __len__(); // now omit? return this; } @@ -297,6 +314,7 @@ return repeat(o.asIndex(Py.OverflowError)); } + @Override public PyObject __add__(PyObject o) { return list___add__(o); } @@ -304,22 +322,22 @@ @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.list___add___doc) final PyObject list___add__(PyObject o) { PyList sum = null; - if(o instanceof PyList) { - PyList other = (PyList)o; - int thisLen = size(); - int otherLen = other.size(); - PyObject[] newList = new PyObject[thisLen + otherLen]; - System.arraycopy(getArray(), 0, newList, 0, thisLen); - System.arraycopy(other.getArray(), 0, newList, thisLen, otherLen); - sum = new PyList(newList); - } else if(!(o instanceof PySequenceList)) { + if (o instanceof PySequenceList && !(o instanceof PyTuple)) { + if (o instanceof PyList) { + List oList = ((PyList) o).list; + List newList = new ArrayList(list.size() + oList.size()); + newList.addAll(list); + newList.addAll(oList); + sum = fromList(newList); + } + } else if (!(o instanceof PySequenceList)) { // also support adding java lists (but not PyTuple!) Object oList = o.__tojava__(List.class); - if(oList != Py.NoConversion && oList != null) { + if (oList != Py.NoConversion && oList != null) { List otherList = (List) oList; sum = new PyList(); sum.list_extend(this); - for(Iterator i = otherList.iterator(); i.hasNext();) { + for (Iterator i = otherList.iterator(); i.hasNext();) { sum.add(i.next()); } } @@ -327,6 +345,7 @@ return sum; } + @Override public PyObject __radd__(PyObject o) { return list___radd__(o); } @@ -335,9 +354,9 @@ @ExposedMethod(type = MethodType.BINARY) final PyObject list___radd__(PyObject o) { // Support adding java.util.List, but prevent adding PyTuple. - // 'o' should never be a PyList since __add__ is defined. + // 'o' should never be a PyNewList since __add__ is defined. PyList sum = null; - if(o instanceof PySequence) { + if (o instanceof PySequence) { return null; } Object oList = o.__tojava__(List.class); @@ -367,12 +386,13 @@ @ExposedMethod(doc = BuiltinDocs.list___getitem___doc) final PyObject list___getitem__(PyObject o) { PyObject ret = seq___finditem__(o); - if(ret == null) { + if (ret == null) { throw Py.IndexError("index out of range: " + o); } return ret; } + @Override public PyObject __iter__() { return list___iter__(); } @@ -397,8 +417,9 @@ seq___delslice__(start, stop, step); } + @Override protected String unsupportedopMessage(String op, PyObject o2) { - if(op.equals("+")) { + if (op.equals("+")) { return "can only concatenate list (not \"{2}\") to list"; } return super.unsupportedopMessage(op, o2); @@ -412,19 +433,19 @@ @ExposedMethod(names = "__repr__") final String list_toString() { ThreadState ts = Py.getThreadState(); - if(!ts.enterRepr(this)) { + if (!ts.enterRepr(this)) { return "[...]"; } StringBuilder buf = new StringBuilder("["); int length = size(); - PyObject[] array = getArray(); - for(int i = 0; i < length - 1; i++) { - buf.append((array[i]).__repr__().toString()); - buf.append(", "); + int i = 0; + for (PyObject item : list) { + buf.append(item.__repr__().toString()); + if (i < length - 1) { + buf.append(", "); + } + i++; } - if(length > 0) { - buf.append((array[length - 1]).__repr__().toString()); - } buf.append("]"); ts.exitRepr(this); return buf.toString(); @@ -459,9 +480,8 @@ @ExposedMethod(doc = BuiltinDocs.list_count_doc) final int list_count(PyObject o) { int count = 0; - PyObject[] array = getArray(); - for(int i = 0, n = size(); i < n; i++) { - if(array[i].equals(o)) { + for (PyObject item : list) { + if (item.equals(o)) { count++; } } @@ -509,10 +529,17 @@ // Follow Python 2.3+ behavior int validStop = boundToSequence(stop); int validStart = boundToSequence(start); - PyObject[] array = getArray(); - for(int i = validStart; i < validStop && i < size(); i++) { - if(array[i].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); } } throw Py.ValueError(message); @@ -533,13 +560,13 @@ @ExposedMethod(doc = BuiltinDocs.list_insert_doc) final void list_insert(int index, PyObject o) { - if(index < 0) { + if (index < 0) { index = Math.max(0, size() + index); } - if(index > size()) { + if (index > size()) { index = size(); } - list.pyadd(index, o); + pyadd(index, o); gListAllocatedStatus = __len__(); } @@ -572,15 +599,7 @@ @ExposedMethod(doc = BuiltinDocs.list_reverse_doc) final void list_reverse() { - PyObject tmp; - int n = size(); - PyObject[] array = getArray(); - int j = n - 1; - for(int i = 0; i < n / 2; i++, j--) { - tmp = array[i]; - array[i] = array[j]; - array[j] = tmp; - } + Collections.reverse(list); gListAllocatedStatus = __len__(); } @@ -604,17 +623,16 @@ @ExposedMethod(defaults = "-1", doc = BuiltinDocs.list_pop_doc) final PyObject list_pop(int n) { int length = size(); - if(length == 0) { + if (length == 0) { throw Py.IndexError("pop from empty list"); } - if(n < 0) { + if (n < 0) { n += length; } - if(n < 0 || n >= length) { + if (n < 0 || n >= length) { throw Py.IndexError("pop index out of range"); } - PyObject v = pyget(n); - setslice(n, n + 1, 1, Py.EmptyTuple); + PyObject v = list.remove(n); return v; } @@ -631,11 +649,17 @@ @ExposedMethod(doc = BuiltinDocs.list_extend_doc) final void list_extend(PyObject o) { - int length = size(); - setslice(length, length, 1, o); + if (o instanceof PyList) { + list.addAll(((PyList) o).list); + } else { + for (PyObject item : o.asIterable()) { + list.add(item); + } + } gListAllocatedStatus = __len__(); } + @Override public PyObject __iadd__(PyObject o) { return list___iadd__(o); } @@ -672,13 +696,10 @@ * @param compare * the comparison function. */ - - /** + /** * Sort the items of the list in place. Items is compared with the normal relative comparison * operators. */ - - @ExposedMethod(doc = BuiltinDocs.list_sort_doc) final void list_sort(PyObject[] args, String[] kwds) { ArgParser ap = new ArgParser("list", args, kwds, new String[]{"cmp", "key", "reverse"}, 0); @@ -696,9 +717,11 @@ sort(Py.None, Py.None, Py.False); } - public void sort(PyObject cmp, PyObject key, PyObject reverse) { - MergeState ms = new MergeState(this, cmp, key, reverse.__nonzero__()); - ms.sort(); + 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() { @@ -710,7 +733,249 @@ throw Py.TypeError(String.format("unhashable type: '%.200s'", getType().fastGetName())); } + @Override public PyTuple __getnewargs__() { - return new PyTuple(new PyTuple(list.getArray())); + return new PyTuple(new PyTuple(getArray())); } + + @Override + public void add(int index, Object element) { + pyadd(index, Py.java2py(element)); + } + + @Override + public boolean add(Object o) { + pyadd(Py.java2py(o)); + return true; + } + + @Override + public boolean addAll(int index, Collection c) { + PyList elements = new PyList(c); + return list.addAll(index, elements.list); + } + + @Override + public boolean addAll(Collection c) { + return addAll(0, c); + } + + @Override + public void clear() { + list.clear(); + } + + @Override + public boolean contains(Object o) { + return list.contains(Py.java2py(o)); + } + + @Override + public boolean containsAll(Collection c) { + if (c instanceof PySequenceList) { + return list.containsAll(c); + } else { + return list.containsAll(new PyList(c)); + } + } + + @Override + public boolean equals(Object o) { + if (o instanceof PyList) { + return (((PyList) o).list.equals(list)); + } else if (o instanceof List) { // XXX copied from PyList, but... + return o.equals(this); // XXX shouldn't this compare using py2java? + } + return false; + } + + @Override + public Object get(int index) { + return list.get(index).__tojava__(Object.class); + } + + /** @deprecated */ + @Override + public PyObject[] getArray() { + PyObject a[] = null; // = new PyObject[list.size()]; + return list.toArray(a); + } + + @Override + public int indexOf(Object o) { + return list.indexOf(o); + } + + @Override + public boolean isEmpty() { + return list.isEmpty(); + } + + @Override + public Iterator iterator() { + return list.iterator(); + } + + @Override + public int lastIndexOf(Object o) { + return list.lastIndexOf(Py.java2py(o)); + } + + @Override + public ListIterator listIterator() { + return listIterator(0); + } + + @Override + public ListIterator listIterator(final int index) { + return new ListIterator() { + + private final ListIterator<PyObject> iter = list.listIterator(index); + + public boolean hasNext() { + return iter.hasNext(); + } + + public Object next() { + return iter.next().__tojava__(Object.class); + } + + public boolean hasPrevious() { + return iter.hasPrevious(); + } + + public Object previous() { + return iter.previous().__tojava__(Object.class); + } + + public int nextIndex() { + return iter.nextIndex(); + } + + public int previousIndex() { + return iter.previousIndex(); + } + + public void remove() { + iter.remove(); + } + + public void set(Object o) { + iter.set(Py.java2py(o)); + } + + public void add(Object o) { + iter.add(Py.java2py(o)); + } + }; + } + + @Override + public void pyadd(int index, PyObject element) { + list.add(index, element); + } + + @Override + public boolean pyadd(PyObject o) { + list.add(o); + return true; + } + + @Override + public PyObject pyget(int index) { + return list.get(index); + } + + public void pyset(int index, PyObject element) { + list.set(index, element); + } + + @Override + public Object remove(int index) { + return list.remove(index); + } + + @Override + public void remove(int start, int stop) { + list.subList(start, stop).clear(); + } + + @Override + public boolean removeAll(Collection c) { + if (c instanceof PySequenceList) { + return list.removeAll(c); + } else { + return list.removeAll(new PyList(c)); + } + } + + @Override + public boolean retainAll(Collection c) { + if (c instanceof PySequenceList) { + return list.retainAll(c); + } else { + return list.retainAll(new PyList(c)); + } + } + + @Override + public Object set(int index, Object element) { + return list.set(index, Py.java2py(element)).__tojava__(Object.class); + } + + @Override + public int size() { + return list.size(); + } + + @Override + public List subList(int fromIndex, int toIndex) { + return fromList(list.subList(fromIndex, toIndex)); + } + + @Override + public Object[] toArray() { + Object copy[] = list.toArray(); + for (int i = 0; i < copy.length; i++) { + copy[i] = ((PyObject) copy[i]).__tojava__(Object.class); + } + return copy; + } + + @Override + public Object[] toArray(Object[] a) { + Object copy[] = list.toArray(); + if (a.length != copy.length) { + a = copy; + } + for (int i = 0; i < copy.length; i++) { + a[i] = ((PyObject) copy[i]).__tojava__(Object.class); + } + for (int i = copy.length; i < a.length; i++) { + a[i] = null; + } + return a; + } + + protected PyObject getslice(int start, int stop, int step) { + if (step > 0 && stop < start) { + stop = start; + } + int n = sliceLength(start, stop, step); + List newList; + if (step == 1) { + newList = new ArrayList<PyObject>(list.subList(start, stop)); + } else { + newList = new ArrayList<PyObject>(n); + for (int i = start, j = 0; j < n; i += step, j++) { + newList.add(list.get(i)); + } + } + return fromList(newList); + } + + @Override + public boolean remove(Object o) { + return list.remove(Py.java2py(o)); + } } Deleted: trunk/jython/src/org/python/core/PyObjectArray.java =================================================================== --- trunk/jython/src/org/python/core/PyObjectArray.java 2009-04-18 23:32:59 UTC (rev 6243) +++ trunk/jython/src/org/python/core/PyObjectArray.java 2009-04-19 00:01:11 UTC (rev 6244) @@ -1,213 +0,0 @@ -//Copyright (c) Corporation for National Research Initiatives -package org.python.core; - - -/** - * Provides mutable behavior on a PyObject array. Supports operations for - * implementing <CODE>java.util.List</CODE>. - * @author Clark Updike - */ -public class PyObjectArray extends AbstractArray { - - public void remove(int start, int stop) { - super.remove(start, stop); - } - - /** - * The underlying array used for storing the data. - */ - protected PyObject[] baseArray; - - /** - * Create the array with the specified size. - */ - public PyObjectArray() { - super(PyObject.class); - } - - public PyObjectArray(PyObject[] rawArray) { - super(rawArray == null ? 0 : rawArray.length); - baseArray = (rawArray == null) ? new PyObject[] {} : rawArray; - } - - /** - * Create the array with the specified size. - * @param size number of int values initially allowed in array - */ - public PyObjectArray(int size) { - super(PyObject.class, size); - } - - /** - * @param toCopy - */ - public PyObjectArray(PyObjectArray toCopy) { - - super(toCopy); - this.baseArray = (PyObject[])toCopy.copyArray(); - } - - /** - * Add a value at a specified index in the array. - * <P><CODE>AbstractList</CODE> subclasses should update their - * <CODE>modCount</CODE> after calling this method. - * - * @param index index position at which to insert element - * @param value value to be inserted into array - */ - public void add(int index, PyObject value) { - makeInsertSpace(index); - baseArray[index] = value; - } - - /** - * Add a value to the array, appending it after the current values. - * <P><CODE>AbstractList</CODE> subclasses should update their - * <CODE>modCount</CODE> after calling this method. - * - * @param value value to be added - * @return index number of added element - */ - public int add(PyObject value) { - int index = getAddIndex(); - baseArray[index] = value; - return index; - } - - /** - * Duplicates the object with the generic call. - * - * @return a copy of the object - */ - public Object clone() { - return new PyObjectArray(this); - } - - public boolean equals(Object o) { - if(o instanceof PyObjectArray) { - PyObjectArray arr = (PyObjectArray)o; - if (size != arr.size) return false; - for (int i = 0; i < size; i++) { - PyObject thisElem = baseArray[i]; - PyObject otherElem = arr.baseArray[i]; - if (thisElem == null) { - if (otherElem == null) continue; - return false; - } - if (!thisElem.equals(otherElem)) return false; - } - return true; - } - return false; - } - - public int hashCode() { - int x, y; - int len = size; - x = 0x345678; - - for (len--; len>=0; len--) { - y = baseArray[len].hashCode(); - x = (x + x + x) ^ y; - } - x ^= size; - return x; - } - - /** - * Discards values for a range of indices from the array. For the array of - * <code>int</code> values, just sets the values to null. - * - * @param from index of first value to be discarded - * @param to index past last value to be discarded - */ - protected void discardValues(int from, int to) { - for (int i = from; i < to; i++) { - baseArray[i] = null; - } - } - - /** - * Retrieve the value present at an index position in the array. - * - * @param index index position for value to be retrieved - * @return value from position in the array - */ - public PyObject get(int index) { - - if (index >= 0 && index < size) { - return baseArray[index]; - } - - String message = (size == 0) - ? "No data was added, unable to get entry at " + index - : "Index must be between " + 0 + " and " + - (size - 1) + ", but was " + index; - throw new ArrayIndexOutOfBoundsException(message); - - } - - /** - * Get the backing array. This method is used by the type-agnostic base - * class code to access the array used for type-specific storage. The array - * should generally not be modified. To get a copy of the array, see - * {@link #toArray()} which returns a copy. Note that - * <CODE>getSize()</CODE> should be used to determine the number of elements - * in the array, not the array's length (which may reflect excess capacity). - * <CODE>toArray()</CODE> returns an array whose length equals the value - * returned by <CODE>getSize()</CODE>. - * - * @return backing array object - */ - public Object getArray() { - return baseArray; - } - - /** - * Set the value at an index position in the array. - * - * @param index index position to be set - * @param value value to be set - */ - public PyObject set(int index, PyObject value) { - if (index >= 0 && index < size) { - PyObject existing = baseArray[index]; - baseArray[index] = value; - return existing; - } - throw new ArrayIndexOutOfBoundsException( - "Index must be between " + 0 + " and " + - (size - 1) + ", but was " + index); - } - - /** - * Set the backing array. This method is used by the type-agnostic base - * class code to set the array used for type-specific storage. - * - * @param array the backing array object - */ - protected void setArray(Object array) { - baseArray = (PyObject[]) array; - } - - /** - * Constructs and returns a simple array containing the same data as held - * in this growable array. The array's length matches the value returned - * by <CODE>getSize()</CODE> - * - * @return array containing a copy of the data - */ - public PyObject[] toArray() { - return (PyObject[]) copyArray(); - } - - public void ensureCapacity(int minCapacity) { - super.ensureCapacity(minCapacity); - } - - @Override - protected PyObject[] createArray(int size) { - return new PyObject[size]; - } -} - Deleted: trunk/jython/src/org/python/core/PyObjectList.java =================================================================== --- trunk/jython/src/org/python/core/PyObjectList.java 2009-04-18 23:32:59 UTC (rev 6243) +++ trunk/jython/src/org/python/core/PyObjectList.java 2009-04-19 00:01:11 UTC (rev 6244) @@ -1,186 +0,0 @@ -//Copyright (c) Corporation for National Research Initiatives -package org.python.core; - -import java.io.Serializable; -import java.util.AbstractList; -import java.util.Collection; -import java.util.RandomAccess; - -/** - * <CODE>java.util.List</CODE> implementation using an underlying PyObject - * array for higher performance. Jython should use the following methods - * where possible, instead of their <CODE>List</CODE> counterparts: - * <UL> - * <LI>pyadd(int, PyObject)</LI> - * <LI>pyadd(PyObject)</LI> - * <LI>pyset(PyObject)</LI> - * <LI>pyget()</LI> - * </UL> - * @author Clark Updike - */ -public class PyObjectList - extends AbstractList<Object> implements RandomAccess, Cloneable, Serializable { - - /* - * Design note: This class lets PySequenceList implement java.util.List by delegating to it. The - * major distinction is that the backing array is PyObject[], not Object[] (as you'd get by - * delegating to ArrayList). There are 2 major benefits: 1) A lot of casting can be avoided - * internally (although use of PySequenceList descendants as java collections does involve some - * casting); 2) PySequenceList descendants can still do bulk array operations, allowing better - * performance and reuse of much of the pre-collections bulk operation implementation. - */ - - - /** - * Provides mutable operations on a PyObject[] array, including features - * that help with implementing java.util.List. - */ - protected PyObjectArray array; - - public PyObjectList() { - array = new PyObjectArray(); - } - - public PyObjectList(PyObject[] pyObjArr) { - array = new PyObjectArray(pyObjArr); - array.baseArray = pyObjArr; - } - - public PyObjectList(Collection<PyObject> c) { - array = new PyObjectArray(); - array.appendArray(c.toArray()); - } - - public PyObjectList(int size) { - array = new PyObjectArray(size); - } - - /** - * For internal jython usage, use {@link #pyadd(int, PyObject)}. - */ - public void add(int index, Object element) { - pyadd(index, Py.java2py(element)); - } - - public void pyadd(int index, PyObject element) { - array.add(index, element); - modCount += array.getModCountIncr(); - } - - /** - * For internal jython usage, use {@link #pyadd(PyObject)}. - */ - public boolean add(Object o) { - pyadd(Py.java2py(o)); - return true; - } - - public boolean pyadd(PyObject o) { - array.add(o); - modCount += array.getModCountIncr(); - return true; - } - - public Object clone(){ - try { - PyObjectList tol = (PyObjectList) super.clone(); - tol.array = (PyObjectArray) array.clone(); - tol.modCount = 0; - return tol; - } catch (CloneNotSupportedException eCNSE) { - throw new InternalError("Unexpected CloneNotSupportedException.\n" - + eCNSE.getMessage()); - } - } - - public boolean equals(Object o) { - if(o instanceof PyObjectList) { - return array.equals(((PyObjectList)o).array); - } - return false; - } - - public int hashCode() { - return array.hashCode(); - } - - /** - * Use <code>pyget(int)</code> for internal jython usage. - */ - public Object get(int index) { - return array.get(index).__tojava__(Object.class); - } - - PyObject pyget(int index) { - return array.get(index); - } - - public Object remove(int index) { - modCount++; - Object existing = array.get(index); - array.remove(index); - return existing; - } - - public void remove(int start, int stop) { - modCount++; - array.remove(start, stop); - } - - /** - * Use <code>pyset(int, PyObject)</code> for internal jython usage. - */ - public Object set(int index, Object element) { - return pyset(index, Py.java2py(element)).__tojava__(Object.class); - } - - PyObject pyset(int index, PyObject element) { - return array.set(index, element); - } - - public int size() { - return array.getSize(); - } - - public boolean addAll(Collection<? extends Object> c) { - return addAll(size(), c); - } - - public boolean addAll(int index, Collection<? extends Object> c) { - if (c instanceof PySequenceList) { - PySequenceList cList = (PySequenceList)c; - PyObject[] cArray = cList.getArray(); - int cOrigSize = cList.size(); - array.makeInsertSpace(index, cOrigSize); - array.replaceSubArray(index, index + cOrigSize, cArray, 0, cOrigSize); - } else { - // need to use add to convert anything pulled from a collection into a PyObject - for (Object element : c) { - add(element); - } - } - return c.size() > 0; - } - - /** - * Get the backing array. The array should generally not be modified. To get a copy of the - * array, see {@link #toArray()} which returns a copy. - * - * @return backing array object - */ - protected PyObject[] getArray() { - return (PyObject[])array.getArray(); - } - - void ensureCapacity(int minCapacity) { - array.ensureCapacity(minCapacity); - } - - void replaceSubArray(int destStart, int destStop, Object srcArray, int srcStart, int srcStop) { - array.replaceSubArray(destStart, destStop, srcArray, srcStart, srcStop); - } - - void setSize(int count) { - array.setSize(count); - } -} Modified: trunk/jython/src/org/python/core/PySequenceList.java =================================================================== --- trunk/jython/src/org/python/core/PySequenceList.java 2009-04-18 23:32:59 UTC (rev 6243) +++ trunk/jython/src/org/python/core/PySequenceList.java 2009-04-19 00:01:11 UTC (rev 6244) @@ -5,171 +5,81 @@ import java.util.List; import java.util.ListIterator; -public abstract class PySequenceList extends PySequence implements List { +public abstract class PySequenceList extends PySequence { - protected PyObjectList list; - public PySequenceList() { - list = new PyObjectList(); } protected PySequenceList(PyType type) { super(type); - list = new PyObjectList(); } - protected PySequenceList(PyType type, PyObject[] elements) { - super(type); - list = new PyObjectList(elements); - } + public abstract void add(int index, Object element); - /** - * Creates an instance directly backed by the array of PyObject elements. - */ - public PySequenceList(PyObject[] elements) { - list = new PyObjectList(elements); - } + public abstract boolean add(Object o); - public PySequenceList(PyType type, Collection<PyObject> c) { - super(type); - list = new PyObjectList(c); - } + public abstract boolean addAll(int index, Collection c); - public void add(int index, Object element) { - list.add(index, element); - } + public abstract boolean addAll(Collection c); - public boolean add(Object o) { - return list.add(o); - } + public abstract void clear(); - public boolean addAll(int index, Collection c) { - return list.addAll(index, c); - } + public abstract boolean contains(Object o); - public boolean addAll(Collection c) { - return list.addAll(c); - } + public abstract boolean containsAll(Collection c); - public void clear() { - list.clear(); - } + public abstract boolean equals(Object o); - public boolean contains(Object o) { - return list.contains(o); - } + public abstract Object get(int index); - public boolean containsAll(Collection c) { - return list.containsAll(c); - } + /** + * Get the backing array. The array should not be modified. To get a copy of the array, see + * {@link #toArray()}. + */ + public abstract PyObject[] getArray(); - public Object get(int index) { - return list.get(index); - } + public abstract int hashCode(); - public int indexOf(Object o) { - return list.indexOf(o); - } + public abstract int indexOf(Object o); - public boolean isEmpty() { - return list.isEmpty(); - } + public abstract boolean isEmpty(); - public Iterator iterator() { - return list.iterator(); - } + public abstract Iterator iterator(); - public int lastIndexOf(Object o) { - return list.lastIndexOf(o); - } + public abstract int lastIndexOf(Object o); - public ListIterator listIterator() { - return list.listIterator(); - } + public abstract ListIterator listIterator(); - public ListIterator listIterator(int index) { - return list.listIterator(index); - } + public abstract ListIterator listIterator(int index); - public void pyadd(int index, PyObject element) { - list.pyadd(index, element); - } + public abstract void pyadd(int index, PyObject element); - public PyObject pyget(int index) { - return list.pyget(index); - } + public abstract boolean pyadd(PyObject o); - public void pyset(int index, PyObject element) { - list.pyset(index, element); - } + public abstract PyObject pyget(int index); - public Object remove(int index) { - return list.remove(index); - } + public abstract void pyset(int index, PyObject element); - public void remove(int start, int stop) { - list.remove(start, stop); - } + public abstract Object remove(int index); - public boolean remove(Object o) { - return list.remove(o); - } + public abstract void remove(int start, int stop); - public boolean removeAll(Collection c) { - return list.removeAll(c); - } + public abstract boolean remove(Object o); - public boolean retainAll(Collection c) { - return list.retainAll(c); - } + public abstract boolean removeAll(Collection c); - public Object set(int index, Object element) { - return list.set(index, element); - } + public abstract boolean retainAll(Collection c); - public int size() { - return list.size(); - } + public abstract Object set(int index, Object element); - public List subList(int fromIndex, int toIndex) { - return list.subList(fromIndex, toIndex); - } + public abstract int size(); - public Object[] toArray() { - return list.toArray(); - } + public abstract List subList(int fromIndex, int toIndex); - public Object[] toArray(Object[] a) { - return list.toArray(a); - } + public abstract Object[] toArray(); - public String toString() { - return list.toString(); - } + public abstract Object[] toArray(Object[] a); - public boolean pyadd(PyObject o) { - return list.pyadd(o); - } + public abstract String toString(); - public boolean equals(Object o) { - if(o instanceof PySequenceList) { - return list.equals(((PySequenceList)o).list); - } else if(o instanceof List) { - return o.equals(this); - } else { - return super.equals(o); - } - } - - public int hashCode() { - return list.hashCode(); - } - - /** - * Get the backing array. The array should not be modified. To get a copy of the array, see - * {@link #toArray()}. - */ - public PyObject[] getArray() { - return list.getArray(); - } } Modified: trunk/jython/src/org/python/core/PyTuple.java =================================================================== --- trunk/jython/src/org/python/core/PyTuple.java 2009-04-18 23:32:59 UTC (rev 6243) +++ trunk/jython/src/org/python/core/PyTuple.java 2009-04-19 00:01:11 UTC (rev 6244) @@ -1,6 +1,7 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Iterator; @@ -15,11 +16,12 @@ /** * A builtin python tuple. */ +@ExposedType(name = "tuple", base = PyObject.class) +public class PyTuple extends PySequenceList implements List { -@ExposedType(name = "tuple", base = PyObject.class) -public class PyTuple extends PySequenceList -{ public static final PyType TYPE = PyType.fromClass(PyTuple.class); + private final PyObject[] array; + private static final PyTuple EMPTY_TUPLE = new PyTuple(); public PyTuple() { this(TYPE, Py.EmptyObjects); @@ -30,25 +32,58 @@ } public PyTuple(PyType subtype, PyObject[] elements) { - super(subtype, elements); + super(subtype); + if (elements == null) { + array = new PyObject[0]; + } else { + array = new PyObject[elements.length]; + System.arraycopy(elements, 0, array, 0, elements.length); + } } + public PyTuple(PyObject[] elements, boolean copy) { + this(TYPE, elements, copy); + } + + public PyTuple(PyType subtype, PyObject[] elements, boolean copy) { + super(subtype); + + if (copy) { + array = new PyObject[elements.length]; + System.arraycopy(elements, 0, array, 0, elements.length); + } else { + array = elements; + } + } + + private static PyTuple fromArrayNoCopy(PyObject[] elements) { + return new PyTuple(elements, false); + } + private volatile List<PyObject> cachedList = null; + + List<PyObject> getList() { + if (cachedList == null) { + cachedList = Arrays.asList(array); + } + return cachedList; + } + @ExposedNew final static PyObject tuple_new(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords) { - ArgParser ap = new ArgParser("tuple", args, keywords, new String[] { "sequence" }, 0); + ArgParser ap = new ArgParser("newtuple", args, keywords, new String[]{"sequence"}, 0); PyObject S = ap.getPyObject(0, null); if (new_.for_type == subtype) { if (S == null) { - return new PyTuple(); + return EMPTY_TUPLE; } if (S instanceof PyTupleDerived) { - return new PyTuple(((PyTuple)S).getArray()); + return new PyTuple(((PyTuple) S).getArray()); } if (S instanceof PyTuple) { return S; } - return new PyTuple(Py.make_array(S)); + return fromArrayNoCopy(Py.make_array(S)); } else { if (S == null) { return new PyTupleDerived(subtype, Py.EmptyObjects); @@ -66,26 +101,26 @@ * @return a PyTuple containing each item in the iterable */ public static PyTuple fromIterable(PyObject iterable) { - return new PyTuple(Py.make_array(iterable)); + return fromArrayNoCopy(Py.make_array(iterable)); } protected PyObject getslice(int start, int stop, int step) { - if (step > 0 && stop < start) + if (step > 0 && stop < start) { stop = start; + } int n = sliceLength(start, stop, step); PyObject[] newArray = new PyObject[n]; - PyObject[] array = getArray(); if (step == 1) { - System.arraycopy(array, start, newArray, 0, stop-start); - return new PyTuple(newArray); + System.arraycopy(array, start, newArray, 0, stop - start); + return fromArrayNoCopy(newArray); } int j = 0; - for (int i=start; j<n; i+=step) { + for (int i = start; j < n; i += step) { newArray[j] = array[i]; j++; } - return new PyTuple(newArray); + return fromArrayNoCopy(newArray); } protected PyObject repeat(int count) { @@ -99,7 +134,7 @@ return this; } if (size == 0) { - return new PyTuple(); + return EMPTY_TUPLE; } } @@ -108,14 +143,14 @@ throw Py.MemoryError(""); } - PyObject[] array = getArray(); PyObject[] newArray = new PyObject[newSize]; for (int i = 0; i < count; i++) { System.arraycopy(array, 0, newArray, i * size, size); } - return new PyTuple(newArray); + return fromArrayNoCopy(newArray); } + @Override public int __len__() { return tuple___len__(); } @@ -124,7 +159,7 @@ final int tuple___len__() { return size(); } - + @ExposedMethod(doc = BuiltinDocs.tuple___contains___doc) final boolean tuple___contains__(PyObject o) { return super.__contains__(o); @@ -160,6 +195,7 @@ return super.__le__(o); } + @Override public PyObject __add__(PyObject generic_other) { return tuple___add__(generic_other); } @@ -168,15 +204,11 @@ final PyObject tuple___add__(PyObject generic_other) { PyTuple sum = null; if (generic_other instanceof PyTuple) { - PyTuple otherTuple = (PyTuple)generic_other; - PyObject[] array = getArray(); - PyObject[] otherArray = otherTuple.getArray(); - int thisLen = size(); - int otherLen = otherTuple.size(); - PyObject[] newArray = new PyObject[thisLen + otherLen]; - System.arraycopy(array, 0, newArray, 0, thisLen); - System.arraycopy(otherArray, 0, newArray, thisLen, otherLen); - sum = new PyTuple(newArray); + PyTuple other = (PyTuple) generic_other; + PyObject[] newArray = new PyObject[array.length + other.array.length]; + System.arraycopy(array, 0, newArray, 0, array.length); + System.arraycopy(other.array, 0, newArray, array.length, other.array.length); + sum = fromArrayNoCopy(newArray); } return sum; } @@ -207,6 +239,7 @@ return repeat(o.asIndex(Py.OverflowError)); } + @Override public PyObject __iter__() { return tuple___iter__(); } @@ -218,13 +251,13 @@ @ExposedMethod(defaults = "null", doc = BuiltinDocs.tuple___getslice___doc) final PyObject tuple___getslice__(PyObject s_start, PyObject s_stop, PyObject s_step) { - return seq___getslice__(s_start,s_stop,s_step); + return seq___getslice__(s_start, s_stop, s_step); } @ExposedMethod(doc = BuiltinDocs.tuple___getitem___doc) final PyObject tuple___getitem__(PyObject index) { PyObject ret = seq___finditem__(index); - if(ret == null) { + if (ret == null) { throw Py.IndexError("index out of range: " + index); } return ret; @@ -232,13 +265,15 @@ @ExposedMethod(doc = BuiltinDocs.tuple___getnewargs___doc) final PyTuple tuple___getnewargs__() { - return new PyTuple(new PyTuple(list.getArray())); + return new PyTuple(new PyTuple(getArray())); } + @Override public PyTuple __getnewargs__() { return tuple___getnewargs__(); } + @Override public int hashCode() { return tuple___hash__(); } @@ -251,7 +286,6 @@ int len = size(); int mult = 1000003; int x = 0x345678; - PyObject[] array = getArray(); while (--len >= 0) { y = array[len].hashCode(); x = (x ^ y) * mult; @@ -261,11 +295,13 @@ } private String subobjRepr(PyObject o) { - if (o == null) + if (o == null) { return "null"; + } return o.__repr__().toString(); } + @Override public String toString() { return tuple___repr__(); } @@ -273,43 +309,54 @@ @ExposedMethod(doc = BuiltinDocs.tuple___repr___doc) final String tuple___repr__() { StringBuilder buf = new StringBuilder("("); - PyObject[] array = getArray(); - int arrayLen = size(); - for (int i = 0; i < arrayLen-1; i++) { + for (int i = 0; i < array.length - 1; i++) { buf.append(subobjRepr(array[i])); buf.append(", "); } - if (arrayLen > 0) - buf.append(subobjRepr(array[arrayLen-1])); - if (arrayLen == 1) + if (array.length > 0) { + buf.append(subobjRepr(array[array.length - 1])); + } + if (array.length == 1) { buf.append(","); + } buf.append(")"); return buf.toString(); } public List subList(int fromIndex, int toIndex) { - return Collections.unmodifiableList(list.subList(fromIndex, toIndex)); + if (fromIndex < 0 || toIndex > size()) { + throw new IndexOutOfBoundsException(); + } else if (fromIndex > toIndex) { + throw new IllegalArgumentException(); + } + System.err.println("subList" + fromIndex + "," + toIndex); + PyObject elements[] = new PyObject[toIndex - fromIndex]; + for (int i = 0, j = fromIndex; i < elements.length; i++, j++) { + elements[i] = array[j]; + } + return new PyTuple(elements); } - // Make PyTuple immutable from the collections interfaces by overriding - // all the mutating methods to throw UnsupportedOperationException exception. - // This is how Collections.unmodifiableList() does it. public Iterator iterator() { return new Iterator() { - Iterator i = list.iterator(); + + private final Iterator<PyObject> iter = getList().iterator(); + public void remove() { throw new UnsupportedOperationException(); } + public boolean hasNext() { ... [truncated message content] |
From: <zy...@us...> - 2009-04-18 23:33:08
|
Revision: 6243 http://jython.svn.sourceforge.net/jython/?rev=6243&view=rev Author: zyasoft Date: 2009-04-18 23:32:59 +0000 (Sat, 18 Apr 2009) Log Message: ----------- Initialized merge tracking via "svnmerge" with revisions "1-6160" from https://jython.svn.sourceforge.net/svnroot/jython/branches/newlist Property Changed: ---------------- trunk/jython/ Property changes on: trunk/jython ___________________________________________________________________ Modified: svnmerge-integrated - /branches/modjy:1-6074 /branches/pbcvm:1-6045 + /branches/modjy:1-6074 /branches/pbcvm:1-6045 /branches/newlist:1-6160 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |