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: <th...@us...> - 2009-03-31 23:54:02
|
Revision: 6142 http://jython.svn.sourceforge.net/jython/?rev=6142&view=rev Author: thobes Date: 2009-03-31 23:53:50 +0000 (Tue, 31 Mar 2009) Log Message: ----------- Fixed a problem with functions being bound to a name before decorators are applied. Also added a test case that checks for it. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Added Paths: ----------- trunk/jython/Lib/test/test_decorators_jy.py Added: trunk/jython/Lib/test/test_decorators_jy.py =================================================================== --- trunk/jython/Lib/test/test_decorators_jy.py (rev 0) +++ trunk/jython/Lib/test/test_decorators_jy.py 2009-03-31 23:53:50 UTC (rev 6142) @@ -0,0 +1,24 @@ +"""Misc decorator related tests + +Made for Jython. +""" +from test import test_support +import unittest + +class TestDecorators(unittest.TestCase): + + def test_lookup_order(self): + class Foo(object): + foo = 'bar' + @property + def property(self): + return self.foo + self.assertEqual(Foo().property, 'bar') + + +def test_main(): + test_support.run_unittest(TestDecorators) + + +if __name__ == '__main__': + test_main() Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-03-31 23:30:57 UTC (rev 6141) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-03-31 23:53:50 UTC (rev 6142) @@ -420,22 +420,29 @@ } else { code.invokespecial( "org/python/core/PyFunction", "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + $pyObjArr + ")V"); } + + applyDecorators(node.getInternalDecorator_list()); set(new Name(node,node.getInternalName(), expr_contextType.Store)); - doDecorators(node,node.getInternalDecorator_list(), node.getInternalName()); + //doDecorators(node,node.getInternalDecorator_list(), node.getInternalName()); return null; } - private void doDecorators(stmt node, java.util.List<expr> decs, String name) throws Exception { - if (decs.size() > 0) { - expr currentExpr = new Name(node, name, expr_contextType.Load); - for (int i=decs.size() - 1;i > -1;i--) { - java.util.List args = new ArrayList(); - args.add(currentExpr); - currentExpr = new Call(node, decs.get(i), args, new ArrayList<keyword>(), null, null); + private void applyDecorators(java.util.List<expr> decorators) throws Exception { + if (decorators != null && !decorators.isEmpty()) { + int res = storeTop(); + for (expr decorator : decorators) { + visit(decorator); stackProduce(); } - visit(currentExpr); - set(new Name(node, name, expr_contextType.Store)); + for (int i = decorators.size(); i > 0; i--) { + stackConsume(); + loadThreadState(); + code.aload(res); + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); + code.astore(res); + } + code.aload(res); + code.freeLocal(res); } } @@ -2023,10 +2030,12 @@ } else { code.invokestatic("org/python/core/Py", "makeClass", "(" + $str + $pyObjArr + $pyCode + $pyObj + $pyObjArr + ")" + $pyObj); } + + applyDecorators(node.getInternalDecorator_list()); //Assign this new class to the given name set(new Name(node,node.getInternalName(), expr_contextType.Store)); - doDecorators(node,node.getInternalDecorator_list(), node.getInternalName()); + //doDecorators(node,node.getInternalDecorator_list(), node.getInternalName()); return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2009-03-31 23:30:59
|
Revision: 6141 http://jython.svn.sourceforge.net/jython/?rev=6141&view=rev Author: otmarhumbel Date: 2009-03-31 23:30:57 +0000 (Tue, 31 Mar 2009) Log Message: ----------- gracefully fall back into the old interactive console if jline classes are not on the classpath 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-03-31 19:41:07 UTC (rev 6140) +++ trunk/jython/src/org/python/util/jython.java 2009-03-31 23:30:57 UTC (rev 6141) @@ -312,7 +312,7 @@ String interpClass = PySystemState.registry.getProperty("python.console", "org.python.util.InteractiveConsole"); return (InteractiveConsole)Class.forName(interpClass).newInstance(); - } catch (Exception e) { + } catch (Throwable t) { return new InteractiveConsole(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-03-31 19:41:10
|
Revision: 6140 http://jython.svn.sourceforge.net/jython/?rev=6140&view=rev Author: fwierzbicki Date: 2009-03-31 19:41:07 +0000 (Tue, 31 Mar 2009) Log Message: ----------- rename test, added (but commented out) tests for http://bugs.jython.org/issue1271 Added Paths: ----------- trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java trunk/jython/tests/java/org/python/tests/props/PropShadow.java Removed Paths: ------------- trunk/jython/tests/java/org/python/tests/props/ReadonlyTest.java Copied: trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java (from rev 6138, trunk/jython/tests/java/org/python/tests/props/ReadonlyTest.java) =================================================================== --- trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java 2009-03-31 19:41:07 UTC (rev 6140) @@ -0,0 +1,44 @@ +package org.python.tests.props; + +import junit.framework.TestCase; + +import org.python.core.PyStringMap; +import org.python.core.PySystemState; +import org.python.util.PythonInterpreter; + +public class BeanPropertyTest extends TestCase { + + private PythonInterpreter interp; + + @Override + protected void setUp() throws Exception { + interp = new PythonInterpreter(new PyStringMap(), new PySystemState()); + } + + public void testReadonly() { + //This used to cause an NPE see http://bugs.jython.org/issue1295 + interp.exec("from org.python.tests.props import Readonly;Readonly().a = 'test'"); + } + + //This test is for http://bugs.jython.org/issue1271 + public void testBaseProp() { + /* + interp.exec("from org.python.tests.props import PropShadow"); + interp.exec("a = PropShadow.Derived()"); + interp.exec("assert a.foo() == 1, 'a'"); + interp.exec("assert a.bar() == 2, 'b'"); + */ + } + + //This test is for http://bugs.jython.org/issue1271 + public void testDerivedProp() { + /* + interp.exec("from org.python.tests.props import PropShadow"); + interp.exec("b = PropShadow.Derived()"); + interp.exec("assert b.getBaz() == 4, 'c'"); + interp.exec("assert b.getFoo() == 3, 'd'"); + interp.exec("assert b.foo() == 1, 'e'"); + interp.exec("assert b.foo() == 1, 'f'"); + */ + } +} Added: trunk/jython/tests/java/org/python/tests/props/PropShadow.java =================================================================== --- trunk/jython/tests/java/org/python/tests/props/PropShadow.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/props/PropShadow.java 2009-03-31 19:41:07 UTC (rev 6140) @@ -0,0 +1,33 @@ +package org.python.tests.props; + +public class PropShadow { + + public static class Base { + + public Base() { + } + + public int foo() { + return 1; + } + + public int bar() { + return 2; + } + } + + + public static class Derived extends Base { + + public Derived() { + } + + public int getFoo() { + return 3; + } + + public int getBaz() { + return 4; + } + } +} Deleted: trunk/jython/tests/java/org/python/tests/props/ReadonlyTest.java =================================================================== --- trunk/jython/tests/java/org/python/tests/props/ReadonlyTest.java 2009-03-31 19:04:48 UTC (rev 6139) +++ trunk/jython/tests/java/org/python/tests/props/ReadonlyTest.java 2009-03-31 19:41:07 UTC (rev 6140) @@ -1,22 +0,0 @@ -package org.python.tests.props; - -import junit.framework.TestCase; - -import org.python.core.PyStringMap; -import org.python.core.PySystemState; -import org.python.util.PythonInterpreter; - -public class ReadonlyTest extends TestCase { - - private PythonInterpreter interp; - - @Override - protected void setUp() throws Exception { - interp = new PythonInterpreter(new PyStringMap(), new PySystemState()); - } - - public void testReadonly() { - //This used to cause an NPE see http://bugs.jython.org/issue1295 - interp.exec("from org.python.tests.props import Readonly;Readonly().a = 'test'"); - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-03-31 19:05:02
|
Revision: 6139 http://jython.svn.sourceforge.net/jython/?rev=6139&view=rev Author: pjenvey Date: 2009-03-31 19:04:48 +0000 (Tue, 31 Mar 2009) Log Message: ----------- o don't use custom __hash__'s for internal weakref identity as weakrefs are unique per referent o avoid calling custom __hash__'s until it's necessary incase they're in an indeterminate state pointed out by Mike Bayer o make the internal ref map thread safe Modified Paths: -------------- trunk/jython/src/org/python/modules/_weakref/AbstractReference.java trunk/jython/src/org/python/modules/_weakref/GlobalRef.java Added Paths: ----------- trunk/jython/Lib/test/test_weakref_jy.py Added: trunk/jython/Lib/test/test_weakref_jy.py =================================================================== --- trunk/jython/Lib/test/test_weakref_jy.py (rev 0) +++ trunk/jython/Lib/test/test_weakref_jy.py 2009-03-31 19:04:48 UTC (rev 6139) @@ -0,0 +1,46 @@ +"""Misc weakref tests + +Made for Jython. +""" +import unittest +import weakref +from test import test_support + +class ReferencesTestCase(unittest.TestCase): + + def test___eq__(self): + class Foo(object): + def __eq__(self, other): + return True + def __hash__(self): + return hash('foo') + foo1, foo2 = Foo(), Foo() + ref1, ref2 = weakref.ref(foo1), weakref.ref(foo2) + self.assertTrue(ref1() is foo1) + self.assertTrue(ref2() is foo2) + + def test___hash__call(self): + hash_called = [] + class Bar(object): + def __hash__(self): + hash = object.__hash__(self) + hash_called.append(hash) + return hash + bar = Bar() + ref = weakref.ref(bar) + self.assertFalse(hash_called) + + hash(ref) + self.assertEqual(len(hash_called), 1) + hash(ref) + self.assertEqual(len(hash_called), 1) + self.assertEqual(hash(bar), hash(ref)) + self.assertEqual(len(hash_called), 2) + + +def test_main(): + test_support.run_unittest(ReferencesTestCase) + + +if __name__ == '__main__': + test_main() Modified: trunk/jython/src/org/python/modules/_weakref/AbstractReference.java =================================================================== --- trunk/jython/src/org/python/modules/_weakref/AbstractReference.java 2009-03-31 16:35:51 UTC (rev 6138) +++ trunk/jython/src/org/python/modules/_weakref/AbstractReference.java 2009-03-31 19:04:48 UTC (rev 6139) @@ -42,10 +42,7 @@ } public int hashCode() { - if (gref.realHash) { - return gref.hash; - } - throw Py.TypeError("unhashable instance"); + return gref.pythonHashCode(); } public PyObject __eq__(PyObject other) { Modified: trunk/jython/src/org/python/modules/_weakref/GlobalRef.java =================================================================== --- trunk/jython/src/org/python/modules/_weakref/GlobalRef.java 2009-03-31 16:35:51 UTC (rev 6138) +++ trunk/jython/src/org/python/modules/_weakref/GlobalRef.java 2009-03-31 19:04:48 UTC (rev 6139) @@ -5,29 +5,38 @@ import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; import java.util.ArrayList; -import java.util.Map; import java.util.List; +import java.util.concurrent.ConcurrentMap; import org.python.core.Py; -import org.python.core.PyException; import org.python.core.PyList; import org.python.core.PyObject; import org.python.util.Generic; public class GlobalRef extends WeakReference { - int hash; + /** + * This reference's hashCode: the System.identityHashCode of the referent. Only used + * internally. + */ + private int hashCode; - /** Whether the hash value was calculated by the underlying object. */ - boolean realHash; + /** + * The public hashCode for the Python AbstractReference wrapper. Derived from the + * referent's hashCode. + */ + private int pythonHashCode; + /** Whether pythonHashCode was already determined. */ + private boolean havePythonHashCode; + private List references = new ArrayList(); private static ReferenceQueue referenceQueue = new ReferenceQueue(); private static RefReaperThread reaperThread; - private static Map<GlobalRef, GlobalRef> objects = Generic.map(); + private static ConcurrentMap<GlobalRef, GlobalRef> objects = Generic.concurrentMap(); static { initReaperThread(); @@ -35,29 +44,9 @@ public GlobalRef(PyObject object) { super(object, referenceQueue); - calcHash(object); + hashCode = System.identityHashCode(object); } - /** - * Calculate a hash code to use for this object. If the PyObject we're - * referencing implements hashCode, we use that value. If not, we use - * System.identityHashCode(refedObject). This allows this object to be - * used in a Map while allowing Python ref objects to tell if the - * hashCode is actually valid for the object. - */ - private void calcHash(PyObject object) { - try { - hash = object.hashCode(); - realHash = true; - } catch (PyException pye) { - if (Py.matchException(pye, Py.TypeError)) { - hash = System.identityHashCode(object); - } else { - throw pye; - } - } - } - public synchronized void add(AbstractReference ref) { Reference r = new WeakReference(ref); references.add(r); @@ -148,16 +137,37 @@ if (t == u) { return true; } - return t.equals(u); + // Don't consult the objects' equals (__eq__) method, it can't be trusted + return false; } /** - * Allow GlobalRef's to be used as hashtable keys. + * Allows GlobalRef to be used as hashtable keys. + * + * @return a hashCode int value */ public int hashCode() { - return hash; + return hashCode; } + /** + * The publicly used hashCode, for the AbstractReference wrapper. + * + * @return a hashCode int value + */ + public int pythonHashCode() { + if (havePythonHashCode) { + return pythonHashCode; + } + Object referent = get(); + if (referent == null) { + throw Py.TypeError("weak object has gone away"); + } + pythonHashCode = referent.hashCode(); + havePythonHashCode = true; + return pythonHashCode; + } + private static void initReaperThread() { reaperThread = new RefReaperThread(); reaperThread.setDaemon(true); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-03-31 16:35:55
|
Revision: 6138 http://jython.svn.sourceforge.net/jython/?rev=6138&view=rev Author: fwierzbicki Date: 2009-03-31 16:35:51 +0000 (Tue, 31 Mar 2009) Log Message: ----------- Added comment to test and removed dead code from Readonly.java Modified Paths: -------------- trunk/jython/tests/java/org/python/tests/props/Readonly.java trunk/jython/tests/java/org/python/tests/props/ReadonlyTest.java Modified: trunk/jython/tests/java/org/python/tests/props/Readonly.java =================================================================== --- trunk/jython/tests/java/org/python/tests/props/Readonly.java 2009-03-31 16:31:06 UTC (rev 6137) +++ trunk/jython/tests/java/org/python/tests/props/Readonly.java 2009-03-31 16:35:51 UTC (rev 6138) @@ -3,6 +3,5 @@ public class Readonly { private String a; public void setA(String a) { this.a = a; } - //public String getA() { return a; } } Modified: trunk/jython/tests/java/org/python/tests/props/ReadonlyTest.java =================================================================== --- trunk/jython/tests/java/org/python/tests/props/ReadonlyTest.java 2009-03-31 16:31:06 UTC (rev 6137) +++ trunk/jython/tests/java/org/python/tests/props/ReadonlyTest.java 2009-03-31 16:35:51 UTC (rev 6138) @@ -16,6 +16,7 @@ } public void testReadonly() { + //This used to cause an NPE see http://bugs.jython.org/issue1295 interp.exec("from org.python.tests.props import Readonly;Readonly().a = 'test'"); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-03-31 16:31:10
|
Revision: 6137 http://jython.svn.sourceforge.net/jython/?rev=6137&view=rev Author: fwierzbicki Date: 2009-03-31 16:31:06 +0000 (Tue, 31 Mar 2009) Log Message: ----------- Fix for http://bugs.jython.org/issue1295 Setting a write-only bean property causes a NPE. Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/core/PyJavaType.java Added Paths: ----------- trunk/jython/tests/java/org/python/tests/props/ trunk/jython/tests/java/org/python/tests/props/Readonly.java trunk/jython/tests/java/org/python/tests/props/ReadonlyTest.java Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-03-31 15:14:19 UTC (rev 6136) +++ trunk/jython/NEWS 2009-03-31 16:31:06 UTC (rev 6137) @@ -2,6 +2,7 @@ Jython 2.5.0 rc 1 Bugs fixed (new numbering due to move to Roundup) + - [ 1295 ] Setting a write-only bean property causes a NPE - [ 1272 ] ASTList ClassCastException - [ 1261 ] jython -c "import sys; sys.exit(1)" not giving correct exit code. - [ 1215 ] extra spaces in import statement break importing Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-03-31 15:14:19 UTC (rev 6136) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-03-31 16:31:06 UTC (rev 6137) @@ -304,6 +304,17 @@ prop.myType = meth.getReturnType(); } else { prop.setMethod = meth; + // Needed for readonly properties. Getter will be used instead + // if there is one. Only works if setX method has exactly one + // param, which is the only reasonable case. + // XXX: should we issue a warning if setX and getX have different + // types? + if (prop.myType == null) { + Class[] params = meth.getParameterTypes(); + if (params.length == 1) { + prop.myType = params[0]; + } + } } } } Added: trunk/jython/tests/java/org/python/tests/props/Readonly.java =================================================================== --- trunk/jython/tests/java/org/python/tests/props/Readonly.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/props/Readonly.java 2009-03-31 16:31:06 UTC (rev 6137) @@ -0,0 +1,8 @@ +package org.python.tests.props; + +public class Readonly { + private String a; + public void setA(String a) { this.a = a; } + //public String getA() { return a; } +} + Added: trunk/jython/tests/java/org/python/tests/props/ReadonlyTest.java =================================================================== --- trunk/jython/tests/java/org/python/tests/props/ReadonlyTest.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/props/ReadonlyTest.java 2009-03-31 16:31:06 UTC (rev 6137) @@ -0,0 +1,21 @@ +package org.python.tests.props; + +import junit.framework.TestCase; + +import org.python.core.PyStringMap; +import org.python.core.PySystemState; +import org.python.util.PythonInterpreter; + +public class ReadonlyTest extends TestCase { + + private PythonInterpreter interp; + + @Override + protected void setUp() throws Exception { + interp = new PythonInterpreter(new PyStringMap(), new PySystemState()); + } + + public void testReadonly() { + interp.exec("from org.python.tests.props import Readonly;Readonly().a = 'test'"); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-03-31 15:14:47
|
Revision: 6136 http://jython.svn.sourceforge.net/jython/?rev=6136&view=rev Author: thobes Date: 2009-03-31 15:14:19 +0000 (Tue, 31 Mar 2009) Log Message: ----------- Updating the patch series to reflect the applied patches. Modified Paths: -------------- trunk/sandbox/tobias/.hg/patches/series Modified: trunk/sandbox/tobias/.hg/patches/series =================================================================== --- trunk/sandbox/tobias/.hg/patches/series 2009-03-31 15:01:43 UTC (rev 6135) +++ trunk/sandbox/tobias/.hg/patches/series 2009-03-31 15:14:19 UTC (rev 6136) @@ -1,6 +1,3 @@ -callpath.patch #+trunk #-advanced -parrot.patch #+trunk #-advanced -types.patch #-trunk #-advanced +parrot.patch #-trunk #-advanced grammar.patch #-trunk #-advanced -decouple.patch #-trunk #-advanced -frames.patch #+trunk #-advanced +frames.patch #-trunk #-advanced This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-03-31 15:02:01
|
Revision: 6135 http://jython.svn.sourceforge.net/jython/?rev=6135&view=rev Author: thobes Date: 2009-03-31 15:01:43 +0000 (Tue, 31 Mar 2009) Log Message: ----------- Applying my callpath.patch (from previous commit). This is probably the only performance improvement I'll add before 2.5 goes RC. Modified Paths: -------------- trunk/jython/src/org/python/compiler/ClassConstants.java trunk/jython/src/org/python/compiler/CodeCompiler.java trunk/jython/src/org/python/compiler/Module.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyBaseCode.java trunk/jython/src/org/python/core/PyCode.java trunk/jython/src/org/python/core/PyFunction.java trunk/jython/src/org/python/core/PyFunctionTable.java trunk/jython/src/org/python/core/PyGenerator.java trunk/jython/src/org/python/core/PyMethod.java trunk/jython/src/org/python/core/PyObject.java trunk/jython/src/org/python/core/PyReflectedFunction.java trunk/jython/src/org/python/core/PyTableCode.java trunk/jython/src/org/python/core/ReflectedArgs.java trunk/jython/src/org/python/core/imp.java Modified: trunk/jython/src/org/python/compiler/ClassConstants.java =================================================================== --- trunk/jython/src/org/python/compiler/ClassConstants.java 2009-03-31 14:56:30 UTC (rev 6134) +++ trunk/jython/src/org/python/compiler/ClassConstants.java 2009-03-31 15:01:43 UTC (rev 6135) @@ -8,6 +8,7 @@ final static String $pyUnicode = "Lorg/python/core/PyUnicode;"; final static String $pyExc = "Lorg/python/core/PyException;"; final static String $pyFrame = "Lorg/python/core/PyFrame;"; + final static String $threadState= "Lorg/python/core/ThreadState;"; final static String $pyCode = "Lorg/python/core/PyCode;"; final static String $pyInteger = "Lorg/python/core/PyInteger;"; final static String $pyLong = "Lorg/python/core/PyLong;"; Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-03-31 14:56:30 UTC (rev 6134) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-03-31 15:01:43 UTC (rev 6135) @@ -135,7 +135,7 @@ int yield_count = 0; - private int stackDepth = 0; + private Stack<String> stack = new Stack<String>(); public CodeCompiler(Module module, boolean print_results) { this.module = module; @@ -157,6 +157,10 @@ code.aload(1); } + public void loadThreadState() throws Exception { + code.aload(2); + } + public void setLastI(int idx) throws Exception { loadFrame(); code.iconst(idx); @@ -587,24 +591,30 @@ } private void stackProduce() { - stackDepth++; + stackProduce("org/python/core/PyObject"); } + private void stackProduce(String signature) { + stack.push(signature); + } + private void stackConsume() { - stackDepth--; + stackConsume(1); } private void stackConsume(int numItems) { - stackDepth -= numItems; + for (int i = 0; i < numItems; i++) { + stack.pop(); + } } private int saveStack() throws Exception { - if (stackDepth > 0) { - int array = code.getLocal("[Lorg/python/core/PyObject;"); - code.iconst(stackDepth); - code.anewarray("org/python/core/PyObject"); + if (stack.size() > 0) { + int array = code.getLocal("[Ljava/lang/Object;"); + code.iconst(stack.size()); + code.anewarray("java/lang/Object"); code.astore(array); - for (int i = 0; i < stackDepth; i++) { + for (int i = 0; i < stack.size(); i++) { code.aload(array); // Stack: |- ... value array code.swap(); @@ -621,13 +631,15 @@ } private void restoreStack(int array) throws Exception { - if (stackDepth > 0) { - for (int i = stackDepth - 1; i >= 0; i--) { + if (stack.size() > 0) { + int i = stack.size() -1; + for (String signature : stack) { code.aload(array); // Stack: |- ... array code.iconst(i); code.aaload(); // Stack: |- ... value + code.checkcast(signature); } code.freeLocal(array); } @@ -1507,44 +1519,45 @@ visit(node.getInternalValue()); stackProduce(); code.ldc(name); code.invokevirtual("org/python/core/PyObject", "__getattr__", "(" + $str + ")" + $pyObj); + loadThreadState(); stackProduce("org/python/core/ThreadState"); switch (values.size()) { case 0: - stackConsume(); // target - code.invokevirtual("org/python/core/PyObject", "__call__", "()" + $pyObj); + stackConsume(2); // target + ts + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + ")" + $pyObj); break; case 1: visit(values.get(0)); - stackConsume(); // target - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + ")" + $pyObj); + stackConsume(2); // target + ts + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); break; case 2: visit(values.get(0)); stackProduce(); visit(values.get(1)); - stackConsume(2); // target + arguments - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + ")" + $pyObj); + stackConsume(3); // target + ts + arguments + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + ")" + $pyObj); break; case 3: visit(values.get(0)); stackProduce(); visit(values.get(1)); stackProduce(); visit(values.get(2)); - stackConsume(3); // target + arguments - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + stackConsume(4); // target + ts + arguments + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + ")" + $pyObj); break; case 4: visit(values.get(0)); stackProduce(); visit(values.get(1)); stackProduce(); visit(values.get(2)); stackProduce(); visit(values.get(3)); - stackConsume(4); // target + arguments - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + stackConsume(5); // target + ts + arguments + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + $pyObj + ")" + $pyObj); break; default: int argArray = makeArray(values); code.aload(argArray); code.freeLocal(argArray); - stackConsume(); // target - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObjArr + ")" + $pyObj); + stackConsume(2); // target + ts + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObjArr + ")" + $pyObj); break; } return null; @@ -1596,52 +1609,54 @@ code.invokevirtual("org/python/core/PyObject", "_callextra", "(" + $pyObjArr + $strArr + $pyObj + $pyObj + ")" + $pyObj); } else if (keys.size() > 0) { + loadThreadState(); stackProduce("org/python/core/ThreadState"); int argArray = makeArray(values); int strArray = makeStrings(code, keys); code.aload(argArray); code.aload(strArray); code.freeLocal(argArray); code.freeLocal(strArray); - stackConsume(); // target - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObjArr + $strArr + ")" + $pyObj); + stackConsume(2); // target + ts + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObjArr + $strArr + ")" + $pyObj); } else { + loadThreadState(); stackProduce("org/python/core/ThreadState"); switch (values.size()) { case 0: - stackConsume(); // target - code.invokevirtual("org/python/core/PyObject", "__call__", "()" + $pyObj); + stackConsume(2); // target + ts + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + ")" + $pyObj); break; case 1: visit(values.get(0)); - stackConsume(); // target - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + ")" + $pyObj); + stackConsume(2); // target + ts + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); break; case 2: visit(values.get(0)); stackProduce(); visit(values.get(1)); - stackConsume(2); // target + arguments - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + ")" + $pyObj); + stackConsume(3); // target + ts + arguments + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + ")" + $pyObj); break; case 3: visit(values.get(0)); stackProduce(); visit(values.get(1)); stackProduce(); visit(values.get(2)); - stackConsume(3); // target + arguments - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + stackConsume(4); // target + ts + arguments + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + ")" + $pyObj); break; case 4: visit(values.get(0)); stackProduce(); visit(values.get(1)); stackProduce(); visit(values.get(2)); stackProduce(); visit(values.get(3)); - stackConsume(4); // target + arguments - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + stackConsume(5); // target + ts + arguments + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + $pyObj + ")" + $pyObj); break; default: int argArray = makeArray(values); code.aload(argArray); code.freeLocal(argArray); - stackConsume(); // target - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObjArr + ")" + $pyObj); + stackConsume(2); // target + ts + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObjArr + ")" + $pyObj); break; } } @@ -1677,9 +1692,9 @@ saveAugTmps(node, 4); ctx = expr_contextType.Load; } + stackConsume(4); } - stackConsume(4); switch (ctx) { case Del: code.invokevirtual("org/python/core/PyObject", "__delslice__", "(" + $pyObj + $pyObj + $pyObj + ")V"); @@ -1711,6 +1726,7 @@ } else { visit(node.getInternalValue()); stackProduce(); visit(node.getInternalSlice()); + stackConsume(); if (node.getInternalCtx() == expr_contextType.AugStore && augmode == expr_contextType.Load) { saveAugTmps(node, 2); @@ -1718,7 +1734,6 @@ } } - stackConsume(); switch (ctx) { case Del: code.invokevirtual("org/python/core/PyObject", "__delitem__", "(" + $pyObj + ")V"); @@ -2222,7 +2237,9 @@ code.freeLocal(genExp); code.swap(); code.invokevirtual("org/python/core/PyObject", "__iter__", "()Lorg/python/core/PyObject;"); - code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + ")" + $pyObj); + loadThreadState(); + code.swap(); + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); return null; } @@ -2239,8 +2256,8 @@ final Label label_end = new Label(); final Method getattr = Method.getMethod("org.python.core.PyObject __getattr__ (String)"); - final Method call = Method.getMethod("org.python.core.PyObject __call__ ()"); - final Method call3 = Method.getMethod("org.python.core.PyObject __call__ (org.python.core.PyObject,org.python.core.PyObject,org.python.core.PyObject)"); + final Method call = Method.getMethod("org.python.core.PyObject __call__ (org.python.core.ThreadState)"); + final Method call3 = Method.getMethod("org.python.core.PyObject __call__ (org.python.core.ThreadState,org.python.core.PyObject,org.python.core.PyObject,org.python.core.PyObject)"); // mgr = (EXPR) visit(node.getInternalContext_expr()); @@ -2254,6 +2271,7 @@ // value = mgr.__enter__() code.ldc("__enter__"); code.invokevirtual(Type.getType(PyObject.class).getInternalName(), getattr.getName(), getattr.getDescriptor()); + loadThreadState(); code.invokevirtual(Type.getType(PyObject.class).getInternalName(), call.getName(), call.getDescriptor()); int value_tmp = code.getLocal("org/python/core/PyObject"); code.astore(value_tmp); @@ -2273,6 +2291,7 @@ @Override public void finalBody(CodeCompiler compiler) throws Exception { compiler.code.aload(__exit__); + loadThreadState(); compiler.getNone(); compiler.code.dup(); compiler.code.dup(); @@ -2317,8 +2336,7 @@ loadFrame(); code.invokestatic("org/python/core/Py", "setException", "(" + $throwable + $pyFrame + ")" + $pyExc); code.pop(); - - code.invokestatic("org/python/core/Py", "getThreadState", "()Lorg/python/core/ThreadState;"); + loadThreadState(); code.getfield("org/python/core/ThreadState", "exception", $pyExc); int ts_tmp = storeTop(); @@ -2326,11 +2344,13 @@ // exc = False # implicit // if not exit(*sys.exc_info()): code.aload(__exit__); + loadThreadState(); code.aload(ts_tmp); code.getfield("org/python/core/PyException", "type", $pyObj); code.aload(ts_tmp); code.getfield("org/python/core/PyException", "value", $pyObj); code.aload(ts_tmp); + code.freeLocal(ts_tmp); code.getfield("org/python/core/PyException", "traceback", "Lorg/python/core/PyTraceback;"); code.checkcast("org/python/core/PyObject"); code.invokevirtual(Type.getType(PyObject.class).getInternalName(), call3.getName(), call3.getDescriptor()); @@ -2341,7 +2361,6 @@ code.invokestatic("org/python/core/Py", "makeException", "()Lorg/python/core/PyException;"); code.checkcast("java/lang/Throwable"); code.athrow(); - code.freeLocal(ts_tmp); code.label(label_end); code.freeLocal(__exit__); Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2009-03-31 14:56:30 UTC (rev 6134) +++ trunk/jython/src/org/python/compiler/Module.java 2009-03-31 15:01:43 UTC (rev 6135) @@ -432,7 +432,7 @@ Code c = classfile.addMethod( code.fname, - "(" + $pyFrame + ")" + $pyObj, + "(" + $pyFrame + $threadState + ")" + $pyObj, ACC_PUBLIC); CodeCompiler compiler = new CodeCompiler(this, printResults); @@ -595,11 +595,12 @@ public void addFunctions() throws IOException { Code code = classfile.addMethod( "call_function", - "(I" + $pyFrame + ")" + $pyObj, + "(I" + $pyFrame + $threadState + ")" + $pyObj, ACC_PUBLIC); - code.aload(0); - code.aload(2); + code.aload(0); // this + code.aload(2); // frame + code.aload(3); // thread state Label def = new Label(); Label[] labels = new Label[codes.size()]; int i; @@ -611,7 +612,7 @@ code.tableswitch(0, labels.length - 1, def, labels); for(i=0; i<labels.length; i++) { code.label(labels[i]); - code.invokevirtual(classfile.name, ((PyCodeConstant)codes.get(i)).fname, "(" + $pyFrame + ")" + $pyObj); + code.invokevirtual(classfile.name, ((PyCodeConstant)codes.get(i)).fname, "(" + $pyFrame + $threadState + ")" + $pyObj); code.areturn(); } code.label(def); Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2009-03-31 14:56:30 UTC (rev 6134) +++ trunk/jython/src/org/python/core/Py.java 2009-03-31 15:01:43 UTC (rev 6135) @@ -1194,16 +1194,17 @@ public static PyObject runCode(PyCode code, PyObject locals, PyObject globals) { PyFrame f; + ThreadState ts = getThreadState(); if (locals == null || locals == Py.None) { if (globals != null && globals != Py.None) { locals = globals; } else { - locals = Py.getFrame().getLocals(); + locals = ts.frame.getLocals(); } } if (globals == null || globals == Py.None) { - globals = Py.getFrame().f_globals; + globals = ts.frame.f_globals; } PyTableCode tc = null; @@ -1213,7 +1214,7 @@ f = new PyFrame(tc, locals, globals, Py.getSystemState().getBuiltins()); - return code.call(f); + return code.call(ts, f); } public static void exec(PyObject o, PyObject globals, PyObject locals) { @@ -1543,9 +1544,9 @@ public static PyObject makeClass(String name, PyObject[] bases, PyCode code, PyObject doc, PyObject[] closure_cells) { - PyObject globals = getFrame().f_globals; - PyObject dict = code.call(Py.EmptyObjects, Py.NoKeywords, globals, Py.EmptyObjects, - new PyTuple(closure_cells)); + ThreadState state = getThreadState(); + PyObject dict = code.call(state, Py.EmptyObjects, Py.NoKeywords, + state.frame.f_globals, Py.EmptyObjects, new PyTuple(closure_cells)); if (doc != null && dict.__finditem__("__doc__") == null) { dict.__setitem__("__doc__", doc); } @@ -1997,45 +1998,51 @@ } } - public PyObject call(PyFrame frame, PyObject closure) { + public PyObject call(ThreadState state, PyFrame frame, PyObject closure) { //XXX: what the heck is this? Looks like debug code, but it's // been here a long time... System.out.println("call #1"); return Py.None; } - public PyObject call(PyObject args[], String keywords[], + public PyObject call(ThreadState state, PyObject args[], String keywords[], PyObject globals, PyObject[] defaults, PyObject closure) { return func.__call__(args, keywords); } - public PyObject call(PyObject self, PyObject args[], String keywords[], + public PyObject call(ThreadState state, PyObject self, PyObject args[], String keywords[], PyObject globals, PyObject[] defaults, PyObject closure) { return func.__call__(self, args, keywords); } - public PyObject call(PyObject globals, PyObject[] defaults, + public PyObject call(ThreadState state, PyObject globals, PyObject[] defaults, PyObject closure) { return func.__call__(); } - public PyObject call(PyObject arg1, PyObject globals, + public PyObject call(ThreadState state, PyObject arg1, PyObject globals, PyObject[] defaults, PyObject closure) { return func.__call__(arg1); } - public PyObject call(PyObject arg1, PyObject arg2, PyObject globals, + public PyObject call(ThreadState state, PyObject arg1, PyObject arg2, PyObject globals, PyObject[] defaults, PyObject closure) { return func.__call__(arg1, arg2); } - public PyObject call(PyObject arg1, PyObject arg2, PyObject arg3, + public PyObject call(ThreadState state, PyObject arg1, PyObject arg2, PyObject arg3, PyObject globals, PyObject[] defaults, PyObject closure) { return func.__call__(arg1, arg2, arg3); } + + public PyObject call(ThreadState state, PyObject arg1, PyObject arg2, + PyObject arg3, PyObject arg4, PyObject globals, + PyObject[] defaults, PyObject closure) { + return func.__call__(arg1, arg2, arg3, arg4); + } } /** Modified: trunk/jython/src/org/python/core/PyBaseCode.java =================================================================== --- trunk/jython/src/org/python/core/PyBaseCode.java 2009-03-31 14:56:30 UTC (rev 6134) +++ trunk/jython/src/org/python/core/PyBaseCode.java 2009-03-31 15:01:43 UTC (rev 6135) @@ -22,9 +22,8 @@ return co_freevars != null && co_freevars.length > 0; } - public PyObject call(PyFrame frame, PyObject closure) { + public PyObject call(ThreadState ts, PyFrame frame, PyObject closure) { // System.err.println("tablecode call: "+co_name); - ThreadState ts = Py.getThreadState(); if (ts.systemState == null) { ts.systemState = Py.defaultSystemState; } @@ -105,38 +104,38 @@ return ret; } - public PyObject call(PyObject globals, PyObject[] defaults, + public PyObject call(ThreadState state, PyObject globals, PyObject[] defaults, PyObject closure) { if (co_argcount != 0 || varargs || varkwargs) - return call(Py.EmptyObjects, Py.NoKeywords, globals, defaults, + return call(state, Py.EmptyObjects, Py.NoKeywords, globals, defaults, closure); PyFrame frame = new PyFrame(this, globals); if (co_flags.isFlagSet(CodeFlag.CO_GENERATOR)) { return new PyGenerator(frame, closure); } - return call(frame, closure); + return call(state, frame, closure); } - public PyObject call(PyObject arg1, PyObject globals, PyObject[] defaults, + public PyObject call(ThreadState state, PyObject arg1, PyObject globals, PyObject[] defaults, PyObject closure) { if (co_argcount != 1 || varargs || varkwargs) - return call(new PyObject[] {arg1}, + return call(state, new PyObject[] {arg1}, Py.NoKeywords, globals, defaults, closure); PyFrame frame = new PyFrame(this, globals); frame.f_fastlocals[0] = arg1; if (co_flags.isFlagSet(CodeFlag.CO_GENERATOR)) { return new PyGenerator(frame, closure); } - return call(frame, closure); + return call(state, frame, closure); } - public PyObject call(PyObject arg1, PyObject arg2, PyObject globals, + public PyObject call(ThreadState state, PyObject arg1, PyObject arg2, PyObject globals, PyObject[] defaults, PyObject closure) { if (co_argcount != 2 || varargs || varkwargs) - return call(new PyObject[] {arg1, arg2}, + return call(state, new PyObject[] {arg1, arg2}, Py.NoKeywords, globals, defaults, closure); PyFrame frame = new PyFrame(this, globals); frame.f_fastlocals[0] = arg1; @@ -144,15 +143,15 @@ if (co_flags.isFlagSet(CodeFlag.CO_GENERATOR)) { return new PyGenerator(frame, closure); } - return call(frame, closure); + return call(state, frame, closure); } - public PyObject call(PyObject arg1, PyObject arg2, PyObject arg3, + public PyObject call(ThreadState state, PyObject arg1, PyObject arg2, PyObject arg3, PyObject globals, PyObject[] defaults, PyObject closure) { if (co_argcount != 3 || varargs || varkwargs) - return call(new PyObject[] {arg1, arg2, arg3}, + return call(state, new PyObject[] {arg1, arg2, arg3}, Py.NoKeywords, globals, defaults, closure); PyFrame frame = new PyFrame(this, globals); frame.f_fastlocals[0] = arg1; @@ -161,20 +160,38 @@ if (co_flags.isFlagSet(CodeFlag.CO_GENERATOR)) { return new PyGenerator(frame, closure); } - return call(frame, closure); + return call(state, frame, closure); } + + @Override + public PyObject call(ThreadState state, PyObject arg1, PyObject arg2, + PyObject arg3, PyObject arg4, PyObject globals, + PyObject[] defaults, PyObject closure) { + if (co_argcount != 4 || varargs || varkwargs) + return call(state, new PyObject[]{arg1, arg2, arg3, arg4}, + Py.NoKeywords, globals, defaults, closure); + PyFrame frame = new PyFrame(this, globals); + frame.f_fastlocals[0] = arg1; + frame.f_fastlocals[1] = arg2; + frame.f_fastlocals[2] = arg3; + frame.f_fastlocals[3] = arg4; + if (co_flags.isFlagSet(CodeFlag.CO_GENERATOR)) { + return new PyGenerator(frame, closure); + } + return call(state, frame, closure); + } - public PyObject call(PyObject self, PyObject args[], + public PyObject call(ThreadState state, PyObject self, PyObject args[], String keywords[], PyObject globals, PyObject[] defaults, PyObject closure) { PyObject[] os = new PyObject[args.length+1]; os[0] = self; System.arraycopy(args, 0, os, 1, args.length); - return call(os, keywords, globals, defaults, closure); + return call(state, os, keywords, globals, defaults, closure); } - public PyObject call(PyObject args[], String kws[], PyObject globals, PyObject[] defs, + public PyObject call(ThreadState state, PyObject args[], String kws[], PyObject globals, PyObject[] defs, PyObject closure) { PyFrame frame = new PyFrame(this, globals); int argcount = args.length - kws.length; @@ -277,7 +294,7 @@ if (co_flags.isFlagSet(CodeFlag.CO_GENERATOR)) { return new PyGenerator(frame, closure); } - return call(frame, closure); + return call(state, frame, closure); } public String toString() { Modified: trunk/jython/src/org/python/core/PyCode.java =================================================================== --- trunk/jython/src/org/python/core/PyCode.java 2009-03-31 14:56:30 UTC (rev 6134) +++ trunk/jython/src/org/python/core/PyCode.java 2009-03-31 15:01:43 UTC (rev 6135) @@ -8,33 +8,44 @@ { public String co_name; - abstract public PyObject call(PyFrame frame, PyObject closure); + abstract public PyObject call(ThreadState state, PyFrame frame, PyObject closure); - public PyObject call(PyFrame frame) { - return call(frame, null); + public PyObject call(ThreadState state, PyFrame frame) { + return call(state, frame, null); } - abstract public PyObject call(PyObject args[], String keywords[], + abstract public PyObject call(ThreadState state, + PyObject args[], String keywords[], PyObject globals, PyObject[] defaults, PyObject closure); - abstract public PyObject call(PyObject self, PyObject args[], + abstract public PyObject call(ThreadState state, + PyObject self, PyObject args[], String keywords[], PyObject globals, PyObject[] defaults, PyObject closure); - abstract public PyObject call(PyObject globals, PyObject[] defaults, + abstract public PyObject call(ThreadState state, + PyObject globals, PyObject[] defaults, PyObject closure); - abstract public PyObject call(PyObject arg1, PyObject globals, + abstract public PyObject call(ThreadState state, + PyObject arg1, PyObject globals, PyObject[] defaults, PyObject closure); - abstract public PyObject call(PyObject arg1, PyObject arg2, + abstract public PyObject call(ThreadState state, + PyObject arg1, PyObject arg2, PyObject globals, PyObject[] defaults, PyObject closure); - abstract public PyObject call(PyObject arg1, PyObject arg2, PyObject arg3, + abstract public PyObject call(ThreadState state, + PyObject arg1, PyObject arg2, PyObject arg3, PyObject globals, PyObject[] defaults, PyObject closure); + abstract public PyObject call(ThreadState state, + PyObject arg1, PyObject arg2, PyObject arg3, PyObject arg4, + PyObject globals, PyObject[] defaults, + PyObject closure); + } Modified: trunk/jython/src/org/python/core/PyFunction.java =================================================================== --- trunk/jython/src/org/python/core/PyFunction.java 2009-03-31 14:56:30 UTC (rev 6134) +++ trunk/jython/src/org/python/core/PyFunction.java 2009-03-31 15:01:43 UTC (rev 6135) @@ -299,39 +299,91 @@ @Override public PyObject __call__() { - return func_code.call(func_globals, func_defaults, func_closure); + return __call__(Py.getThreadState()); } + + @Override + public PyObject __call__(ThreadState state) { + return func_code.call(state, func_globals, func_defaults, func_closure); + } @Override public PyObject __call__(PyObject arg) { - return func_code.call(arg, func_globals, func_defaults, func_closure); + return __call__(Py.getThreadState(), arg); } + + @Override + public PyObject __call__(ThreadState state, PyObject arg0) { + return func_code.call(state, arg0, func_globals, func_defaults, func_closure); + } @Override public PyObject __call__(PyObject arg1, PyObject arg2) { - return func_code.call(arg1, arg2, func_globals, func_defaults, func_closure); + return __call__(Py.getThreadState(), arg1, arg2); } + + @Override + public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1) { + return func_code.call(state, arg0, arg1, func_globals, func_defaults, func_closure); + } @Override public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3) { - return func_code.call(arg1, arg2, arg3, func_globals, func_defaults, - func_closure); + return __call__(Py.getThreadState(), arg1, arg2, arg3); } + + @Override + public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, + PyObject arg2) { + return func_code.call(state, arg0, arg1, arg2, func_globals, func_defaults, func_closure); + } + + @Override + public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2, + PyObject arg3) { + return __call__(Py.getThreadState(), arg0, arg1, arg2, arg3); + } + + @Override + public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, + PyObject arg2, PyObject arg3) { + return func_code.call(state, arg0, arg1, arg2, arg3, func_globals, func_defaults, func_closure); + } + + @Override + public PyObject __call__(PyObject[] args) { + return __call__(Py.getThreadState(), args); + } + + @Override + public PyObject __call__(ThreadState state, PyObject[] args) { + return __call__(state, args, Py.NoKeywords); + } @Override public PyObject __call__(PyObject[] args, String[] keywords) { return function___call__(args, keywords); } + + @Override + public PyObject __call__(ThreadState state, PyObject[] args, String[] keywords) { + return func_code.call(state, args, keywords, func_globals, func_defaults, func_closure); + } @ExposedMethod(doc = BuiltinDocs.function___call___doc) final PyObject function___call__(PyObject[] args, String[] keywords) { - return func_code.call(args, keywords, func_globals, func_defaults, func_closure); + return __call__(Py.getThreadState(), args, keywords); } @Override public PyObject __call__(PyObject arg1, PyObject[] args, String[] keywords) { - return func_code.call(arg1, args, keywords, func_globals, func_defaults, func_closure); + return __call__(Py.getThreadState(), arg1, args, keywords); } + + @Override + public PyObject __call__(ThreadState state, PyObject arg1, PyObject[] args, String[] keywords) { + return func_code.call(state, arg1, args, keywords, func_globals, func_defaults, func_closure); + } @Override public String toString() { Modified: trunk/jython/src/org/python/core/PyFunctionTable.java =================================================================== --- trunk/jython/src/org/python/core/PyFunctionTable.java 2009-03-31 14:56:30 UTC (rev 6134) +++ trunk/jython/src/org/python/core/PyFunctionTable.java 2009-03-31 15:01:43 UTC (rev 6135) @@ -10,5 +10,5 @@ */ public abstract class PyFunctionTable { - abstract public PyObject call_function(int index, PyFrame frame); + abstract public PyObject call_function(int index, PyFrame frame, ThreadState ts); } Modified: trunk/jython/src/org/python/core/PyGenerator.java =================================================================== --- trunk/jython/src/org/python/core/PyGenerator.java 2009-03-31 14:56:30 UTC (rev 6134) +++ trunk/jython/src/org/python/core/PyGenerator.java 2009-03-31 15:01:43 UTC (rev 6135) @@ -106,8 +106,13 @@ super.finalize(); } } + + @Override + public PyObject __iternext__() { + return __iternext__(Py.getThreadState()); + } - public PyObject __iternext__() { + public PyObject __iternext__(ThreadState state) { if (gi_running) throw Py.ValueError("generator already executing"); if (gi_frame == null) { @@ -121,7 +126,7 @@ gi_running = true; PyObject result = null; try { - result = gi_frame.f_code.call(gi_frame, closure); + result = gi_frame.f_code.call(state, gi_frame, closure); } catch(PyException e) { if (!(e.type == Py.StopIteration || e.type == Py.GeneratorExit)) { gi_frame = null; Modified: trunk/jython/src/org/python/core/PyMethod.java =================================================================== --- trunk/jython/src/org/python/core/PyMethod.java 2009-03-31 14:56:30 UTC (rev 6134) +++ trunk/jython/src/org/python/core/PyMethod.java 2009-03-31 15:01:43 UTC (rev 6135) @@ -93,21 +93,143 @@ return this; } } - + /*// This has been disabled since JavaFunc expects to be called with self + boxed args @Override + public PyObject __call__() { + return __call__(Py.getThreadState()); + } + + @Override + public PyObject __call__(ThreadState state) { + PyObject self = checkSelf(null, null); + if (self == null) { + return im_func.__call__(state); + } else { + return im_func.__call__(state, self); + } + } + + @Override + public PyObject __call__(PyObject arg0) { + return __call__(Py.getThreadState(), arg0); + } + + @Override + public PyObject __call__(ThreadState state, PyObject arg0) { + PyObject self = checkSelf(arg0, null); + if (self == null) { + return im_func.__call__(state, arg0); + } else { + return im_func.__call__(state, self, arg0); + } + } + + @Override + public PyObject __call__(PyObject arg0, PyObject arg1) { + return __call__(Py.getThreadState(), arg0, arg1); + } + + @Override + public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1) { + PyObject self = checkSelf(arg0, null); + if (self == null) { + return im_func.__call__(state, arg0, arg1); + } else { + return im_func.__call__(state, self, arg0, arg1); + } + } + + @Override + public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2) { + return __call__(Py.getThreadState(), arg0, arg1, arg2); + } + + @Override + public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, + PyObject arg2) { + PyObject self = checkSelf(arg0, null); + if (self == null) { + return im_func.__call__(state, arg0, arg1, arg2); + } else { + return im_func.__call__(state, self, arg0, arg1, arg2); + } + } + + @Override + public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3) { + return __call__(Py.getThreadState(), arg0, arg1, arg2, arg3); + } + + @Override + public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, + PyObject arg2, PyObject arg3) { + PyObject self = checkSelf(arg0, null); + if (self == null) { + return im_func.__call__(state, arg0, arg1, arg2, arg3); + } else { + return im_func.__call__(state, self, new PyObject[]{arg0, arg1, arg2, arg3}, Py.NoKeywords); + } + } + + + @Override + public PyObject __call__(PyObject arg1, PyObject[] args, String[] keywords) { + return __call__(Py.getThreadState(), arg1, args, keywords); + } + + @Override + public PyObject __call__(ThreadState state, PyObject arg1, PyObject[] args, + String[] keywords) { + PyObject self = checkSelf(arg1, args); + if (self == null) { + return im_func.__call__(state, arg1, args, keywords); + } else { + PyObject[] new_args = new PyObject[args.length+1]; + System.arraycopy(args, 0, new_args, 1, args.length); + new_args[0] = arg1; + return im_func.__call__(state, self, new_args, keywords); + } + } + + @Override + public PyObject __call__(PyObject[] args) { + return __call__(Py.getThreadState(), args); + } + + @Override + public PyObject __call__(ThreadState state, PyObject[] args) { + return __call__(state, args, Py.NoKeywords); + } + */ + @Override public PyObject __call__(PyObject[] args, String[] keywords) { return instancemethod___call__(args, keywords); } - + + @Override + public PyObject __call__(ThreadState state, PyObject[] args, String[] keywords) { + PyObject self = checkSelf(null, args); + if (self == null) { + return im_func.__call__(state, args, keywords); + } else { + return im_func.__call__(state, self, args, keywords); + } + } + @ExposedMethod(doc = BuiltinDocs.instancemethod___call___doc) final PyObject instancemethod___call__(PyObject[] args, String[] keywords) { + return __call__(Py.getThreadState(), args, keywords); + } + + private PyObject checkSelf(PyObject arg, PyObject[] args) { PyObject self = im_self; - if (self == null) { // Unbound methods must be called with an instance of the // class (or a derived class) as first argument boolean ok; - if (args.length >= 1) { + if (arg != null) { + self = arg; + } else if (args != null && args.length >= 1) { self = args[0]; } if (self == null) { @@ -125,9 +247,9 @@ self == null ? "" : " instance"); throw Py.TypeError(msg); } - return im_func.__call__(args, keywords); + return null; } else { - return im_func.__call__(self, args, keywords); + return self; } } Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2009-03-31 14:56:30 UTC (rev 6134) +++ trunk/jython/src/org/python/core/PyObject.java 2009-03-31 15:01:43 UTC (rev 6135) @@ -314,6 +314,10 @@ public PyObject __call__(PyObject args[], String keywords[]) { throw Py.TypeError(String.format("'%s' object is not callable", getType().fastGetName())); } + + public PyObject __call__(ThreadState state, PyObject args[], String keywords[]) { + return __call__(args, keywords); + } /** * A variant of the __call__ method with one extra initial argument. @@ -329,15 +333,16 @@ * keyword arguments). * @param keywords the keywords used for all keyword arguments. **/ - public PyObject __call__( - PyObject arg1, - PyObject args[], - String keywords[]) { + public PyObject __call__(PyObject arg1, PyObject args[], String keywords[]) { PyObject[] newArgs = new PyObject[args.length + 1]; System.arraycopy(args, 0, newArgs, 1, args.length); newArgs[0] = arg1; return __call__(newArgs, keywords); } + + public PyObject __call__(ThreadState state, PyObject arg1, PyObject args[], String keywords[]) { + return __call__(arg1, args, keywords); + } /** * A variant of the __call__ method when no keywords are passed. The @@ -350,6 +355,10 @@ public PyObject __call__(PyObject args[]) { return __call__(args, Py.NoKeywords); } + + public PyObject __call__(ThreadState state, PyObject args[]) { + return __call__(args); + } /** * A variant of the __call__ method with no arguments. The default @@ -360,6 +369,10 @@ public PyObject __call__() { return __call__(Py.EmptyObjects, Py.NoKeywords); } + + public PyObject __call__(ThreadState state) { + return __call__(); + } /** * A variant of the __call__ method with one argument. The default @@ -372,6 +385,10 @@ public PyObject __call__(PyObject arg0) { return __call__(new PyObject[] { arg0 }, Py.NoKeywords); } + + public PyObject __call__(ThreadState state, PyObject arg0) { + return __call__(arg0); + } /** * A variant of the __call__ method with two arguments. The default @@ -386,6 +403,10 @@ return __call__(new PyObject[] { arg0, arg1 }, Py.NoKeywords); } + public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1) { + return __call__(arg0, arg1); + } + /** * A variant of the __call__ method with three arguments. The default * behavior is to invoke <code>__call__(args, keywords)</code> with the @@ -399,6 +420,10 @@ public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2) { return __call__(new PyObject[] { arg0, arg1, arg2 }, Py.NoKeywords); } + + public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, PyObject arg2) { + return __call__(arg0, arg1, arg2); + } /** * A variant of the __call__ method with four arguments. The default @@ -411,15 +436,15 @@ * @param arg2 the third argument to the function. * @param arg3 the fourth argument to the function. **/ - public PyObject __call__( - PyObject arg0, - PyObject arg1, - PyObject arg2, - PyObject arg3) { + public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3) { return __call__( new PyObject[] { arg0, arg1, arg2, arg3 }, Py.NoKeywords); } + + public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3) { + return __call__(arg0, arg1, arg2, arg3); + } /** @deprecated **/ public PyObject _callextra(PyObject[] args, Modified: trunk/jython/src/org/python/core/PyReflectedFunction.java =================================================================== --- trunk/jython/src/org/python/core/PyReflectedFunction.java 2009-03-31 14:56:30 UTC (rev 6134) +++ trunk/jython/src/org/python/core/PyReflectedFunction.java 2009-03-31 15:01:43 UTC (rev 6135) @@ -180,7 +180,14 @@ } public PyObject __call__(PyObject[] args, String[] keywords) { - return __call__(null, args, keywords); + PyObject self = null; + /* + PyObject[] new_args = new PyObject[args.length - 1]; + System.arraycopy(args, 1, new_args, 0, new_args.length); + self = args[0]; + args = new_args; + */ + return __call__(self, args, keywords); } // A bunch of code to make error handling prettier Modified: trunk/jython/src/org/python/core/PyTableCode.java =================================================================== --- trunk/jython/src/org/python/core/PyTableCode.java 2009-03-31 14:56:30 UTC (rev 6134) +++ trunk/jython/src/org/python/core/PyTableCode.java 2009-03-31 15:01:43 UTC (rev 6135) @@ -122,9 +122,8 @@ } @Override - public PyObject call(PyFrame frame, PyObject closure) { + public PyObject call(ThreadState ts, PyFrame frame, PyObject closure) { // System.err.println("tablecode call: "+co_name); - ThreadState ts = Py.getThreadState(); if (ts.systemState == null) { ts.systemState = Py.defaultSystemState; } @@ -163,7 +162,7 @@ PyObject ret; try { - ret = funcs.call_function(func_id, frame); + ret = funcs.call_function(func_id, frame, ts); } catch (Throwable t) { // Convert exceptions that occured in Java code to PyExceptions PyException pye = Py.JavaError(t); Modified: trunk/jython/src/org/python/core/ReflectedArgs.java =================================================================== --- trunk/jython/src/org/python/core/ReflectedArgs.java 2009-03-31 14:56:30 UTC (rev 6134) +++ trunk/jython/src/org/python/core/ReflectedArgs.java 2009-03-31 15:01:43 UTC (rev 6135) @@ -52,10 +52,11 @@ if (this.isStatic) { if (self != null) { /* - * PyObject[] newArgs = new PyObject[pyArgs.length+1]; - * System.arraycopy(pyArgs, 0, newArgs, 1, pyArgs.length); - * newArgs[0] = self; pyArgs = newArgs; - */ + PyObject[] newArgs = new PyObject[pyArgs.length+1]; + System.arraycopy(pyArgs, 0, newArgs, 1, pyArgs.length); + newArgs[0] = self; + pyArgs = newArgs; + //*/ self = null; } } else { Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2009-03-31 14:56:30 UTC (rev 6134) +++ trunk/jython/src/org/python/core/imp.java 2009-03-31 15:01:43 UTC (rev 6135) @@ -313,7 +313,7 @@ try { PyFrame f = new PyFrame(code, module.__dict__, module.__dict__, null); - code.call(f); + code.call(Py.getThreadState(), f); } catch (RuntimeException t) { removeModule(name); throw t; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-03-31 14:56:41
|
Revision: 6134 http://jython.svn.sourceforge.net/jython/?rev=6134&view=rev Author: thobes Date: 2009-03-31 14:56:30 +0000 (Tue, 31 Mar 2009) Log Message: ----------- Created a patch (callpath.patch) for passing the thread state along from function to function. This gives a 2x speedup to function calls before warmup, and up to 1.5x after warmup. Modified Paths: -------------- trunk/sandbox/tobias/.hg/patches/parrot.patch trunk/sandbox/tobias/.hg/patches/series Added Paths: ----------- trunk/sandbox/tobias/.hg/patches/callpath.patch Added: trunk/sandbox/tobias/.hg/patches/callpath.patch =================================================================== --- trunk/sandbox/tobias/.hg/patches/callpath.patch (rev 0) +++ trunk/sandbox/tobias/.hg/patches/callpath.patch 2009-03-31 14:56:30 UTC (rev 6134) @@ -0,0 +1,1133 @@ +diff --git a/jython/src/org/python/compiler/ClassConstants.java b/jython/src/org/python/compiler/ClassConstants.java +--- a/jython/src/org/python/compiler/ClassConstants.java ++++ b/jython/src/org/python/compiler/ClassConstants.java +@@ -8,6 +8,7 @@ + final static String $pyUnicode = "Lorg/python/core/PyUnicode;"; + final static String $pyExc = "Lorg/python/core/PyException;"; + final static String $pyFrame = "Lorg/python/core/PyFrame;"; ++ final static String $threadState= "Lorg/python/core/ThreadState;"; + final static String $pyCode = "Lorg/python/core/PyCode;"; + final static String $pyInteger = "Lorg/python/core/PyInteger;"; + final static String $pyLong = "Lorg/python/core/PyLong;"; +diff --git a/jython/src/org/python/compiler/CodeCompiler.java b/jython/src/org/python/compiler/CodeCompiler.java +--- a/jython/src/org/python/compiler/CodeCompiler.java ++++ b/jython/src/org/python/compiler/CodeCompiler.java +@@ -135,7 +135,7 @@ + + int yield_count = 0; + +- private int stackDepth = 0; ++ private Stack<String> stack = new Stack<String>(); + + public CodeCompiler(Module module, boolean print_results) { + this.module = module; +@@ -157,6 +157,10 @@ + code.aload(1); + } + ++ public void loadThreadState() throws Exception { ++ code.aload(2); ++ } ++ + public void setLastI(int idx) throws Exception { + loadFrame(); + code.iconst(idx); +@@ -587,24 +591,30 @@ + } + + private void stackProduce() { +- stackDepth++; ++ stackProduce("org/python/core/PyObject"); + } + ++ private void stackProduce(String signature) { ++ stack.push(signature); ++ } ++ + private void stackConsume() { +- stackDepth--; ++ stackConsume(1); + } + + private void stackConsume(int numItems) { +- stackDepth -= numItems; ++ for (int i = 0; i < numItems; i++) { ++ stack.pop(); ++ } + } + + private int saveStack() throws Exception { +- if (stackDepth > 0) { +- int array = code.getLocal("[Lorg/python/core/PyObject;"); +- code.iconst(stackDepth); +- code.anewarray("org/python/core/PyObject"); ++ if (stack.size() > 0) { ++ int array = code.getLocal("[Ljava/lang/Object;"); ++ code.iconst(stack.size()); ++ code.anewarray("java/lang/Object"); + code.astore(array); +- for (int i = 0; i < stackDepth; i++) { ++ for (int i = 0; i < stack.size(); i++) { + code.aload(array); + // Stack: |- ... value array + code.swap(); +@@ -621,13 +631,15 @@ + } + + private void restoreStack(int array) throws Exception { +- if (stackDepth > 0) { +- for (int i = stackDepth - 1; i >= 0; i--) { ++ if (stack.size() > 0) { ++ int i = stack.size() -1; ++ for (String signature : stack) { + code.aload(array); + // Stack: |- ... array + code.iconst(i); + code.aaload(); + // Stack: |- ... value ++ code.checkcast(signature); + } + code.freeLocal(array); + } +@@ -1507,44 +1519,45 @@ + visit(node.getInternalValue()); stackProduce(); + code.ldc(name); + code.invokevirtual("org/python/core/PyObject", "__getattr__", "(" + $str + ")" + $pyObj); ++ loadThreadState(); stackProduce("org/python/core/ThreadState"); + + switch (values.size()) { + case 0: +- stackConsume(); // target +- code.invokevirtual("org/python/core/PyObject", "__call__", "()" + $pyObj); ++ stackConsume(2); // target + ts ++ code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + ")" + $pyObj); + break; + case 1: + visit(values.get(0)); +- stackConsume(); // target +- code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + ")" + $pyObj); ++ stackConsume(2); // target + ts ++ code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); + break; + case 2: + visit(values.get(0)); stackProduce(); + visit(values.get(1)); +- stackConsume(2); // target + arguments +- code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + ")" + $pyObj); ++ stackConsume(3); // target + ts + arguments ++ code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + ")" + $pyObj); + break; + case 3: + visit(values.get(0)); stackProduce(); + visit(values.get(1)); stackProduce(); + visit(values.get(2)); +- stackConsume(3); // target + arguments +- code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + $pyObj + ")" + $pyObj); ++ stackConsume(4); // target + ts + arguments ++ code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + break; + case 4: + visit(values.get(0)); stackProduce(); + visit(values.get(1)); stackProduce(); + visit(values.get(2)); stackProduce(); + visit(values.get(3)); +- stackConsume(4); // target + arguments +- code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + $pyObj + $pyObj + ")" + $pyObj); ++ stackConsume(5); // target + ts + arguments ++ code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + break; + default: + int argArray = makeArray(values); + code.aload(argArray); + code.freeLocal(argArray); +- stackConsume(); // target +- code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObjArr + ")" + $pyObj); ++ stackConsume(2); // target + ts ++ code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObjArr + ")" + $pyObj); + break; + } + return null; +@@ -1596,52 +1609,54 @@ + + code.invokevirtual("org/python/core/PyObject", "_callextra", "(" + $pyObjArr + $strArr + $pyObj + $pyObj + ")" + $pyObj); + } else if (keys.size() > 0) { ++ loadThreadState(); stackProduce("org/python/core/ThreadState"); + int argArray = makeArray(values); + int strArray = makeStrings(code, keys); + code.aload(argArray); + code.aload(strArray); + code.freeLocal(argArray); + code.freeLocal(strArray); +- stackConsume(); // target +- code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObjArr + $strArr + ")" + $pyObj); ++ stackConsume(2); // target + ts ++ code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObjArr + $strArr + ")" + $pyObj); + } else { ++ loadThreadState(); stackProduce("org/python/core/ThreadState"); + switch (values.size()) { + case 0: +- stackConsume(); // target +- code.invokevirtual("org/python/core/PyObject", "__call__", "()" + $pyObj); ++ stackConsume(2); // target + ts ++ code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + ")" + $pyObj); + break; + case 1: + visit(values.get(0)); +- stackConsume(); // target +- code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + ")" + $pyObj); ++ stackConsume(2); // target + ts ++ code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); + break; + case 2: + visit(values.get(0)); stackProduce(); + visit(values.get(1)); +- stackConsume(2); // target + arguments +- code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + ")" + $pyObj); ++ stackConsume(3); // target + ts + arguments ++ code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + ")" + $pyObj); + break; + case 3: + visit(values.get(0)); stackProduce(); + visit(values.get(1)); stackProduce(); + visit(values.get(2)); +- stackConsume(3); // target + arguments +- code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + $pyObj + ")" + $pyObj); ++ stackConsume(4); // target + ts + arguments ++ code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + break; + case 4: + visit(values.get(0)); stackProduce(); + visit(values.get(1)); stackProduce(); + visit(values.get(2)); stackProduce(); + visit(values.get(3)); +- stackConsume(4); // target + arguments +- code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + $pyObj + $pyObj + ")" + $pyObj); ++ stackConsume(5); // target + ts + arguments ++ code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + break; + default: + int argArray = makeArray(values); + code.aload(argArray); + code.freeLocal(argArray); +- stackConsume(); // target +- code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObjArr + ")" + $pyObj); ++ stackConsume(2); // target + ts ++ code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObjArr + ")" + $pyObj); + break; + } + } +@@ -1677,9 +1692,9 @@ + saveAugTmps(node, 4); + ctx = expr_contextType.Load; + } ++ stackConsume(4); + } + +- stackConsume(4); + switch (ctx) { + case Del: + code.invokevirtual("org/python/core/PyObject", "__delslice__", "(" + $pyObj + $pyObj + $pyObj + ")V"); +@@ -1711,6 +1726,7 @@ + } else { + visit(node.getInternalValue()); stackProduce(); + visit(node.getInternalSlice()); ++ stackConsume(); + + if (node.getInternalCtx() == expr_contextType.AugStore && augmode == expr_contextType.Load) { + saveAugTmps(node, 2); +@@ -1718,7 +1734,6 @@ + } + } + +- stackConsume(); + switch (ctx) { + case Del: + code.invokevirtual("org/python/core/PyObject", "__delitem__", "(" + $pyObj + ")V"); +@@ -2222,7 +2237,9 @@ + code.freeLocal(genExp); + code.swap(); + code.invokevirtual("org/python/core/PyObject", "__iter__", "()Lorg/python/core/PyObject;"); +- code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + ")" + $pyObj); ++ loadThreadState(); ++ code.swap(); ++ code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $threadState + $pyObj + ")" + $pyObj); + + return null; + } +@@ -2239,8 +2256,8 @@ + final Label label_end = new Label(); + + final Method getattr = Method.getMethod("org.python.core.PyObject __getattr__ (String)"); +- final Method call = Method.getMethod("org.python.core.PyObject __call__ ()"); +- final Method call3 = Method.getMethod("org.python.core.PyObject __call__ (org.python.core.PyObject,org.python.core.PyObject,org.python.core.PyObject)"); ++ final Method call = Method.getMethod("org.python.core.PyObject __call__ (org.python.core.ThreadState)"); ++ final Method call3 = Method.getMethod("org.python.core.PyObject __call__ (org.python.core.ThreadState,org.python.core.PyObject,org.python.core.PyObject,org.python.core.PyObject)"); + + // mgr = (EXPR) + visit(node.getInternalContext_expr()); +@@ -2254,6 +2271,7 @@ + // value = mgr.__enter__() + code.ldc("__enter__"); + code.invokevirtual(Type.getType(PyObject.class).getInternalName(), getattr.getName(), getattr.getDescriptor()); ++ loadThreadState(); + code.invokevirtual(Type.getType(PyObject.class).getInternalName(), call.getName(), call.getDescriptor()); + int value_tmp = code.getLocal("org/python/core/PyObject"); + code.astore(value_tmp); +@@ -2273,6 +2291,7 @@ + @Override + public void finalBody(CodeCompiler compiler) throws Exception { + compiler.code.aload(__exit__); ++ loadThreadState(); + compiler.getNone(); + compiler.code.dup(); + compiler.code.dup(); +@@ -2317,8 +2336,7 @@ + loadFrame(); + code.invokestatic("org/python/core/Py", "setException", "(" + $throwable + $pyFrame + ")" + $pyExc); + code.pop(); +- +- code.invokestatic("org/python/core/Py", "getThreadState", "()Lorg/python/core/ThreadState;"); ++ loadThreadState(); + code.getfield("org/python/core/ThreadState", "exception", $pyExc); + int ts_tmp = storeTop(); + +@@ -2326,11 +2344,13 @@ + // exc = False # implicit + // if not exit(*sys.exc_info()): + code.aload(__exit__); ++ loadThreadState(); + code.aload(ts_tmp); + code.getfield("org/python/core/PyException", "type", $pyObj); + code.aload(ts_tmp); + code.getfield("org/python/core/PyException", "value", $pyObj); + code.aload(ts_tmp); ++ code.freeLocal(ts_tmp); + code.getfield("org/python/core/PyException", "traceback", "Lorg/python/core/PyTraceback;"); + code.checkcast("org/python/core/PyObject"); + code.invokevirtual(Type.getType(PyObject.class).getInternalName(), call3.getName(), call3.getDescriptor()); +@@ -2341,7 +2361,6 @@ + code.invokestatic("org/python/core/Py", "makeException", "()Lorg/python/core/PyException;"); + code.checkcast("java/lang/Throwable"); + code.athrow(); +- code.freeLocal(ts_tmp); + + code.label(label_end); + code.freeLocal(__exit__); +diff --git a/jython/src/org/python/compiler/Module.java b/jython/src/org/python/compiler/Module.java +--- a/jython/src/org/python/compiler/Module.java ++++ b/jython/src/org/python/compiler/Module.java +@@ -432,7 +432,7 @@ + + Code c = classfile.addMethod( + code.fname, +- "(" + $pyFrame + ")" + $pyObj, ++ "(" + $pyFrame + $threadState + ")" + $pyObj, + ACC_PUBLIC); + + CodeCompiler compiler = new CodeCompiler(this, printResults); +@@ -595,11 +595,12 @@ + public void addFunctions() throws IOException { + Code code = classfile.addMethod( + "call_function", +- "(I" + $pyFrame + ")" + $pyObj, ++ "(I" + $pyFrame + $threadState + ")" + $pyObj, + ACC_PUBLIC); + +- code.aload(0); +- code.aload(2); ++ code.aload(0); // this ++ code.aload(2); // frame ++ code.aload(3); // thread state + Label def = new Label(); + Label[] labels = new Label[codes.size()]; + int i; +@@ -611,7 +612,7 @@ + code.tableswitch(0, labels.length - 1, def, labels); + for(i=0; i<labels.length; i++) { + code.label(labels[i]); +- code.invokevirtual(classfile.name, ((PyCodeConstant)codes.get(i)).fname, "(" + $pyFrame + ")" + $pyObj); ++ code.invokevirtual(classfile.name, ((PyCodeConstant)codes.get(i)).fname, "(" + $pyFrame + $threadState + ")" + $pyObj); + code.areturn(); + } + code.label(def); +diff --git a/jython/src/org/python/core/Py.java b/jython/src/org/python/core/Py.java +--- a/jython/src/org/python/core/Py.java ++++ b/jython/src/org/python/core/Py.java +@@ -1194,16 +1194,17 @@ + public static PyObject runCode(PyCode code, PyObject locals, + PyObject globals) { + PyFrame f; ++ ThreadState ts = getThreadState(); + if (locals == null || locals == Py.None) { + if (globals != null && globals != Py.None) { + locals = globals; + } else { +- locals = Py.getFrame().getLocals(); ++ locals = ts.frame.getLocals(); + } + } + + if (globals == null || globals == Py.None) { +- globals = Py.getFrame().f_globals; ++ globals = ts.frame.f_globals; + } + + PyTableCode tc = null; +@@ -1213,7 +1214,7 @@ + + f = new PyFrame(tc, locals, globals, + Py.getSystemState().getBuiltins()); +- return code.call(f); ++ return code.call(ts, f); + } + + public static void exec(PyObject o, PyObject globals, PyObject locals) { +@@ -1543,9 +1544,9 @@ + public static PyObject makeClass(String name, PyObject[] bases, + PyCode code, PyObject doc, + PyObject[] closure_cells) { +- PyObject globals = getFrame().f_globals; +- PyObject dict = code.call(Py.EmptyObjects, Py.NoKeywords, globals, Py.EmptyObjects, +- new PyTuple(closure_cells)); ++ ThreadState state = getThreadState(); ++ PyObject dict = code.call(state, Py.EmptyObjects, Py.NoKeywords, ++ state.frame.f_globals, Py.EmptyObjects, new PyTuple(closure_cells)); + if (doc != null && dict.__finditem__("__doc__") == null) { + dict.__setitem__("__doc__", doc); + } +@@ -1997,45 +1998,51 @@ + } + } + +- public PyObject call(PyFrame frame, PyObject closure) { ++ public PyObject call(ThreadState state, PyFrame frame, PyObject closure) { + //XXX: what the heck is this? Looks like debug code, but it's + // been here a long time... + System.out.println("call #1"); + return Py.None; + } + +- public PyObject call(PyObject args[], String keywords[], ++ public PyObject call(ThreadState state, PyObject args[], String keywords[], + PyObject globals, PyObject[] defaults, + PyObject closure) { + return func.__call__(args, keywords); + } + +- public PyObject call(PyObject self, PyObject args[], String keywords[], ++ public PyObject call(ThreadState state, PyObject self, PyObject args[], String keywords[], + PyObject globals, PyObject[] defaults, + PyObject closure) { + return func.__call__(self, args, keywords); + } + +- public PyObject call(PyObject globals, PyObject[] defaults, ++ public PyObject call(ThreadState state, PyObject globals, PyObject[] defaults, + PyObject closure) { + return func.__call__(); + } + +- public PyObject call(PyObject arg1, PyObject globals, ++ public PyObject call(ThreadState state, PyObject arg1, PyObject globals, + PyObject[] defaults, PyObject closure) { + return func.__call__(arg1); + } + +- public PyObject call(PyObject arg1, PyObject arg2, PyObject globals, ++ public PyObject call(ThreadState state, PyObject arg1, PyObject arg2, PyObject globals, + PyObject[] defaults, PyObject closure) { + return func.__call__(arg1, arg2); + } + +- public PyObject call(PyObject arg1, PyObject arg2, PyObject arg3, ++ public PyObject call(ThreadState state, PyObject arg1, PyObject arg2, PyObject arg3, + PyObject globals, PyObject[] defaults, + PyObject closure) { + return func.__call__(arg1, arg2, arg3); + } ++ ++ public PyObject call(ThreadState state, PyObject arg1, PyObject arg2, ++ PyObject arg3, PyObject arg4, PyObject globals, ++ PyObject[] defaults, PyObject closure) { ++ return func.__call__(arg1, arg2, arg3, arg4); ++ } + } + + /** +diff --git a/jython/src/org/python/core/PyBaseCode.java b/jython/src/org/python/core/PyBaseCode.java +--- a/jython/src/org/python/core/PyBaseCode.java ++++ b/jython/src/org/python/core/PyBaseCode.java +@@ -22,9 +22,8 @@ + return co_freevars != null && co_freevars.length > 0; + } + +- public PyObject call(PyFrame frame, PyObject closure) { ++ public PyObject call(ThreadState ts, PyFrame frame, PyObject closure) { + // System.err.println("tablecode call: "+co_name); +- ThreadState ts = Py.getThreadState(); + if (ts.systemState == null) { + ts.systemState = Py.defaultSystemState; + } +@@ -105,38 +104,38 @@ + return ret; + } + +- public PyObject call(PyObject globals, PyObject[] defaults, ++ public PyObject call(ThreadState state, PyObject globals, PyObject[] defaults, + PyObject closure) + { + if (co_argcount != 0 || varargs || varkwargs) +- return call(Py.EmptyObjects, Py.NoKeywords, globals, defaults, ++ return call(state, Py.EmptyObjects, Py.NoKeywords, globals, defaults, + closure); + PyFrame frame = new PyFrame(this, globals); + if (co_flags.isFlagSet(CodeFlag.CO_GENERATOR)) { + return new PyGenerator(frame, closure); + } +- return call(frame, closure); ++ return call(state, frame, closure); + } + +- public PyObject call(PyObject arg1, PyObject globals, PyObject[] defaults, ++ public PyObject call(ThreadState state, PyObject arg1, PyObject globals, PyObject[] defaults, + PyObject closure) + { + if (co_argcount != 1 || varargs || varkwargs) +- return call(new PyObject[] {arg1}, ++ return call(state, new PyObject[] {arg1}, + Py.NoKeywords, globals, defaults, closure); + PyFrame frame = new PyFrame(this, globals); + frame.f_fastlocals[0] = arg1; + if (co_flags.isFlagSet(CodeFlag.CO_GENERATOR)) { + return new PyGenerator(frame, closure); + } +- return call(frame, closure); ++ return call(state, frame, closure); + } + +- public PyObject call(PyObject arg1, PyObject arg2, PyObject globals, ++ public PyObject call(ThreadState state, PyObject arg1, PyObject arg2, PyObject globals, + PyObject[] defaults, PyObject closure) + { + if (co_argcount != 2 || varargs || varkwargs) +- return call(new PyObject[] {arg1, arg2}, ++ return call(state, new PyObject[] {arg1, arg2}, + Py.NoKeywords, globals, defaults, closure); + PyFrame frame = new PyFrame(this, globals); + frame.f_fastlocals[0] = arg1; +@@ -144,15 +143,15 @@ + if (co_flags.isFlagSet(CodeFlag.CO_GENERATOR)) { + return new PyGenerator(frame, closure); + } +- return call(frame, closure); ++ return call(state, frame, closure); + } + +- public PyObject call(PyObject arg1, PyObject arg2, PyObject arg3, ++ public PyObject call(ThreadState state, PyObject arg1, PyObject arg2, PyObject arg3, + PyObject globals, PyObject[] defaults, + PyObject closure) + { + if (co_argcount != 3 || varargs || varkwargs) +- return call(new PyObject[] {arg1, arg2, arg3}, ++ return call(state, new PyObject[] {arg1, arg2, arg3}, + Py.NoKeywords, globals, defaults, closure); + PyFrame frame = new PyFrame(this, globals); + frame.f_fastlocals[0] = arg1; +@@ -161,20 +160,38 @@ + if (co_flags.isFlagSet(CodeFlag.CO_GENERATOR)) { + return new PyGenerator(frame, closure); + } +- return call(frame, closure); ++ return call(state, frame, closure); ++ } ++ ++ @Override ++ public PyObject call(ThreadState state, PyObject arg1, PyObject arg2, ++ PyObject arg3, PyObject arg4, PyObject globals, ++ PyObject[] defaults, PyObject closure) { ++ if (co_argcount != 4 || varargs || varkwargs) ++ return call(state, new PyObject[]{arg1, arg2, arg3, arg4}, ++ Py.NoKeywords, globals, defaults, closure); ++ PyFrame frame = new PyFrame(this, globals); ++ frame.f_fastlocals[0] = arg1; ++ frame.f_fastlocals[1] = arg2; ++ frame.f_fastlocals[2] = arg3; ++ frame.f_fastlocals[3] = arg4; ++ if (co_flags.isFlagSet(CodeFlag.CO_GENERATOR)) { ++ return new PyGenerator(frame, closure); ++ } ++ return call(state, frame, closure); + } + +- public PyObject call(PyObject self, PyObject args[], ++ public PyObject call(ThreadState state, PyObject self, PyObject args[], + String keywords[], PyObject globals, + PyObject[] defaults, PyObject closure) + { + PyObject[] os = new PyObject[args.length+1]; + os[0] = self; + System.arraycopy(args, 0, os, 1, args.length); +- return call(os, keywords, globals, defaults, closure); ++ return call(state, os, keywords, globals, defaults, closure); + } + +- public PyObject call(PyObject args[], String kws[], PyObject globals, PyObject[] defs, ++ public PyObject call(ThreadState state, PyObject args[], String kws[], PyObject globals, PyObject[] defs, + PyObject closure) { + PyFrame frame = new PyFrame(this, globals); + int argcount = args.length - kws.length; +@@ -277,7 +294,7 @@ + if (co_flags.isFlagSet(CodeFlag.CO_GENERATOR)) { + return new PyGenerator(frame, closure); + } +- return call(frame, closure); ++ return call(state, frame, closure); + } + + public String toString() { +diff --git a/jython/src/org/python/core/PyCode.java b/jython/src/org/python/core/PyCode.java +--- a/jython/src/org/python/core/PyCode.java ++++ b/jython/src/org/python/core/PyCode.java +@@ -8,32 +8,43 @@ + { + public String co_name; + +- abstract public PyObject call(PyFrame frame, PyObject closure); ++ abstract public PyObject call(ThreadState state, PyFrame frame, PyObject closure); + +- public PyObject call(PyFrame frame) { +- return call(frame, null); ++ public PyObject call(ThreadState state, PyFrame frame) { ++ return call(state, frame, null); + } + +- abstract public PyObject call(PyObject args[], String keywords[], ++ abstract public PyObject call(ThreadState state, ++ PyObject args[], String keywords[], + PyObject globals, PyObject[] defaults, + PyObject closure); + +- abstract public PyObject call(PyObject self, PyObject args[], ++ abstract public PyObject call(ThreadState state, ++ PyObject self, PyObject args[], + String keywords[], + PyObject globals, PyObject[] defaults, + PyObject closure); + +- abstract public PyObject call(PyObject globals, PyObject[] defaults, +- PyObject closure); +- +- abstract public PyObject call(PyObject arg1, PyObject globals, +- PyObject[] defaults, PyObject closure); +- +- abstract public PyObject call(PyObject arg1, PyObject arg2, ++ abstract public PyObject call(ThreadState state, + PyObject globals, PyObject[] defaults, + PyObject closure); + +- abstract public PyObject call(PyObject arg1, PyObject arg2, PyObject arg3, ++ abstract public PyObject call(ThreadState state, ++ PyObject arg1, PyObject globals, ++ PyObject[] defaults, PyObject closure); ++ ++ abstract public PyObject call(ThreadState state, ++ PyObject arg1, PyObject arg2, ++ PyObject globals, PyObject[] defaults, ++ PyObject closure); ++ ++ abstract public PyObject call(ThreadState state, ++ PyObject arg1, PyObject arg2, PyObject arg3, ++ PyObject globals, PyObject[] defaults, ++ PyObject closure); ++ ++ abstract public PyObject call(ThreadState state, ++ PyObject arg1, PyObject arg2, PyObject arg3, PyObject arg4, + PyObject globals, PyObject[] defaults, + PyObject closure); + +diff --git a/jython/src/org/python/core/PyFunction.java b/jython/src/org/python/core/PyFunction.java +--- a/jython/src/org/python/core/PyFunction.java ++++ b/jython/src/org/python/core/PyFunction.java +@@ -299,38 +299,90 @@ + + @Override + public PyObject __call__() { +- return func_code.call(func_globals, func_defaults, func_closure); ++ return __call__(Py.getThreadState()); ++ } ++ ++ @Override ++ public PyObject __call__(ThreadState state) { ++ return func_code.call(state, func_globals, func_defaults, func_closure); + } + + @Override + public PyObject __call__(PyObject arg) { +- return func_code.call(arg, func_globals, func_defaults, func_closure); ++ return __call__(Py.getThreadState(), arg); ++ } ++ ++ @Override ++ public PyObject __call__(ThreadState state, PyObject arg0) { ++ return func_code.call(state, arg0, func_globals, func_defaults, func_closure); + } + + @Override + public PyObject __call__(PyObject arg1, PyObject arg2) { +- return func_code.call(arg1, arg2, func_globals, func_defaults, func_closure); ++ return __call__(Py.getThreadState(), arg1, arg2); ++ } ++ ++ @Override ++ public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1) { ++ return func_code.call(state, arg0, arg1, func_globals, func_defaults, func_closure); + } + + @Override + public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3) { +- return func_code.call(arg1, arg2, arg3, func_globals, func_defaults, +- func_closure); ++ return __call__(Py.getThreadState(), arg1, arg2, arg3); ++ } ++ ++ @Override ++ public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, ++ PyObject arg2) { ++ return func_code.call(state, arg0, arg1, arg2, func_globals, func_defaults, func_closure); ++ } ++ ++ @Override ++ public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2, ++ PyObject arg3) { ++ return __call__(Py.getThreadState(), arg0, arg1, arg2, arg3); ++ } ++ ++ @Override ++ public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, ++ PyObject arg2, PyObject arg3) { ++ return func_code.call(state, arg0, arg1, arg2, arg3, func_globals, func_defaults, func_closure); ++ } ++ ++ @Override ++ public PyObject __call__(PyObject[] args) { ++ return __call__(Py.getThreadState(), args); ++ } ++ ++ @Override ++ public PyObject __call__(ThreadState state, PyObject[] args) { ++ return __call__(state, args, Py.NoKeywords); + } + + @Override + public PyObject __call__(PyObject[] args, String[] keywords) { + return function___call__(args, keywords); + } ++ ++ @Override ++ public PyObject __call__(ThreadState state, PyObject[] args, String[] keywords) { ++ return func_code.call(state, args, keywords, func_globals, func_defaults, func_closure); ++ } + + @ExposedMethod(doc = BuiltinDocs.function___call___doc) + final PyObject function___call__(PyObject[] args, String[] keywords) { +- return func_code.call(args, keywords, func_globals, func_defaults, func_closure); ++ return __call__(Py.getThreadState(), args, keywords); + } + + @Override + public PyObject __call__(PyObject arg1, PyObject[] args, String[] keywords) { +- return func_code.call(arg1, args, keywords, func_globals, func_defaults, func_closure); ++ return __call__(Py.getThreadState(), arg1, args, keywords); ++ } ++ ++ @Override ++ public PyObject __call__(ThreadState state, PyObject arg1, PyObject[] args, String[] keywords) { ++ return func_code.call(state, arg1, args, keywords, func_globals, func_defaults, func_closure); + } + + @Override +diff --git a/jython/src/org/python/core/PyFunctionTable.java b/jython/src/org/python/core/PyFunctionTable.java +--- a/jython/src/org/python/core/PyFunctionTable.java ++++ b/jython/src/org/python/core/PyFunctionTable.java +@@ -10,5 +10,5 @@ + */ + + public abstract class PyFunctionTable { +- abstract public PyObject call_function(int index, PyFrame frame); ++ abstract public PyObject call_function(int index, PyFrame frame, ThreadState ts); + } +diff --git a/jython/src/org/python/core/PyGenerator.java b/jython/src/org/python/core/PyGenerator.java +--- a/jython/src/org/python/core/PyGenerator.java ++++ b/jython/src/org/python/core/PyGenerator.java +@@ -106,8 +106,13 @@ + super.finalize(); + } + } ++ ++ @Override ++ public PyObject __iternext__() { ++ return __iternext__(Py.getThreadState()); ++ } + +- public PyObject __iternext__() { ++ public PyObject __iternext__(ThreadState state) { + if (gi_running) + throw Py.ValueError("generator already executing"); + if (gi_frame == null) { +@@ -121,7 +126,7 @@ + gi_running = true; + PyObject result = null; + try { +- result = gi_frame.f_code.call(gi_frame, closure); ++ result = gi_frame.f_code.call(state, gi_frame, closure); + } catch(PyException e) { + if (!(e.type == Py.StopIteration || e.type == Py.GeneratorExit)) { + gi_frame = null; +diff --git a/jython/src/org/python/core/PyMethod.java b/jython/src/org/python/core/PyMethod.java +--- a/jython/src/org/python/core/PyMethod.java ++++ b/jython/src/org/python/core/PyMethod.java +@@ -93,21 +93,143 @@ + return this; + } + } +- ++ /*// This has been disabled since JavaFunc expects to be called with self + boxed args ++ @Override ++ public PyObject __call__() { ++ return __call__(Py.getThreadState()); ++ } ++ ++ @Override ++ public PyObject __call__(ThreadState state) { ++ PyObject self = checkSelf(null, null); ++ if (self == null) { ++ return im_func.__call__(state); ++ } else { ++ return im_func.__call__(state, self); ++ } ++ } ++ ++ @Override ++ public PyObject __call__(PyObject arg0) { ++ return __call__(Py.getThreadState(), arg0); ++ } ++ ++ @Override ++ public PyObject __call__(ThreadState state, PyObject arg0) { ++ PyObject self = checkSelf(arg0, null); ++ if (self == null) { ++ return im_func.__call__(state, arg0); ++ } else { ++ return im_func.__call__(state, self, arg0); ++ } ++ } ++ ++ @Override ++ public PyObject __call__(PyObject arg0, PyObject arg1) { ++ return __call__(Py.getThreadState(), arg0, arg1); ++ } ++ ++ @Override ++ public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1) { ++ PyObject self = checkSelf(arg0, null); ++ if (self == null) { ++ return im_func.__call__(state, arg0, arg1); ++ } else { ++ return im_func.__call__(state, self, arg0, arg1); ++ } ++ } ++ ++ @Override ++ public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2) { ++ return __call__(Py.getThreadState(), arg0, arg1, arg2); ++ } ++ ++ @Override ++ public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, ++ PyObject arg2) { ++ PyObject self = checkSelf(arg0, null); ++ if (self == null) { ++ return im_func.__call__(state, arg0, arg1, arg2); ++ } else { ++ return im_func.__call__(state, self, arg0, arg1, arg2); ++ } ++ } ++ ++ @Override ++ public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3) { ++ return __call__(Py.getThreadState(), arg0, arg1, arg2, arg3); ++ } ++ ++ @Override ++ public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, ++ PyObject arg2, PyObject arg3) { ++ PyObject self = checkSelf(arg0, null); ++ if (self == null) { ++ return im_func.__call__(state, arg0, arg1, arg2, arg3); ++ } else { ++ return im_func.__call__(state, self, new PyObject[]{arg0, arg1, arg2, arg3}, Py.NoKeywords); ++ } ++ } ++ ++ ++ @Override ++ public PyObject __call__(PyObject arg1, PyObject[] args, String[] keywords) { ++ return __call__(Py.getThreadState(), arg1, args, keywords); ++ } ++ ++ @Override ++ public PyObject __call__(ThreadState state, PyObject arg1, PyObject[] args, ++ String[] keywords) { ++ PyObject self = checkSelf(arg1, args); ++ if (self == null) { ++ return im_func.__call__(state, arg1, args, keywords); ++ } else { ++ PyObject[] new_args = new PyObject[args.length+1]; ++ System.arraycopy(args, 0, new_args, 1, args.length); ++ new_args[0] = arg1; ++ return im_func.__call__(state, self, new_args, keywords); ++ } ++ } ++ ++ @Override ++ public PyObject __call__(PyObject[] args) { ++ return __call__(Py.getThreadState(), args); ++ } ++ ++ @Override ++ public PyObject __call__(ThreadState state, PyObject[] args) { ++ return __call__(state, args, Py.NoKeywords); ++ } ++ */ + @Override + public PyObject __call__(PyObject[] args, String[] keywords) { + return instancemethod___call__(args, keywords); + } +- ++ ++ @Override ++ public PyObject __call__(ThreadState state, PyObject[] args, String[] keywords) { ++ PyObject self = checkSelf(null, args); ++ if (self == null) { ++ return im_func.__call__(state, args, keywords); ++ } else { ++ return im_func.__call__(state, self, args, keywords); ++ } ++ } ++ + @ExposedMethod(doc = BuiltinDocs.instancemethod___call___doc) + final PyObject instancemethod___call__(PyObject[] args, String[] keywords) { ++ return __call__(Py.getThreadState(), args, keywords); ++ } ++ ++ private PyObject checkSelf(PyObject arg, PyObject[] args) { + PyObject self = im_self; +- + if (self == null) { + // Unbound methods must be called with an instance of the + // class (or a derived class) as first argument + boolean ok; +- if (args.length >= 1) { ++ if (arg != null) { ++ self = arg; ++ } else if (args != null && args.length >= 1) { + self = args[0]; + } + if (self == null) { +@@ -125,9 +247,9 @@ + self == null ? "" : " instance"); + throw Py.TypeError(msg); + } +- return im_func.__call__(args, keywords); ++ return null; + } else { +- return im_func.__call__(self, args, keywords); ++ return self; + } + } + +diff --git a/jython/src/org/python/core/PyObject.java b/jython/src/org/python/core/PyObject.java +--- a/jython/src/org/python/core/PyObject.java ++++ b/jython/src/org/python/core/PyObject.java +@@ -314,6 +314,10 @@ + public PyObject __call__(PyObject args[], String keywords[]) { + throw Py.TypeError(String.format("'%s' object is not callable", getType().fastGetName())); + } ++ ++ public PyObject __call__(ThreadState state, PyObject args[], String keywords[]) { ++ return __call__(args, keywords); ++ } + + /** + * A variant of the __call__ method with one extra initial argument. +@@ -329,15 +333,16 @@ + * keyword arguments). + * @param keywords the keywords used for all keyword arguments. + **/ +- public PyObject __call__( +- PyObject arg1, +- PyObject args[], +- String keywords[]) { ++ public PyObject __call__(PyObject arg1, PyObject args[], String keywords[]) { + PyObject[] newArgs = new PyObject[args.length + 1]; + System.arraycopy(args, 0, newArgs, 1, args.length); + newArgs[0] = arg1; + return __call__(newArgs, keywords); + } ++ ++ public PyObject __call__(ThreadState state, PyObject arg1, PyObject args[], String keywords[]) { ++ return __call__(arg1, args, keywords); ++ } + + /** + * A variant of the __call__ method when no keywords are passed. The +@@ -350,6 +355,10 @@ + public PyObject __call__(PyObject args[]) { + return __call__(args, Py.NoKeywords); + } ++ ++ public PyObject __call__(ThreadState state, PyObject args[]) { ++ return __call__(args); ++ } + + /** + * A variant of the __call__ method with no arguments. The default +@@ -360,6 +369,10 @@ + public PyObject __call__() { + return __call__(Py.EmptyObjects, Py.NoKeywords); + } ++ ++ public PyObject __call__(ThreadState state) { ++ return __call__(); ++ } + + /** + * A variant of the __call__ method with one argument. The default +@@ -372,6 +385,10 @@ + public PyObject __call__(PyObject arg0) { + return __call__(new PyObject[] { arg0 }, Py.NoKeywords); + } ++ ++ public PyObject __call__(ThreadState state, PyObject arg0) { ++ return __call__(arg0); ++ } + + /** + * A variant of the __call__ method with two arguments. The default +@@ -386,6 +403,10 @@ + return __call__(new PyObject[] { arg0, arg1 }, Py.NoKeywords); + } + ++ public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1) { ++ return __call__(arg0, arg1); ++ } ++ + /** + * A variant of the __call__ method with three arguments. The default + * behavior is to invoke <code>__call__(args, keywords)</code> with the +@@ -399,6 +420,10 @@ + public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2) { + return __call__(new PyObject[] { arg0, arg1, arg2 }, Py.NoKeywords); + } ++ ++ public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, PyObject arg2) { ++ return __call__(arg0, arg1, arg2); ++ } + + /** + * A variant of the __call__ method with four arguments. The default +@@ -411,15 +436,15 @@ + * @param arg2 the third argument to the function. + * @param arg3 the fourth argument to the function. + **/ +- public PyObject __call__( +- PyObject arg0, +- PyObject arg1, +- PyObject arg2, +- PyObject arg3) { ++ public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3) { + return __call__( + new PyObject[] { arg0, arg1, arg2, arg3 }, + Py.NoKeywords); + } ++ ++ public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3) { ++ return __call__(arg0, arg1, arg2, arg3); ++ } + + /** @deprecated **/ + public PyObject _callextra(PyObject[] args, +diff --git a/jython/src/org/python/core/PyReflectedFunction.java b/jython/src/org/python/core/PyReflectedFunction.java +--- a/jython/src/org/python/core/PyReflectedFunction.java ++++ b/jython/src/org/python/core/PyReflectedFunction.java +@@ -180,7 +180,14 @@ + } + + public PyObject __call__(PyObject[] args, String[] keywords) { +- return __call__(null, args, keywords); ++ PyObject self = null; ++ /* ++ PyObject[] new_args = new PyObject[args.length - 1]; ++ System.arraycopy(args, 1, new_args, 0, new_args.length); ++ self = args[0]; ++ args = new_args; ++ */ ++ return __call__(self, args, keywords); + } + + // A bunch of code to make error handling prettier +diff --git a/jython/src/org/python/core/PyTableCode.java b/jython/src/org/python/core/PyTableCode.java +--- a/jython/src/org/python/core/PyTableCode.java ++++ b/jython/src/org/python/core/PyTableCode.java +@@ -122,9 +122,8 @@ + } + + @Override +- public PyObject call(PyFrame frame, PyObject closure) { ++ public PyObject call(ThreadState ts, PyFrame frame, PyObject closure) { + // System.err.println("tablecode call: "+co_name); +- ThreadState ts = Py.getThreadState(); + if (ts.systemState == null) { + ts.systemState = Py.defaultSystemState; + } +@@ -163,7 +162,7 @@ + + PyObject ret; + try { +- ret = funcs.call_function(func_id, frame); ++ ret = funcs.call_function(func_id, frame, ts); + } catch (Throwable t) { + // Convert exceptions that occured in Java code to PyExceptions + PyException pye = Py.JavaError(t); +diff --git a/jython/src/org/python/core/ReflectedArgs.java b/jython/src/org/python/core/ReflectedArgs.java +--- a/jython/src/org/python/core/ReflectedArgs.java ++++ b/jython/src/org/python/core/ReflectedArgs.java +@@ -52,10 +52,11 @@ + if (this.isStatic) { + if (self != null) { + /* +- * PyObject[] newArgs = new PyObject[pyArgs.length+1]; +- * System.arraycopy(pyArgs, 0, newArgs, 1, pyArgs.length); +- * newArgs[0] = self; pyArgs = newArgs; +- */ ++ PyObject[] newArgs = new PyObject[pyArgs.length+1]; ++ System.arraycopy(pyArgs, 0, newArgs, 1, pyArgs.length); ++ newArgs[0] = self; ++ pyArgs = newArgs; ++ //*/ + self = null; + } + } else { +diff --git a/jython/src/org/python/core/imp.java b/jython/src/org/python/core/imp.java +--- a/jython/src/org/python/core/imp.java ++++ b/jython/src/org/python/core/imp.java +@@ -313,7 +313,7 @@ + + try { + PyFrame f = new PyFrame(code, module.__dict__, module.__dict__, null); +- code.call(f); ++ code.call(Py.getThreadState(), f); + } catch (RuntimeException t) { + removeModule(name); + throw t; Modified: trunk/sandbox/tobias/.hg/patches/parrot.patch =================================================================== --- trunk/sandbox/tobias/.hg/patches/parrot.patch 2009-03-31 12:39:31 UTC (rev 6133) +++ trunk/sandbox/tobias/.hg/patches/parrot.patch 2009-03-31 14:56:30 UTC (rev 6134) @@ -1,7 +1,7 @@ diff --git a/jython/src/org/python/core/PyGenerator.java b/jython/src/org/python/core/PyGenerator.java --- a/jython/src/org/python/core/PyGenerator.java +++ b/jython/src/org/python/core/PyGenerator.java -@@ -26,13 +26,19 @@ +@@ -26,6 +26,12 @@ // the generator generatorExit = Py.makeException(Py.GeneratorExit); } @@ -14,55 +14,3 @@ @ExposedMethod public PyObject send(PyObject value) { - if (gi_frame == null) { - throw Py.StopIteration(""); - } -- if (gi_frame.f_lasti == 0 && value != Py.None) { -+ if (gi_frame.getLastI() == 0 && value != Py.None) { - throw Py.TypeError("can't send non-None value to a just-started generator"); - } - gi_frame.setGeneratorInput(value); -@@ -75,7 +81,7 @@ - } - - private PyObject raiseException(PyException ex) { -- if (gi_frame == null || gi_frame.f_lasti == 0) { -+ if (gi_frame == null || gi_frame.getLastI() == 0) { - throw ex; - } - gi_frame.setGeneratorInput(ex); -@@ -84,7 +90,7 @@ - - @Override - protected void finalize() throws Throwable { -- if (gi_frame == null || gi_frame.f_lasti == -1) -+ if (gi_frame == null || gi_frame.getLastI() == -1) - return; - try { - close(); -@@ -114,14 +120,14 @@ - return null; - } - -- if (gi_frame.f_lasti == -1) { -+ if (gi_frame.getLastI() == -1) { - gi_frame = null; - return null; - } - gi_running = true; - PyObject result = null; - try { -- result = gi_frame.f_code.call(gi_frame, closure); -+ result = gi_frame.getCode().call(gi_frame, closure); - } catch(PyException e) { - if (!(e.type == Py.StopIteration || e.type == Py.GeneratorExit)) { - gi_frame = null; -@@ -134,7 +140,7 @@ - } finally { - gi_running = false; - } -- if (result == Py.None && gi_frame.f_lasti == -1) { -+ if (result == Py.None && gi_frame.getLastI() == -1) { - return null; - } - return result; Modified: trunk/sandbox/tobias/.hg/patches/series =================================================================== --- trunk/sandbox/tobias/.hg/patches/series 2009-03-31 12:39:31 UTC (rev 6133) +++ trunk/sandbox/tobias/.hg/patches/series 2009-03-31 14:56:30 UTC (rev 6134) @@ -1,3 +1,5 @@ +callpath.patch #+trunk #-advanced +parrot.patch #+trunk #-advanced types.patch #-trunk #-advanced grammar.patch #-trunk #-advanced decouple.patch #-trunk #-advanced @@ -2,2 +4 @@ frames.patch #+trunk #-advanced -parrot.patch #-trunk This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <am...@us...> - 2009-03-31 12:39:40
|
Revision: 6133 http://jython.svn.sourceforge.net/jython/?rev=6133&view=rev Author: amak Date: 2009-03-31 12:39:31 +0000 (Tue, 31 Mar 2009) Log Message: ----------- Undoing a change that got checked in here http://fisheye3.atlassian.com/changelog/jython/?cs=4791 Which came originally from here http://svn.python.org/view/python/trunk/Lib/socket.py?view=diff&r1=61007&r2=61008 But was wrong; changing min() to max() solves this problem. The cpython change was ostensibly made to correct a memory allocation problem, but was wrong, and was undone here http://svn.python.org/view?view=rev&revision=62627 We should probably review _fileobject implementation sometime, since the cpython one has now changed a fair amount. Modified Paths: -------------- branches/Release_2_2maint/jython/Lib/socket.py Modified: branches/Release_2_2maint/jython/Lib/socket.py =================================================================== --- branches/Release_2_2maint/jython/Lib/socket.py 2009-03-31 12:38:36 UTC (rev 6132) +++ branches/Release_2_2maint/jython/Lib/socket.py 2009-03-31 12:39:31 UTC (rev 6133) @@ -1212,7 +1212,7 @@ self._rbuf = "" while True: left = size - buf_len - recv_size = min(self._rbufsize, left) + recv_size = max(self._rbufsize, left) data = self._sock.recv(recv_size) if not data: break This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <am...@us...> - 2009-03-31 12:38:51
|
Revision: 6132 http://jython.svn.sourceforge.net/jython/?rev=6132&view=rev Author: amak Date: 2009-03-31 12:38:36 +0000 (Tue, 31 Mar 2009) Log Message: ----------- Undoing a change that got checked in here http://fisheye3.atlassian.com/changelog/jython/?cs=4791 Which came originally from here http://svn.python.org/view/python/trunk/Lib/socket.py?view=diff&r1=61007&r2=61008 But was wrong; changing min() to max() solves this problem. The cpython change was ostensibly made to correct a memory allocation problem, but was wrong, and was undone here http://svn.python.org/view?view=rev&revision=62627 We should probably review _fileobject implementation sometime, since the cpython one has now changed a fair amount. Modified Paths: -------------- trunk/jython/Lib/socket.py Modified: trunk/jython/Lib/socket.py =================================================================== --- trunk/jython/Lib/socket.py 2009-03-31 03:35:14 UTC (rev 6131) +++ trunk/jython/Lib/socket.py 2009-03-31 12:38:36 UTC (rev 6132) @@ -1265,7 +1265,7 @@ self._rbuf = "" while True: left = size - buf_len - recv_size = min(self._rbufsize, left) + recv_size = max(self._rbufsize, left) data = self._sock.recv(recv_size) if not data: break This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-03-31 03:35:18
|
Revision: 6131 http://jython.svn.sourceforge.net/jython/?rev=6131&view=rev Author: zyasoft Date: 2009-03-31 03:35:14 +0000 (Tue, 31 Mar 2009) Log Message: ----------- Default to JLineConsole so that we have a usable readline out-of-the-box. Modified Paths: -------------- trunk/jython/registry Modified: trunk/jython/registry =================================================================== --- trunk/jython/registry 2009-03-30 23:44:23 UTC (rev 6130) +++ trunk/jython/registry 2009-03-31 03:35:14 UTC (rev 6131) @@ -36,7 +36,7 @@ # 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.ReadlineConsole +python.console=org.python.util.JLineConsole #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: <pj...@us...> - 2009-03-30 23:44:37
|
Revision: 6130 http://jython.svn.sourceforge.net/jython/?rev=6130&view=rev Author: pjenvey Date: 2009-03-30 23:44:23 +0000 (Mon, 30 Mar 2009) Log Message: ----------- small cleanup Modified Paths: -------------- trunk/jython/src/org/python/modules/_weakref/ReferenceType.java Modified: trunk/jython/src/org/python/modules/_weakref/ReferenceType.java =================================================================== --- trunk/jython/src/org/python/modules/_weakref/ReferenceType.java 2009-03-30 22:02:06 UTC (rev 6129) +++ trunk/jython/src/org/python/modules/_weakref/ReferenceType.java 2009-03-30 23:44:23 UTC (rev 6130) @@ -3,7 +3,6 @@ import org.python.core.ArgParser; import org.python.core.Py; -import org.python.core.PyBuiltinCallable; import org.python.core.PyNewWrapper; import org.python.core.PyObject; import org.python.core.PyType; @@ -54,7 +53,7 @@ final void weakref___init__(PyObject[] args, String[] keywords) { // Just ensure at least one arg, leaving other args alone ArgParser ap = parseInitArgs("__init__", args, keywords); - PyObject ob = ap.getPyObject(0); + ap.getPyObject(0); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-03-30 22:02:10
|
Revision: 6129 http://jython.svn.sourceforge.net/jython/?rev=6129&view=rev Author: pjenvey Date: 2009-03-30 22:02:06 +0000 (Mon, 30 Mar 2009) Log Message: ----------- only modify __module__ in classDict after it's been copied thanks Mike Bayer Modified Paths: -------------- trunk/jython/Lib/test/test_class_jy.py trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/Lib/test/test_class_jy.py =================================================================== --- trunk/jython/Lib/test/test_class_jy.py 2009-03-30 21:40:00 UTC (rev 6128) +++ trunk/jython/Lib/test/test_class_jy.py 2009-03-30 22:02:06 UTC (rev 6129) @@ -330,6 +330,11 @@ class Bar(object): self.assertEqual(__module__, module_name) + def test_dundermodule_in_class_dict_copy(self): + class_dict = {'a': 'this is a', 'b': 'this is b'} + Foo = type.__new__(type, 'Foo', (object,), class_dict) + Foo.keys = class_dict.keys + assert sorted(Foo().keys()) == sorted(['a', 'b']), sorted(Foo().keys()) class ClassMetaclassRepr(unittest.TestCase): """Verifies #1131 is fixed""" Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-03-30 21:40:00 UTC (rev 6128) +++ trunk/jython/src/org/python/core/PyType.java 2009-03-30 22:02:06 UTC (rev 6129) @@ -166,19 +166,6 @@ } } - if (dict.__finditem__("__module__") == null) { - PyFrame frame = Py.getFrame(); - if (frame != null) { - PyObject globals = frame.f_globals; - PyObject modname; - if ((modname = globals.__finditem__("__name__")) != null) { - dict.__setitem__("__module__", modname); - } - } - } - // XXX also __doc__ __module__ - - Class<?> proxyClass = null; if (baseClass != null || interfaces.size() != 0) { String proxyName = name; @@ -227,6 +214,19 @@ } else { dict = ((PyDictionary)dict).copy(); } + + if (dict.__finditem__("__module__") == null) { + PyFrame frame = Py.getFrame(); + if (frame != null) { + PyObject globals = frame.f_globals; + PyObject modname; + if ((modname = globals.__finditem__("__name__")) != null) { + dict.__setitem__("__module__", modname); + } + } + } + // XXX also __doc__ __module__ + newtype.dict = dict; newtype.name = name; newtype.base = best_base(bases_list); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-03-30 21:40:09
|
Revision: 6128 http://jython.svn.sourceforge.net/jython/?rev=6128&view=rev Author: fwierzbicki Date: 2009-03-30 21:40:00 +0000 (Mon, 30 Mar 2009) Log Message: ----------- Fix BIGINT trouble for postgresql. Modified Paths: -------------- trunk/jython/src/com/ziclix/python/sql/DataHandler.java Modified: trunk/jython/src/com/ziclix/python/sql/DataHandler.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/DataHandler.java 2009-03-30 19:57:57 UTC (rev 6127) +++ trunk/jython/src/com/ziclix/python/sql/DataHandler.java 2009-03-30 21:40:00 UTC (rev 6128) @@ -22,6 +22,7 @@ import java.io.Reader; import java.io.StringReader; import java.lang.reflect.Constructor; +import java.math.BigInteger; import java.math.BigDecimal; import java.sql.CallableStatement; import java.sql.Date; @@ -122,7 +123,13 @@ public void setJDBCObject(PreparedStatement stmt, int index, PyObject object) throws SQLException { try { - stmt.setObject(index, object.__tojava__(Object.class)); + Object o = object.__tojava__(Object.class); + if (o instanceof BigInteger) { + //XXX: This is in here to specifically fix passing a PyLong into Postgresql. + stmt.setObject(index, o, Types.BIGINT); + } else { + stmt.setObject(index, o); + } } catch (Exception e) { SQLException cause = null, ex = new SQLException("error setting index [" + index + "]"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-03-30 19:58:09
|
Revision: 6127 http://jython.svn.sourceforge.net/jython/?rev=6127&view=rev Author: pjenvey Date: 2009-03-30 19:57:57 +0000 (Mon, 30 Mar 2009) Log Message: ----------- description[0] should be the label, not name pointed out by Mike Bayer Modified Paths: -------------- trunk/jython/src/com/ziclix/python/sql/Fetch.java Modified: trunk/jython/src/com/ziclix/python/sql/Fetch.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/Fetch.java 2009-03-30 19:55:09 UTC (rev 6126) +++ trunk/jython/src/com/ziclix/python/sql/Fetch.java 2009-03-30 19:57:57 UTC (rev 6127) @@ -259,7 +259,7 @@ for (int i = 1; i <= meta.getColumnCount(); i++) { PyObject[] a = new PyObject[7]; - a[0] = Py.newString(meta.getColumnName(i)); + a[0] = Py.newString(meta.getColumnLabel(i)); a[1] = Py.newInteger(meta.getColumnType(i)); a[2] = Py.newInteger(meta.getColumnDisplaySize(i)); a[3] = Py.None; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-03-30 19:55:19
|
Revision: 6126 http://jython.svn.sourceforge.net/jython/?rev=6126&view=rev Author: pjenvey Date: 2009-03-30 19:55:09 +0000 (Mon, 30 Mar 2009) Log Message: ----------- unused imports Modified Paths: -------------- trunk/jython/src/com/ziclix/python/sql/PyCursor.java Modified: trunk/jython/src/com/ziclix/python/sql/PyCursor.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/PyCursor.java 2009-03-30 19:15:47 UTC (rev 6125) +++ trunk/jython/src/com/ziclix/python/sql/PyCursor.java 2009-03-30 19:55:09 UTC (rev 6126) @@ -17,10 +17,8 @@ import org.python.core.ClassDictInit; import org.python.core.Py; import org.python.core.PyBuiltinMethodSet; -import org.python.core.PyClass; import org.python.core.PyDictionary; import org.python.core.PyException; -import org.python.core.PyInteger; import org.python.core.PyList; import org.python.core.PyObject; import org.python.core.PyString; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-03-30 19:15:52
|
Revision: 6125 http://jython.svn.sourceforge.net/jython/?rev=6125&view=rev Author: pjenvey Date: 2009-03-30 19:15:47 +0000 (Mon, 30 Mar 2009) Log Message: ----------- handle the case where a module that failed to import was already deleted from sys.modules thanks Thijs Triemstra fixes #1246 Modified Paths: -------------- trunk/jython/Lib/test/test_import_jy.py trunk/jython/src/org/python/core/imp.java Added Paths: ----------- trunk/jython/Lib/test/module_deleter.py Added: trunk/jython/Lib/test/module_deleter.py =================================================================== --- trunk/jython/Lib/test/module_deleter.py (rev 0) +++ trunk/jython/Lib/test/module_deleter.py 2009-03-30 19:15:47 UTC (rev 6125) @@ -0,0 +1,3 @@ +import sys +del sys.modules[__name__] +1 / 0 Modified: trunk/jython/Lib/test/test_import_jy.py =================================================================== --- trunk/jython/Lib/test/test_import_jy.py 2009-03-30 17:12:32 UTC (rev 6124) +++ trunk/jython/Lib/test/test_import_jy.py 2009-03-30 19:15:47 UTC (rev 6125) @@ -159,6 +159,9 @@ self.assertEquals(Metis, Zeus.Athena.__bases__[0]) self.assertEquals(Zeus, Metis.__bases__[0]) + def test_sys_modules_deletion(self): + self.assertRaises(ZeroDivisionError, __import__, 'test.module_deleter') + def test_main(): test_support.run_unittest(MislabeledImportTestCase, OverrideBuiltinsImportTestCase, Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2009-03-30 17:12:32 UTC (rev 6124) +++ trunk/jython/src/org/python/core/imp.java 2009-03-30 19:15:47 UTC (rev 6125) @@ -66,6 +66,26 @@ return module; } + /** + * Remove name form sys.modules if it's there. + * + * @param name the module name + */ + private static void removeModule(String name) { + name = name.intern(); + PyObject modules = Py.getSystemState().modules; + if (modules.__finditem__(name) != null) { + try { + modules.__delitem__(name); + } catch (PyException pye) { + // another thread may have deleted it + if (!Py.matchException(pye, Py.KeyError)) { + throw pye; + } + } + } + } + private static byte[] readBytes(InputStream fp) { try { return FileUtil.readBytes(fp); @@ -295,7 +315,7 @@ PyFrame f = new PyFrame(code, module.__dict__, module.__dict__, null); code.call(f); } catch (RuntimeException t) { - Py.getSystemState().modules.__delitem__(name.intern()); + removeModule(name); throw t; } return module; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-03-30 17:12:52
|
Revision: 6124 http://jython.svn.sourceforge.net/jython/?rev=6124&view=rev Author: pjenvey Date: 2009-03-30 17:12:32 +0000 (Mon, 30 Mar 2009) Log Message: ----------- revert r2556, so == doesn't swallow AttributeErrors thanks Michele Cella fixes #1209 Modified Paths: -------------- trunk/jython/Lib/test/test_descr_jy.py trunk/jython/src/org/python/core/PyObject.java Modified: trunk/jython/Lib/test/test_descr_jy.py =================================================================== --- trunk/jython/Lib/test/test_descr_jy.py 2009-03-30 16:26:41 UTC (rev 6123) +++ trunk/jython/Lib/test/test_descr_jy.py 2009-03-30 17:12:32 UTC (rev 6124) @@ -331,6 +331,13 @@ self.assertRaises(AttributeError, func, old) self.assertRaises(TypeError, func, new) + def test_eq(self): + class A(object): + def __eq__(self, other): + return self.value == other.value + self.assertRaises(AttributeError, lambda: A() == A()) + + class GetAttrTestCase(unittest.TestCase): def test_raising_custom_attribute_error(self): # Very similar to Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2009-03-30 16:26:41 UTC (rev 6123) +++ trunk/jython/src/org/python/core/PyObject.java 2009-03-30 17:12:32 UTC (rev 6124) @@ -1410,11 +1410,6 @@ if (res != null) return res; return _cmpeq_unsafe(o) == 0 ? Py.True : Py.False; - } catch (PyException e) { - if (Py.matchException(e, Py.AttributeError)) { - return Py.False; - } - throw e; } finally { delete_token(ts, token); ts.compareStateNesting--; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-03-30 16:26:55
|
Revision: 6123 http://jython.svn.sourceforge.net/jython/?rev=6123&view=rev Author: thobes Date: 2009-03-30 16:26:41 +0000 (Mon, 30 Mar 2009) Log Message: ----------- Moved the frame introspection library to kenai. Property Changed: ---------------- trunk/sandbox/tobias/ Property changes on: trunk/sandbox/tobias ___________________________________________________________________ Modified: svn:externals - jython https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython frame https://projects.thobe.org/svn/public/javaframe + jython https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython frame https://kenai.com/svn/jvm-frame-introspect~svn/frame This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-03-30 16:18:02
|
Revision: 6122 http://jython.svn.sourceforge.net/jython/?rev=6122&view=rev Author: fwierzbicki Date: 2009-03-30 16:17:56 +0000 (Mon, 30 Mar 2009) Log Message: ----------- arbitrarily locked CPythonLib version to r70085. Did not do this for the experimental branches pbvcm or advanced. Property Changed: ---------------- branches/Release_2_2maint/jython/ branches/Release_2_3maint/jython/ branches/jy3k/ Property changes on: branches/Release_2_2maint/jython ___________________________________________________________________ Modified: svn:externals - CPythonLib http://svn.python.org/projects/python/branches/release22-maint/Lib/ + CPythonLib -r70085 http://svn.python.org/projects/python/branches/release22-maint/Lib/ Property changes on: branches/Release_2_3maint/jython ___________________________________________________________________ Modified: svn:externals - CPythonLib http://svn.python.org/projects/python/branches/release23-maint/Lib/ + CPythonLib -r70085 http://svn.python.org/projects/python/branches/release23-maint/Lib/ Property changes on: branches/jy3k ___________________________________________________________________ Modified: svn:externals - CPythonLib http://svn.python.org/projects/python/branches/py3k/Lib/ + CPythonLib -r70085 http://svn.python.org/projects/python/branches/py3k/Lib/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-03-30 15:57:43
|
Revision: 6121 http://jython.svn.sourceforge.net/jython/?rev=6121&view=rev Author: thobes Date: 2009-03-30 15:57:27 +0000 (Mon, 30 Mar 2009) Log Message: ----------- Checking in current progress on the advanced compiler before diving in to the PyCon sprinting session. Modified Paths: -------------- trunk/sandbox/tobias/.classpath trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch trunk/sandbox/tobias/.hg/patches/series trunk/sandbox/tobias/.hg/patches/types.patch trunk/sandbox/tobias/build.xml trunk/sandbox/tobias/bytecode/build.xml trunk/sandbox/tobias/bytecode/src/org/python/bytecode/ReferenceResolver.java trunk/sandbox/tobias/compiler/build.xml trunk/sandbox/tobias/compiler/src/org/python/compiler/AdvancedCompiler.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/YieldPoint.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/Graph.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/IfNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/Node.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/OpNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/PhiNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/SwitchNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/Value.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/ValueNode.java trunk/sandbox/tobias/util/build.xml trunk/sandbox/tobias/util/src/org/python/code/CodeTable.java trunk/sandbox/tobias/util/src/org/python/code/SpecializedCode.java Added Paths: ----------- trunk/sandbox/tobias/.hg/patches/frames.patch trunk/sandbox/tobias/.hg/patches/grammar.patch trunk/sandbox/tobias/.hg/patches/parrot.patch trunk/sandbox/tobias/bin/ trunk/sandbox/tobias/bin/jython trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/Assignment.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/AssignmentGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/AugAssignCallback.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/BytecodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/BytecodeCodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/CodeGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/CompilerDirector.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/Constant.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ConstantChecker.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ConstantCodeGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ConstantOwner.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ConstantPool.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ConstraintsDefinition.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/IntermediateCodeGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/IntermediateCodeGeneratorFactory.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/PragmaParser.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/Preferences.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ScopeAnalyzer.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ScopeBuilder.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ScopeFactory.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ScopeInformation.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ScopesBuilder.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/SyntaxErrorPolicy.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/direct/ trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/direct/DirectCodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/direct/DirectGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/flowgraph/ trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/flowgraph/CodeGeneratorGraphVisitor.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/flowgraph/FlowGraphBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/flowgraph/FlowGraphGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/flowgraph/GeneratedCodeState.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/sea/ trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/sea/NodeSeaBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/sea/NodeSeaConstantGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/sea/NodeSeaGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/sea/SeaScope.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/sea/ValueCarrier.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/ trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/BlockCallback.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/CallStrategy.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/FrameStrategy.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/GeneratorCallback.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/GraphBuilder.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/InvocationStrategy.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/LoopCallback.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/LoopHandle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/PythonOperation.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/PythonTypes.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/SelectionCallback.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/StateCarrier.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/SuperGraph.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/SupergraphVisitor.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/UnrollerCallback.java trunk/sandbox/tobias/compiler/src/org/python/compiler/sea/Variable.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/ArrayNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/ArrayValue.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/CodeGenerationTraverser.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/Continuation.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/ExceptionValue.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/GraphBuilder.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/GraphTraverser.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/InvocationNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/InvocationType.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/LoadNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/NamespacePopulator.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/NodeSorter.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/Selection.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/SerializationTraverser.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/StoreNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/ThrowNode.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/TransformationTraverser.java trunk/sandbox/tobias/compiler/src/org/thobe/compiler/sea/VariableFactory.java trunk/sandbox/tobias/compiler/test/ trunk/sandbox/tobias/compiler/test/org/ trunk/sandbox/tobias/compiler/test/org/python/ trunk/sandbox/tobias/compiler/test/org/python/compiler/ trunk/sandbox/tobias/compiler/test/org/python/compiler/sea/ trunk/sandbox/tobias/compiler/test/org/python/compiler/sea/output/ trunk/sandbox/tobias/compiler/test/org/python/compiler/sea/output/GraphvizOutput.java trunk/sandbox/tobias/util/src/META-INF/ trunk/sandbox/tobias/util/src/META-INF/services/ trunk/sandbox/tobias/util/src/META-INF/services/org.python.core.FrameAccessor$Factory trunk/sandbox/tobias/util/src/org/python/frame/ trunk/sandbox/tobias/util/src/org/python/frame/JavaFrameAccessor.java Removed Paths: ------------- trunk/sandbox/tobias/compiler/src/org/python/compiler/AdvancedPreferences.java trunk/sandbox/tobias/compiler/src/org/python/compiler/BytecodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/BytecodeCodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/CodeGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/CodeGeneratorGraphVisitor.java trunk/sandbox/tobias/compiler/src/org/python/compiler/CompilerDirector.java trunk/sandbox/tobias/compiler/src/org/python/compiler/ConstantChecker.java trunk/sandbox/tobias/compiler/src/org/python/compiler/ConstraintsDefinition.java trunk/sandbox/tobias/compiler/src/org/python/compiler/DirectCodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/DirectGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/FlowGraphBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/FlowGraphGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/GeneratedCodeState.java trunk/sandbox/tobias/compiler/src/org/python/compiler/IntermediateCodeGenerator.java trunk/sandbox/tobias/compiler/src/org/python/compiler/IntermediateCodeGeneratorFactory.java trunk/sandbox/tobias/compiler/src/org/python/compiler/PragmaParser.java trunk/sandbox/tobias/compiler/src/org/python/compiler/ScopeBuilder.java trunk/sandbox/tobias/compiler/src/org/python/compiler/ScopeFactory.java trunk/sandbox/tobias/compiler/src/org/python/compiler/ScopeInformation.java trunk/sandbox/tobias/compiler/src/org/python/compiler/ScopesBuilder.java trunk/sandbox/tobias/compiler/src/org/python/compiler/SyntaxErrorPolicy.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/AbstractEnvironment.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/BytecodeBundle.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/BytecodeLoader.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ClassEnvironment.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/CodeInfo.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/CompilerFlag.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/CompilerPolicy.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/CompilerVariable.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/Environment.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/EnvironmentError.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/EnvironmentHolder.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/EnvironmentInfo.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/FunctionEnvironment.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/Future.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/GlobalEnvironment.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ScopeInfo.java trunk/sandbox/tobias/compiler/src/org/python/compiler/advanced/ast/ trunk/sandbox/tobias/compiler/src/org/python/compiler/bytecode/ Modified: trunk/sandbox/tobias/.classpath =================================================================== --- trunk/sandbox/tobias/.classpath 2009-03-30 14:21:06 UTC (rev 6120) +++ trunk/sandbox/tobias/.classpath 2009-03-30 15:57:27 UTC (rev 6121) @@ -9,6 +9,7 @@ <classpathentry kind="src" path="frame/test"/> <classpathentry kind="src" path="jython/build/gensrc"/> <classpathentry kind="src" path="jython/tests/java"/> + <classpathentry kind="src" path="compiler/test"/> <classpathentry kind="lib" path="jython/Demo/jreload/example.jar"/> <classpathentry kind="lib" path="jython/extlibs/antlr-2.7.7.jar"/> <classpathentry kind="lib" path="jython/extlibs/asm-3.1.jar"/> Modified: trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch =================================================================== --- trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch 2009-03-30 14:21:06 UTC (rev 6120) +++ trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch 2009-03-30 15:57:27 UTC (rev 6121) @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?><launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType"> -<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="antlr_gen,"/> -<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="antlr_gen,"/> +<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="brand-version,antlr_gen,"/> +<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="brand-version,antlr_gen,"/> <booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/> <booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/> <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> @@ -13,7 +13,16 @@ <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/> <booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="advanced-compiler"/> +<mapAttribute key="org.eclipse.ui.externaltools.ATTR_ANT_PROPERTIES"> +<mapEntry key="eclipse.pdebuild.scripts" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/scripts/"/> +<mapEntry key="eclipse.running" value="true"/> +<mapEntry key="eclipse.pdebuild.home" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/./"/> +<mapEntry key="eclipse.home" value="/Library/eclipse"/> +<mapEntry key="compile.dir" value="${project_loc}/target/build"/> +<mapEntry key="eclipse.pdebuild.templates" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/templates/"/> +</mapAttribute> <stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/advanced-compiler/jython/build.xml}"/> <stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/> <booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/> +<stringAttribute key="process_factory_id" value="org.eclipse.ant.ui.remoteAntProcessFactory"/> </launchConfiguration> Added: trunk/sandbox/tobias/.hg/patches/frames.patch =================================================================== --- trunk/sandbox/tobias/.hg/patches/frames.patch (rev 0) +++ trunk/sandbox/tobias/.hg/patches/frames.patch 2009-03-30 15:57:27 UTC (rev 6121) @@ -0,0 +1,1646 @@ +diff --git a/jython/src/org/python/compiler/ClassConstants.java b/jython/src/org/python/compiler/ClassConstants.java +--- a/jython/src/org/python/compiler/ClassConstants.java ++++ b/jython/src/org/python/compiler/ClassConstants.java +@@ -7,6 +7,7 @@ + final static String $pyStr = "Lorg/python/core/PyString;"; + final static String $pyUnicode = "Lorg/python/core/PyUnicode;"; + final static String $pyExc = "Lorg/python/core/PyException;"; ++ final static String $pyBaseFrame= "Lorg/python/core/PyBaseFrame;"; + final static String $pyFrame = "Lorg/python/core/PyFrame;"; + final static String $pyCode = "Lorg/python/core/PyCode;"; + final static String $pyInteger = "Lorg/python/core/PyInteger;"; +diff --git a/jython/src/org/python/compiler/CodeCompiler.java b/jython/src/org/python/compiler/CodeCompiler.java +--- a/jython/src/org/python/compiler/CodeCompiler.java ++++ b/jython/src/org/python/compiler/CodeCompiler.java +@@ -164,7 +164,7 @@ + } + + private void loadf_back() throws Exception { +- code.getfield("org/python/core/PyFrame", "f_back", $pyFrame); ++ code.getfield("org/python/core/PyFrame", "f_back", $pyBaseFrame); + } + + public int storeTop() throws Exception { +@@ -376,7 +376,7 @@ + } + SymInfo symInfo = upTbl.get(scope.freevars.elementAt(i)); + code.iconst(symInfo.env_index); +- code.invokevirtual("org/python/core/PyFrame", "getclosure", "(I)" + $pyObj); ++ code.invokevirtual("org/python/core/PyBaseFrame", "getclosure", "(I)" + $pyObj); + code.aastore(); + } + +@@ -780,7 +780,7 @@ + asname = a.getInternalAsname(); + code.ldc(name); + loadFrame(); +- code.invokestatic("org/python/core/imp", "importOneAs", "(" + $str + $pyFrame + ")" + $pyObj); ++ code.invokestatic("org/python/core/imp", "importOneAs", "(" + $str + $pyBaseFrame + ")" + $pyObj); + } else { + String name = a.getInternalName(); + asname = name; +@@ -788,7 +788,7 @@ + asname = asname.substring(0, asname.indexOf('.')); + code.ldc(name); + loadFrame(); +- code.invokestatic("org/python/core/imp", "importOne", "(" + $str + $pyFrame + ")" + $pyObj); ++ code.invokestatic("org/python/core/imp", "importOne", "(" + $str + $pyBaseFrame + ")" + $pyObj); + } + set(new Name(a, asname, expr_contextType.Store)); + } +@@ -826,7 +826,7 @@ + } + + loadFrame(); +- code.invokestatic("org/python/core/imp", "importAll", "(" + $str + $pyFrame + ")V"); ++ code.invokestatic("org/python/core/imp", "importAll", "(" + $str + $pyBaseFrame + ")V"); + } else { + java.util.List<String> fromNames = new ArrayList<String>();//[names.size()]; + java.util.List<String> asnames = new ArrayList<String>();//[names.size()]; +@@ -851,7 +851,7 @@ + } else { + code.iconst(node.getInternalLevel()); + } +- code.invokestatic("org/python/core/imp", "importFrom", "(" + $str + $strArr + $pyFrame + "I" + ")" + $pyObjArr); ++ code.invokestatic("org/python/core/imp", "importFrom", "(" + $str + $strArr + $pyBaseFrame + "I" + ")" + $pyObjArr); + int tmp = storeTop(); + for (int i = 0; i < names.size(); i++) { + code.aload(tmp); +@@ -1188,7 +1188,7 @@ + code.aload(excLocal); + loadFrame(); + +- code.invokestatic("org/python/core/Py", "addTraceback", "(" + $throwable + $pyFrame + ")V"); ++ code.invokestatic("org/python/core/Py", "addTraceback", "(" + $throwable + $pyBaseFrame + ")V"); + + inlineFinally(inFinally); + code.aload(excLocal); +@@ -1271,7 +1271,7 @@ + + loadFrame(); + +- code.invokestatic("org/python/core/Py", "setException", "(" + $throwable + $pyFrame + ")" + $pyExc); ++ code.invokestatic("org/python/core/Py", "setException", "(" + $throwable + $pyBaseFrame + ")" + $pyExc); + + int exc = code.getFinallyLocal("java/lang/Throwable"); + code.astore(exc); +@@ -2315,7 +2315,7 @@ + code.label(label_catch); + + loadFrame(); +- code.invokestatic("org/python/core/Py", "setException", "(" + $throwable + $pyFrame + ")" + $pyExc); ++ code.invokestatic("org/python/core/Py", "setException", "(" + $throwable + $pyBaseFrame + ")" + $pyExc); + code.pop(); + + code.invokestatic("org/python/core/Py", "getThreadState", "()Lorg/python/core/ThreadState;"); +diff --git a/jython/src/org/python/core/CompilerFlags.java b/jython/src/org/python/core/CompilerFlags.java +--- a/jython/src/org/python/core/CompilerFlags.java ++++ b/jython/src/org/python/core/CompilerFlags.java +@@ -83,7 +83,7 @@ + | CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT.flag + | CodeFlag.CO_FUTURE_WITH_STATEMENT.flag; + +- public static CompilerFlags getCompilerFlags(int flags, PyFrame frame) { ++ public static CompilerFlags getCompilerFlags(int flags, PyBaseFrame frame) { + if ((flags & ~CO_ALL_FEATURES) != 0) { + throw Py.ValueError("compile(): unrecognised flags"); + } +@@ -91,9 +91,9 @@ + } + + public static CompilerFlags getCompilerFlags(CompilerFlags flags, +- PyFrame frame) { +- if (frame != null && frame.f_code != null) { +- return frame.f_code.co_flags.combine(flags); ++ PyBaseFrame frame) { ++ if (frame != null && frame.getCode() != null) { ++ return frame.getCode().co_flags.combine(flags); + } else { + return flags; + } +diff --git a/jython/src/org/python/core/FrameAccessor.java b/jython/src/org/python/core/FrameAccessor.java +new file mode 100644 +--- /dev/null ++++ b/jython/src/org/python/core/FrameAccessor.java +@@ -0,0 +1,51 @@ ++package org.python.core; ++ ++import java.util.Comparator; ++import java.util.SortedSet; ++import java.util.TreeSet; ++ ++import org.python.util.ServiceLoader; ++ ++public abstract class FrameAccessor { ++ ++ protected abstract PyBaseFrame getFrame(); ++ ++ protected abstract void setFrame(PyBaseFrame frame); ++ ++ public static abstract class Factory { ++ protected abstract FrameAccessor createAccessor(); ++ ++ @Override ++ public final boolean equals(Object other) { ++ return other != null && getClass().equals(other.getClass()); ++ } ++ ++ protected abstract boolean isAvailable(); ++ ++ @Override ++ public final int hashCode() { ++ return getClass().hashCode(); ++ } ++ } ++ ++ static Factory getFactory() { ++ return best_factory; ++ } ++ ++ private static final Factory best_factory; ++ static { ++ SortedSet<Factory> factories = new TreeSet<Factory>( ++ new Comparator<Factory>() { ++ public int compare(Factory one, Factory two) { ++ throw new UnsupportedOperationException( ++ /* TODO: */"Need a way to sort Frame Accessor factories."); ++ } ++ }); ++ for (Factory candidate : ServiceLoader.load(Factory.class)) { ++ if (candidate.isAvailable()) { ++ factories.add(candidate); ++ } ++ } ++ best_factory = factories.isEmpty() ? null : factories.first(); ++ } ++} +diff --git a/jython/src/org/python/core/NewCompilerResources.java b/jython/src/org/python/core/NewCompilerResources.java +--- a/jython/src/org/python/core/NewCompilerResources.java ++++ b/jython/src/org/python/core/NewCompilerResources.java +@@ -16,7 +16,7 @@ + * Called from jython generated code when a statement like "from spam.eggs + * import *" is executed. + */ +- public static void importAll(PyObject module, PyFrame frame) { ++ public static void importAll(PyObject module, PyBaseFrame frame) { + // System.out.println("importAll(" + mod + ")"); + PyObject names; + boolean filter = true; +diff --git a/jython/src/org/python/core/Py.java b/jython/src/org/python/core/Py.java +--- a/jython/src/org/python/core/Py.java ++++ b/jython/src/org/python/core/Py.java +@@ -925,11 +925,11 @@ + printException(t, null, null); + } + +- public static void printException(Throwable t, PyFrame f) { ++ public static void printException(Throwable t, PyBaseFrame f) { + printException(t, f, null); + } + +- public static synchronized void printException(Throwable t, PyFrame f, ++ public static synchronized void printException(Throwable t, PyBaseFrame f, + PyObject file) { + StdoutWrapper stderr = Py.stderr; + +@@ -1122,12 +1122,12 @@ + } + + /* Helpers to implement finally clauses */ +- public static void addTraceback(Throwable t, PyFrame frame) { ++ public static void addTraceback(Throwable t, PyBaseFrame frame) { + Py.JavaError(t).tracebackHere(frame, true); + } + + /* Helpers to implement except clauses */ +- public static PyException setException(Throwable t, PyFrame frame) { ++ public static PyException setException(Throwable t, PyBaseFrame frame) { + PyException pye = Py.JavaError(t); + pye.normalize(); + pye.tracebackHere(frame); +@@ -1203,7 +1203,7 @@ + } + + if (globals == null || globals == Py.None) { +- globals = Py.getFrame().f_globals; ++ globals = Py.getFrame().getGlobals(); + } + + PyTableCode tc = null; +@@ -1275,16 +1275,16 @@ + } + + /* Get and set the current frame */ +- public static PyFrame getFrame() { ++ public static PyBaseFrame getFrame() { + ThreadState ts = getThreadState(); + if (ts == null) { + return null; + } +- return ts.frame; ++ return ts.getFrame(); + } + +- public static void setFrame(PyFrame f) { +- getThreadState().frame = f; ++ public static void setFrame(PyBaseFrame f) { ++ getThreadState().setFrame(f); + } + + /* A collection of functions for implementing the print statement */ +@@ -1530,7 +1530,7 @@ + public static PyObject makeClass(String name, PyObject[] bases, + PyCode code, PyObject doc, + PyObject[] closure_cells) { +- PyObject globals = getFrame().f_globals; ++ PyObject globals = getFrame().getGlobals(); + PyObject dict = code.call(Py.EmptyObjects, Py.NoKeywords, globals, Py.EmptyObjects, + new PyTuple(closure_cells)); + if (doc != null && dict.__finditem__("__doc__") == null) { +@@ -1554,7 +1554,7 @@ + * @return a new Python Class PyObject + */ + public static PyObject makeClass(String name, PyObject[] bases, PyObject dict) { +- PyFrame frame = getFrame(); ++ PyBaseFrame frame = getFrame(); + if (dict.__finditem__("__module__") == null) { + PyObject module = frame.getglobal("__name__"); + if (module != null) { +@@ -1572,7 +1572,7 @@ + metaclass = base.getType(); + } + } else { +- PyObject globals = frame.f_globals; ++ PyObject globals = frame.getGlobals(); + if (globals != null) { + metaclass = globals.__finditem__("__metaclass__"); + } +@@ -1617,7 +1617,7 @@ + } + + public static CompilerFlags getCompilerFlags(int flags, boolean dont_inherit) { +- final PyFrame frame; ++ final PyBaseFrame frame; + if (dont_inherit) { + frame = null; + } else { +@@ -1627,7 +1627,7 @@ + } + + public static CompilerFlags getCompilerFlags(CompilerFlags flags, boolean dont_inherit) { +- final PyFrame frame; ++ final PyBaseFrame frame; + if (dont_inherit) { + frame = null; + } else { +@@ -1984,7 +1984,7 @@ + } + } + +- public PyObject call(PyFrame frame, PyObject closure) { ++ public PyObject call(PyBaseFrame frame, PyObject closure) { + //XXX: what the heck is this? Looks like debug code, but it's + // been here a long time... + System.out.println("call #1"); +diff --git a/jython/src/org/python/core/PyBaseCode.java b/jython/src/org/python/core/PyBaseCode.java +--- a/jython/src/org/python/core/PyBaseCode.java ++++ b/jython/src/org/python/core/PyBaseCode.java +@@ -22,8 +22,9 @@ + return co_freevars != null && co_freevars.length > 0; + } + +- public PyObject call(PyFrame frame, PyObject closure) { ++ public PyObject call(PyBaseFrame _frame, PyObject closure) { + // System.err.println("tablecode call: "+co_name); ++ PyFrame frame = (PyFrame)_frame; + ThreadState ts = Py.getThreadState(); + if (ts.systemState == null) { + ts.systemState = Py.defaultSystemState; +@@ -34,26 +35,26 @@ + PyException previous_exception = ts.exception; + + // Push frame +- frame.f_back = ts.frame; +- if (frame.f_builtins == null) { +- if (frame.f_back != null) { +- frame.f_builtins = frame.f_back.f_builtins; ++ frame.setPrevious(ts.getFrame()); ++ if (frame.getBuiltins() == null) { ++ if (frame.getPrevious() != null) { ++ frame.setBuiltins(frame.getPrevious().getBuiltins()); + } else { + //System.err.println("ts: "+ts); + //System.err.println("ss: "+ts.systemState); +- frame.f_builtins = PySystemState.builtins; ++ frame.setBuiltins(PySystemState.builtins); + } + } + // nested scopes: setup env with closure + // this should only be done once, so let the frame take care of it + frame.setupEnv((PyTuple)closure); + +- ts.frame = frame; ++ ts.setFrame(frame); + + // Handle trace function for debugging + if (ts.tracefunc != null) { +- frame.f_lineno = co_firstlineno; +- frame.tracefunc = ts.tracefunc.traceCall(frame); ++ frame.setLineno(co_firstlineno); ++ frame.setTraceFunction(ts.tracefunc.traceCall(frame)); + } + + // Handle trace function for profiling +@@ -69,10 +70,11 @@ + PyException pye = Py.JavaError(t); + pye.tracebackHere(frame); + +- frame.f_lasti = -1; ++ frame.setLastI(-1); + +- if (frame.tracefunc != null) { +- frame.tracefunc.traceException(frame, pye); ++ TraceFunction tracefunc = frame.getTraceFunction(); ++ if (tracefunc != null) { ++ tracefunc.traceException(frame, pye); + } + if (ts.profilefunc != null) { + ts.profilefunc.traceException(frame, pye); +@@ -80,12 +82,13 @@ + + // Rethrow the exception to the next stack frame + ts.exception = previous_exception; +- ts.frame = ts.frame.f_back; ++ ts.setFrame(ts.getFrame().getPrevious()); + throw pye; + } + +- if (frame.tracefunc != null) { +- frame.tracefunc.traceReturn(frame, ret); ++ TraceFunction tracefunc = frame.getTraceFunction(); ++ if (tracefunc != null) { ++ tracefunc.traceReturn(frame, ret); + } + // Handle trace function for profiling + if (ts.profilefunc != null) { +@@ -95,7 +98,7 @@ + // Restore previously defined exception + ts.exception = previous_exception; + +- ts.frame = ts.frame.f_back; ++ ts.setFrame(ts.getFrame().getPrevious()); + + // Check for interruption, which is used for restarting the interpreter + // on Jython +@@ -288,7 +291,7 @@ + protected abstract PyObject interpret(PyFrame f, ThreadState ts); + + protected int getline(PyFrame f) { +- return f.f_lineno; ++ return f.getLineno(); + } + + // returns the augmented version of CompilerFlags (instead of just as a bit vector int) +diff --git a/jython/src/org/python/core/PyBaseFrame.java b/jython/src/org/python/core/PyBaseFrame.java +new file mode 100644 +--- /dev/null ++++ b/jython/src/org/python/core/PyBaseFrame.java +@@ -0,0 +1,121 @@ ++package org.python.core; ++ ++public abstract class PyBaseFrame extends PyObject { ++ ++ private static final String[] __members__ = {"f_back", "f_code", "f_locals", "f_globals", ++ "f_lineno", "f_builtins", "f_trace"}; ++ ++ public PyBaseFrame(PyType objtype) { ++ super(objtype); ++ } ++ ++ public PyBaseFrame(boolean ignored) { ++ super(ignored); ++ } ++ ++ public abstract void setderef(int index, PyObject value); ++ ++ public abstract PyObject getderef(int index); ++ ++ public abstract PyObject getclosure(int index); ++ ++ public abstract void delglobal(String index); ++ ++ public abstract void dellocal(String index); ++ ++ public abstract void dellocal(int index); ++ ++ public abstract void setglobal(String index, PyObject value); ++ ++ public abstract void setlocal(String index, PyObject value); ++ ++ public abstract void setlocal(int index, PyObject value); ++ ++ public abstract PyObject getglobal(String index); ++ ++ public abstract PyObject getname_or_null(String index); ++ ++ public abstract PyObject getname(String index); ++ ++ public abstract PyObject getlocal(int index); ++ ++ public abstract PyObject getLocals(); ++ ++ public abstract int getLastI(); ++ ++ public abstract void setLastI(int f_lasti); ++ ++ public abstract PyObject getBuiltins(); ++ ++ public abstract int getLineno(); ++ ++ public abstract PyObject getGlobals(); ++ ++ public abstract PyBaseCode getCode(); ++ ++ public abstract PyBaseFrame getPrevious(); ++ ++ public abstract TraceFunction getTraceFunction(); ++ ++ public abstract void setTraceFunction(TraceFunction trace); ++ ++ public PyBaseFrame() { ++ super(); ++ } ++ ++ public PyObject __dir__() { ++ PyString members[] = new PyString[__members__.length]; ++ for (int i = 0; i < __members__.length; i++) { ++ members[i] = new PyString(__members__[i]); ++ } ++ return new PyList(members); ++ } ++ ++ private void throwReadonly(String name) { ++ for (String member : __members__) { ++ if (member == name) { ++ throw Py.TypeError("readonly attribute"); ++ } ++ } ++ throw Py.AttributeError(name); ++ } ++ ++ public void __setattr__(String name, PyObject value) { ++ // In CPython, some of the frame's attributes are read/writeable ++ if (name == "f_trace") { ++ setTraceFunction(new PythonTraceFunction(value)); ++ } else { ++ throwReadonly(name); ++ } ++ // not yet implemented: ++ // f_exc_type ++ // f_exc_value ++ // f_exc_traceback ++ } ++ ++ public void __delattr__(String name) { ++ if (name == "f_trace") { ++ setTraceFunction(null); ++ } else { ++ throwReadonly(name); ++ } ++ // not yet implemented: ++ // f_exc_type ++ // f_exc_value ++ // f_exc_traceback ++ } ++ ++ public PyObject __findattr_ex__(String name) { ++ if (name == "f_locals") { ++ return getLocals(); ++ } else if (name == "f_trace") { ++ TraceFunction tracefunc = getTraceFunction(); ++ if (tracefunc instanceof PythonTraceFunction) { ++ return ((PythonTraceFunction)tracefunc).tracefunc; ++ } ++ return Py.None; ++ } ++ return super.__findattr_ex__(name); ++ } ++ ++} +\ No newline at end of file +diff --git a/jython/src/org/python/core/PyBytecode.java b/jython/src/org/python/core/PyBytecode.java +--- a/jython/src/org/python/core/PyBytecode.java ++++ b/jython/src/org/python/core/PyBytecode.java +@@ -204,11 +204,11 @@ + } + + private static String stringify_blocks(PyFrame f) { +- if (f.f_exits == null || f.f_lineno == 0) { ++ if (f.f_exits == null || f.getLineno() == 0) { + return "[]"; + } + StringBuilder buf = new StringBuilder("["); +- int len = f.f_lineno; ++ int len = f.getLineno(); + for (int i = 0; i < len; i++) { + buf.append(f.f_exits[i].toString()); + if (i < len - 1) { +@@ -222,7 +222,7 @@ + private void print_debug(int count, int next_instr, int line, int opcode, int oparg, PyStack stack, PyFrame f) { + if (debug) { + System.err.println(co_name + " " + line + ":" + +- count + "," + f.f_lasti + "> " + ++ count + "," + f.getLastI() + "> " + + get_opname().__getitem__(Py.newInteger(opcode)) + + (opcode >= Opcode.HAVE_ARGUMENT ? " " + oparg : "") + + ", stack: " + stack.toString() + +@@ -270,7 +270,7 @@ + // in a shadow version of the frame that we copy back to on entry/exit and downcalls + + if (debug) { +- System.err.println(co_name + ":" + f.f_lasti + "/" + co_code.length + ++ System.err.println(co_name + ":" + f.getLastI() + "/" + co_code.length + + ", cells:" + Arrays.toString(co_cellvars) + ", free:" + Arrays.toString(co_freevars)); + int i = 0; + for (String cellvar : co_cellvars) { +@@ -282,11 +282,11 @@ + get_dis().invoke("disassemble", this); + + } +- if (f.f_lasti >= co_code.length) { ++ if (f.getLastI() >= co_code.length) { + throw Py.SystemError(""); // XXX - chose an appropriate error!!! + } + +- next_instr = f.f_lasti; ++ next_instr = f.getLastI(); + + // the restore stack aspects should occur ONLY after a yield + boolean checkGeneratorInput = false; +@@ -301,7 +301,7 @@ + + while (!debug || (maxCount == -1 || count < maxCount)) { // XXX - replace with while(true) + +- if (f.tracefunc != null || debug) { ++ if (f.getTraceFunction() != null || debug) { + if (lineCache == null) { + lineCache = new LineCache(); + if (debug) { +@@ -334,7 +334,7 @@ + + count += 1; + next_instr += 1; +- f.f_lasti = next_instr; ++ f.setLastI(next_instr); + + switch (opcode) { + case Opcode.NOP: +@@ -702,7 +702,7 @@ + } + + case Opcode.LOAD_LOCALS: +- stack.push(f.f_locals); ++ stack.push(f.getf_locals()); + break; + + case Opcode.RETURN_VALUE: +@@ -828,7 +828,7 @@ + cell.ob_ref = f.f_fastlocals[i]; + } + } else { +- cell.ob_ref = f.f_locals.__finditem__(name); ++ cell.ob_ref = f.getf_locals().__finditem__(name); + } + } + stack.push(cell); +@@ -862,7 +862,7 @@ + cell.ob_ref = f.f_fastlocals[i]; + } + } else { +- cell.ob_ref = f.f_locals.__finditem__(name); ++ cell.ob_ref = f.getf_locals().__finditem__(name); + } + } + stack.push(cell.ob_ref); +@@ -941,7 +941,7 @@ + } + + case Opcode.IMPORT_NAME: { +- PyObject __import__ = f.f_builtins.__finditem__("__import__"); ++ PyObject __import__ = f.getBuiltins().__finditem__("__import__"); + if (__import__ == null) { + throw Py.ImportError("__import__ not found"); + } +@@ -950,9 +950,9 @@ + PyObject level = stack.pop(); + + if (level.asInt() != -1) { +- stack.push(__import__.__call__(new PyObject[]{name, f.f_globals, f.f_locals, fromlist, level})); ++ stack.push(__import__.__call__(new PyObject[]{name, f.getGlobals(), f.getf_locals(), fromlist, level})); + } else { +- stack.push(__import__.__call__(new PyObject[]{name, f.f_globals, f.f_locals, fromlist})); ++ stack.push(__import__.__call__(new PyObject[]{name, f.getGlobals(), f.getf_locals(), fromlist})); + } + break; + } +@@ -1118,7 +1118,7 @@ + if (code instanceof PyBytecode && ((PyBytecode) code).co_consts.length > 0) { + doc = ((PyBytecode) code).co_consts[0]; + } +- PyFunction func = new PyFunction(f.f_globals, defaults, code, doc); ++ PyFunction func = new PyFunction(f.getGlobals(), defaults, code, doc); + stack.push(func); + break; + } +@@ -1131,7 +1131,7 @@ + if (code instanceof PyBytecode && ((PyBytecode) code).co_consts.length > 0) { + doc = ((PyBytecode) code).co_consts[0]; + } +- PyFunction func = new PyFunction(f.f_globals, defaults, code, doc, closure_cells); ++ PyFunction func = new PyFunction(f.getGlobals(), defaults, code, doc, closure_cells); + stack.push(func); + break; + } +@@ -1154,7 +1154,7 @@ + Py.print(Py.getSystemState().stderr, + Py.newString( + String.format("XXX lineno: %d, opcode: %d\n", +- f.f_lasti, opcode))); ++ f.getLastI(), opcode))); + throw Py.SystemError("unknown opcode"); + + } // end switch +@@ -1236,10 +1236,10 @@ + f.f_savedlocals = stack.popN(stack.size()); + } + +- f.f_lasti = next_instr; // need to update on function entry, etc ++ f.setLastI(next_instr); // need to update on function entry, etc + + if (debug) { +- System.err.println(count + "," + f.f_lasti + "> Returning from " + why + ": " + retval + ++ System.err.println(count + "," + f.getLastI() + "> Returning from " + why + ": " + retval + + ", stack: " + stack.toString() + + ", blocks: " + stringify_blocks(f)); + } +@@ -1249,7 +1249,7 @@ + } + + if (co_flags.isFlagSet(CodeFlag.CO_GENERATOR) && why == Why.RETURN && retval == Py.None) { +- f.f_lasti = -1; ++ f.setLastI(-1); + } + + return retval; +@@ -1503,7 +1503,7 @@ + + @Override + protected int getline(PyFrame f) { +- int addrq = f.f_lasti; ++ int addrq = f.getLastI(); + int size = co_lnotab.length / 2; + int p = 0; + int line = co_firstlineno; +diff --git a/jython/src/org/python/core/PyClass.java b/jython/src/org/python/core/PyClass.java +--- a/jython/src/org/python/core/PyClass.java ++++ b/jython/src/org/python/core/PyClass.java +@@ -62,9 +62,9 @@ + protected void findModule(PyObject dict) { + PyObject module = dict.__finditem__("__module__"); + if (module == null || module == Py.None) { +- PyFrame f = Py.getFrame(); ++ PyBaseFrame f = Py.getFrame(); + if (f != null) { +- PyObject nm = f.f_globals.__finditem__("__name__"); ++ PyObject nm = f.getGlobals().__finditem__("__name__"); + if (nm != null) { + dict.__setitem__("__module__", nm); + } +diff --git a/jython/src/org/python/core/PyCode.java b/jython/src/org/python/core/PyCode.java +--- a/jython/src/org/python/core/PyCode.java ++++ b/jython/src/org/python/core/PyCode.java +@@ -8,9 +8,9 @@ + { + public String co_name; + +- abstract public PyObject call(PyFrame frame, PyObject closure); ++ abstract public PyObject call(PyBaseFrame frame, PyObject closure); + +- public PyObject call(PyFrame frame) { ++ public PyObject call(PyBaseFrame frame) { + return call(frame, null); + } + +diff --git a/jython/src/org/python/core/PyException.java b/jython/src/org/python/core/PyException.java +--- a/jython/src/org/python/core/PyException.java ++++ b/jython/src/org/python/core/PyException.java +@@ -136,7 +136,7 @@ + * + * @param here the current PyFrame + */ +- public void tracebackHere(PyFrame here) { ++ public void tracebackHere(PyBaseFrame here) { + tracebackHere(here, false); + } + +@@ -146,7 +146,7 @@ + * @param here the current PyFrame + * @param isFinally whether caller is a Python finally block + */ +- public void tracebackHere(PyFrame here, boolean isFinally) { ++ public void tracebackHere(PyBaseFrame here, boolean isFinally) { + if (!isReRaise && here != null) { + // the frame is either inapplicable or already registered (from a finally) + // during a re-raise +diff --git a/jython/src/org/python/core/PyFrame.java b/jython/src/org/python/core/PyFrame.java +--- a/jython/src/org/python/core/PyFrame.java ++++ b/jython/src/org/python/core/PyFrame.java +@@ -4,11 +4,13 @@ + /** + * A Python frame object. + */ +-public class PyFrame extends PyObject ++public class PyFrame extends PyBaseFrame + { +- public PyFrame f_back; ++ // These are public because they are accessed from generated code ++ ++ public PyBaseFrame f_back; + +- public PyBaseCode f_code; ++ public final PyBaseCode f_code; + + public PyObject f_locals; + +@@ -18,6 +20,10 @@ + + public PyObject f_builtins; + ++ public int f_lasti; ++ ++ // Internal ++ + public PyObject[] f_fastlocals; + + /** nested scopes: cell + free env. */ +@@ -27,8 +33,6 @@ + + public int f_nfreevars; + +- public int f_lasti; +- + public Object[] f_savedlocals; + + private int env_j = 0; +@@ -36,11 +40,11 @@ + private Object generatorInput = Py.None; + + // with context exits - used by generated bytecode +- public PyObject[] f_exits; ++ public PyObject[] f_exits; // Impl. + + /** an interface to functions suitable for tracing, e.g. via + * sys.settrace(). */ +- public TraceFunction tracefunc; ++ private TraceFunction tracefunc; // Publ. + + private static final String NAME_ERROR_MSG = "name '%.200s' is not defined"; + +@@ -49,8 +53,62 @@ + private static final String UNBOUNDLOCAL_ERROR_MSG = + "local variable '%.200s' referenced before assignment"; + +- private static final String[] __members__ = {"f_back", "f_code", "f_locals", "f_globals", +- "f_lineno", "f_builtins", "f_trace"}; ++ @Override ++ public PyBaseFrame getPrevious() { ++ return f_back; ++ } ++ ++ void setPrevious(PyBaseFrame f_back) { ++ this.f_back = f_back; ++ } ++ ++ @Override ++ public PyBaseCode getCode() { ++ return f_code; ++ } ++ ++ @Override ++ public PyObject getGlobals() { ++ return f_globals; ++ } ++ ++ void setLineno(int f_lineno) { ++ this.f_lineno = f_lineno; ++ } ++ ++ @Override ++ public int getLineno() { ++ return f_lineno; ++ } ++ ++ void setBuiltins(PyObject f_builtins) { ++ this.f_builtins = f_builtins; ++ } ++ ++ @Override ++ public PyObject getBuiltins() { ++ return f_builtins; ++ } ++ ++ @Override ++ public void setLastI(int f_lasti) { ++ this.f_lasti = f_lasti; ++ } ++ ++ @Override ++ public int getLastI() { ++ return f_lasti; ++ } ++ ++ @Override ++ public TraceFunction getTraceFunction() { ++ return tracefunc; ++ } ++ ++ @Override ++ public void setTraceFunction(TraceFunction trace) { ++ tracefunc = trace; ++ } + + public PyFrame(PyBaseCode code, PyObject locals, PyObject globals, + PyObject builtins) +@@ -106,14 +164,6 @@ + } + } + +- public PyObject __dir__() { +- PyString members[] = new PyString[__members__.length]; +- for (int i = 0; i < __members__.length; i++) { +- members[i] = new PyString(__members__[i]); +- } +- return new PyList(members); +- } +- + void setGeneratorInput(Object value) { + generatorInput = value; + } +@@ -128,58 +178,13 @@ + return generatorInput; + } + +- private void throwReadonly(String name) { +- for (String member : __members__) { +- if (member == name) { +- throw Py.TypeError("readonly attribute"); +- } +- } +- throw Py.AttributeError(name); +- } +- +- public void __setattr__(String name, PyObject value) { +- // In CPython, some of the frame's attributes are read/writeable +- if (name == "f_trace") { +- tracefunc = new PythonTraceFunction(value); +- } else { +- throwReadonly(name); +- } +- // not yet implemented: +- // f_exc_type +- // f_exc_value +- // f_exc_traceback +- } +- +- public void __delattr__(String name) { +- if (name == "f_trace") { +- tracefunc = null; +- } else { +- throwReadonly(name); +- } +- // not yet implemented: +- // f_exc_type +- // f_exc_value +- // f_exc_traceback +- } +- +- public PyObject __findattr_ex__(String name) { +- if (name == "f_locals") { +- return getLocals(); +- } else if (name == "f_trace") { +- if (tracefunc instanceof PythonTraceFunction) { +- return ((PythonTraceFunction)tracefunc).tracefunc; +- } +- return Py.None; +- } +- return super.__findattr_ex__(name); +- } +- + /** + * Return the locals dict. First merges the fast locals into + * f_locals, then returns the updated f_locals. + * + * @return a PyObject mapping of locals + */ ++ @Override + public PyObject getLocals() { + if (f_locals == null) { + f_locals = new PyStringMap(); +@@ -241,6 +246,7 @@ + return f_code.getline(this); + } + ++ @Override + public PyObject getlocal(int index) { + if (f_fastlocals != null) { + PyObject ret = f_fastlocals[index]; +@@ -259,6 +265,7 @@ + throw Py.UnboundLocalError(String.format(UNBOUNDLOCAL_ERROR_MSG, name)); + } + ++ @Override + public PyObject getname(String index) { + PyObject ret; + if (f_locals == null || f_locals == f_globals) { +@@ -276,6 +283,7 @@ + throw Py.NameError(String.format(NAME_ERROR_MSG, index)); + } + ++ @Override + public PyObject getname_or_null(String index) { + PyObject ret; + if (f_locals == null || f_locals == f_globals) { +@@ -290,6 +298,7 @@ + return ret; + } + ++ @Override + public PyObject getglobal(String index) { + PyObject ret = doGetglobal(index); + if (ret != null) { +@@ -311,6 +320,7 @@ + return f_builtins.__finditem__(index); + } + ++ @Override + public void setlocal(int index, PyObject value) { + if (f_fastlocals != null) { + f_fastlocals[index] = value; +@@ -319,6 +329,7 @@ + } + } + ++ @Override + public void setlocal(String index, PyObject value) { + if (f_locals != null) { + f_locals.__setitem__(index, value); +@@ -327,10 +338,12 @@ + } + } + ++ @Override + public void setglobal(String index, PyObject value) { + f_globals.__setitem__(index, value); + } + ++ @Override + public void dellocal(int index) { + if (f_fastlocals != null) { + if (f_fastlocals[index] == null) { +@@ -343,6 +356,7 @@ + } + } + ++ @Override + public void dellocal(String index) { + if (f_locals != null) { + try { +@@ -358,6 +372,7 @@ + } + } + ++ @Override + public void delglobal(String index) { + try { + f_globals.__delitem__(index); +@@ -371,10 +386,12 @@ + + // nested scopes helpers + ++ @Override + public PyObject getclosure(int index) { + return f_env[index]; + } + ++ @Override + public PyObject getderef(int index) { + PyObject obj = f_env[index].ob_ref; + if (obj != null) { +@@ -389,6 +406,7 @@ + throw Py.UnboundLocalError(String.format(UNBOUNDLOCAL_ERROR_MSG, name)); + } + ++ @Override + public void setderef(int index, PyObject value) { + f_env[index].ob_ref = value; + } +diff --git a/jython/src/org/python/core/PyObject.java b/jython/src/org/python/core/PyObject.java +--- a/jython/src/org/python/core/PyObject.java ++++ b/jython/src/org/python/core/PyObject.java +@@ -3459,7 +3459,7 @@ + } + } else { + ThreadState ts = Py.getThreadState(); +- if (ts.frame == null) { ++ if (ts.getFrame() == null) { + Py.maybeSystemExit(e); + } + if (Options.showPythonProxyExceptions) { +diff --git a/jython/src/org/python/core/PySystemState.java b/jython/src/org/python/core/PySystemState.java +--- a/jython/src/org/python/core/PySystemState.java ++++ b/jython/src/org/python/core/PySystemState.java +@@ -140,6 +140,8 @@ + public PyObject __dict__; + + private int recursionlimit = 1000; ++ ++ private final FrameAccessor.Factory frameAccessorFactory = FrameAccessor.getFactory(); + + public PySystemState() { + initialize(); +@@ -1157,21 +1159,42 @@ + Py.getThreadState().exception = null; + } + +- public static PyFrame _getframe() { ++ public static PyBaseFrame _getframe() { + return _getframe(-1); + } + +- public static PyFrame _getframe(int depth) { +- PyFrame f = Py.getFrame(); ++ public static PyBaseFrame _getframe(int depth) { ++ PyBaseFrame f = Py.getFrame(); + + while (depth > 0 && f != null) { +- f = f.f_back; ++ f = f.getPrevious(); + --depth; + } + if (f == null) + throw Py.ValueError("call stack is not deep enough"); + return f; + } ++ ++ FrameAccessor newFrameAccessor() { ++ if (frameAccessorFactory != null) { ++ return frameAccessorFactory.createAccessor(); ++ } else { ++ return new FrameStore(); ++ } ++ } ++} ++ ++final class FrameStore extends FrameAccessor { ++ private PyBaseFrame frame = null; ++ @Override ++ protected PyBaseFrame getFrame() { ++ return frame; ++ } ++ ++ @Override ++ protected void setFrame(PyBaseFrame frame) { ++ this.frame = frame; ++ } + } + + class PySystemStateFunctions extends PyBuiltinFunctionSet +diff --git a/jython/src/org/python/core/PyTableCode.java b/jython/src/org/python/core/PyTableCode.java +--- a/jython/src/org/python/core/PyTableCode.java ++++ b/jython/src/org/python/core/PyTableCode.java +@@ -122,8 +122,9 @@ + } + + @Override +- public PyObject call(PyFrame frame, PyObject closure) { ++ public PyObject call(PyBaseFrame _frame, PyObject closure) { + // System.err.println("tablecode call: "+co_name); ++ PyFrame frame = (PyFrame)_frame; + ThreadState ts = Py.getThreadState(); + if (ts.systemState == null) { + ts.systemState = Py.defaultSystemState; +@@ -134,26 +135,26 @@ + PyException previous_exception = ts.exception; + + // Push frame +- frame.f_back = ts.frame; +- if (frame.f_builtins == null) { +- if (frame.f_back != null) { +- frame.f_builtins = frame.f_back.f_builtins; ++ frame.setPrevious(ts.getFrame()); ++ if (frame.getBuiltins() == null) { ++ if (frame.getPrevious() != null) { ++ frame.setBuiltins(frame.getPrevious().getBuiltins()); + } else { + //System.err.println("ts: "+ts); + //System.err.println("ss: "+ts.systemState); +- frame.f_builtins = PySystemState.builtins; ++ frame.setBuiltins(PySystemState.builtins); + } + } + // nested scopes: setup env with closure + // this should only be done once, so let the frame take care of it + frame.setupEnv((PyTuple)closure); + +- ts.frame = frame; ++ ts.setFrame(frame); + + // Handle trace function for debugging + if (ts.tracefunc != null) { +- frame.f_lineno = co_firstlineno; +- frame.tracefunc = ts.tracefunc.traceCall(frame); ++ frame.setLineno(co_firstlineno); ++ frame.setTraceFunction(ts.tracefunc.traceCall(frame)); + } + + // Handle trace function for profiling +@@ -169,10 +170,11 @@ + PyException pye = Py.JavaError(t); + pye.tracebackHere(frame); + +- frame.f_lasti = -1; ++ frame.setLastI(-1); + +- if (frame.tracefunc != null) { +- frame.tracefunc.traceException(frame, pye); ++ TraceFunction tracefunc = frame.getTraceFunction(); ++ if (tracefunc != null) { ++ tracefunc.traceException(frame, pye); + } + if (ts.profilefunc != null) { + ts.profilefunc.traceException(frame, pye); +@@ -180,12 +182,13 @@ + + // Rethrow the exception to the next stack frame + ts.exception = previous_exception; +- ts.frame = ts.frame.f_back; ++ ts.setFrame(ts.getFrame().getPrevious()); + throw pye; + } + +- if (frame.tracefunc != null) { +- frame.tracefunc.traceReturn(frame, ret); ++ TraceFunction tracefunc = frame.getTraceFunction(); ++ if (tracefunc != null) { ++ tracefunc.traceReturn(frame, ret); + } + // Handle trace function for profiling + if (ts.profilefunc != null) { +@@ -195,7 +198,7 @@ + // Restore previously defined exception + ts.exception = previous_exception; + +- ts.frame = ts.frame.f_back; ++ ts.setFrame(ts.getFrame().getPrevious()); + + // Check for interruption, which is used for restarting the interpreter + // on Jython +diff --git a/jython/src/org/python/core/PyTraceback.java b/jython/src/org/python/core/PyTraceback.java +--- a/jython/src/org/python/core/PyTraceback.java ++++ b/jython/src/org/python/core/PyTraceback.java +@@ -17,27 +17,27 @@ + public PyObject tb_next; + + @ExposedGet +- public PyFrame tb_frame; ++ public PyBaseFrame tb_frame; + + @ExposedGet + public int tb_lineno; + +- public PyTraceback(PyTraceback next, PyFrame frame) { ++ public PyTraceback(PyTraceback next, PyBaseFrame frame) { + tb_next = next; + tb_frame = frame; +- tb_lineno = frame.getline(); ++ tb_lineno = frame.getLineno(); + } + + private String tracebackInfo() { +- if (tb_frame == null || tb_frame.f_code == null) { ++ if (tb_frame == null || tb_frame.getCode() == null) { + return String.format(" (no code object) at line %s\n", tb_lineno); + } + String line = null; +- if (tb_frame.f_code.co_filename != null) { +- line = getLine(tb_frame.f_code.co_filename, tb_lineno); ++ if (tb_frame.getCode().co_filename != null) { ++ line = getLine(tb_frame.getCode().co_filename, tb_lineno); + } + return String.format(" File \"%.500s\", line %d, in %.500s\n%s", +- tb_frame.f_code.co_filename, tb_lineno, tb_frame.f_code.co_name, ++ tb_frame.getCode().co_filename, tb_linen... [truncated message content] |
From: <fwi...@us...> - 2009-03-30 14:21:18
|
Revision: 6120 http://jython.svn.sourceforge.net/jython/?rev=6120&view=rev Author: fwierzbicki Date: 2009-03-30 14:21:06 +0000 (Mon, 30 Mar 2009) Log Message: ----------- Only test single item dicts in test_same_as_repr Modified Paths: -------------- trunk/jython/Lib/test/test_pprint.py Modified: trunk/jython/Lib/test/test_pprint.py =================================================================== --- trunk/jython/Lib/test/test_pprint.py 2009-03-30 14:19:24 UTC (rev 6119) +++ trunk/jython/Lib/test/test_pprint.py 2009-03-30 14:21:06 UTC (rev 6120) @@ -120,10 +120,10 @@ {}, dict2(), dict3(), verify, pprint, -6, -6L, -6-6j, -1.5, "x", uni("x"), (3,), [3], {3: 6}, - (1,2), [3,4], {5: 6, 7: 8}, + (1,2), [3,4], {5: 6}, tuple2((1,2)), tuple3((1,2)), tuple3(range(100)), [3,4], list2([3,4]), list3([3,4]), list3(range(100)), - {5: 6, 7: 8}, dict2({5: 6}), dict3({5: 6}), + dict2({5: 6}), dict3({5: 6}), range(10, -11, -1) ): native = repr(simple) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-03-30 14:19:35
|
Revision: 6119 http://jython.svn.sourceforge.net/jython/?rev=6119&view=rev Author: fwierzbicki Date: 2009-03-30 14:19:24 +0000 (Mon, 30 Mar 2009) Log Message: ----------- from http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_pprint@51333 Added Paths: ----------- trunk/jython/Lib/test/test_pprint.py Added: trunk/jython/Lib/test/test_pprint.py =================================================================== --- trunk/jython/Lib/test/test_pprint.py (rev 0) +++ trunk/jython/Lib/test/test_pprint.py 2009-03-30 14:19:24 UTC (rev 6119) @@ -0,0 +1,217 @@ +import pprint +import test.test_support +import unittest + +try: + uni = unicode +except NameError: + def uni(x): + return x + +# list, tuple and dict subclasses that do or don't overwrite __repr__ +class list2(list): + pass + +class list3(list): + def __repr__(self): + return list.__repr__(self) + +class tuple2(tuple): + pass + +class tuple3(tuple): + def __repr__(self): + return tuple.__repr__(self) + +class dict2(dict): + pass + +class dict3(dict): + def __repr__(self): + return dict.__repr__(self) + +class QueryTestCase(unittest.TestCase): + + def setUp(self): + self.a = range(100) + self.b = range(200) + self.a[-12] = self.b + + def test_basic(self): + # Verify .isrecursive() and .isreadable() w/o recursion + verify = self.assert_ + pp = pprint.PrettyPrinter() + for safe in (2, 2.0, 2j, "abc", [3], (2,2), {3: 3}, uni("yaddayadda"), + self.a, self.b): + # module-level convenience functions + verify(not pprint.isrecursive(safe), + "expected not isrecursive for %r" % (safe,)) + verify(pprint.isreadable(safe), + "expected isreadable for %r" % (safe,)) + # PrettyPrinter methods + verify(not pp.isrecursive(safe), + "expected not isrecursive for %r" % (safe,)) + verify(pp.isreadable(safe), + "expected isreadable for %r" % (safe,)) + + def test_knotted(self): + # Verify .isrecursive() and .isreadable() w/ recursion + # Tie a knot. + self.b[67] = self.a + # Messy dict. + self.d = {} + self.d[0] = self.d[1] = self.d[2] = self.d + + verify = self.assert_ + pp = pprint.PrettyPrinter() + + for icky in self.a, self.b, self.d, (self.d, self.d): + verify(pprint.isrecursive(icky), "expected isrecursive") + verify(not pprint.isreadable(icky), "expected not isreadable") + verify(pp.isrecursive(icky), "expected isrecursive") + verify(not pp.isreadable(icky), "expected not isreadable") + + # Break the cycles. + self.d.clear() + del self.a[:] + del self.b[:] + + for safe in self.a, self.b, self.d, (self.d, self.d): + # module-level convenience functions + verify(not pprint.isrecursive(safe), + "expected not isrecursive for %r" % (safe,)) + verify(pprint.isreadable(safe), + "expected isreadable for %r" % (safe,)) + # PrettyPrinter methods + verify(not pp.isrecursive(safe), + "expected not isrecursive for %r" % (safe,)) + verify(pp.isreadable(safe), + "expected isreadable for %r" % (safe,)) + + def test_unreadable(self): + # Not recursive but not readable anyway + verify = self.assert_ + pp = pprint.PrettyPrinter() + for unreadable in type(3), pprint, pprint.isrecursive: + # module-level convenience functions + verify(not pprint.isrecursive(unreadable), + "expected not isrecursive for %r" % (unreadable,)) + verify(not pprint.isreadable(unreadable), + "expected not isreadable for %r" % (unreadable,)) + # PrettyPrinter methods + verify(not pp.isrecursive(unreadable), + "expected not isrecursive for %r" % (unreadable,)) + verify(not pp.isreadable(unreadable), + "expected not isreadable for %r" % (unreadable,)) + + def test_same_as_repr(self): + # Simple objects, small containers and classes that overwrite __repr__ + # For those the result should be the same as repr(). + # Ahem. The docs don't say anything about that -- this appears to + # be testing an implementation quirk. Starting in Python 2.5, it's + # not true for dicts: pprint always sorts dicts by key now; before, + # it sorted a dict display if and only if the display required + # multiple lines. For that reason, dicts with more than one element + # aren't tested here. + verify = self.assert_ + for simple in (0, 0L, 0+0j, 0.0, "", uni(""), + (), tuple2(), tuple3(), + [], list2(), list3(), + {}, dict2(), dict3(), + verify, pprint, + -6, -6L, -6-6j, -1.5, "x", uni("x"), (3,), [3], {3: 6}, + (1,2), [3,4], {5: 6, 7: 8}, + tuple2((1,2)), tuple3((1,2)), tuple3(range(100)), + [3,4], list2([3,4]), list3([3,4]), list3(range(100)), + {5: 6, 7: 8}, dict2({5: 6}), dict3({5: 6}), + range(10, -11, -1) + ): + native = repr(simple) + for function in "pformat", "saferepr": + f = getattr(pprint, function) + got = f(simple) + verify(native == got, "expected %s got %s from pprint.%s" % + (native, got, function)) + + def test_basic_line_wrap(self): + # verify basic line-wrapping operation + o = {'RPM_cal': 0, + 'RPM_cal2': 48059, + 'Speed_cal': 0, + 'controldesk_runtime_us': 0, + 'main_code_runtime_us': 0, + 'read_io_runtime_us': 0, + 'write_io_runtime_us': 43690} + exp = """\ +{'RPM_cal': 0, + 'RPM_cal2': 48059, + 'Speed_cal': 0, + 'controldesk_runtime_us': 0, + 'main_code_runtime_us': 0, + 'read_io_runtime_us': 0, + 'write_io_runtime_us': 43690}""" + for type in [dict, dict2]: + self.assertEqual(pprint.pformat(type(o)), exp) + + o = range(100) + exp = '[%s]' % ',\n '.join(map(str, o)) + for type in [list, list2]: + self.assertEqual(pprint.pformat(type(o)), exp) + + o = tuple(range(100)) + exp = '(%s)' % ',\n '.join(map(str, o)) + for type in [tuple, tuple2]: + self.assertEqual(pprint.pformat(type(o)), exp) + + # indent parameter + o = range(100) + exp = '[ %s]' % ',\n '.join(map(str, o)) + for type in [list, list2]: + self.assertEqual(pprint.pformat(type(o), indent=4), exp) + + def test_sorted_dict(self): + # Starting in Python 2.5, pprint sorts dict displays by key regardless + # of how small the dictionary may be. + # Before the change, on 32-bit Windows pformat() gave order + # 'a', 'c', 'b' here, so this test failed. + d = {'a': 1, 'b': 1, 'c': 1} + self.assertEqual(pprint.pformat(d), "{'a': 1, 'b': 1, 'c': 1}") + self.assertEqual(pprint.pformat([d, d]), + "[{'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 1}]") + + # The next one is kind of goofy. The sorted order depends on the + # alphabetic order of type names: "int" < "str" < "tuple". Before + # Python 2.5, this was in the test_same_as_repr() test. It's worth + # keeping around for now because it's one of few tests of pprint + # against a crazy mix of types. + self.assertEqual(pprint.pformat({"xy\tab\n": (3,), 5: [[]], (): {}}), + r"{5: [[]], 'xy\tab\n': (3,), (): {}}") + + def test_subclassing(self): + o = {'names with spaces': 'should be presented using repr()', + 'others.should.not.be': 'like.this'} + exp = """\ +{'names with spaces': 'should be presented using repr()', + others.should.not.be: like.this}""" + self.assertEqual(DottedPrettyPrinter().pformat(o), exp) + + +class DottedPrettyPrinter(pprint.PrettyPrinter): + + def format(self, object, context, maxlevels, level): + if isinstance(object, str): + if ' ' in object: + return repr(object), 1, 0 + else: + return object, 0, 0 + else: + return pprint.PrettyPrinter.format( + self, object, context, maxlevels, level) + + +def test_main(): + test.test_support.run_unittest(QueryTestCase) + + +if __name__ == "__main__": + test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-03-30 07:17:49
|
Revision: 6118 http://jython.svn.sourceforge.net/jython/?rev=6118&view=rev Author: thobes Date: 2009-03-30 07:17:38 +0000 (Mon, 30 Mar 2009) Log Message: ----------- Fix to bug 1294. Modified Paths: -------------- trunk/jython/src/org/python/core/Py.java Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2009-03-29 23:21:00 UTC (rev 6117) +++ trunk/jython/src/org/python/core/Py.java 2009-03-30 07:17:38 UTC (rev 6118) @@ -1219,6 +1219,19 @@ public static void exec(PyObject o, PyObject globals, PyObject locals) { PyCode code; int flags = 0; + if (o instanceof PyTuple) { + PyTuple tuple = (PyTuple) o; + int len = tuple.__len__(); + if ((globals == null || globals.equals(None)) + && (locals == null || locals.equals(None)) + && (len >= 2 && len <= 3)) { + o = tuple.__getitem__(0); + globals = tuple.__getitem__(1); + if (len == 3) { + locals = tuple.__getitem__(2); + } + } + } if (o instanceof PyCode) { code = (PyCode) o; if (locals == null && o instanceof PyBaseCode && ((PyBaseCode) o).hasFreevars()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |