You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <fwi...@us...> - 2009-09-09 12:11:54
|
Revision: 6774 http://jython.svn.sourceforge.net/jython/?rev=6774&view=rev Author: fwierzbicki Date: 2009-09-09 12:11:47 +0000 (Wed, 09 Sep 2009) Log Message: ----------- tab -> spaces. Modified Paths: -------------- trunk/jython/src/org/python/antlr/PythonTree.java Modified: trunk/jython/src/org/python/antlr/PythonTree.java =================================================================== --- trunk/jython/src/org/python/antlr/PythonTree.java 2009-09-09 05:47:17 UTC (rev 6773) +++ trunk/jython/src/org/python/antlr/PythonTree.java 2009-09-09 12:11:47 UTC (rev 6774) @@ -18,19 +18,19 @@ private CommonTree node; private PythonTree parent; - /** A single token is the payload */ - //private Token token; + /** A single token is the payload */ + //private Token token; - /** What token indexes bracket all tokens associated with this node - * and below? - */ - //protected int startIndex=-1, stopIndex=-1; + /** What token indexes bracket all tokens associated with this node + * and below? + */ + //protected int startIndex=-1, stopIndex=-1; - /** Who is the parent node of this node; if null, implies node is root */ - //private PythonTree parent; + /** Who is the parent node of this node; if null, implies node is root */ + //private PythonTree parent; - /** What index is this node in the child list? Range: 0..n-1 */ - //private int childIndex = -1; + /** What index is this node in the child list? Range: 0..n-1 */ + //private int childIndex = -1; public PythonTree() { node = new CommonTree(); @@ -60,73 +60,73 @@ charStartIndex = tree.getCharStartIndex(); charStopIndex = tree.getCharStopIndex(); } - + public CommonTree getNode() { return node; } - public Token getToken() { - return node.getToken(); - } + public Token getToken() { + return node.getToken(); + } - public PythonTree dupNode() { - return new PythonTree(this); - } + public PythonTree dupNode() { + return new PythonTree(this); + } - public boolean isNil() { - return node.isNil(); - } + public boolean isNil() { + return node.isNil(); + } - public int getAntlrType() { - return node.getType(); - } + public int getAntlrType() { + return node.getType(); + } - public String getText() { - return node.getText(); - } + public String getText() { + return node.getText(); + } - public int getLine() { - if (node.getToken()==null || node.getToken().getLine()==0) { - if ( getChildCount()>0 ) { - return getChild(0).getLine(); - } - return 1; - } - return node.getToken().getLine(); - } + public int getLine() { + if (node.getToken()==null || node.getToken().getLine()==0) { + if ( getChildCount()>0 ) { + return getChild(0).getLine(); + } + return 1; + } + return node.getToken().getLine(); + } - public int getCharPositionInLine() { + public int getCharPositionInLine() { Token token = node.getToken(); - if (token==null || token.getCharPositionInLine()==-1) { - if (getChildCount()>0) { - return getChild(0).getCharPositionInLine(); - } - return 0; - } else if (token != null && token.getCharPositionInLine() == -2) { + if (token==null || token.getCharPositionInLine()==-1) { + if (getChildCount()>0) { + return getChild(0).getCharPositionInLine(); + } + return 0; + } else if (token != null && token.getCharPositionInLine() == -2) { //XXX: yucky fix because CPython's ast uses -1 as a real value // for char pos in certain circumstances (for example, the // char pos of multi-line strings. I would just use -1, // but ANTLR is using -1 in special ways also. return -1; } - return token.getCharPositionInLine(); - } + return token.getCharPositionInLine(); + } - public int getTokenStartIndex() { + public int getTokenStartIndex() { return node.getTokenStartIndex(); - } + } - public void setTokenStartIndex(int index) { - node.setTokenStartIndex(index); - } + public void setTokenStartIndex(int index) { + node.setTokenStartIndex(index); + } - public int getTokenStopIndex() { + public int getTokenStopIndex() { return node.getTokenStopIndex(); - } + } - public void setTokenStopIndex(int index) { - node.setTokenStopIndex(index); - } + public void setTokenStopIndex(int index) { + node.setTokenStopIndex(index); + } public int getCharStartIndex() { if (charStartIndex == -1 && node.getToken() != null) { @@ -160,33 +160,33 @@ charStopIndex = index; } - public int getChildIndex() { - return node.getChildIndex(); - } + public int getChildIndex() { + return node.getChildIndex(); + } - public PythonTree getParent() { - return parent; - } + public PythonTree getParent() { + return parent; + } - public void setParent(PythonTree t) { - this.parent = t; - } + public void setParent(PythonTree t) { + this.parent = t; + } - public void setChildIndex(int index) { - node.setChildIndex(index); - } + public void setChildIndex(int index) { + node.setChildIndex(index); + } @Override public String toString() { if (isNil()) { return "None"; } - if ( getAntlrType()==Token.INVALID_TOKEN_TYPE ) { - return "<errornode>"; - } - if ( node.getToken()==null ) { - return null; - } + if ( getAntlrType()==Token.INVALID_TOKEN_TYPE ) { + return "<errornode>"; + } + if ( node.getToken()==null ) { + return null; + } return node.getToken().getText() + "(" + this.getLine() + "," + this.getCharPositionInLine() + ")"; } @@ -251,203 +251,203 @@ } //XXX: From here down copied from org.antlr.runtime.tree.BaseTree - protected List<PythonTree> children; + protected List<PythonTree> children; - public PythonTree getChild(int i) { - if ( children==null || i>=children.size() ) { - return null; - } - return children.get(i); - } + public PythonTree getChild(int i) { + if ( children==null || i>=children.size() ) { + return null; + } + return children.get(i); + } - /** Get the children internal List; note that if you directly mess with - * the list, do so at your own risk. - */ - public List<PythonTree> getChildren() { - return children; - } + /** Get the children internal List; note that if you directly mess with + * the list, do so at your own risk. + */ + public List<PythonTree> getChildren() { + return children; + } - public PythonTree getFirstChildWithType(int type) { - for (int i = 0; children!=null && i < children.size(); i++) { - PythonTree t = children.get(i); - if ( t.getAntlrType()==type ) { - return t; - } - } - return null; - } + public PythonTree getFirstChildWithType(int type) { + for (int i = 0; children!=null && i < children.size(); i++) { + PythonTree t = children.get(i); + if ( t.getAntlrType()==type ) { + return t; + } + } + return null; + } - public int getChildCount() { - if ( children==null ) { - return 0; - } - return children.size(); - } + public int getChildCount() { + if ( children==null ) { + return 0; + } + return children.size(); + } - /** Add t as child of this node. - * - * Warning: if t has no children, but child does - * and child isNil then this routine moves children to t via - * t.children = child.children; i.e., without copying the array. - */ - public void addChild(PythonTree t) { - //System.out.println("add child "+t.toStringTree()+" "+this.toStringTree()); - //System.out.println("existing children: "+children); - if ( t==null ) { - return; // do nothing upon addChild(null) - } - PythonTree childTree = t; - if ( childTree.isNil() ) { // t is an empty node possibly with children - if ( this.children!=null && this.children == childTree.children ) { - throw new RuntimeException("attempt to add child list to itself"); - } - // just add all of childTree's children to this - if ( childTree.children!=null ) { - if ( this.children!=null ) { // must copy, this has children already - int n = childTree.children.size(); - for (int i = 0; i < n; i++) { - PythonTree c = childTree.children.get(i); - this.children.add(c); - // handle double-link stuff for each child of nil root - c.setParent(this); - c.setChildIndex(children.size()-1); - } - } - else { - // no children for this but t has children; just set pointer - // call general freshener routine - this.children = childTree.children; - this.freshenParentAndChildIndexes(); - } - } - } - else { // child is not nil (don't care about children) - if ( children==null ) { - children = createChildrenList(); // create children list on demand - } - children.add(t); - childTree.setParent(this); - childTree.setChildIndex(children.size()-1); - } - // System.out.println("now children are: "+children); - } + /** Add t as child of this node. + * + * Warning: if t has no children, but child does + * and child isNil then this routine moves children to t via + * t.children = child.children; i.e., without copying the array. + */ + public void addChild(PythonTree t) { + //System.out.println("add child "+t.toStringTree()+" "+this.toStringTree()); + //System.out.println("existing children: "+children); + if ( t==null ) { + return; // do nothing upon addChild(null) + } + PythonTree childTree = t; + if ( childTree.isNil() ) { // t is an empty node possibly with children + if ( this.children!=null && this.children == childTree.children ) { + throw new RuntimeException("attempt to add child list to itself"); + } + // just add all of childTree's children to this + if ( childTree.children!=null ) { + if ( this.children!=null ) { // must copy, this has children already + int n = childTree.children.size(); + for (int i = 0; i < n; i++) { + PythonTree c = childTree.children.get(i); + this.children.add(c); + // handle double-link stuff for each child of nil root + c.setParent(this); + c.setChildIndex(children.size()-1); + } + } + else { + // no children for this but t has children; just set pointer + // call general freshener routine + this.children = childTree.children; + this.freshenParentAndChildIndexes(); + } + } + } + else { // child is not nil (don't care about children) + if ( children==null ) { + children = createChildrenList(); // create children list on demand + } + children.add(t); + childTree.setParent(this); + childTree.setChildIndex(children.size()-1); + } + // System.out.println("now children are: "+children); + } - /** Add all elements of kids list as children of this node */ - public void addChildren(List<PythonTree> kids) { - for (int i = 0; i < kids.size(); i++) { - PythonTree t = kids.get(i); - addChild(t); - } - } + /** Add all elements of kids list as children of this node */ + public void addChildren(List<PythonTree> kids) { + for (int i = 0; i < kids.size(); i++) { + PythonTree t = kids.get(i); + addChild(t); + } + } - public void setChild(int i, PythonTree t) { - if ( t==null ) { - return; - } - if ( t.isNil() ) { - throw new IllegalArgumentException("Can't set single child to a list"); - } - if ( children==null ) { - children = createChildrenList(); - } - children.set(i, t); - t.setParent(this); - t.setChildIndex(i); - } - - public Object deleteChild(int i) { - if ( children==null ) { - return null; - } - PythonTree killed = children.remove(i); - // walk rest and decrement their child indexes - this.freshenParentAndChildIndexes(i); - return killed; - } + public void setChild(int i, PythonTree t) { + if ( t==null ) { + return; + } + if ( t.isNil() ) { + throw new IllegalArgumentException("Can't set single child to a list"); + } + if ( children==null ) { + children = createChildrenList(); + } + children.set(i, t); + t.setParent(this); + t.setChildIndex(i); + } + + public Object deleteChild(int i) { + if ( children==null ) { + return null; + } + PythonTree killed = children.remove(i); + // walk rest and decrement their child indexes + this.freshenParentAndChildIndexes(i); + return killed; + } - /** Delete children from start to stop and replace with t even if t is - * a list (nil-root tree). num of children can increase or decrease. - * For huge child lists, inserting children can force walking rest of - * children to set their childindex; could be slow. - */ - public void replaceChildren(int startChildIndex, int stopChildIndex, Object t) { - /* - System.out.println("replaceChildren "+startChildIndex+", "+stopChildIndex+ - " with "+((PythonTree)t).toStringTree()); - System.out.println("in="+toStringTree()); - */ - if ( children==null ) { - throw new IllegalArgumentException("indexes invalid; no children in list"); - } - int replacingHowMany = stopChildIndex - startChildIndex + 1; - int replacingWithHowMany; - PythonTree newTree = (PythonTree)t; - List<PythonTree> newChildren = null; - // normalize to a list of children to add: newChildren - if ( newTree.isNil() ) { - newChildren = newTree.children; - } - else { - newChildren = new ArrayList<PythonTree>(1); - newChildren.add(newTree); - } - replacingWithHowMany = newChildren.size(); - int numNewChildren = newChildren.size(); - int delta = replacingHowMany - replacingWithHowMany; - // if same number of nodes, do direct replace - if ( delta == 0 ) { - int j = 0; // index into new children - for (int i=startChildIndex; i<=stopChildIndex; i++) { - PythonTree child = newChildren.get(j); - children.set(i, child); - child.setParent(this); - child.setChildIndex(i); + /** Delete children from start to stop and replace with t even if t is + * a list (nil-root tree). num of children can increase or decrease. + * For huge child lists, inserting children can force walking rest of + * children to set their childindex; could be slow. + */ + public void replaceChildren(int startChildIndex, int stopChildIndex, Object t) { + /* + System.out.println("replaceChildren "+startChildIndex+", "+stopChildIndex+ + " with "+((PythonTree)t).toStringTree()); + System.out.println("in="+toStringTree()); + */ + if ( children==null ) { + throw new IllegalArgumentException("indexes invalid; no children in list"); + } + int replacingHowMany = stopChildIndex - startChildIndex + 1; + int replacingWithHowMany; + PythonTree newTree = (PythonTree)t; + List<PythonTree> newChildren = null; + // normalize to a list of children to add: newChildren + if ( newTree.isNil() ) { + newChildren = newTree.children; + } + else { + newChildren = new ArrayList<PythonTree>(1); + newChildren.add(newTree); + } + replacingWithHowMany = newChildren.size(); + int numNewChildren = newChildren.size(); + int delta = replacingHowMany - replacingWithHowMany; + // if same number of nodes, do direct replace + if ( delta == 0 ) { + int j = 0; // index into new children + for (int i=startChildIndex; i<=stopChildIndex; i++) { + PythonTree child = newChildren.get(j); + children.set(i, child); + child.setParent(this); + child.setChildIndex(i); j++; } - } - else if ( delta > 0 ) { // fewer new nodes than there were - // set children and then delete extra - for (int j=0; j<numNewChildren; j++) { - children.set(startChildIndex+j, newChildren.get(j)); - } - int indexToDelete = startChildIndex+numNewChildren; - for (int c=indexToDelete; c<=stopChildIndex; c++) { - // delete same index, shifting everybody down each time - PythonTree killed = children.remove(indexToDelete); - } - freshenParentAndChildIndexes(startChildIndex); - } - else { // more new nodes than were there before - // fill in as many children as we can (replacingHowMany) w/o moving data - for (int j=0; j<replacingHowMany; j++) { - children.set(startChildIndex+j, newChildren.get(j)); - } - int numToInsert = replacingWithHowMany-replacingHowMany; - for (int j=replacingHowMany; j<replacingWithHowMany; j++) { - children.add(startChildIndex+j, newChildren.get(j)); - } - freshenParentAndChildIndexes(startChildIndex); - } - //System.out.println("out="+toStringTree()); - } + } + else if ( delta > 0 ) { // fewer new nodes than there were + // set children and then delete extra + for (int j=0; j<numNewChildren; j++) { + children.set(startChildIndex+j, newChildren.get(j)); + } + int indexToDelete = startChildIndex+numNewChildren; + for (int c=indexToDelete; c<=stopChildIndex; c++) { + // delete same index, shifting everybody down each time + PythonTree killed = children.remove(indexToDelete); + } + freshenParentAndChildIndexes(startChildIndex); + } + else { // more new nodes than were there before + // fill in as many children as we can (replacingHowMany) w/o moving data + for (int j=0; j<replacingHowMany; j++) { + children.set(startChildIndex+j, newChildren.get(j)); + } + int numToInsert = replacingWithHowMany-replacingHowMany; + for (int j=replacingHowMany; j<replacingWithHowMany; j++) { + children.add(startChildIndex+j, newChildren.get(j)); + } + freshenParentAndChildIndexes(startChildIndex); + } + //System.out.println("out="+toStringTree()); + } - /** Override in a subclass to change the impl of children list */ - protected List<PythonTree> createChildrenList() { - return new ArrayList<PythonTree>(); - } + /** Override in a subclass to change the impl of children list */ + protected List<PythonTree> createChildrenList() { + return new ArrayList<PythonTree>(); + } - /** Set the parent and child index values for all child of t */ - public void freshenParentAndChildIndexes() { - freshenParentAndChildIndexes(0); - } + /** Set the parent and child index values for all child of t */ + public void freshenParentAndChildIndexes() { + freshenParentAndChildIndexes(0); + } - public void freshenParentAndChildIndexes(int offset) { - int n = getChildCount(); - for (int c = offset; c < n; c++) { - PythonTree child = getChild(c); - child.setChildIndex(c); - child.setParent(this); - } - } + public void freshenParentAndChildIndexes(int offset) { + int n = getChildCount(); + for (int c = offset; c < n; c++) { + PythonTree child = getChild(c); + child.setChildIndex(c); + child.setParent(this); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-09-09 05:47:34
|
Revision: 6773 http://jython.svn.sourceforge.net/jython/?rev=6773&view=rev Author: pjenvey Date: 2009-09-09 05:47:17 +0000 (Wed, 09 Sep 2009) Log Message: ----------- whitespace Modified Paths: -------------- trunk/jython/Lib/test/test_zlib_jy.py Modified: trunk/jython/Lib/test/test_zlib_jy.py =================================================================== --- trunk/jython/Lib/test/test_zlib_jy.py 2009-09-09 04:59:15 UTC (rev 6772) +++ trunk/jython/Lib/test/test_zlib_jy.py 2009-09-09 05:47:17 UTC (rev 6773) @@ -22,11 +22,9 @@ self._test_array(compress, decompress) def _test_array(self, compress, decompress): - self.assertEqual(compress(array('c', 'jython')), - compress('jython')) + self.assertEqual(compress(array('c', 'jython')), compress('jython')) intarray = array('i', range(5)) - self.assertEqual(compress(intarray), - compress(intarray.tostring())) + self.assertEqual(compress(intarray), compress(intarray.tostring())) compressed = array('c', compress('jython')) self.assertEqual('jython', decompress(compressed)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-09-09 04:59:27
|
Revision: 6772 http://jython.svn.sourceforge.net/jython/?rev=6772&view=rev Author: pjenvey Date: 2009-09-09 04:59:15 +0000 (Wed, 09 Sep 2009) Log Message: ----------- allow zlib input from arrays fixes #1444 Modified Paths: -------------- trunk/jython/Lib/zlib.py trunk/jython/NEWS Added Paths: ----------- trunk/jython/Lib/test/test_zlib_jy.py Added: trunk/jython/Lib/test/test_zlib_jy.py =================================================================== --- trunk/jython/Lib/test/test_zlib_jy.py (rev 0) +++ trunk/jython/Lib/test/test_zlib_jy.py 2009-09-09 04:59:15 UTC (rev 6772) @@ -0,0 +1,39 @@ +"""Misc zlib tests + +Made for Jython. +""" +import unittest +import zlib +from array import array +from test import test_support + +class ArrayTestCase(unittest.TestCase): + + def test_array(self): + self._test_array(zlib.compress, zlib.decompress) + + def test_array_compressobj(self): + def compress(value): + co = zlib.compressobj() + return co.compress(value) + co.flush() + def decompress(value): + dco = zlib.decompressobj() + return dco.decompress(value) + dco.flush() + self._test_array(compress, decompress) + + def _test_array(self, compress, decompress): + self.assertEqual(compress(array('c', 'jython')), + compress('jython')) + intarray = array('i', range(5)) + self.assertEqual(compress(intarray), + compress(intarray.tostring())) + compressed = array('c', compress('jython')) + self.assertEqual('jython', decompress(compressed)) + + +def test_main(): + test_support.run_unittest(ArrayTestCase) + + +if __name__ == '__main__': + test_main() Modified: trunk/jython/Lib/zlib.py =================================================================== --- trunk/jython/Lib/zlib.py 2009-09-09 04:16:49 UTC (rev 6771) +++ trunk/jython/Lib/zlib.py 2009-09-09 04:59:15 UTC (rev 6772) @@ -13,7 +13,9 @@ Compressor objects support compress() and flush() methods; decompressor objects support decompress() and flush(). """ -import jarray, binascii +import array +import binascii +import jarray from java.util.zip import Adler32, Deflater, Inflater, DataFormatException from java.lang import Long, String @@ -59,13 +61,14 @@ if level < Z_BEST_SPEED or level > Z_BEST_COMPRESSION: raise error, "Bad compression level" deflater = Deflater(level, 0) + string = _to_input(string) deflater.setInput(string, 0, len(string)) deflater.finish() return _get_deflate_data(deflater) def decompress(string, wbits=0, bufsize=16384): inflater = Inflater(wbits < 0) - inflater.setInput(string) + inflater.setInput(_to_input(string)) return _get_inflate_data(inflater) @@ -84,6 +87,7 @@ def compress(self, string): if self._ended: raise error("compressobj may not be used after flush(Z_FINISH)") + string = _to_input(string) self.deflater.setInput(string, 0, len(string)) return _get_deflate_data(self.deflater) @@ -123,6 +127,7 @@ if max_length < 0: raise ValueError("max_length must be a positive integer") + string = _to_input(string) self.inflater.setInput(string) inflated = _get_inflate_data(self.inflater, max_length) @@ -146,6 +151,8 @@ self.inflater.end() return last +def _to_input(string): + return string.tostring() if isinstance(string, array.array) else string def _get_deflate_data(deflater): buf = jarray.zeros(1024, 'b') Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-09-09 04:16:49 UTC (rev 6771) +++ trunk/jython/NEWS 2009-09-09 04:59:15 UTC (rev 6772) @@ -8,6 +8,7 @@ - [ 1457 ] Cannot write an array in a file opened in r+b mode. - [ 1382 ] __cmp__ on certain types raises ArrayStoreException - [ 1443 ] Can't update() hashlib.sha1() with array.array('c') + - [ 1444 ] Can't zlib.compress() with array.array('c') Jython 2.5.1rc1 New Features This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-09-09 04:16:57
|
Revision: 6771 http://jython.svn.sourceforge.net/jython/?rev=6771&view=rev Author: pjenvey Date: 2009-09-09 04:16:49 +0000 (Wed, 09 Sep 2009) Log Message: ----------- allow hashlib updating from arrays fixes #1443 Modified Paths: -------------- trunk/jython/Lib/test/test_hashlib_jy.py trunk/jython/NEWS trunk/jython/src/org/python/modules/_hashlib.java Modified: trunk/jython/Lib/test/test_hashlib_jy.py =================================================================== --- trunk/jython/Lib/test/test_hashlib_jy.py 2009-09-09 03:47:22 UTC (rev 6770) +++ trunk/jython/Lib/test/test_hashlib_jy.py 2009-09-09 04:16:49 UTC (rev 6771) @@ -5,6 +5,7 @@ """ import hashlib import unittest +from array import array from test import test_support class HashlibTestCase(unittest.TestCase): @@ -14,7 +15,14 @@ 'acbd18db4cc2f85cedef654fccc4a4d8') self.assertRaises(UnicodeEncodeError, hashlib.md5, u'Gráin amháiñ') + def test_array(self): + self.assertEqual(hashlib.sha1(array('c', 'hovercraft')).hexdigest(), + '496df4d8de2c71973d7e917c4fbe57e6ad46d738') + intarray = array('i', range(5)) + self.assertEqual(hashlib.sha1(intarray).hexdigest(), + hashlib.sha1(intarray.tostring()).hexdigest()) + def test_main(): test_support.run_unittest(HashlibTestCase) Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-09-09 03:47:22 UTC (rev 6770) +++ trunk/jython/NEWS 2009-09-09 04:16:49 UTC (rev 6771) @@ -7,6 +7,7 @@ - [ 1425 ] distutils/util.py assumes too much posix - [ 1457 ] Cannot write an array in a file opened in r+b mode. - [ 1382 ] __cmp__ on certain types raises ArrayStoreException + - [ 1443 ] Can't update() hashlib.sha1() with array.array('c') Jython 2.5.1rc1 New Features Modified: trunk/jython/src/org/python/modules/_hashlib.java =================================================================== --- trunk/jython/src/org/python/modules/_hashlib.java 2009-09-09 03:47:22 UTC (rev 6770) +++ trunk/jython/src/org/python/modules/_hashlib.java 2009-09-09 04:16:49 UTC (rev 6771) @@ -8,6 +8,7 @@ import org.python.core.ClassDictInit; import org.python.core.Py; +import org.python.core.PyArray; import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyType; @@ -168,15 +169,19 @@ @ExposedMethod final void HASH_update(PyObject obj) { - if (!(obj instanceof PyString)) { + String string; + if (obj instanceof PyUnicode) { + string = ((PyUnicode)obj).encode(); + } else if (obj instanceof PyString) { + string = obj.toString(); + } else if (obj instanceof PyArray) { + string = ((PyArray)obj).tostring(); + } + else { throw Py.TypeError("update() argument 1 must be string or read-only buffer, not " + obj.getType().fastGetName()); } - if (obj instanceof PyUnicode) { - obj = obj.__str__(); - } - byte[] bytes = ((PyString)obj).toBytes(); - digest.update(bytes); + digest.update(StringUtil.toBytes(string)); } public PyObject digest() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-09-09 03:47:32
|
Revision: 6770 http://jython.svn.sourceforge.net/jython/?rev=6770&view=rev Author: pjenvey Date: 2009-09-09 03:47:22 +0000 (Wed, 09 Sep 2009) Log Message: ----------- regen per r6769 Modified Paths: -------------- trunk/jython/src/org/python/antlr/ast/AssertDerived.java trunk/jython/src/org/python/antlr/ast/AssignDerived.java trunk/jython/src/org/python/antlr/ast/AttributeDerived.java trunk/jython/src/org/python/antlr/ast/AugAssignDerived.java trunk/jython/src/org/python/antlr/ast/BinOpDerived.java trunk/jython/src/org/python/antlr/ast/BoolOpDerived.java trunk/jython/src/org/python/antlr/ast/BreakDerived.java trunk/jython/src/org/python/antlr/ast/CallDerived.java trunk/jython/src/org/python/antlr/ast/ClassDefDerived.java trunk/jython/src/org/python/antlr/ast/CompareDerived.java trunk/jython/src/org/python/antlr/ast/ContinueDerived.java trunk/jython/src/org/python/antlr/ast/DeleteDerived.java trunk/jython/src/org/python/antlr/ast/DictDerived.java trunk/jython/src/org/python/antlr/ast/EllipsisDerived.java trunk/jython/src/org/python/antlr/ast/ExceptHandlerDerived.java trunk/jython/src/org/python/antlr/ast/ExecDerived.java trunk/jython/src/org/python/antlr/ast/ExprDerived.java trunk/jython/src/org/python/antlr/ast/ExpressionDerived.java trunk/jython/src/org/python/antlr/ast/ExtSliceDerived.java trunk/jython/src/org/python/antlr/ast/ForDerived.java trunk/jython/src/org/python/antlr/ast/FunctionDefDerived.java trunk/jython/src/org/python/antlr/ast/GeneratorExpDerived.java trunk/jython/src/org/python/antlr/ast/GlobalDerived.java trunk/jython/src/org/python/antlr/ast/IfDerived.java trunk/jython/src/org/python/antlr/ast/IfExpDerived.java trunk/jython/src/org/python/antlr/ast/ImportDerived.java trunk/jython/src/org/python/antlr/ast/ImportFromDerived.java trunk/jython/src/org/python/antlr/ast/IndexDerived.java trunk/jython/src/org/python/antlr/ast/InteractiveDerived.java trunk/jython/src/org/python/antlr/ast/LambdaDerived.java trunk/jython/src/org/python/antlr/ast/ListCompDerived.java trunk/jython/src/org/python/antlr/ast/ListDerived.java trunk/jython/src/org/python/antlr/ast/ModuleDerived.java trunk/jython/src/org/python/antlr/ast/NameDerived.java trunk/jython/src/org/python/antlr/ast/NumDerived.java trunk/jython/src/org/python/antlr/ast/PassDerived.java trunk/jython/src/org/python/antlr/ast/PrintDerived.java trunk/jython/src/org/python/antlr/ast/RaiseDerived.java trunk/jython/src/org/python/antlr/ast/ReprDerived.java trunk/jython/src/org/python/antlr/ast/ReturnDerived.java trunk/jython/src/org/python/antlr/ast/SliceDerived.java trunk/jython/src/org/python/antlr/ast/StrDerived.java trunk/jython/src/org/python/antlr/ast/SubscriptDerived.java trunk/jython/src/org/python/antlr/ast/SuiteDerived.java trunk/jython/src/org/python/antlr/ast/TryExceptDerived.java trunk/jython/src/org/python/antlr/ast/TryFinallyDerived.java trunk/jython/src/org/python/antlr/ast/TupleDerived.java trunk/jython/src/org/python/antlr/ast/UnaryOpDerived.java trunk/jython/src/org/python/antlr/ast/WhileDerived.java trunk/jython/src/org/python/antlr/ast/WithDerived.java trunk/jython/src/org/python/antlr/ast/YieldDerived.java trunk/jython/src/org/python/antlr/ast/aliasDerived.java trunk/jython/src/org/python/antlr/ast/argumentsDerived.java trunk/jython/src/org/python/antlr/ast/comprehensionDerived.java trunk/jython/src/org/python/antlr/ast/keywordDerived.java trunk/jython/src/org/python/antlr/op/AddDerived.java trunk/jython/src/org/python/antlr/op/AndDerived.java trunk/jython/src/org/python/antlr/op/AugLoadDerived.java trunk/jython/src/org/python/antlr/op/AugStoreDerived.java trunk/jython/src/org/python/antlr/op/BitAndDerived.java trunk/jython/src/org/python/antlr/op/BitOrDerived.java trunk/jython/src/org/python/antlr/op/BitXorDerived.java trunk/jython/src/org/python/antlr/op/DelDerived.java trunk/jython/src/org/python/antlr/op/DivDerived.java trunk/jython/src/org/python/antlr/op/EqDerived.java trunk/jython/src/org/python/antlr/op/FloorDivDerived.java trunk/jython/src/org/python/antlr/op/GtDerived.java trunk/jython/src/org/python/antlr/op/GtEDerived.java trunk/jython/src/org/python/antlr/op/InDerived.java trunk/jython/src/org/python/antlr/op/InvertDerived.java trunk/jython/src/org/python/antlr/op/IsDerived.java trunk/jython/src/org/python/antlr/op/IsNotDerived.java trunk/jython/src/org/python/antlr/op/LShiftDerived.java trunk/jython/src/org/python/antlr/op/LoadDerived.java trunk/jython/src/org/python/antlr/op/LtDerived.java trunk/jython/src/org/python/antlr/op/LtEDerived.java trunk/jython/src/org/python/antlr/op/ModDerived.java trunk/jython/src/org/python/antlr/op/MultDerived.java trunk/jython/src/org/python/antlr/op/NotDerived.java trunk/jython/src/org/python/antlr/op/NotEqDerived.java trunk/jython/src/org/python/antlr/op/NotInDerived.java trunk/jython/src/org/python/antlr/op/OrDerived.java trunk/jython/src/org/python/antlr/op/ParamDerived.java trunk/jython/src/org/python/antlr/op/PowDerived.java trunk/jython/src/org/python/antlr/op/RShiftDerived.java trunk/jython/src/org/python/antlr/op/StoreDerived.java trunk/jython/src/org/python/antlr/op/SubDerived.java trunk/jython/src/org/python/antlr/op/UAddDerived.java trunk/jython/src/org/python/antlr/op/USubDerived.java trunk/jython/src/org/python/core/ClasspathPyImporterDerived.java trunk/jython/src/org/python/core/PyArrayDerived.java trunk/jython/src/org/python/core/PyBaseExceptionDerived.java trunk/jython/src/org/python/core/PyBooleanDerived.java trunk/jython/src/org/python/core/PyClassMethodDerived.java trunk/jython/src/org/python/core/PyComplexDerived.java trunk/jython/src/org/python/core/PyDictionaryDerived.java trunk/jython/src/org/python/core/PyEnumerateDerived.java trunk/jython/src/org/python/core/PyFileDerived.java trunk/jython/src/org/python/core/PyFloatDerived.java trunk/jython/src/org/python/core/PyFrozenSetDerived.java trunk/jython/src/org/python/core/PyIntegerDerived.java trunk/jython/src/org/python/core/PyListDerived.java trunk/jython/src/org/python/core/PyLongDerived.java trunk/jython/src/org/python/core/PyModuleDerived.java trunk/jython/src/org/python/core/PyObjectDerived.java trunk/jython/src/org/python/core/PyPropertyDerived.java trunk/jython/src/org/python/core/PySetDerived.java trunk/jython/src/org/python/core/PySliceDerived.java trunk/jython/src/org/python/core/PyStringDerived.java trunk/jython/src/org/python/core/PySuperDerived.java trunk/jython/src/org/python/core/PyTupleDerived.java trunk/jython/src/org/python/core/PyTypeDerived.java trunk/jython/src/org/python/core/PyUnicodeDerived.java trunk/jython/src/org/python/modules/_collections/PyDefaultDictDerived.java trunk/jython/src/org/python/modules/_collections/PyDequeDerived.java trunk/jython/src/org/python/modules/_csv/PyDialectDerived.java trunk/jython/src/org/python/modules/_functools/PyPartialDerived.java trunk/jython/src/org/python/modules/_weakref/ReferenceTypeDerived.java trunk/jython/src/org/python/modules/random/PyRandomDerived.java trunk/jython/src/org/python/modules/thread/PyLocalDerived.java trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java Modified: trunk/jython/src/org/python/antlr/ast/AssertDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/AssertDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/AssertDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/AssignDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/AssignDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/AssignDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/AttributeDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/AttributeDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/AttributeDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/AugAssignDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/AugAssignDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/AugAssignDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/BinOpDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/BinOpDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/BinOpDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/BoolOpDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/BoolOpDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/BoolOpDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/BreakDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/BreakDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/BreakDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/CallDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/CallDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/CallDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/ClassDefDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ClassDefDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/ClassDefDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/CompareDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/CompareDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/CompareDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/ContinueDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ContinueDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/ContinueDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/DeleteDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/DeleteDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/DeleteDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/DictDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/DictDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/DictDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/EllipsisDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/EllipsisDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/EllipsisDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/ExceptHandlerDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExceptHandlerDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/ExceptHandlerDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/ExecDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExecDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/ExecDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/ExprDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExprDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/ExprDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/ExpressionDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExpressionDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/ExpressionDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/ExtSliceDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExtSliceDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/ExtSliceDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/ForDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ForDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/ForDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/FunctionDefDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/FunctionDefDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/FunctionDefDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/GeneratorExpDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/GeneratorExpDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/GeneratorExpDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/GlobalDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/GlobalDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/GlobalDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/IfDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/IfDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/IfDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/IfExpDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/IfExpDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/IfExpDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/ImportDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ImportDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/ImportDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/ImportFromDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ImportFromDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/ImportFromDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/IndexDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/IndexDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/IndexDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/InteractiveDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/InteractiveDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/InteractiveDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/LambdaDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/LambdaDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/LambdaDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/ListCompDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ListCompDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/ListCompDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/ListDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ListDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/ListDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/ModuleDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ModuleDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/ModuleDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/NameDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/NameDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/NameDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/NumDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/NumDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/NumDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/PassDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/PassDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/PassDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/PrintDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/PrintDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/PrintDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/RaiseDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/RaiseDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/RaiseDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/ReprDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ReprDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/ReprDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/ReturnDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ReturnDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/ReturnDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/SliceDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/SliceDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/SliceDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/StrDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/StrDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/StrDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/SubscriptDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/SubscriptDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/SubscriptDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/SuiteDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/SuiteDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/SuiteDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/TryExceptDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/TryExceptDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/TryExceptDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/TryFinallyDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/TryFinallyDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/TryFinallyDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/TupleDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/TupleDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/TupleDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/UnaryOpDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/UnaryOpDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/UnaryOpDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/WhileDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/WhileDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/WhileDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/WithDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/WithDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/WithDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/YieldDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/YieldDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/YieldDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/aliasDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/aliasDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/aliasDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/argumentsDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/argumentsDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/argumentsDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/comprehensionDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/comprehensionDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/comprehensionDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/ast/keywordDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/keywordDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/ast/keywordDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/AddDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/AddDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/AddDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/AndDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/AndDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/AndDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/AugLoadDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/AugLoadDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/AugLoadDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/AugStoreDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/AugStoreDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/AugStoreDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/BitAndDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/BitAndDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/BitAndDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/BitOrDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/BitOrDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/BitOrDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/BitXorDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/BitXorDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/BitXorDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/DelDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/DelDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/DelDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/DivDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/DivDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/DivDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/EqDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/EqDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/EqDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/FloorDivDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/FloorDivDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/FloorDivDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/GtDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/GtDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/GtDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/GtEDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/GtEDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/GtEDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/InDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/InDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/InDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/InvertDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/InvertDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/InvertDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/IsDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/IsDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/IsDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/IsNotDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/IsNotDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/IsNotDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/LShiftDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/LShiftDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/LShiftDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/LoadDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/LoadDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/LoadDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/LtDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/LtDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/LtDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the Modified: trunk/jython/src/org/python/antlr/op/LtEDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/op/LtEDerived.java 2009-09-09 03:45:43 UTC (rev 6769) +++ trunk/jython/src/org/python/antlr/op/LtEDerived.java 2009-09-09 03:47:22 UTC (rev 6770) @@ -768,7 +768,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[]where_type=new PyType[1]; + PyObject[]where_type=new PyObject[1]; PyObject impl=self_type.lookup_where("__cmp__",where_type); // Full Compatibility with CPython __cmp__: // If ... [truncated message content] |
From: <pj...@us...> - 2009-09-09 03:45:49
|
Revision: 6769 http://jython.svn.sourceforge.net/jython/?rev=6769&view=rev Author: pjenvey Date: 2009-09-09 03:45:43 +0000 (Wed, 09 Sep 2009) Log Message: ----------- fix __cmp__ specifying the wrong array type to lookup_where triggering an ArrayStoreException in some cases fixes #1382 Modified Paths: -------------- trunk/jython/Lib/test/test_cmp_jy.py trunk/jython/NEWS trunk/jython/src/templates/object.derived Modified: trunk/jython/Lib/test/test_cmp_jy.py =================================================================== --- trunk/jython/Lib/test/test_cmp_jy.py 2009-09-09 03:24:04 UTC (rev 6768) +++ trunk/jython/Lib/test/test_cmp_jy.py 2009-09-09 03:45:43 UTC (rev 6769) @@ -1,7 +1,18 @@ "Tests for cmp() compatibility with CPython" +import UserDict import unittest from test import test_support +class CmpGeneralTestCase(unittest.TestCase): + + def test_type_crash(self): + # Used to throw ArrayStoreException: + # http://bugs.jython.org/issue1382 + class Configuration(object, UserDict.DictMixin): + pass + self.assertNotEqual(Configuration(), None) + + class UnicodeDerivedCmp(unittest.TestCase): "Test for http://bugs.jython.org/issue1889394" def testCompareWithString(self): @@ -14,6 +25,7 @@ class B(unicode): pass self.assertEqual(A(), B()) + class LongDerivedCmp(unittest.TestCase): def testCompareWithString(self): class Test(long): @@ -21,6 +33,7 @@ self.assertNotEqual(Test(0), 'foo') self.assertTrue('foo' in [Test(12), 'foo']) + class IntStrCmp(unittest.TestCase): def testIntStrCompares(self): assert not (-1 > 'a') @@ -31,6 +44,7 @@ assert (-2 < 'a') assert not (-1 == 'a') + class CustomCmp(unittest.TestCase): def test___cmp___returns(self): class Foo(object): @@ -63,13 +77,16 @@ __eq__ = lambda self, other: True self.assertEqual(cmp(Foo(), Bar()), 1) + def test_main(): test_support.run_unittest( + CmpGeneralTestCase, UnicodeDerivedCmp, LongDerivedCmp, IntStrCmp, CustomCmp ) + if __name__ == '__main__': test_main() Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-09-09 03:24:04 UTC (rev 6768) +++ trunk/jython/NEWS 2009-09-09 03:45:43 UTC (rev 6769) @@ -5,6 +5,8 @@ - [ 1079 ] fixed regression on issue: twisted.python.threadable module: missing attribute '_RLock' - [ 1461 ] assert statement should lookup AssertionError using getglobal - [ 1425 ] distutils/util.py assumes too much posix + - [ 1457 ] Cannot write an array in a file opened in r+b mode. + - [ 1382 ] __cmp__ on certain types raises ArrayStoreException Jython 2.5.1rc1 New Features Modified: trunk/jython/src/templates/object.derived =================================================================== --- trunk/jython/src/templates/object.derived 2009-09-09 03:24:04 UTC (rev 6768) +++ trunk/jython/src/templates/object.derived 2009-09-09 03:45:43 UTC (rev 6769) @@ -99,7 +99,7 @@ public int __cmp__(PyObject other) { PyType self_type=getType(); - PyType[] where_type = new PyType[1]; + PyObject[] where_type = new PyObject[1]; PyObject impl = self_type.lookup_where("__cmp__", where_type); // Full Compatibility with CPython __cmp__: // If the derived type don't override __cmp__, the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-09-09 03:24:25
|
Revision: 6768 http://jython.svn.sourceforge.net/jython/?rev=6768&view=rev Author: pjenvey Date: 2009-09-09 03:24:04 +0000 (Wed, 09 Sep 2009) Log Message: ----------- fix array.to/fromfile on files in + mode fixes #1457 Modified Paths: -------------- trunk/jython/Lib/test/test_array_jy.py trunk/jython/src/org/python/core/PyArray.java Modified: trunk/jython/Lib/test/test_array_jy.py =================================================================== --- trunk/jython/Lib/test/test_array_jy.py 2009-09-09 03:06:20 UTC (rev 6767) +++ trunk/jython/Lib/test/test_array_jy.py 2009-09-09 03:24:04 UTC (rev 6768) @@ -1,6 +1,7 @@ # The jarray module is being phased out, with all functionality # now available in the array module. - +from __future__ import with_statement +import os import unittest from test import test_support from array import array, zeros @@ -11,7 +12,6 @@ class ArrayJyTestCase(unittest.TestCase): def test_jarray(self): # until it is fully formally removed - # While jarray is still being phased out, just flex the initializers. # The rest of the test for array will catch all the big problems. import jarray @@ -44,8 +44,34 @@ Color.RGBtoHSB(0, 255, 255, hsb1) self.assertEqual(hsb, hsb1, "hsb float arrays were not equal") + +class ToFromfileTestCase(unittest.TestCase): + + def tearDown(self): + if os.path.exists(test_support.TESTFN): + os.remove(test_support.TESTFN) + + def test_tofromfile(self): + # http://bugs.jython.org/issue1457 + x = array('i', range(5)) + with open(test_support.TESTFN, 'wb') as f: + x.tofile(f) + + x = array('i', []) + with open(test_support.TESTFN, 'r+b') as f: + x.fromfile(f, 5) + x *= 2 + x.tofile(f) + + with open(test_support.TESTFN, 'rb') as f: + x.fromfile(f, 10) + self.assertEqual(x, array('i', range(5) * 4)) + + def test_main(): - test_support.run_unittest(ArrayJyTestCase) + test_support.run_unittest(ArrayJyTestCase, + ToFromfileTestCase) + if __name__ == "__main__": test_main() Modified: trunk/jython/src/org/python/core/PyArray.java =================================================================== --- trunk/jython/src/org/python/core/PyArray.java 2009-09-09 03:06:20 UTC (rev 6767) +++ trunk/jython/src/org/python/core/PyArray.java 2009-09-09 03:24:04 UTC (rev 6768) @@ -802,15 +802,10 @@ */ public void fromfile(PyObject f, int count) { // check for arg1 as file object - if(!(f instanceof PyFile)) { + if (!(f instanceof PyFile)) { throw Py.TypeError("arg1 must be open file"); } PyFile file = (PyFile)f; - // check for read only - if(file.mode.indexOf("r") == -1) { - throw Py.TypeError("file needs to be in read mode"); - } - // read the data via the PyFile int readbytes = count * getStorageSize(); String buffer = file.read(readbytes).toString(); // load whatever was collected into the array @@ -1588,13 +1583,10 @@ * Python builtin file object to write data */ public void tofile(PyObject f) { - if(!(f instanceof PyFile)) + if (!(f instanceof PyFile)) { throw Py.TypeError("arg must be open file"); - PyFile file = (PyFile)f; - if(file.mode.indexOf("w") == -1 && file.mode.indexOf("a") == -1) { - throw Py.TypeError("file needs to be in write or append mode"); } - // write via the PyFile + PyFile file = (PyFile)f; file.write(tostring()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-09-09 03:06:38
|
Revision: 6767 http://jython.svn.sourceforge.net/jython/?rev=6767&view=rev Author: pjenvey Date: 2009-09-09 03:06:20 +0000 (Wed, 09 Sep 2009) Log Message: ----------- fix os.popen*/popen2 to only invoke a shell if cmd is a string refs http://bugs.python.org/issue5329 Modified Paths: -------------- trunk/jython/Lib/popen2.py Modified: trunk/jython/Lib/popen2.py =================================================================== --- trunk/jython/Lib/popen2.py 2009-09-09 02:58:36 UTC (rev 6766) +++ trunk/jython/Lib/popen2.py 2009-09-09 03:06:20 UTC (rev 6767) @@ -34,7 +34,8 @@ process.""" stderr = subprocess.PIPE if capturestderr else None PIPE = subprocess.PIPE - self._popen = subprocess.Popen(cmd, bufsize=bufsize, shell=True, + self._popen = subprocess.Popen(cmd, bufsize=bufsize, + shell=isinstance(cmd, basestring), stdin=PIPE, stdout=PIPE, stderr=stderr) self._setup(cmd) @@ -73,7 +74,8 @@ def __init__(self, cmd, bufsize=-1): PIPE = subprocess.PIPE - self._popen = subprocess.Popen(cmd, bufsize=bufsize, shell=True, + self._popen = subprocess.Popen(cmd, bufsize=bufsize, + shell=isinstance(cmd, basestring), stdin=PIPE, stdout=PIPE, stderr=subprocess.STDOUT) self._setup(cmd) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-09-09 02:59:02
|
Revision: 6766 http://jython.svn.sourceforge.net/jython/?rev=6766&view=rev Author: pjenvey Date: 2009-09-09 02:58:36 +0000 (Wed, 09 Sep 2009) Log Message: ----------- don't assume posix fixes #1425 thanks Matthew L Daniel Modified Paths: -------------- trunk/jython/Lib/distutils/util.py trunk/jython/NEWS Modified: trunk/jython/Lib/distutils/util.py =================================================================== --- trunk/jython/Lib/distutils/util.py 2009-09-08 19:18:26 UTC (rev 6765) +++ trunk/jython/Lib/distutils/util.py 2009-09-09 02:58:36 UTC (rev 6766) @@ -155,25 +155,26 @@ Otherwise, it requires making 'pathname' relative and then joining the two, which is tricky on DOS/Windows and Mac OS. """ - if os.name == 'posix' or os.name == 'java': + os_name = os._name if sys.platform.startswith('java') else os.name + if os_name == 'posix': if not os.path.isabs(pathname): return os.path.join(new_root, pathname) else: return os.path.join(new_root, pathname[1:]) - elif os.name == 'nt': + elif os_name == 'nt': (drive, path) = os.path.splitdrive(pathname) if path[0] == '\\': path = path[1:] return os.path.join(new_root, path) - elif os.name == 'os2': + elif os_name == 'os2': (drive, path) = os.path.splitdrive(pathname) if path[0] == os.sep: path = path[1:] return os.path.join(new_root, path) - elif os.name == 'mac': + elif os_name == 'mac': if not os.path.isabs(pathname): return os.path.join(new_root, pathname) else: @@ -184,7 +185,7 @@ else: raise DistutilsPlatformError, \ - "nothing known about platform '%s'" % os.name + "nothing known about platform '%s'" % os_name _environ_checked = 0 Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-09-08 19:18:26 UTC (rev 6765) +++ trunk/jython/NEWS 2009-09-09 02:58:36 UTC (rev 6766) @@ -4,6 +4,7 @@ Bugs Fixed - [ 1079 ] fixed regression on issue: twisted.python.threadable module: missing attribute '_RLock' - [ 1461 ] assert statement should lookup AssertionError using getglobal + - [ 1425 ] distutils/util.py assumes too much posix Jython 2.5.1rc1 New Features This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-08 19:18:38
|
Revision: 6765 http://jython.svn.sourceforge.net/jython/?rev=6765&view=rev Author: fwierzbicki Date: 2009-09-08 19:18:26 +0000 (Tue, 08 Sep 2009) Log Message: ----------- Cleanup, add guard and custome call site for experimentation. Modified Paths: -------------- branches/indy/src/org/python/compiler/IndyTest.java Modified: branches/indy/src/org/python/compiler/IndyTest.java =================================================================== --- branches/indy/src/org/python/compiler/IndyTest.java 2009-09-08 18:21:38 UTC (rev 6764) +++ branches/indy/src/org/python/compiler/IndyTest.java 2009-09-08 19:18:26 UTC (rev 6765) @@ -2,6 +2,7 @@ import java.dyn.CallSite; import java.dyn.InvokeDynamic; +import java.dyn.JavaMethodHandle; import java.dyn.Linkage; import java.dyn.MethodType; import java.dyn.MethodHandle; @@ -18,9 +19,19 @@ import org.python.core.ThreadState; public class IndyTest { + private static MethodType oneArgCall = MethodType.make( + PyObject.class, //return type + ThreadState.class, // state + PyObject.class, // arg1 + PyObject.class, // globals + PyObject[].class, // defaults + PyObject.class // closure + ); public static void run() throws Throwable { - PyObject result = InvokeDynamic.<PyObject>foo(new PyInteger(4), Py.None, + ThreadState ts = Py.getThreadState(); + PyCode func_code = ((PyFunction)ts.frame.getname("foo")).func_code; + PyObject result = InvokeDynamic.<PyObject>foo(func_code, ts, new PyInteger(4), Py.None, Py.EmptyObjects, new PyTuple()); System.out.println("result = " + result); } @@ -29,22 +40,47 @@ private static CallSite linkDynamic(Class<?> caller, String name, MethodType type) { System.out.println("linkDynamic..."); CallSite site = new CallSite(caller, name, type); - ThreadState ts = Py.getThreadState(); - PyCode func_code = ((PyFunction)ts.frame.getname(name)).func_code; - - MethodType oneArgCall = MethodType.make( - PyObject.class, //return type - ThreadState.class, // state - PyObject.class, // arg1 - PyObject.class, // globals - PyObject[].class, // defaults - PyObject.class // closure - ); MethodHandle call = MethodHandles.lookup().findVirtual(PyCode.class, "call", oneArgCall); - call = MethodHandles.insertArguments(call, 0, func_code, ts); call = MethodHandles.convertArguments(call, type); site.setTarget(call); return site; } + + private static class Guard extends JavaMethodHandle { + MethodHandle target; + CSite site; + + Guard(CSite site, MethodHandle target) { + super(INVOKE); + this.target = target; + this.site = site; + } + + PyObject invoke(ThreadState t, PyObject arg1, PyObject globals, PyObject[] defaults, PyObject closure) throws Throwable { + return target.<PyObject>invoke(arg1, globals, defaults, closure); + } + + private static final MethodHandle INVOKE = + MethodHandles.lookup().findVirtual(Guard.class, "invoke", oneArgCall); + + public String toString() { + return "Guard:" + target; + } + } + + // Use a local call site subclass. (These are optional but fun.) + private static class CSite extends CallSite { + public CSite(Class caller, String name, MethodType type) { + super(caller, name, type); + System.out.println("[link] new call site: "+this); + setTarget(new Guard(this, /*FIXME*/null)); + } + + // this is just for the noise value: + public void setTarget(MethodHandle t) { + System.out.println("[link] set target to "+t); + super.setTarget(t); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-08 18:21:55
|
Revision: 6764 http://jython.svn.sourceforge.net/jython/?rev=6764&view=rev Author: fwierzbicki Date: 2009-09-08 18:21:38 +0000 (Tue, 08 Sep 2009) Log Message: ----------- Merged revisions 6662-6665,6667-6698,6710,6713,6717-6719,6724-6725,6735-6741 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r6662 | cgroves | 2009-08-11 02:45:00 -0400 (Tue, 11 Aug 2009) | 1 line Documentation and formatting cleanup ........ r6663 | pjenvey | 2009-08-11 23:12:07 -0400 (Tue, 11 Aug 2009) | 2 lines cleanup/quiet warnings ........ r6664 | fwierzbicki | 2009-08-12 21:54:15 -0400 (Wed, 12 Aug 2009) | 2 lines Better lineno col_offset match with CPython on elif. ........ r6665 | fwierzbicki | 2009-08-12 22:49:57 -0400 (Wed, 12 Aug 2009) | 2 lines Adjusted BinOp lineno and col_offset to align better with CPython. ........ r6667 | pjenvey | 2009-08-15 21:11:01 -0400 (Sat, 15 Aug 2009) | 2 lines allow Oracle's touchy DML returning ResultSet to be used here ........ r6668 | pjenvey | 2009-08-15 21:30:38 -0400 (Sat, 15 Aug 2009) | 3 lines steal Python3's _wrap_close to fix popen files' close to return the exit status when its non-zero ........ r6669 | pjenvey | 2009-08-15 21:32:41 -0400 (Sat, 15 Aug 2009) | 1 line changelog r6668, fixes #1434 ........ r6670 | pjenvey | 2009-08-15 22:36:35 -0400 (Sat, 15 Aug 2009) | 1 line preserve our old exit code behavior ........ r6671 | fwierzbicki | 2009-08-15 22:49:27 -0400 (Sat, 15 Aug 2009) | 2 lines Better match with CPython for col_offset on BoolOp with left arg in parens. ........ r6672 | fwierzbicki | 2009-08-15 22:51:07 -0400 (Sat, 15 Aug 2009) | 2 lines Bugfix for test ast generation code. ........ r6673 | fwierzbicki | 2009-08-15 22:55:25 -0400 (Sat, 15 Aug 2009) | 2 lines Added tests for BoolOp and parens. ........ r6674 | fwierzbicki | 2009-08-15 23:04:08 -0400 (Sat, 15 Aug 2009) | 2 lines Fix col_offset for some NOT expressions. ........ r6675 | cgroves | 2009-08-16 04:11:44 -0400 (Sun, 16 Aug 2009) | 1 line Have lookup call through to lookup_where rather than duplicating the lookup functionality ........ r6676 | cgroves | 2009-08-16 06:28:49 -0400 (Sun, 16 Aug 2009) | 1 line Continue looking for methods to merge up the inheritance chain if the non-public class being merged has a parent that's non-public as well. Fixes issue 1430. ........ r6677 | fwierzbicki | 2009-08-16 10:26:06 -0400 (Sun, 16 Aug 2009) | 2 lines Fix for http://bugs.jython.org/issue1439: Can't write() array.array ........ r6678 | fwierzbicki | 2009-08-16 10:32:28 -0400 (Sun, 16 Aug 2009) | 2 lines Update NEWS. ........ r6679 | fwierzbicki | 2009-08-16 11:32:04 -0400 (Sun, 16 Aug 2009) | 2 lines Test file.write(array) ........ r6680 | fwierzbicki | 2009-08-16 13:46:24 -0400 (Sun, 16 Aug 2009) | 3 lines Added some bug fixes to NEWS that didn't make it in before. Also re-ordered my most recent additions since most people grow the fix list downwards :) ........ r6681 | fwierzbicki | 2009-08-16 14:21:50 -0400 (Sun, 16 Aug 2009) | 2 lines Found a couple more closed bugs that didn't make it into NEWS. ........ r6682 | cgroves | 2009-08-16 18:25:58 -0400 (Sun, 16 Aug 2009) | 3 lines Remove the ant exposer from Eclipse as it never seemed to work. ........ r6683 | pjenvey | 2009-08-16 18:40:47 -0400 (Sun, 16 Aug 2009) | 2 lines restrict array writes to binary mode ........ r6684 | pjenvey | 2009-08-16 19:39:05 -0400 (Sun, 16 Aug 2009) | 1 line fix javadoc, small cleanup ........ r6685 | cgroves | 2009-08-16 20:17:36 -0400 (Sun, 16 Aug 2009) | 5 lines WHERE_PLACEHOLDER could hold on to a reference to a type for a while, and it's causing static initialization problems. Screw using a static array and just pass in null if we don't want to know where the item was found. ........ r6686 | pjenvey | 2009-08-16 21:43:09 -0400 (Sun, 16 Aug 2009) | 2 lines fix writelines' handling of non-strs and not resetting softspace ........ r6687 | pjenvey | 2009-08-16 21:47:30 -0400 (Sun, 16 Aug 2009) | 1 line quiet warnings ........ r6688 | fwierzbicki | 2009-08-16 22:29:34 -0400 (Sun, 16 Aug 2009) | 5 lines Added ast tests for "naked tuples" in for statements like: for a,b in c: pass ........ r6689 | fwierzbicki | 2009-08-16 22:30:53 -0400 (Sun, 16 Aug 2009) | 3 lines Removed dynamic scope on expr::lparen. Need to pass the lparen info up to each rule anyway. ........ r6690 | fwierzbicki | 2009-08-16 23:15:31 -0400 (Sun, 16 Aug 2009) | 4 lines Better match of CPython col_offset for factors with parens like: (a - b) * c ........ r6691 | fwierzbicki | 2009-08-17 09:25:59 -0400 (Mon, 17 Aug 2009) | 2 lines Better BinOp col_offsets. ........ r6692 | fwierzbicki | 2009-08-17 14:41:12 -0400 (Mon, 17 Aug 2009) | 3 lines Added "devclean": deletes everything but the generated antlr files, cachedir, and Lib. ........ r6693 | pjenvey | 2009-08-17 22:19:12 -0400 (Mon, 17 Aug 2009) | 1 line small cleanup ........ r6694 | pjenvey | 2009-08-17 22:44:03 -0400 (Mon, 17 Aug 2009) | 2 lines add __unicode__ ........ r6695 | fwierzbicki | 2009-08-19 09:23:14 -0400 (Wed, 19 Aug 2009) | 6 lines A simple class that allows a jarred up Jython app with a __run__.py to run with java -jar myapp.jar as long as it is specified as the main class in the manifest. ........ r6696 | fwierzbicki | 2009-08-19 10:30:14 -0400 (Wed, 19 Aug 2009) | 2 lines Added support for "jython -J-classpath cp_arg_goes_here" in jython unix shell. ........ r6697 | fwierzbicki | 2009-08-19 10:31:17 -0400 (Wed, 19 Aug 2009) | 2 lines Need to add the shell support for -J-classpath to NEWS ........ r6698 | otmarhumbel | 2009-08-19 12:15:00 -0400 (Wed, 19 Aug 2009) | 1 line add livetribe-jsr223-2.0.5.jar to the eclipse .classpath to enable compilation of the jsr223 packages ........ r6710 | fwierzbicki | 2009-08-23 13:35:06 -0400 (Sun, 23 Aug 2009) | 3 lines From CPython http://svn.python.org/python/trunk/Parser/asdl.py@74541 ........ r6713 | cgroves | 2009-08-23 15:47:55 -0400 (Sun, 23 Aug 2009) | 1 line Roll back 6532-6534 and 6548 to keep __javaname__ and sys.javaproxy_dir from going out with 2.5.1. __javaname__ just went away in favor of a naming proxymaker on the customizable-proxymaker branch, and sys.javaproxy_dir doesn't make sense without named proxies. I'll need to re-commit 6533, 6534 and 6548 when I merge customizable-proxymaker to trunk. ........ r6717 | leosoto | 2009-08-23 23:30:29 -0400 (Sun, 23 Aug 2009) | 1 line Fixing typo in org.pyton.modules.thread.thread docs ........ r6718 | cgroves | 2009-08-25 03:59:28 -0400 (Tue, 25 Aug 2009) | 1 line Need to flush the underlying io object after writing our buffer to it to get things really flushed. Fixes issue #1433. ........ r6719 | pjenvey | 2009-08-26 00:19:39 -0400 (Wed, 26 Aug 2009) | 2 lines always flush the raw io, even when nothing is buffered ........ r6724 | pjenvey | 2009-08-29 13:54:06 -0400 (Sat, 29 Aug 2009) | 1 line use @Override ........ r6725 | pjenvey | 2009-08-29 14:30:16 -0400 (Sat, 29 Aug 2009) | 4 lines treat line buffered read streams as the default buffered mode. CPython 2 line buffered read uses a different bufsize than the default depending on the platform (sometimes smaller, sometimes bigger) ........ r6735 | fwierzbicki | 2009-08-31 14:46:06 -0400 (Mon, 31 Aug 2009) | 3 lines Fix for http://bugs.jython.org/issue1424 "Relative imports do not work in some cases". ........ r6736 | fwierzbicki | 2009-08-31 14:47:55 -0400 (Mon, 31 Aug 2009) | 2 lines Update NEWS ........ r6737 | fwierzbicki | 2009-09-01 09:57:52 -0400 (Tue, 01 Sep 2009) | 2 lines Increment APIVersion for coroutine bugfixes in compiler. ........ r6738 | fwierzbicki | 2009-09-01 09:59:14 -0400 (Tue, 01 Sep 2009) | 2 lines Update version numbers. ........ r6739 | fwierzbicki | 2009-09-01 10:02:31 -0400 (Tue, 01 Sep 2009) | 2 lines Update README ........ r6740 | fwierzbicki | 2009-09-01 10:24:42 -0400 (Tue, 01 Sep 2009) | 2 lines Mark release as Gamma level (release candidate) and serial of 1. ........ r6741 | fwierzbicki | 2009-09-01 10:25:55 -0400 (Tue, 01 Sep 2009) | 2 lines Crud, also update the version text strings. ........ Modified Paths: -------------- branches/indy/.classpath branches/indy/.project branches/indy/Lib/os.py branches/indy/Lib/test/test_array.py branches/indy/Lib/test/test_ast.py branches/indy/Lib/test/test_java_subclasses.py branches/indy/Lib/test/test_java_visibility.py branches/indy/NEWS branches/indy/README.txt branches/indy/ast/asdl.py branches/indy/build.xml branches/indy/grammar/Python.g branches/indy/src/com/ziclix/python/sql/PyConnection.java branches/indy/src/com/ziclix/python/sql/PyStatement.java branches/indy/src/com/ziclix/python/sql/connect/Connectx.java branches/indy/src/com/ziclix/python/sql/connect/Lookup.java branches/indy/src/com/ziclix/python/sql/handler/OracleDataHandler.java branches/indy/src/org/python/antlr/GrammarActions.java branches/indy/src/org/python/compiler/Module.java branches/indy/src/org/python/core/MakeProxies.java branches/indy/src/org/python/core/Py.java branches/indy/src/org/python/core/PyFile.java branches/indy/src/org/python/core/PyJavaType.java branches/indy/src/org/python/core/PyOverridableNew.java branches/indy/src/org/python/core/PySystemState.java branches/indy/src/org/python/core/PyType.java branches/indy/src/org/python/core/imp.java branches/indy/src/org/python/core/io/BinaryIOWrapper.java branches/indy/src/org/python/core/io/BufferedIOMixin.java branches/indy/src/org/python/core/io/BufferedRandom.java branches/indy/src/org/python/core/io/BufferedReader.java branches/indy/src/org/python/core/io/BufferedWriter.java branches/indy/src/org/python/core/io/DatagramSocketIO.java branches/indy/src/org/python/core/io/FileIO.java branches/indy/src/org/python/core/io/LineBufferedRandom.java branches/indy/src/org/python/core/io/LineBufferedWriter.java branches/indy/src/org/python/core/io/RawIOBase.java branches/indy/src/org/python/core/io/ServerSocketIO.java branches/indy/src/org/python/core/io/SocketIO.java branches/indy/src/org/python/core/io/SocketIOBase.java branches/indy/src/org/python/core/io/StreamIO.java branches/indy/src/org/python/core/io/TextIOBase.java branches/indy/src/org/python/core/io/TextIOWrapper.java branches/indy/src/org/python/core/io/UniversalIOWrapper.java branches/indy/src/org/python/core/util/ByteSwapper.java branches/indy/src/org/python/core/util/ConcurrentHashSet.java branches/indy/src/org/python/core/util/StringUtil.java branches/indy/src/org/python/expose/ExposedNew.java branches/indy/src/org/python/expose/generate/ExposeTask.java branches/indy/src/org/python/expose/generate/ExposedTypeProcessor.java branches/indy/src/org/python/expose/generate/NewExposer.java branches/indy/src/org/python/modules/thread/thread.java branches/indy/src/org/python/util/GlobMatchingTask.java branches/indy/src/org/python/util/JycompileAntTask.java branches/indy/src/shell/jython Added Paths: ----------- branches/indy/src/org/python/util/JarRunner.java branches/indy/tests/java/org/python/tests/multihidden/ branches/indy/tests/java/org/python/tests/multihidden/BaseConnection.java branches/indy/tests/java/org/python/tests/multihidden/SpecialConnection.java Removed Paths: ------------- branches/indy/.externalToolBuilders/ branches/indy/Lib/test/import_as_java_class.py branches/indy/Lib/test/static_proxy.py branches/indy/src/org/python/util/CompileProxiesTask.java branches/indy/src/org/python/util/FileNameMatchingTask.java branches/indy/tests/java/org/python/tests/multihidden/BaseConnection.java branches/indy/tests/java/org/python/tests/multihidden/SpecialConnection.java Property Changed: ---------------- branches/indy/ branches/indy/extlibs/xercesImpl-2.9.1.jar branches/indy/tests/java/org/python/tests/RedundantInterfaceDeclarations.java Property changes on: branches/indy ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-6660 + /trunk/jython:1-6751 Modified: svn:mergeinfo - /branches/jsr223:6285-6565 /branches/newstyle-java-types:5564-5663,5666-5729 + /branches/jsr223:6285-6565 /branches/newstyle-java-types:5564-5663,5666-5729 /trunk/jython:6662-6741 Modified: branches/indy/.classpath =================================================================== --- branches/indy/.classpath 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/.classpath 2009-09-08 18:21:38 UTC (rev 6764) @@ -1,10 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry excluding="com/ziclix/python/sql/handler/InformixDataHandler.java|com/ziclix/python/sql/handler/OracleDataHandler.java" kind="src" output="build/classes" path="src"/> + <classpathentry excluding="com/ziclix/python/sql/handler/InformixDataHandler.java|com/ziclix/python/sql/handler/OracleDataHandler.java" kind="src" path="src"/> <classpathentry kind="src" path="tests/modjy/java"/> - <classpathentry kind="src" output="build/classes" path="build/gensrc"/> - <classpathentry kind="src" output="build/classes" path="tests/java"/> - <classpathentry kind="src" path="bugtests/classes"/> + <classpathentry kind="src" path="build/gensrc"/> + <classpathentry kind="src" path="tests/java"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/> <classpathentry kind="lib" path="extlibs/jline-0.9.95-SNAPSHOT.jar"/> @@ -20,7 +19,8 @@ <classpathentry kind="lib" path="extlibs/constantine-0.4.jar"/> <classpathentry kind="lib" path="extlibs/jna-posix.jar"/> <classpathentry kind="lib" path="extlibs/mockrunner-0.4.1/jar/jdom.jar"/> - <classpathentry kind="lib" path="extlibs/mockrunner-0.4.1/lib/jdk1.5/j2ee1.3/mockrunner-servlet.jar"/> - <classpathentry kind="lib" path="extlibs/jna.jar"/> - <classpathentry kind="output" path="bugtests/classes"/> + <classpathentry kind="lib" path="extlibs/mockrunner-0.4.1/lib/jdk1.5/j2ee1.3/mockrunner-servlet.jar"/> + <classpathentry kind="lib" path="extlibs/jna.jar"/> + <classpathentry kind="lib" path="extlibs/livetribe-jsr223-2.0.5.jar"/> + <classpathentry kind="output" path="build/classes"/> </classpath> Modified: branches/indy/.project =================================================================== --- branches/indy/.project 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/.project 2009-09-08 18:21:38 UTC (rev 6764) @@ -10,16 +10,6 @@ <arguments> </arguments> </buildCommand> - <buildCommand> - <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name> - <triggers>auto,</triggers> - <arguments> - <dictionary> - <key>LaunchConfigHandle</key> - <value><project>/.externalToolBuilders/Expose and jar.launch</value> - </dictionary> - </arguments> - </buildCommand> </buildSpec> <natures> <nature>org.eclipse.jdt.core.javanature</nature> Modified: branches/indy/Lib/os.py =================================================================== --- branches/indy/Lib/os.py 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/Lib/os.py 2009-09-08 18:21:38 UTC (rev 6764) @@ -732,14 +732,35 @@ """ import subprocess if mode == 'r': - return subprocess.Popen(command, bufsize=bufsize, shell=True, - stdout=subprocess.PIPE).stdout + proc = subprocess.Popen(command, bufsize=bufsize, shell=True, + stdout=subprocess.PIPE) + return _wrap_close(proc.stdout, proc) elif mode == 'w': - return subprocess.Popen(command, bufsize=bufsize, shell=True, - stdin=subprocess.PIPE).stdin + proc = subprocess.Popen(command, bufsize=bufsize, shell=True, + stdin=subprocess.PIPE) + return _wrap_close(proc.stdin, proc) else: raise OSError(errno.EINVAL, strerror(errno.EINVAL)) +# Helper for popen() -- a proxy for a file whose close waits for the process +class _wrap_close(object): + def __init__(self, stream, proc): + self._stream = stream + self._proc = proc + def close(self): + self._stream.close() + returncode = self._proc.wait() + if returncode == 0: + return None + if _name == 'nt': + return returncode + else: + return returncode + def __getattr__(self, name): + return getattr(self._stream, name) + def __iter__(self): + return iter(self._stream) + # os module versions of the popen# methods have different return value # order than popen2 functions Deleted: branches/indy/Lib/test/import_as_java_class.py =================================================================== --- branches/indy/Lib/test/import_as_java_class.py 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/Lib/test/import_as_java_class.py 2009-09-08 18:21:38 UTC (rev 6764) @@ -1,7 +0,0 @@ -# Part of test_java_subclasses.StaticProxyCompilationTest -from java.lang import Class - -# Grab the proxy class statically compiled by the containing test -cls = Class.forName("test.static_proxy.RunnableImpl") -# Instantiating the proxy class should import the module containing it and create the Python side -assert cls.newInstance().meth() == 78 Deleted: branches/indy/Lib/test/static_proxy.py =================================================================== --- branches/indy/Lib/test/static_proxy.py 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/Lib/test/static_proxy.py 2009-09-08 18:21:38 UTC (rev 6764) @@ -1,11 +0,0 @@ -# Part of test_java_subclasses.StaticProxyCompilationTest. This needs to be its own module -# so the statically compiled proxy can import it. -from java.lang import Runnable - -class RunnableImpl(Runnable): - __javaname__ = "test.static_proxy.RunnableImpl" - def run(self): - pass - - def meth(self): - return 78 Modified: branches/indy/Lib/test/test_array.py =================================================================== --- branches/indy/Lib/test/test_array.py 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/Lib/test/test_array.py 2009-09-08 18:21:38 UTC (rev 6764) @@ -216,6 +216,25 @@ if a.itemsize>1 and self.typecode not in ('b', 'B'): self.assertRaises(ValueError, b.fromstring, "x") + def test_filewrite(self): + a = array.array(self.typecode, 2*self.example) + f = open(test_support.TESTFN, 'wb') + try: + f.write(a) + f.close() + b = array.array(self.typecode) + f = open(test_support.TESTFN, 'rb') + b.fromfile(f, len(self.example)) + self.assertEqual(b, array.array(self.typecode, self.example)) + self.assertNotEqual(a, b) + b.fromfile(f, len(self.example)) + self.assertEqual(a, b) + f.close() + finally: + if not f.closed: + f.close() + test_support.unlink(test_support.TESTFN) + def test_repr(self): a = array.array(self.typecode, 2*self.example) self.assertEqual(a, eval(repr(a), {"array": array.array})) Modified: branches/indy/Lib/test/test_ast.py =================================================================== --- branches/indy/Lib/test/test_ast.py 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/Lib/test/test_ast.py 2009-09-08 18:21:38 UTC (rev 6764) @@ -64,6 +64,15 @@ "break", # Continue "continue", + # Parens and BoolOp + "(a == '') and b", + "not (a == '') or b", + # Parens and BinOp + "(a - b) * c", + # for statements with naked tuples + "for a,b in c: pass", + "[(a,b) for a,b in c]", + "((a,b) for a,b in c)", ] # These are compiled through "single" @@ -297,7 +306,7 @@ print kind+"_results = [" for s in statements: print repr(to_tuple(compile(s, "?", kind, 0x400)))+"," - print "]" + print "]" print "main()" raise SystemExit test_main() @@ -326,6 +335,12 @@ ('Module', [('Pass', (1, 0))]), ('Module', [('Break', (1, 0))]), ('Module', [('Continue', (1, 0))]), +('Module', [('Expr', (1, 0), ('BoolOp', (1, 0), ('And',), [('Compare', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('Eq',)], [('Str', (1, 6), '')]), ('Name', (1, 14), 'b', ('Load',))]))]), +('Module', [('Expr', (1, 0), ('BoolOp', (1, 0), ('Or',), [('UnaryOp', (1, 0), ('Not',), ('Compare', (1, 5), ('Name', (1, 5), 'a', ('Load',)), [('Eq',)], [('Str', (1, 10), '')])), ('Name', (1, 17), 'b', ('Load',))]))]), +('Module', [('Expr', (1, 0), ('BinOp', (1, 0), ('BinOp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), ('Sub',), ('Name', (1, 5), 'b', ('Load',))), ('Mult',), ('Name', (1, 10), 'c', ('Load',))))]), +('Module', [('For', (1, 0), ('Tuple', (1, 4), [('Name', (1, 4), 'a', ('Store',)), ('Name', (1, 6), 'b', ('Store',))], ('Store',)), ('Name', (1, 11), 'c', ('Load',)), [('Pass', (1, 14))], [])]), +('Module', [('Expr', (1, 0), ('ListComp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]), +('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]), ] single_results = [ ('Interactive', [('Expr', (1, 0), ('BinOp', (1, 0), ('Num', (1, 0), 1), ('Add',), ('Num', (1, 2), 2)))]), Modified: branches/indy/Lib/test/test_java_subclasses.py =================================================================== --- branches/indy/Lib/test/test_java_subclasses.py 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/Lib/test/test_java_subclasses.py 2009-09-08 18:21:38 UTC (rev 6764) @@ -1,8 +1,6 @@ '''Tests subclassing Java classes in Python''' import os import sys -import tempfile -import subprocess import unittest from test import test_support @@ -323,56 +321,10 @@ self.assertEquals(len(called), 1) -class SettingJavaClassNameTest(unittest.TestCase): - def test_setting_name(self): - class Fixedname(Runnable): - __javaname__ = 'name.set.in.Python' - def run(self): - pass - self.assertEquals('name.set.in.Python', Fixedname().getClass().name) - try: - class NumberPackageName(Runnable): - __javaname__ = 'ok.7.ok' - def run(self): - pass - self.fail("Shouldn't be able to set a package name that starts with a digit") - except TypeError: - pass - try: - class LiteralPackageName(Runnable): - __javaname__ = 'ok.true.ok' - def run(self): - pass - self.fail("Shouldn't be able to use a Java literal as a package name") - except TypeError: - pass - -class StaticProxyCompilationTest(unittest.TestCase): - def setUp(self): - self.orig_proxy_dir = sys.javaproxy_dir - sys.javaproxy_dir = tempfile.mkdtemp() - - def tearDown(self): - sys.javaproxy_dir = self.orig_proxy_dir - - def test_proxies_without_classloader(self): - # importing with proxy_dir set compiles RunnableImpl there - import static_proxy - - # Use the existing environment with the proxy dir added on the classpath - env = dict(os.environ) - env["CLASSPATH"] = sys.javaproxy_dir - script = test_support.findfile("import_as_java_class.py") - self.assertEquals(subprocess.call([sys.executable, "-J-Dpython.cachedir.skip=true", - script], env=env), - 0) - def test_main(): test_support.run_unittest(InterfaceTest, TableModelTest, AutoSuperTest, PythonSubclassesTest, AbstractOnSyspathTest, - ContextClassloaderTest, - SettingJavaClassNameTest, - StaticProxyCompilationTest) + ContextClassloaderTest) Modified: branches/indy/Lib/test/test_java_visibility.py =================================================================== --- branches/indy/Lib/test/test_java_visibility.py 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/Lib/test/test_java_visibility.py 2009-09-08 18:21:38 UTC (rev 6764) @@ -10,6 +10,7 @@ from org.python.tests import VisibilityResults as Results from org.python.tests.RedundantInterfaceDeclarations import (Implementation, ExtraClass, ExtraString, ExtraStringAndClass, ExtraClassAndString) +from org.python.tests.multihidden import BaseConnection class VisibilityTest(unittest.TestCase): def test_invisible(self): @@ -167,6 +168,15 @@ self.assertEquals("int", instance.call(7)) self.assertEquals("Class", instance.call(LinkedList)) + def test_extending_multiple_hidden_classes(self): + '''Tests multiple levels of non-public classes overriding public methods from superclasses + + Bug #1430''' + conn = BaseConnection.newConnection() + self.assertEquals("wrapper close", conn.close()) + self.assertEquals("special close", conn.close(7)) + + class JavaClassTest(unittest.TestCase): def test_class_methods_visible(self): self.assertFalse(HashMap.isInterface(), Modified: branches/indy/NEWS =================================================================== --- branches/indy/NEWS 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/NEWS 2009-09-08 18:21:38 UTC (rev 6764) @@ -1,14 +1,12 @@ Jython NEWS -Jython 2.5.1 +Jython 2.5.1rc1 New Features - Upgraded to ANTLR 3.1.3 - [ 1859477 ] Dynamically loaded ServletFilters like PyServlet - - Setting __javaname__ in classes subclassing Java classes or implementing Java interfaces sets - the name of the produced proxy class. - Built in JSR 223 scripting engine, with LiveTribe JSR 223 implementation for JDK 5 + - Jython "-J-classpath cp_args_here" now works as expected for unix shell. Bugs Fixed - - [ 1415 ] ast Node creation fails with no arg constructors - [ 645615 ] cannot import through symbolic links - [ 1366 ] parsing of lamda expression fails - [ 1365 ] continuation lines fail in interactive interpreter @@ -19,6 +17,19 @@ - [ 1145 ] Jython 2.5 compatibility problem with JSR 223 - [ 1400 ] Evaluating expression via JSR 223 ScriptEngine returns null instead of True/False - [ 1413 ] Array data type (PostgreSQL) is not supported (NPE) + - [ 1434 ] Cannot get return code from a process started with os.popen with Jython 2.5 (worked in 2.2) + - [ 1391 ] socket.getaddrinfo() breaks ftplib FTP client + - [ 1409 ] JSR-233 engine version numbers backwards + - [ 1408 ] JSR-223 engine doesn't implement I/O redirection + - [ 1393 ] TypeError: _new_impl(): expected 1 args; got 0 + - [ 1415 ] ast Node creation fails with no arg constructors + - [ 1405 ] Executing __run__.py from .jar throws exception(SystemExit: 0) in main when sys.exit(0) is called + - [ 1439 ] Can't write() array.array + - [ 1139 ] crashes on isinstance + - [ 1430 ] Oracle JDBC Connection close + - [ 1406 ] Parsing a simple PEP 342 coroutine crashes Jython 2.5 + - [ 1407 ] ClassCastException in plain Python coroutine + - [ 1424 ] Relative imports do not work in some cases Jython 2.5.0 The same as rc4. Modified: branches/indy/README.txt =================================================================== --- branches/indy/README.txt 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/README.txt 2009-09-08 18:21:38 UTC (rev 6764) @@ -1,11 +1,10 @@ -Welcome to Jython 2.5.0 -======================= +Welcome to Jython 2.5.1rc1 +========================== -This is the final release of the 2.5.0 version of Jython and brings us up to -language level compatibility with the 2.5 version of CPython. This release has -had a strong focus on CPython compatibility, and so this release of Jython can -run more pure Python apps then any previous release. Please see the NEWS file -for detailed release notes. +This is the first release candidate of the 2.5.1 version of Jython. This +release fixes a number of bugs, including some major errors when using +coroutines and when using relative imports. Please see the NEWS file for +detailed release notes. The release was compiled on Mac OS X with JDK 5 and requires JDK 5 to run. Modified: branches/indy/ast/asdl.py =================================================================== --- branches/indy/ast/asdl.py 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/ast/asdl.py 2009-09-08 18:21:38 UTC (rev 6764) @@ -10,14 +10,12 @@ Changes for Python: Add support for module versions """ -#__metaclass__ = type - import os import traceback import spark -class Token: +class Token(object): # spark seems to dispatch in the parser based on a token's # type attribute def __init__(self, type, lineno): @@ -45,7 +43,7 @@ self.value = value self.lineno = lineno -class ASDLSyntaxError: +class ASDLSyntaxError(Exception): def __init__(self, lineno, token=None, msg=None): self.lineno = lineno @@ -167,7 +165,7 @@ return Product(fields) def p_sum_0(self, (constructor,)): - " sum ::= constructor """ + " sum ::= constructor " return [constructor] def p_sum_1(self, (constructor, _, sum)): @@ -206,19 +204,19 @@ def p_field_2(self, (type, _, name)): " field ::= Id * Id " - return Field(type, name, seq=1) + return Field(type, name, seq=True) def p_field_3(self, (type, _, name)): " field ::= Id ? Id " - return Field(type, name, opt=1) + return Field(type, name, opt=True) def p_field_4(self, (type, _)): " field ::= Id * " - return Field(type, seq=1) + return Field(type, seq=True) def p_field_5(self, (type, _)): " field ::= Id ? " - return Field(type, opt=1) + return Field(type, opt=True) builtin_types = ("identifier", "string", "int", "bool", "object") @@ -226,7 +224,7 @@ # not sure if any of the methods are useful yet, but I'm adding them # piecemeal as they seem helpful -class AST: +class AST(object): pass # a marker class class Module(AST): @@ -258,7 +256,7 @@ return "Constructor(%s, %s)" % (self.name, self.fields) class Field(AST): - def __init__(self, type, name=None, seq=0, opt=0): + def __init__(self, type, name=None, seq=False, opt=False): self.type = type self.name = name self.seq = seq @@ -266,9 +264,9 @@ def __repr__(self): if self.seq: - extra = ", seq=1" + extra = ", seq=True" elif self.opt: - extra = ", opt=1" + extra = ", opt=True" else: extra = "" if self.name is None: @@ -296,7 +294,7 @@ class VisitorBase(object): - def __init__(self, skip=0): + def __init__(self, skip=False): self.cache = {} self.skip = skip @@ -331,7 +329,7 @@ class Check(VisitorBase): def __init__(self): - super(Check, self).__init__(skip=1) + super(Check, self).__init__(skip=True) self.cons = {} self.errors = 0 self.types = {} @@ -373,7 +371,7 @@ v.visit(mod) for t in v.types: - if not mod.types.has_key(t) and not t in builtin_types: + if t not in mod.types and not t in builtin_types: v.errors += 1 uses = ", ".join(v.types[t]) print "Undefined type %s, used in %s" % (t, uses) Modified: branches/indy/build.xml =================================================================== --- branches/indy/build.xml 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/build.xml 2009-09-08 18:21:38 UTC (rev 6764) @@ -108,12 +108,43 @@ <target name="full-build" depends="full-check, install" description="a full build with svn checkout" /> <target name="needed-check" unless="full-build"> - <uptodate property="antlr.notneeded" targetfile="${dist.dir}/${jython.dev.jar}"> + <uptodate property="antlr.notneeded" targetfile="${gensrc.dir}/org/python/antlr/PythonParser.java"> <srcfiles dir="grammar" includes="*.g" /> </uptodate> </target> - <target name="init" depends="version-init"> + <target name="init"> + <property file="${user.home}/ant.properties" /> + <property file="${basedir}/ant.properties" /> + + <property name="PY_RELEASE_LEVEL_ALPHA" value="10"/> <!-- 0xA --> + <property name="PY_RELEASE_LEVEL_BETA" value="11"/> <!-- 0xB --> + <property name="PY_RELEASE_LEVEL_GAMMA" value="12"/> <!-- 0xC --> + <property name="PY_RELEASE_LEVEL_FINAL" value="15"/> <!-- 0xF --> + <property name="PY_RELEASE_LEVEL_SNAPSHOT" value="170"/> <!-- 0xAA --> + + <!-- The current version info --> + <property name="jython.version" value="2.5.1+"/> + <property name="jython.version.noplus" value="2.5.1"/> + <property name="jython.major_version" value="2"/> + <property name="jython.minor_version" value="5"/> + <property name="jython.micro_version" value="1"/> + <property name="jython.release_level" value="${PY_RELEASE_LEVEL_GAMMA}"/> + <property name="jython.release_serial" value="1"/> + + <condition property="do.snapshot.build"> + <isset property="snapshot.revision" /> + </condition> + <!-- Switch to a snapshot release_level when appropriate --> + <condition property="jython.real_release_level" value="${PY_RELEASE_LEVEL_SNAPSHOT}" else="${jython.release_level}"> + <isset property="do.snapshot.build" /> + </condition> + <condition property="os.family.unix"> + <os family="unix"/> + </condition> + <condition property="os.family.windows"> + <os family="windows"/> + </condition> <property name="build.compiler" value="modern" /> <property name="jdk.target.version" value="1.7" /> <property name="jdk.source.version" value="1.7" /> @@ -158,10 +189,14 @@ <pathelement path="${extlibs.dir}/antlr-3.1.3.jar" /> <pathelement path="${extlibs.dir}/stringtemplate-3.2.jar" /> + <pathelement path="${extlibs.dir}/livetribe-jsr223-2.0.5.jar" /> <pathelement path="${extlibs.dir}/asm-all-3.2.jar" /> + <pathelement path="${extlibs.dir}/jna.jar"/> <pathelement path="${extlibs.dir}/constantine-0.4.jar" /> <pathelement path="${extlibs.dir}/jna-posix.jar"/> + <!-- <pathelement path="${extlibs.dir}/jsr292-mock.jar"/> + --> </path> <available property="informix.present" classname="com.informix.jdbc.IfxDriver" classpath="${informix.jar}" /> @@ -311,6 +346,23 @@ </delete> </target> + <target name="devclean" depends="init" + description="clean up build working directories, without deleting antlr files, cachedir, or Lib."> + + <delete includeemptydirs="true" failonerror="false"> + <fileset dir="${output.dir}" includes="**/*" excludes="gensrc/**"/> + </delete> + <!-- deletes all files and subdirectories of ${dist.dir}, without ${dist.dir} itself. --> + <delete includeemptydirs="true" failonerror="false"> + <fileset dir="${dist.dir}" includes="**/*" excludes="cachedir/**,Lib/**"/> + </delete> + <!-- delete the installation .jar file from ${work.dir}, but no other files --> + <delete failonerror="false"> + <fileset dir="${work.dir}" includes="jython*.jar" /> + </delete> + </target> + + <!-- clean svn.checkout.dir if we really checkout --> <target name="clean-checkout-dir" if="do.checkout"> <delete includeemptydirs="true" failonerror="false"> Property changes on: branches/indy/extlibs/xercesImpl-2.9.1.jar ___________________________________________________________________ Modified: svn:mergeinfo - /branches/newstyle-java-types/extlibs/xercesImpl.jar:5564-5663,5666-5729 + /branches/newstyle-java-types/extlibs/xercesImpl.jar:5564-5663,5666-5729 /trunk/jython/extlibs/xercesImpl-2.9.1.jar:6662-6741 Modified: branches/indy/grammar/Python.g =================================================================== --- branches/indy/grammar/Python.g 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/grammar/Python.g 2009-09-08 18:21:38 UTC (rev 6764) @@ -885,23 +885,23 @@ //if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] if_stmt - : IF test[expr_contextType.Load] COLON ifsuite=suite[false] elif_clause[$test.start]? + : IF test[expr_contextType.Load] COLON ifsuite=suite[false] elif_clause? -> ^(IF<If>[$IF, actions.castExpr($test.tree), actions.castStmts($ifsuite.stypes), actions.makeElse($elif_clause.stypes, $elif_clause.tree)]) ; //not in CPython's Grammar file elif_clause - [Token iftest] returns [List stypes] + returns [List stypes] : else_clause { $stypes = $else_clause.stypes; } | ELIF test[expr_contextType.Load] COLON suite[false] - (e2=elif_clause[$iftest] - -> ^(ELIF<If>[$iftest, actions.castExpr($test.tree), actions.castStmts($suite.stypes), actions.makeElse($e2.stypes, $e2.tree)]) + (e2=elif_clause + -> ^(ELIF<If>[$test.start, actions.castExpr($test.tree), actions.castStmts($suite.stypes), actions.makeElse($e2.stypes, $e2.tree)]) | - -> ^(ELIF<If>[$iftest, actions.castExpr($test.tree), actions.castStmts($suite.stypes), new ArrayList<stmt>()]) + -> ^(ELIF<If>[$test.start, actions.castExpr($test.tree), actions.castStmts($suite.stypes), new ArrayList<stmt>()]) ) ; @@ -1038,10 +1038,15 @@ ; //or_test: and_test ('or' and_test)* -or_test[expr_contextType ctype] +or_test + [expr_contextType ctype] returns [Token leftTok] @after { if ($or != null) { - $or_test.tree = actions.makeBoolOp($left.tree, boolopType.Or, $right); + Token tok = $left.start; + if ($left.leftTok != null) { + tok = $left.leftTok; + } + $or_test.tree = actions.makeBoolOp(tok, $left.tree, boolopType.Or, $right); } } : left=and_test[ctype] @@ -1053,10 +1058,15 @@ ; //and_test: not_test ('and' not_test)* -and_test[expr_contextType ctype] +and_test + [expr_contextType ctype] returns [Token leftTok] @after { if ($and != null) { - $and_test.tree = actions.makeBoolOp($left.tree, boolopType.And, $right); + Token tok = $left.start; + if ($left.leftTok != null) { + tok = $left.leftTok; + } + $and_test.tree = actions.makeBoolOp(tok, $left.tree, boolopType.And, $right); } } : left=not_test[ctype] @@ -1068,18 +1078,21 @@ ; //not_test: 'not' not_test | comparison -not_test[expr_contextType ctype] +not_test + [expr_contextType ctype] returns [Token leftTok] : NOT nt=not_test[ctype] -> ^(NOT<UnaryOp>[$NOT, unaryopType.Not, actions.castExpr($nt.tree)]) - | comparison[ctype] + | comparison[ctype] {$leftTok = $comparison.leftTok;} ; //comparison: expr (comp_op expr)* -comparison[expr_contextType ctype] +comparison + [expr_contextType ctype] returns [Token leftTok] @init { List cmps = new ArrayList(); } @after { + $leftTok = $left.leftTok; if (!cmps.isEmpty()) { $comparison.tree = new Compare($left.start, actions.castExpr($left.tree), actions.makeCmpOps(cmps), actions.castExprs($right)); @@ -1125,7 +1138,8 @@ //expr: xor_expr ('|' xor_expr)* -expr[expr_contextType ect] +expr + [expr_contextType ect] returns [Token leftTok] scope { expr_contextType ctype; } @@ -1133,8 +1147,13 @@ $expr::ctype = ect; } @after { + $leftTok = $left.lparen; if ($op != null) { - $expr.tree = actions.makeBinOp($left.tree, operatorType.BitOr, $right); + Token tok = $left.start; + if ($left.lparen != null) { + tok = $left.lparen; + } + $expr.tree = actions.makeBinOp(tok, $left.tree, operatorType.BitOr, $right); } } : left=xor_expr @@ -1148,10 +1167,16 @@ //xor_expr: and_expr ('^' and_expr)* xor_expr + returns [Token lparen = null] @after { if ($op != null) { - $xor_expr.tree = actions.makeBinOp($left.tree, operatorType.BitXor, $right); + Token tok = $left.start; + if ($left.lparen != null) { + tok = $left.lparen; + } + $xor_expr.tree = actions.makeBinOp(tok, $left.tree, operatorType.BitXor, $right); } + $lparen = $left.lparen; } : left=and_expr ( (op=CIRCUMFLEX right+=and_expr @@ -1163,10 +1188,16 @@ //and_expr: shift_expr ('&' shift_expr)* and_expr + returns [Token lparen = null] @after { if ($op != null) { - $and_expr.tree = actions.makeBinOp($left.tree, operatorType.BitAnd, $right); + Token tok = $left.start; + if ($left.lparen != null) { + tok = $left.lparen; + } + $and_expr.tree = actions.makeBinOp(tok, $left.tree, operatorType.BitAnd, $right); } + $lparen = $left.lparen; } : left=shift_expr ( (op=AMPER right+=shift_expr @@ -1178,18 +1209,26 @@ //shift_expr: arith_expr (('<<'|'>>') arith_expr)* shift_expr + returns [Token lparen = null] @init { List ops = new ArrayList(); + List toks = new ArrayList(); } @after { if (!ops.isEmpty()) { - $shift_expr.tree = actions.makeBinOp($left.tree, ops, $right); + Token tok = $left.start; + if ($left.lparen != null) { + tok = $left.lparen; + } + $shift_expr.tree = actions.makeBinOp(tok, $left.tree, ops, $right, toks); } + $lparen = $left.lparen; } : left=arith_expr ( ( shift_op right+=arith_expr { ops.add($shift_op.op); + toks.add($shift_op.start); } )+ | @@ -1207,18 +1246,26 @@ //arith_expr: term (('+'|'-') term)* arith_expr + returns [Token lparen = null] @init { List ops = new ArrayList(); + List toks = new ArrayList(); } @after { if (!ops.isEmpty()) { - $arith_expr.tree = actions.makeBinOp($left.tree, ops, $right); + Token tok = $left.start; + if ($left.lparen != null) { + tok = $left.lparen; + } + $arith_expr.tree = actions.makeBinOp(tok, $left.tree, ops, $right, toks); } + $lparen = $left.lparen; } : left=term ( (arith_op right+=term { ops.add($arith_op.op); + toks.add($arith_op.start); } )+ | @@ -1244,18 +1291,26 @@ //term: factor (('*'|'/'|'%'|'//') factor)* term + returns [Token lparen = null] @init { List ops = new ArrayList(); + List toks = new ArrayList(); } @after { + $lparen = $left.lparen; if (!ops.isEmpty()) { - $term.tree = actions.makeBinOp($left.tree, ops, $right); + Token tok = $left.start; + if ($left.lparen != null) { + tok = $left.lparen; + } + $term.tree = actions.makeBinOp(tok, $left.tree, ops, $right, toks); } } : left=factor ( (term_op right+=factor { ops.add($term_op.op); + toks.add($term_op.start); } )+ | @@ -1277,7 +1332,7 @@ //factor: ('+'|'-'|'~') factor | power factor - returns [expr etype] + returns [expr etype, Token lparen = null] @after { $factor.tree = $etype; } @@ -1288,17 +1343,21 @@ | TILDE t=factor {$etype = new UnaryOp($TILDE, unaryopType.Invert, $t.etype);} | power - {$etype = actions.castExpr($power.tree);} + { + $etype = actions.castExpr($power.tree); + $lparen = $power.lparen; + } ; //power: atom trailer* ['**' factor] power - returns [expr etype] + returns [expr etype, Token lparen = null] @after { $power.tree = $etype; } : atom (t+=trailer[$atom.start, $atom.tree])* (options {greedy=true;}:d=DOUBLESTAR factor)? { + $lparen = $atom.lparen; //XXX: This could be better. $etype = actions.castExpr($atom.tree); if ($t != null) { @@ -1325,7 +1384,7 @@ if ($d != null) { List right = new ArrayList(); right.add($factor.tree); - $etype = actions.makeBinOp($etype, operatorType.Pow, right); + $etype = actions.makeBinOp($atom.start, $etype, operatorType.Pow, right); } } ; @@ -1336,7 +1395,8 @@ // '`' testlist1 '`' | // NAME | NUMBER | STRING+) atom - : LPAREN + returns [Token lparen = null] + : LPAREN {$lparen = $LPAREN;} ( yield_expr -> yield_expr | testlist_gexp Modified: branches/indy/src/com/ziclix/python/sql/PyConnection.java =================================================================== --- branches/indy/src/com/ziclix/python/sql/PyConnection.java 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/src/com/ziclix/python/sql/PyConnection.java 2009-09-08 18:21:38 UTC (rev 6764) @@ -12,13 +12,11 @@ import java.sql.SQLException; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import org.python.core.ClassDictInit; import org.python.core.Py; import org.python.core.PyBuiltinMethodSet; -import org.python.core.PyClass; import org.python.core.PyInteger; import org.python.core.PyList; import org.python.core.PyObject; @@ -36,39 +34,25 @@ */ public class PyConnection extends PyObject implements ClassDictInit { - /** - * Field closed - */ + /** True if closed. */ protected boolean closed; - /** - * Field connection - */ - protected Connection connection; - - /** - * Field supportsTransactions - */ + /** Whether transactions are supported. */ protected boolean supportsTransactions; - /** - * Field cursors - */ - private Set cursors; + /** The underlying java.sql.Connection. */ + protected Connection connection; - /** - * Field statements - */ - private Set statements; + /** Underlying cursors. */ + private Set<PyCursor> cursors; - /** - * Field __members__ - */ + /** Underlying statements. */ + private Set<PyStatement> statements; + + /** Field __members__ */ protected static PyList __members__; - /** - * Field __methods__ - */ + /** Field __methods__ */ protected static PyList __methods__; static { @@ -101,11 +85,10 @@ * @throws SQLException */ public PyConnection(Connection connection) throws SQLException { - this.closed = false; - this.cursors = new HashSet(); + this.cursors = new HashSet<PyCursor>(); this.connection = connection; - this.statements = new HashSet(); + this.statements = new HashSet<PyStatement>(); this.supportsTransactions = this.connection.getMetaData().supportsTransactions(); if (this.supportsTransactions) { @@ -120,7 +103,6 @@ */ @Override public String toString() { - try { return String.format("<PyConnection object at %s user='%s', url='%s'>", Py.idstr(this), connection.getMetaData().getUserName(), @@ -136,14 +118,20 @@ * @param dict */ static public void classDictInit(PyObject dict) { - + PyObject version = + Py.newString("$Revision$").__getslice__(Py.newInteger(11), + Py.newInteger(-2)); + dict.__setitem__("__version__", version); dict.__setitem__("autocommit", new PyInteger(0)); - dict.__setitem__("__version__", Py.newString("$Revision$").__getslice__(Py.newInteger(11), Py.newInteger(-2), null)); dict.__setitem__("close", new ConnectionFunc("close", 0, 0, 0, zxJDBC.getString("close"))); - dict.__setitem__("commit", new ConnectionFunc("commit", 1, 0, 0, zxJDBC.getString("commit"))); - dict.__setitem__("cursor", new ConnectionFunc("cursor", 2, 0, 4, zxJDBC.getString("cursor"))); - dict.__setitem__("rollback", new ConnectionFunc("rollback", 3, 0, 0, zxJDBC.getString("rollback"))); - dict.__setitem__("nativesql", new ConnectionFunc("nativesql", 4, 1, 1, zxJDBC.getString("nativesql"))); + dict.__setitem__("commit", new ConnectionFunc("commit", 1, 0, 0, + zxJDBC.getString("commit"))); + dict.__setitem__("cursor", new ConnectionFunc("cursor", 2, 0, 4, + zxJDBC.getString("cursor"))); + dict.__setitem__("rollback", new ConnectionFunc("rollback", 3, 0, 0, + zxJDBC.getString("rollback"))); + dict.__setitem__("nativesql", new ConnectionFunc("nativesql", 4, 1, 1, + zxJDBC.getString("nativesql"))); // hide from python dict.__setitem__("initModule", null); @@ -161,8 +149,8 @@ * @param name * @param value */ + @Override public void __setattr__(String name, PyObject value) { - if ("autocommit".equals(name)) { try { if (this.supportsTransactions) { @@ -171,7 +159,6 @@ } catch (SQLException e) { throw zxJDBC.makeException(zxJDBC.DatabaseError, e); } - return; } @@ -184,8 +171,8 @@ * @param name the name of the attribute of interest * @return the value for the attribute of the specified name */ + @Override public PyObject __findattr_ex__(String name) { - if ("autocommit".equals(name)) { try { return connection.getAutoCommit() ? Py.One : Py.Zero; @@ -240,40 +227,31 @@ } /** - * Close the connection now (rather than whenever __del__ is called). - * The connection will be unusable from this point forward; an Error - * (or subclass) exception will be raised if any operation is attempted - * with the connection. The same applies to all cursor objects trying - * to use the connection. + * Close the connection now (rather than whenever __del__ is called). The connection + * will be unusable from this point forward; an Error (or subclass) exception will be + * raised if any operation is attempted with the connection. The same applies to all + * cursor objects trying to use the connection. */ public void close() { - if (closed) { throw zxJDBC.makeException(zxJDBC.ProgrammingError, "connection is closed"); } - // mark ourselves closed now so that any callbacks we - // get from closing down cursors and statements to not - // try and modify our internal sets + // mark ourselves closed now so that any callbacks we get from closing down + // cursors and statements to not try and modify our internal sets this.closed = true; synchronized (this.cursors) { - - // close the cursors - for (Iterator i = this.cursors.iterator(); i.hasNext();) { - ((PyCursor) i.next()).close(); + for (PyCursor cursor: cursors) { + cursor.close(); } - this.cursors.clear(); } synchronized (this.statements) { - - // close the cursors - for (Iterator i = this.statements.iterator(); i.hasNext();) { - ((PyStatement) i.next()).close(); + for (PyStatement statement : statements) { + statement.close(); } - this.statements.clear(); } @@ -285,15 +263,14 @@ } /** - * Commit any pending transaction to the database. Note that if the - * database supports an auto-commit feature, this must be initially - * off. An interface method may be provided to turn it back on. + * Commit any pending transaction to the database. Note that if the database supports + * an auto-commit feature, this must be initially off. An interface method may be + * provided to turn it back on. * <p/> - * Database modules that do not support transactions should implement - * this method with void functionality. + * Database modules that do not support transactions should implement this method with + * void functionality. */ public void commit() { - if (closed) { throw zxJDBC.makeException(zxJDBC.ProgrammingError, "connection is closed"); } @@ -310,16 +287,13 @@ } /** - * <i>This method is optional since not all databases provide transaction - * support.</i> + * <i>This method is optional since not all databases provide transaction support.</i> * <p/> - * In case a database does provide transactions this method causes the database - * to roll back to the start of any pending transaction. Closing a connection - * without committing the changes first will cause an implicit rollback to be - * performed. + * In case a database does provide transactions this method causes the database to + * roll back to the start of any pending transaction. Closing a connection without + * committing the changes first will cause an implicit rollback to be performed. */ public void rollback() { - if (closed) { throw zxJDBC.makeException(zxJDBC.ProgrammingError, "connection is closed"); } @@ -336,10 +310,10 @@ } /** - * Converts the given SQL statement into the system's native SQL grammar. A - * driver may convert the JDBC sql grammar into its system's native SQL grammar - * prior to sending it; this method returns the native form of the statement - * that the driver would have sent. + * Converts the given SQL statement into the system's native SQL grammar. A driver may + * convert the JDBC sql grammar into its system's native SQL grammar prior to sending + * it; this method returns the native form of the statement that the driver would have + * sent. * * @param nativeSQL * @return the native form of this statement @@ -364,9 +338,9 @@ } /** - * Return a new Cursor Object using the connection. If the database does not - * provide a direct cursor concept, the module will have to emulate cursors - * using other means to the extent needed by this specification. + * Return a new Cursor Object using the connection. If the database does not provide a + * direct cursor concept, the module will have to emulate cursors using other means to + * the extent needed by this specification. * * @return a new cursor using this connection */ @@ -375,9 +349,9 @@ } /** - * Return a new Cursor Object using the connection. If the database does not - * provide a direct cursor concept, the module will have to emulate cursors - * using other means to the extent needed by this specification. + * Return a new Cursor Object using the connection. If the database does not provide a + * direct cursor concept, the module will have to emulate cursors using other means to + * the extent needed by this specification. * * @param dynamicFetch if true, dynamically iterate the result * @return a new cursor using this connection @@ -387,9 +361,9 @@ } /** - * Return a new Cursor Object using the connection. If the database does not - * provide a direct cursor concept, the module will have to emulate cursors - * using other means to the extent needed by this specification. + * Return a new Cursor Object using the connection. If the database does not provide a + * direct cursor concept, the module will have to emulate cursors using other means to + * the extent needed by this specification. * * @param dynamicFetch if true, dynamically iterate the result * @param rsType the type of the underlying ResultSet @@ -397,15 +371,12 @@ * @return a new cursor using this connection */ public PyCursor cursor(boolean dynamicFetch, PyObject rsType, PyObject rsConcur) { - if (closed) { throw zxJDBC.makeException(zxJDBC.ProgrammingError, "connection is closed"); } PyCursor cursor = new PyExtendedCursor(this, dynamicFetch, rsType, rsConcur); - this.cursors.add(cursor); - return cursor; } @@ -415,11 +386,9 @@ * @param cursor */ void remove(PyCursor cursor) { - if (closed) { return; } - this.cursors.remove(cursor); } @@ -429,11 +398,9 @@ * @param statement statement */ void add(PyStatement statement) { - if (closed) { return; } - this.statements.add(statement); } @@ -444,20 +411,20 @@ * @return boolean */ boolean contains(PyStatement statement) { - if (closed) { return false; } - return this.statements.contains(statement); } } class ConnectionFunc extends PyBuiltinMethodSet { + ConnectionFunc(String name, int index, int minargs, int maxargs, String doc) { super(name, index, minargs, maxargs, doc, PyConnection.class); } + @Override public PyObject __call__() { PyConnection c = (PyConnection) __self__; switch (index) { @@ -472,11 +439,12 @@ case 3: c.rollback(); return Py.None; - default : + default: throw info.unexpectedCall(0, false); } } + @Override public PyObject __call__(PyObject arg) { PyConnection c = (PyConnection) __self__; switch (index) { @@ -484,21 +452,23 @@ return c.cursor(arg.__nonzero__()); case 4: return c.nativesql(arg); - default : + default: throw info.unexpectedCall(1, false); } } + @Override public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3) { PyConnection c = (PyConnection) __self__; switch (index) { case 2: return c.cursor(arg1.__nonzero__(), arg2, arg3); - default : + default: throw info.unexpectedCall(3, false); } } + @Override public PyObject __call__(PyObject[] args, String[] keywords) { PyConnection c = (PyConnection) __self__; PyArgParser parser = new PyArgParser(args, keywords); @@ -514,7 +484,7 @@ return c.cursor(dynamic.__nonzero__(), rstype, rsconcur); - default : + default: throw info.unexpectedCall(args.length, true); } } Modified: branches/indy/src/com/ziclix/python/sql/PyStatement.java =================================================================== --- branches/indy/src/com/ziclix/python/sql/PyStatement.java 2009-09-07 21:48:20 UTC (rev 6763) +++ branches/indy/src/com/ziclix/python/sql/PyStatement.java 2009-09-08 18:21:38 UTC (rev 6764) @@ -8,12 +8,13 @@ */ package com.ziclix.python.sql; +import org.python.core.codecs; impor... [truncated message content] |
From: <zy...@us...> - 2009-09-07 21:48:27
|
Revision: 6763 http://jython.svn.sourceforge.net/jython/?rev=6763&view=rev Author: zyasoft Date: 2009-09-07 21:48:20 +0000 (Mon, 07 Sep 2009) Log Message: ----------- CodeCompiler#visitAssert now looks up the AssertionError by using PyFrame#getglobal, so user code can redefine the behavior of assert. Fixes #1461 Bumped bytecode magic. Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/compiler/CodeCompiler.java trunk/jython/src/org/python/core/imp.java Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-09-07 20:41:45 UTC (rev 6762) +++ trunk/jython/NEWS 2009-09-07 21:48:20 UTC (rev 6763) @@ -3,6 +3,7 @@ Jython 2.5.1rc2 Bugs Fixed - [ 1079 ] fixed regression on issue: twisted.python.threadable module: missing attribute '_RLock' + - [ 1461 ] assert statement should lookup AssertionError using getglobal Jython 2.5.1rc1 New Features Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-09-07 20:41:45 UTC (rev 6762) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-09-07 21:48:20 UTC (rev 6763) @@ -964,8 +964,9 @@ getNone(); } - /* Push exception type onto stack(Py.AssertionError) */ - code.getstatic("org/python/core/Py", "AssertionError", "Lorg/python/core/PyObject;"); + /* Push exception type onto stack(AssertionError) */ + loadFrame(); + emitGetGlobal("AssertionError"); code.swap(); // The type is the first argument, but the message could be a yield Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2009-09-07 20:41:45 UTC (rev 6762) +++ trunk/jython/src/org/python/core/imp.java 2009-09-07 21:48:20 UTC (rev 6763) @@ -21,7 +21,7 @@ private static final String UNKNOWN_SOURCEFILE = "<unknown>"; - private static final int APIVersion = 25; + private static final int APIVersion = 26; public static final int NO_MTIME = -1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-09-07 20:41:58
|
Revision: 6762 http://jython.svn.sourceforge.net/jython/?rev=6762&view=rev Author: zyasoft Date: 2009-09-07 20:41:45 +0000 (Mon, 07 Sep 2009) Log Message: ----------- Fixed regression where threading._Lock, _RLock were no longer available as synonyms to Lock and RLock respectively, which Twisted needs. Added a test case to prevent recurrence. This resolves #1079. Modified Paths: -------------- trunk/jython/Lib/test/test_threading_jy.py trunk/jython/Lib/threading.py trunk/jython/NEWS trunk/jython/src/org/python/modules/_threading/_threading.java Modified: trunk/jython/Lib/test/test_threading_jy.py =================================================================== --- trunk/jython/Lib/test/test_threading_jy.py 2009-09-06 23:26:58 UTC (rev 6761) +++ trunk/jython/Lib/test/test_threading_jy.py 2009-09-07 20:41:45 UTC (rev 6762) @@ -36,8 +36,14 @@ time.sleep(random.random()) +class TwistedTestCase(unittest.TestCase): + + def test_needs_underscored_versions(self): + self.assertEqual(threading.Lock, threading._Lock) + self.assertEqual(threading.RLock, threading._RLock) + def test_main(): - test_support.run_unittest(ThreadingTestCase) + test_support.run_unittest(ThreadingTestCase, TwistedTestCase) if __name__ == "__main__": Modified: trunk/jython/Lib/threading.py =================================================================== --- trunk/jython/Lib/threading.py 2009-09-06 23:26:58 UTC (rev 6761) +++ trunk/jython/Lib/threading.py 2009-09-07 20:41:45 UTC (rev 6762) @@ -5,7 +5,7 @@ from org.python.util import jython from thread import _newFunctionThread from thread import _local as local -from _threading import Lock, RLock, Condition +from _threading import Lock, RLock, Condition, _Lock, _RLock import java.lang.Thread import weakref Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-09-06 23:26:58 UTC (rev 6761) +++ trunk/jython/NEWS 2009-09-07 20:41:45 UTC (rev 6762) @@ -1,5 +1,9 @@ Jython NEWS +Jython 2.5.1rc2 + Bugs Fixed + - [ 1079 ] fixed regression on issue: twisted.python.threadable module: missing attribute '_RLock' + Jython 2.5.1rc1 New Features - Upgraded to ANTLR 3.1.3 Modified: trunk/jython/src/org/python/modules/_threading/_threading.java =================================================================== --- trunk/jython/src/org/python/modules/_threading/_threading.java 2009-09-06 23:26:58 UTC (rev 6761) +++ trunk/jython/src/org/python/modules/_threading/_threading.java 2009-09-07 20:41:45 UTC (rev 6762) @@ -10,6 +10,8 @@ dict.__setitem__("__name__", Py.newString("_threading")); dict.__setitem__("Lock", Lock.TYPE); dict.__setitem__("RLock", Lock.TYPE); + dict.__setitem__("_Lock", Lock.TYPE); + dict.__setitem__("_RLock", Lock.TYPE); dict.__setitem__("Condition", Condition.TYPE); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-09-06 09:42:15
|
Revision: 6760 http://jython.svn.sourceforge.net/jython/?rev=6760&view=rev Author: cgroves Date: 2009-09-06 09:42:02 +0000 (Sun, 06 Sep 2009) Log Message: ----------- Kill the JavaMaker/ProxyMaker distinction to collect the set of proxy code generation methods together, and unify the actual code generation around visit methods for each type of thing a proxy class might be interested in. Hopefully this is leading to more straightforward subclasses. Modified Paths: -------------- branches/customizable-proxymaker/Lib/javaproxymaker.py branches/customizable-proxymaker/Lib/test/test_class_jy.py branches/customizable-proxymaker/src/org/python/compiler/AdapterMaker.java branches/customizable-proxymaker/src/org/python/compiler/ClassFile.java branches/customizable-proxymaker/src/org/python/compiler/Module.java branches/customizable-proxymaker/src/org/python/compiler/ProxyCodeHelpers.java branches/customizable-proxymaker/src/org/python/compiler/ProxyMaker.java branches/customizable-proxymaker/src/org/python/core/MakeProxies.java Added Paths: ----------- branches/customizable-proxymaker/src/org/python/compiler/VerifyingClassFile.java Removed Paths: ------------- branches/customizable-proxymaker/src/org/python/compiler/JavaMaker.java Modified: branches/customizable-proxymaker/Lib/javaproxymaker.py =================================================================== --- branches/customizable-proxymaker/Lib/javaproxymaker.py 2009-09-06 07:34:32 UTC (rev 6759) +++ branches/customizable-proxymaker/Lib/javaproxymaker.py 2009-09-06 09:42:02 UTC (rev 6760) @@ -1,15 +1,15 @@ from java.lang.reflect import Modifier from org.python.compiler import JavaMaker as NamedProxyMaker +from org.python.core.util import StringUtil def make_proxynamer(classname): '''Creates a callable for use in __proxymaker__ that names the generated classes the given name - If the given name is an invalid Java class name, an exception will be raised at class definition - time.''' + If the given name is an invalid Java class name, a ValueError will be raised.''' + if not StringUtil.isJavaClassName(classname): + raise ValueError("%s is not a valid Java class name. See http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#40625" % classname) def make_proxymaker(superclass, interfaces, pythonClassName, pythonClassDict): - proxymaker = NamedProxyMaker(superclass, interfaces, pythonClassName, pythonClassDict) - proxymaker.proxyClassName = classname - return proxymaker + return NamedProxyMaker(superclass, interfaces, pythonClassName, pythonClassDict, classname) return make_proxymaker class StrictProxyMaker(NamedProxyMaker): @@ -30,4 +30,4 @@ handle it from __getattribute__ unlike from regular proxy classes. Also, if the overriden method is abstract and isn't handled by the Python class, a noop return will be performed.''' def visitMethod(self, meth): - self.addMethod(meth) + self.addOverrideMethod(meth) Modified: branches/customizable-proxymaker/Lib/test/test_class_jy.py =================================================================== --- branches/customizable-proxymaker/Lib/test/test_class_jy.py 2009-09-06 07:34:32 UTC (rev 6759) +++ branches/customizable-proxymaker/Lib/test/test_class_jy.py 2009-09-06 09:42:02 UTC (rev 6760) @@ -39,7 +39,7 @@ self.assertEqual(str(cls), "<class '%s.%s'>" % (__name__, cls.__name__)) self.assertEqual(repr(cls), "<class '%s.%s'>" % (__name__, cls.__name__)) self.assert_(str(Bar()).startswith('<%s.Bar object at' % __name__)) - self.assert_(str(Baz()).startswith("org.python.proxies.%s$Baz" % __name__)) + self.assert_(str(Baz()).startswith("org.python.proxies.%s.Baz$" % __name__)) def test_builtin_attributes(self): for attr, val in dict(__name__='foo', __module__='bar', __dict__={}, Modified: branches/customizable-proxymaker/src/org/python/compiler/AdapterMaker.java =================================================================== --- branches/customizable-proxymaker/src/org/python/compiler/AdapterMaker.java 2009-09-06 07:34:32 UTC (rev 6759) +++ branches/customizable-proxymaker/src/org/python/compiler/AdapterMaker.java 2009-09-06 09:42:02 UTC (rev 6760) @@ -1,9 +1,8 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.compiler; +import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import java.util.HashSet; - import org.objectweb.asm.Label; public class AdapterMaker extends ProxyMaker { @@ -13,23 +12,19 @@ } @Override - protected void build() { - classfile.addInterface(mapClass(interfaces[0])); - visitMethods(interfaces[0], new HashSet<MethodDescr>()); - try { - addConstructor(Object.class.getConstructor()); - } catch (NoSuchMethodException e) { - throw new RuntimeException( - "Object.class doesn't have a no-arg constructor? What the dickens?", e); - } + public void visitConstructor(Constructor<?> constructor) { + doReturn(addOpenConstructor(constructor), superclass); } @Override - protected void addOverrideMethod(Method method) { + protected void visitMethod(Method method) { + if (!method.getDeclaringClass().isInterface()) { + return; + } Class<?>[] parameters = method.getParameterTypes(); Class<?> ret = method.getReturnType(); String name = method.getName(); - Code code = classfile.addMethod(name, makeSig(ret, parameters), ACC_PUBLIC); + Code code = classfile.addMethod(ACC_PUBLIC, ret, name, parameters); code.aload(0); code.getfield(classfile.name, name, $pyObj); code.dup(); Modified: branches/customizable-proxymaker/src/org/python/compiler/ClassFile.java =================================================================== --- branches/customizable-proxymaker/src/org/python/compiler/ClassFile.java 2009-09-06 07:34:32 UTC (rev 6759) +++ branches/customizable-proxymaker/src/org/python/compiler/ClassFile.java 2009-09-06 09:42:02 UTC (rev 6760) @@ -9,7 +9,6 @@ import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; - import org.python.core.imp; import org.python.util.Generic; @@ -34,18 +33,6 @@ * - The name of the class in internal form. * @param superclass * - The name of the superclass of the generated class in internal form. - */ - public ClassFile(String name, String superclass) { - this(name, superclass, imp.NO_MTIME, null); - } - - /** - * Creates a generator for a class of the given name. - * - * @param name - * - The name of the class in internal form. - * @param superclass - * - The name of the superclass of the generated class in internal form. * @param mtime * - the time the source was last modified, or {@link imp#NO_MTIME} if it's unknown. * @param sourceFilename @@ -77,7 +64,7 @@ * @param access * - the method's access level as constructed from {@link Opcodes}. */ - public Code addMethod(String name, String descriptor, int access, String... exceptions) { + protected Code addMethod(String name, String descriptor, int access, String... exceptions) { MethodVisitor mv = cw.visitMethod(access, name, descriptor, null, exceptions); Code pmv = new Code(mv, descriptor, access); methodVisitors.add(pmv); @@ -106,8 +93,6 @@ cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, name, null, superclass, interfaces.toArray(new String[interfaces.size()])); AnnotationVisitor av = cw.visitAnnotation("Lorg/python/compiler/APIVersion;", true); - // XXX: should imp.java really house this value or should imp.java point into - // org.python.compiler? av.visit("value", imp.getAPIVersion()); av.visitEnd(); Deleted: branches/customizable-proxymaker/src/org/python/compiler/JavaMaker.java =================================================================== --- branches/customizable-proxymaker/src/org/python/compiler/JavaMaker.java 2009-09-06 07:34:32 UTC (rev 6759) +++ branches/customizable-proxymaker/src/org/python/compiler/JavaMaker.java 2009-09-06 09:42:02 UTC (rev 6760) @@ -1,88 +0,0 @@ -// Copyright (c) Corporation for National Research Initiatives -package org.python.compiler; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -import org.python.core.PyObject; - -public class JavaMaker extends ProxyMaker { - - public final String pythonClass, pythonModule; - - public PyObject dict; - - private final boolean proxyNeeded; - - public JavaMaker(Class<?> superclass, - Class<?>[] interfaces, - String qualifiedPythonClassName, - PyObject pythonClassDict) { - super(qualifiedPythonClassName, superclass, interfaces); - proxyNeeded = superclass != null || interfaces.length > 0; - int lastDot = qualifiedPythonClassName.lastIndexOf('.'); - if (lastDot != -1) { - pythonClass = qualifiedPythonClassName.substring(lastDot + 1); - pythonModule = qualifiedPythonClassName.substring(0, lastDot); - } else { - pythonClass = qualifiedPythonClassName; - pythonModule = ""; - } - this.dict = pythonClassDict; - } - - @Override - protected void build() { - super.build(); - - addInitProxy(); - } - - @Override - public void visitConstructor(Constructor<?> constructor) - { - /* Need a fancy constructor for the Java side of things */ - Code code = addOpenConstructor(constructor); - callInitProxy(constructor.getParameterTypes(), code); - } - - /** - * Calls __initProxy__ on this class with the given given types of parameters, which must be - * available as arguments to the currently called method in the order of the parameters. - */ - protected void callInitProxy(Class<?>[] parameters, Code code) { - code.visitVarInsn(ALOAD, 0); - getArgs(code, parameters); - code.visitMethodInsn(INVOKEVIRTUAL, classfile.name, "__initProxy__", makeSig("V", $objArr)); - code.visitInsn(RETURN); - } - - protected void addInitProxy() { - Code code = classfile.addMethod("__initProxy__", makeSig("V", $objArr), Modifier.PUBLIC); - - code.visitVarInsn(ALOAD, 0); - code.visitLdcInsn(pythonModule); - code.visitLdcInsn(pythonClass); - code.visitVarInsn(ALOAD, 1); - code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "initProxy", - makeSig("V", $pyProxy, $str, $str, $objArr)); - code.visitInsn(RETURN); - - } - - @Override - public void visitMethod(Method method) { - if (Modifier.isAbstract(method.getModifiers())) { - super.visitMethod(method); - } else if (dict.__finditem__(method.getName().intern()) != null) { - super.visitMethod(method); - } else if (Modifier.isProtected(method.getModifiers())) { - addSuperMethod(method); - } - } - - public boolean isProxyNeeded() { - return proxyNeeded; - } -} Modified: branches/customizable-proxymaker/src/org/python/compiler/Module.java =================================================================== --- branches/customizable-proxymaker/src/org/python/compiler/Module.java 2009-09-06 07:34:32 UTC (rev 6759) +++ branches/customizable-proxymaker/src/org/python/compiler/Module.java 2009-09-06 09:42:02 UTC (rev 6760) @@ -24,6 +24,7 @@ import org.python.core.Py; import org.python.core.PyException; import org.python.core.PyRunnableBootstrap; +import org.python.core.imp; import org.python.core.util.StringUtil; class PyIntegerConstant extends Constant implements ClassConstants, Opcodes @@ -306,7 +307,8 @@ public Module(String name, String filename, boolean linenumbers, long mtime) { this.linenumbers = linenumbers; this.mtime = mtime; - classfile = new ClassFile(name, "org/python/core/PyFunctionTable", mtime, sfilename); + classfile = new ClassFile(ProxyCodeHelpers.mapClass(name), + "org/python/core/PyFunctionTable", mtime, sfilename); constants = new Hashtable<Constant,Constant>(); sfilename = filename; codes = new ArrayList<PyCodeConstant>(); @@ -622,13 +624,15 @@ } throw new ParseException(msg,node); } - public static void compile(mod node, OutputStream ostream, - String name, String filename, - boolean linenumbers, boolean printResults, - CompilerFlags cflags) - throws Exception - { - compile(node, ostream, name, filename, linenumbers, printResults, cflags, org.python.core.imp.NO_MTIME); + + public static void compile(mod node, + OutputStream ostream, + String name, + String filename, + boolean linenumbers, + boolean printResults, + CompilerFlags cflags) throws Exception { + compile(node, ostream, name, filename, linenumbers, printResults, cflags, imp.NO_MTIME); } public static void compile(mod node, OutputStream ostream, Modified: branches/customizable-proxymaker/src/org/python/compiler/ProxyCodeHelpers.java =================================================================== --- branches/customizable-proxymaker/src/org/python/compiler/ProxyCodeHelpers.java 2009-09-06 07:34:32 UTC (rev 6759) +++ branches/customizable-proxymaker/src/org/python/compiler/ProxyCodeHelpers.java 2009-09-06 09:42:02 UTC (rev 6760) @@ -251,7 +251,7 @@ public static void callSuper(Code code, String name, - String superclass, + Class<?> superclass, Class<?>[] parameters, Class<?> ret, boolean doReturn) { @@ -286,7 +286,7 @@ break; } } - code.invokespecial(superclass, name, makeSig(ret, parameters)); + code.invokespecial(mapClass(superclass), name, makeSig(ret, parameters)); if (doReturn) { doReturn(code, ret); Modified: branches/customizable-proxymaker/src/org/python/compiler/ProxyMaker.java =================================================================== --- branches/customizable-proxymaker/src/org/python/compiler/ProxyMaker.java 2009-09-06 07:34:32 UTC (rev 6759) +++ branches/customizable-proxymaker/src/org/python/compiler/ProxyMaker.java 2009-09-06 09:42:02 UTC (rev 6760) @@ -4,15 +4,20 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; + +import java.util.List; import java.util.Set; import org.objectweb.asm.Label; +import org.python.core.ClassDictInit; import org.python.core.Py; import org.python.core.PyMethod; import org.python.core.PyObject; import org.python.core.PyProxy; import org.python.core.PyReflectedFunction; +import org.python.core.PySystemState; import org.python.util.Generic; +import org.python.util.Preconditions; public class ProxyMaker extends ProxyCodeHelpers { /** @@ -42,72 +47,141 @@ return ret; } + /** The name of the class to build. */ + public final String proxyClassName; + protected VerifyingClassFile classfile; protected final Class<?> superclass; - protected final Class<?>[] interfaces; - private final Set<String> names = Generic.set(); + protected final List<Class<?>> interfaces = Generic.list(); private final Set<String> supernames = Generic.set(); - protected ClassFile classfile; - /** The name of the class to build. */ - public String proxyClassName; + private final boolean proxyNeeded; + public final String pythonClass, pythonModule; + public final PyObject dict; + /** * Creates a proxy class maker that produces classes named <code>proxyClassName</code> that * extends <code>superclass</code> and implements the interfaces in <code>interfaces</code>. */ - public ProxyMaker(String proxyClassName, Class<?> superclass, Class<?>... interfaces) { + ProxyMaker(String proxyClassName, Class<?> superclass, Class<?>... interfaces) { + this(superclass, interfaces, null, null, proxyClassName); + } + + public ProxyMaker(Class<?> superclass, + Class<?>[] interfaces, + String qualifiedPythonClassName, + PyObject pythonClassDict) { + this(superclass, interfaces, qualifiedPythonClassName, pythonClassDict, + qualifiedPythonClassName); + } + + public ProxyMaker(Class<?> superclass, + Class<?>[] interfaces, + String qualifiedPythonClassName, + PyObject pythonClassDict, + String proxyClassName) { this.proxyClassName = proxyClassName; + proxyNeeded = superclass != null || interfaces.length > 0; if (superclass == null) { superclass = Object.class; } - if (superclass.isInterface()) { - throw new IllegalArgumentException("Given an interface, " + superclass.getName() - + ", for a proxy superclass"); - } else if ((superclass.getModifiers() & Modifier.FINAL) != 0) { - throw new IllegalArgumentException("Can't subclass final class " + superclass.getName()); - } + Preconditions.checkArgument(!superclass.isInterface(), "Given an interface, " + + superclass.getName() + ", for a proxy superclass"); + Preconditions.checkArgument((superclass.getModifiers() & Modifier.FINAL) == 0, + "Can't subclass final class " + superclass.getName()); this.superclass = superclass; - if (interfaces == null) { - interfaces = new Class[0]; - } - for (Class<?> interfac : interfaces) { - if (!interfac.isInterface()) { - throw new IllegalArgumentException( - "All classes in the interfaces array must be interfaces, unlike " - + interfac.getName()); + for (Class<?> iface : interfaces) { + Preconditions.checkArgument(iface.isInterface(), + "Asked to add non-interface to proxy class as interface: " + iface.getName()); + if (iface.isAssignableFrom(superclass)) { + Py.writeWarning("compiler", "discarding redundant interface: " + iface.getName()); } + this.interfaces.add(iface); } - this.interfaces = interfaces; + int lastDot = qualifiedPythonClassName.lastIndexOf('.'); + if (lastDot != -1) { + pythonClass = qualifiedPythonClassName.substring(lastDot + 1); + pythonModule = qualifiedPythonClassName.substring(0, lastDot); + } else { + pythonClass = qualifiedPythonClassName; + pythonModule = ""; + } + this.dict = pythonClassDict; } + public boolean isProxyNeeded() { + return proxyNeeded; + } + /** * Builds this proxy and returns its bytecode. */ public synchronized byte[] make() { - classfile = new ClassFile(proxyClassName, mapClass(superclass)); - build(); + classfile = new VerifyingClassFile(mapClass(proxyClassName), mapClass(superclass)); + addProxy(); + for (Constructor<?> constructor : superclass.getDeclaredConstructors()) { + if (Modifier.isPrivate(constructor.getModifiers())) { + continue; + } + classfile.noteSuperclassConstructor(constructor); + visitConstructor(constructor); + } + visitMethods(superclass); + for (Class<?> iface : interfaces) { + classfile.addInterface(mapClass(iface)); + visitMethods(iface); + } + didVisits(); + addClassDictInit(); + supernames.clear(); byte[] result = classfile.create(); classfile = null; return result; } /** - * Called once per created proxy class. Should fill in the necessary methods, constructors and - * interfaces on <code>classfile</code>. Only one call to build will be active at a time, so - * data can be collected in the class as the call proceed, but it should be cleaned up before - * returning to keep later calls to build functioning properly. + * Called for every constructor on the proxy's superclass that can be overridden by + * the proxy class. */ - protected void build() { - addProxy(); - visitConstructors(); - classfile.addInterface("org/python/core/PyProxy"); + protected void visitConstructor(Constructor<?> constructor) + { + /* Need a fancy constructor for the Java side of things */ + callInitProxy(constructor.getParameterTypes(), addOpenConstructor(constructor)); + } - visitMethods(); - addClassDictInit(); - names.clear(); - supernames.clear(); + /** + * Called for every method on the proxy's superclass and interfaces that can be overridden by + * the proxy class. If the proxy wants to perform Python lookup and calling for the method, + * {@link #addOverrideMethod(Method)} should be called. For abstract methods, a method matching + * this signature must be added to the proxy class. + * <p> + * ProxyMaker's implementation of this method calls <code>addOverrideMethod</code> if the given + * method is abstract or if the Python dict contains an item for the method's name. If the + * method is protected, a super method is added. Otherwise, it doesn't add a method with this + * signature on the proxy class. + */ + protected void visitMethod(Method method) { + if (Modifier.isAbstract(method.getModifiers())) { + addOverrideMethod(method); + } else if (dict.__finditem__(method.getName().intern()) != null) { + addOverrideMethod(method); + } else if (Modifier.isProtected(method.getModifiers())) { + addSuperMethod(method, false); + } } + protected void visitFinalMethod(Method method) { + if (Modifier.isProtected(method.getModifiers())) { + addSuperMethod(method, true); + } + } + /** + * Called as part of {@link #make} after the visit methods have been called for every + * constructor and method. + */ + protected void didVisits() {} + + /** * Adds an override of <code>method</code> to the class being implemented. If * <code>method</code> is abstract, the generated method will expect to find an object of the * method's name in the Python object and call it. If it isn't abstract, if an object is found @@ -115,7 +189,6 @@ */ protected void addOverrideMethod(Method method) { boolean isAbstract = Modifier.isAbstract(method.getModifiers()); - addMethod(method.getName(), method.getReturnType(), method.getParameterTypes(), method.getExceptionTypes(), Modifier.PUBLIC, isAbstract ? null : method.getDeclaringClass()); @@ -123,33 +196,113 @@ /** * Adds a method to the class being implemented with the given signature. The generated method - * will expect to find an object of the method's name in the Python object and call it. - * - * @param - the modifier to be used on the generated method. + * will call an object of the method's name in the Python object. */ - protected void addMethod(String name, - Class<?> ret, - Class<?>[] parameters, + protected void addMethod(String name, Class<?> ret, Class<?>[] parameters, Class<?>[] exceptions) { addMethod(name, ret, parameters, exceptions, Modifier.PUBLIC, null); } /** - * Adds a method of the given name to the class being implemented. If - * <code>declaringClass</code> is null, the generated method will expect to find an object of - * the method's name in the Python object and call it. If it isn't null, if an object is found - * in the Python object, it'll be called. Otherwise the superclass will be called. No checking - * is done to guarantee that the superclass has a method with the same signature. + * Adds a "super" method to the class being generated. A super method is a public method that + * calls through to the method with the same signature on a superclass. If + * <code>prefixWithSuper</code> is given, super__ is prefixed to the method name on this class. + * <p> + * ProxyMaker automatically generates super methods with the prefix in two cases: + * <p> + * <ol> + * <li>for protected final methods to expose the method to Python without overriding a final + * method.</li> + * <li>for methods overridden for Python to give access to the superclass method from Python.</li> + * </ol> + * + * All other super method generation is under the control of subclasses. */ + protected void addSuperMethod(Method method, boolean prefixWithSuper) { + String methodName = method.getName(); + if (prefixWithSuper) { + methodName = "super__" + methodName; + } + addSuperMethod(methodName, method.getName(), method.getDeclaringClass(), + method.getParameterTypes(), method.getReturnType()); + } + + + /** + * Calls __initProxy__ on this class with the given given types of parameters, which must be + * available as arguments to the currently called method in the order of the parameters. + */ + protected void callInitProxy(Class<?>[] parameters, Code code) { + code.visitVarInsn(ALOAD, 0); + getArgs(code, parameters); + code.visitMethodInsn(INVOKEVIRTUAL, classfile.name, "__initProxy__", makeSig("V", $objArr)); + code.visitInsn(RETURN); + } + + /** + * Adds a constructor that calls through to the superclass constructor with the same signature + * and leaves the returned Code open for more operations. The caller of this method must add a + * return to the Code. + */ + protected Code addOpenConstructor(Constructor<?> constructor) { + Code code = classfile.addMethod(ACC_PUBLIC, Void.TYPE, "<init>", constructor + .getParameterTypes(), constructor.getExceptionTypes()); + callSuper(code, "<init>", superclass, constructor.getParameterTypes(), Void.TYPE, false); + return code; + } + + /** + * Visits all methods declared on the given class and classes in its inheritance hierarchy. + * Methods visible to subclasses are added to the classfile. + */ + private void visitMethods(Class<?> klass) { + for (Method method : klass.getDeclaredMethods()) { + + int access = method.getModifiers(); + if (Modifier.isStatic(access) || Modifier.isPrivate(access) || + PyReflectedFunction.isPackagedProtected(access)) { + // package protected and private aren't visible to our class, so they don't enter + // into the namespace, and likewise for static methods, regardless of their access. + + // TODO - allow overriding of package protected methods if the generated class is in + // the same package, throw an exception otherwise. + continue; + } else if (classfile.noteSuperclassMethod(method)) { + // No method with the same signature has been added, check if we want to + if (Modifier.isFinal(access)) { + visitFinalMethod(method); + } else { + visitMethod(method); + } + } + } + + Class<?> superClass = klass.getSuperclass(); + if (superClass != null) { + visitMethods(superClass); + } + + for (Class<?> iface : klass.getInterfaces()) { + visitMethods(iface); + } + } + + /** + * Adds a method of the given name to the class being implemented that attempts to find a + * callable with the given name in the Python instance and calls through to it. + * <p> + * If <code>declaringClass</code> is null, the Python instance must provide an implementation. + * If it isn't null, a super__ method will be added for this method, and if a Python callable + * isn't found under the method's name, the super method will be called. No checking is done to + * guarantee that the superclass has a method with the same signature. + */ private void addMethod(String name, Class<?> ret, Class<?>[] parameters, Class<?>[] exceptions, int access, Class<?> declaringClass) { - names.add(name); - Code code = classfile.addMethod(name, makeSig(ret, parameters), access, - mapClasses(exceptions)); + Code code = classfile.addMethod(access, ret, name, parameters, exceptions); code.aload(0); code.ldc(name); if (declaringClass != null) { @@ -160,12 +313,11 @@ code.aload(tmp); Label callPython = new Label(); code.ifnonnull(callPython); - String superClass = mapClass(declaringClass); - callSuper(code, name, superClass, parameters, ret, true); + callSuper(code, name, declaringClass, parameters, ret, true); code.label(callPython); code.aload(tmp); callMethod(code, name, parameters, ret, exceptions); - addSuperMethod("super__" + name, name, superClass, parameters, ret); + addSuperMethod("super__" + name, name, declaringClass, parameters, ret); } else { code.invokestatic("org/python/compiler/ProxyMaker", "findPython", makeSig($pyObj, $pyProxy, $str)); @@ -179,143 +331,9 @@ } } - protected static class MethodDescr { - - public final Class<?> returnType; - - public final String name; - - public final Class<?>[] parameters; - - public final Class<?>[] exceptions; - - public MethodDescr(Method m) { - this(m.getName(), m.getReturnType(), m.getParameterTypes(), m.getExceptionTypes()); - } - - public MethodDescr(String name, - Class<?> returnType, - Class<?>[] parameters, - Class<?>[] exceptions) { - this.name = name; - this.returnType = returnType; - this.parameters = parameters; - this.exceptions = exceptions; - } - - @Override - public int hashCode() { - return name.hashCode() + parameters.length; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof MethodDescr)) { - return false; - } - MethodDescr oDescr = (MethodDescr)obj; - if (!name.equals(oDescr.name) || parameters.length != oDescr.parameters.length) { - return false; - } - for (int i = 0; i < parameters.length; i++) { - if (!parameters[i].equals(oDescr.parameters[i])) { - return false; - } - } - return true; - } - } - - protected static class ConstructorDescr extends MethodDescr { - - public ConstructorDescr(Constructor<?> cons) { - this(cons.getParameterTypes(), cons.getExceptionTypes()); - } - - public ConstructorDescr(Class<?>[] parameters, Class<?>[] exceptions) { - super("<init>", Void.TYPE, parameters, exceptions); - } - } - - /** Adds a constructor that calls through to superclass and returns immediately. */ - protected void addConstructor(Constructor<?> constructor) { - Code code = addOpenConstructor(constructor); - doReturn(code, superclass); - } - - /** - * Adds a constructor that calls through to superclass and leaves the returned Code open for - * more operations. The caller of this method must add a return to the returned Code. - */ - protected Code addOpenConstructor(Constructor<?> constructor) { - String sig = makeSig(Void.TYPE, constructor.getParameterTypes()); - Code code = classfile.addMethod("<init>", sig, ACC_PUBLIC, - mapClasses(constructor.getExceptionTypes())); - callSuper(code, "<init>", mapClass(superclass), constructor.getParameterTypes(), Void.TYPE, - false); - return code; - } - - /** - * Visits constructors from this proxy's superclass. - */ - private void visitConstructors() { - for (Constructor<?> constructor : superclass.getDeclaredConstructors()) { - if (Modifier.isPrivate(constructor.getModifiers())) { - continue; - } - visitConstructor(constructor); - } - } - - /** - * Called for every method on the proxy's superclass and interfaces that can be overridden by - * the proxy class. If the proxy wants to perform Python lookup and calling for the method, - * {@link #addOverrideMethod(Method)} should be called. For abstract methods, addMethod must be - * called. - */ - protected void visitMethod(Method method) { - addOverrideMethod(method); - } - - - /** - * Called for every constructor on the proxy's superclass that can be overridden by - * the proxy class. - */ - protected void visitConstructor(Constructor<?> constructor) { - addConstructor(constructor); - } - - // Super methods are added for the following three reasons: - // - // 1) for a protected non-final method add a public method with no - // super__ prefix. This gives needed access to this method for - // subclasses - // - // 2) for protected final methods, add a public method with the - // super__ prefix. This avoids the danger of trying to override a - // final method - // - // 3) For any other method that is overridden, add a method with the - // super__ prefix. This gives access to super. version or the - // method. - // - protected void addSuperMethod(Method method) { - Class<?>[] parameters = method.getParameterTypes(); - Class<?> ret = method.getReturnType(); - String superClass = mapClass(method.getDeclaringClass()); - String superName = method.getName(); - String methodName = superName; - if (Modifier.isFinal(method.getModifiers())) { - methodName = "super__" + superName; - } - addSuperMethod(methodName, superName, superClass, parameters, ret); - } - private void addSuperMethod(String methodName, String superName, - String declClass, + Class<?> declClass, Class<?>[] parameters, Class<?> ret) { if (methodName.startsWith("super__")) { @@ -330,53 +348,59 @@ return; } catch (NoSuchMethodException e) { // OK, no one else defines it, so we need to - } catch (SecurityException e) { - return; } } supernames.add(methodName); - Code code = classfile.addMethod(methodName, makeSig(ret, parameters), Modifier.PUBLIC); + Code code = classfile.addMethod(ACC_PUBLIC, ret, methodName, parameters); callSuper(code, superName, declClass, parameters, ret, true); } - /** - * Adds the methods and fields necessary to implement PyProxy. - */ private void addProxy() { + if (dict == null) { + return; + } + classfile.addInterface(mapClass(PyProxy.class)); classfile.addField("__proxy", $pyObj, Modifier.PROTECTED); - Code code = classfile.addMethod("_setPyInstance", makeSig("V", $pyObj), Modifier.PUBLIC); + Code code = classfile.addMethod(ACC_PUBLIC, Void.TYPE, "_setPyInstance", PyObject.class); code.aload(0); code.aload(1); code.putfield(classfile.name, "__proxy", $pyObj); code.return_(); - - code = classfile.addMethod("_getPyInstance", makeSig($pyObj), Modifier.PUBLIC); + code = classfile.addMethod(ACC_PUBLIC, PyObject.class, "_getPyInstance"); code.aload(0); code.getfield(classfile.name, "__proxy", $pyObj); code.areturn(); - - String pySys = "Lorg/python/core/PySystemState;"; + String pySys = "Lorg/python/core/PySystemState;"; classfile.addField("__systemState", pySys, Modifier.PROTECTED | Modifier.TRANSIENT); - - code = classfile.addMethod("_setPySystemState", makeSig("V", pySys), Modifier.PUBLIC); + code = classfile.addMethod(ACC_PUBLIC, Void.TYPE, "_setPySystemState", PySystemState.class); code.aload(0); code.aload(1); code.putfield(classfile.name, "__systemState", pySys); code.return_(); - - code = classfile.addMethod("_getPySystemState", makeSig(pySys), Modifier.PUBLIC); + code = classfile.addMethod(ACC_PUBLIC, PySystemState.class, "_getPySystemState"); code.aload(0); code.getfield(classfile.name, "__systemState", pySys); code.areturn(); + code = classfile.addMethod(ACC_PUBLIC, Void.TYPE, "__initProxy__", Object[].class); + code.visitVarInsn(ALOAD, 0); + code.visitLdcInsn(pythonModule); + code.visitLdcInsn(pythonClass); + code.visitVarInsn(ALOAD, 1); + code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "initProxy", + makeSig("V", $pyProxy, $str, $str, $objArr)); + code.visitInsn(RETURN); } /** * Adds the classDictInit static method to fill in __supernames__ on the class' dict */ private void addClassDictInit() { - classfile.addInterface(mapClass(org.python.core.ClassDictInit.class)); - Code code = classfile.addMethod("classDictInit", makeSig("V", $pyObj), - Modifier.PUBLIC | Modifier.STATIC); + if (dict == null) { + return; + } + classfile.addInterface(mapClass(ClassDictInit.class)); + Code code = classfile.addMethod(ACC_PUBLIC | ACC_STATIC, Void.TYPE, "classDictInit", + PyObject.class); code.aload(0); code.ldc("__supernames__"); @@ -387,61 +411,4 @@ code.invokevirtual("org/python/core/PyObject", "__setitem__", makeSig("V", $str, $pyObj)); code.return_(); } - - /** - * Visits all methods declared on the given class and classes in its inheritance hierarchy. - * Methods visible to subclasses are added to <code>seen</code>. - */ - void visitMethods(Class<?> klass, Set<MethodDescr> seen) { - for (Method method : klass.getDeclaredMethods()) { - - int access = method.getModifiers(); - if (Modifier.isStatic(access) || Modifier.isPrivate(access) || - PyReflectedFunction.isPackagedProtected(access)) { - // package protected and private aren't visible to our class, so they don't enter - // into the namespace, and likewise for static methods, regardless of their access. - - // TODO - allow overriding of package protected methods if the generated class is in - // the same package, throw an exception otherwise. - continue; - } - - if (!seen.add(new MethodDescr(method))) { - // A method with the same signature has already been added, skip this. - continue; - } - - // TODO - Track accessible final methods in their own Set, protect from overrides - if (Modifier.isFinal(access)) { - if (Modifier.isProtected(access)) { - addSuperMethod(method); - } - continue; - } - visitMethod(method); - } - - Class<?> superClass = klass.getSuperclass(); - if (superClass != null) { - visitMethods(superClass, seen); - } - - for (Class<?> iface : klass.getInterfaces()) { - visitMethods(iface, seen); - } - } - - private Set<MethodDescr> visitMethods() { - Set<MethodDescr> seenmethods = Generic.set(); - visitMethods(superclass, seenmethods); - for (Class<?> iface : interfaces) { - if (iface.isAssignableFrom(superclass)) { - Py.writeWarning("compiler", "discarding redundant interface: " + iface.getName()); - continue; - } - classfile.addInterface(mapClass(iface)); - visitMethods(iface, seenmethods); - } - return seenmethods; - } } Added: branches/customizable-proxymaker/src/org/python/compiler/VerifyingClassFile.java =================================================================== --- branches/customizable-proxymaker/src/org/python/compiler/VerifyingClassFile.java (rev 0) +++ branches/customizable-proxymaker/src/org/python/compiler/VerifyingClassFile.java 2009-09-06 09:42:02 UTC (rev 6760) @@ -0,0 +1,109 @@ +package org.python.compiler; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +import java.util.Set; + +import org.python.core.imp; +import org.python.util.Generic; + + +public class VerifyingClassFile extends ClassFile { + + public VerifyingClassFile(String name, String superclass) { + super(name, superclass, imp.NO_MTIME, null); + } + + public boolean noteSuperclassMethod(Method meth) { + return superclassMeths.add(new MethodDescr(meth)); + } + + public boolean hasMethod(String name, Class<?> returns, Class<?>[] parameters, + Class<?>[] thrown) { + // TODO Auto-generated method stub + return false; + } + + public boolean hasConstructor(Class<?>[] parameterClasses, Class<?>[] thrownClasses) { + // TODO Auto-generated method stub + return false; + } + + public void noteSuperclassConstructor(Constructor<?> constructor) { + // TODO Auto-generated method stub + + } + + public Code addMethod(int access, Class<?> returns, String name, Class<?>...parameters) { + return addMethod(access, returns, name, parameters, new Class<?>[0]); + } + + public Code addMethod(int access, + Class<?> returns, + String name, + Class<?>[] parameters, + Class<?>... exceptions) { + return addMethod(name, ProxyCodeHelpers.makeSig(returns, parameters), access, + ProxyCodeHelpers.mapClasses(exceptions)); + } + + private static class MethodDescr { + + public final Class<?> returnType; + + public final String name; + + public final Class<?>[] parameters; + + public final Class<?>[] exceptions; + + public MethodDescr(Method m) { + this(m.getName(), m.getReturnType(), m.getParameterTypes(), m.getExceptionTypes()); + } + + public MethodDescr(String name, + Class<?> returnType, + Class<?>[] parameters, + Class<?>[] exceptions) { + this.name = name; + this.returnType = returnType; + this.parameters = parameters; + this.exceptions = exceptions; + } + + @Override + public int hashCode() { + return name.hashCode() + parameters.length; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof MethodDescr)) { + return false; + } + MethodDescr oDescr = (MethodDescr)obj; + if (!name.equals(oDescr.name) || parameters.length != oDescr.parameters.length) { + return false; + } + for (int i = 0; i < parameters.length; i++) { + if (!parameters[i].equals(oDescr.parameters[i])) { + return false; + } + } + return true; + } + } + + private static class ConstructorDescr extends MethodDescr { + public ConstructorDescr(Constructor<?> cons) { + this(cons.getParameterTypes(), cons.getExceptionTypes()); + } + + public ConstructorDescr(Class<?>[] parameters, Class<?>[] exceptions) { + super("<init>", Void.TYPE, parameters, exceptions); + } + } + + protected final Set<MethodDescr> superclassMeths = Generic.set(); +} Modified: branches/customizable-proxymaker/src/org/python/core/MakeProxies.java =================================================================== --- branches/customizable-proxymaker/src/org/python/core/MakeProxies.java 2009-09-06 07:34:32 UTC (rev 6759) +++ branches/customizable-proxymaker/src/org/python/core/MakeProxies.java 2009-09-06 09:42:02 UTC (rev 6760) @@ -6,7 +6,7 @@ import java.util.List; import org.python.compiler.AdapterMaker; -import org.python.compiler.JavaMaker; +import org.python.compiler.ProxyMaker; import org.python.core.util.StringUtil; class MakeProxies { @@ -34,45 +34,44 @@ } Class<?>[] interfacesArr = interfaces.toArray(new Class<?>[interfaces.size()]); - JavaMaker javaMaker; - // Grab the proxy maker from the class if it exists, and if it does, use the proxy class - // name from the maker + ProxyMaker maker; + // Use the proxy maker from the class if it exists PyObject customProxyMaker = dict.__finditem__("__proxymaker__"); if (customProxyMaker != null) { if (module == null) { throw Py.TypeError("Classes using __proxymaker__ must define __module__"); } PyObject[] args = Py.javas2pys(superclass, interfacesArr, qualifiedClassName, dict); - javaMaker = Py.tojava(customProxyMaker.__call__(args), JavaMaker.class); - if (!StringUtil.isJavaClassName(javaMaker.proxyClassName)) { - throw Py.TypeError(javaMaker.proxyClassName + " isn't a valid Java class name. " + - "Classes must be valid Java identifiers: " + - "http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#40625"); + maker = Py.tojava(customProxyMaker.__call__(args), ProxyMaker.class); + if (!StringUtil.isJavaClassName(maker.proxyClassName)) { + throw Py.TypeError(maker.proxyClassName + " isn't a valid Java class name. Classes " + + "must be valid Java identifiers: " + + "http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#40625"); } // If we've gotten a proxy name, check if it's available on the classpath - Class<?> proxy = Py.findClass(javaMaker.proxyClassName); + Class<?> proxy = Py.findClass(maker.proxyClassName); // TODO - check proxy class version if (proxy != null) { return proxy; } } else { - javaMaker = new JavaMaker(superclass, interfacesArr, qualifiedClassName, dict); // This is a purely dynamic proxy - javaMaker.proxyClassName = proxyPrefix + qualifiedClassName + "$" + proxyNumber++; + maker = new ProxyMaker(superclass, interfacesArr, qualifiedClassName, dict, + proxyPrefix + qualifiedClassName + "$" + proxyNumber++); } - if (!javaMaker.isProxyNeeded()) { + if (!maker.isProxyNeeded()) { return null; } - byte[] bytecode = javaMaker.make(); + byte[] bytecode = maker.make(); if (customProxyMaker != null) { - saveBytecode(javaMaker.proxyClassName, bytecode, Py.getSystemState().javaproxy_dir); + saveBytecode(maker.proxyClassName, bytecode, Py.getSystemState().javaproxy_dir); } else { - saveDebugBytecode(javaMaker.proxyClassName, bytecode); + saveDebugBytecode(maker.proxyClassName, bytecode); } - return makeClass(superclass, interfaces, javaMaker.proxyClassName, bytecode); + return makeClass(superclass, interfaces, maker.proxyClassName, bytecode); } private static Class<?> makeClass(Class<?> referent, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-09-06 07:34:46
|
Revision: 6759 http://jython.svn.sourceforge.net/jython/?rev=6759&view=rev Author: cgroves Date: 2009-09-06 07:34:32 +0000 (Sun, 06 Sep 2009) Log Message: ----------- Add a class to do simple argument validity checking, Preconditions. Like util.Generic, this is a reimplementation of some stuff from Google collections. It'd be nice to get proguard and jarjar set up to include little bits like this, but that's way more work. I wanted to use it in a couple places in antlr.PythonTree and antlr.PythonTokenSource, but those are in some non-standard format and use tabs for indentation. Are we keeping them pristine as they come from antlr, or have they just not been brought into our style? Modified Paths: -------------- branches/customizable-proxymaker/src/org/python/core/AbstractArray.java branches/customizable-proxymaker/src/org/python/core/FilelikeInputStream.java branches/customizable-proxymaker/src/org/python/core/PyList.java branches/customizable-proxymaker/src/org/python/core/PyString.java branches/customizable-proxymaker/src/org/python/core/PyTuple.java branches/customizable-proxymaker/src/org/python/core/io/TextIOInputStream.java branches/customizable-proxymaker/src/org/python/expose/generate/Exposer.java branches/customizable-proxymaker/src/org/python/jsr223/PyScriptEngine.java branches/customizable-proxymaker/src/org/python/modules/sre/SRE_STATE.java branches/customizable-proxymaker/src/org/python/util/Generic.java Added Paths: ----------- branches/customizable-proxymaker/src/org/python/util/Preconditions.java Modified: branches/customizable-proxymaker/src/org/python/core/AbstractArray.java =================================================================== --- branches/customizable-proxymaker/src/org/python/core/AbstractArray.java 2009-09-06 00:24:01 UTC (rev 6758) +++ branches/customizable-proxymaker/src/org/python/core/AbstractArray.java 2009-09-06 07:34:32 UTC (rev 6759) @@ -1,6 +1,9 @@ package org.python.core; import java.io.Serializable; + +import org.python.util.Preconditions; + import java.lang.reflect.Array; import java.util.Arrays; @@ -169,7 +172,7 @@ this.modCountIncr = 0; if (this.size != 0) { this.modCountIncr = 1; - clearRange(0, this.size); + clearRange(0, this.size); setSize(0); } @@ -354,9 +357,7 @@ } } else { - if (this.size == 0) { - throw new IllegalStateException("Cannot remove data from an empty array"); - } + Preconditions.checkState(!isEmpty(), "Cannot remove data from an empty array"); throw new IndexOutOfBoundsException("Index must be between 0 and " + (this.size - 1) + ", but was " + index); @@ -400,43 +401,41 @@ int arrayLen = Array.getLength(array); replaceSubArray(atIndex, Math.min(this.size, atIndex + arrayLen), array, 0, arrayLen); } - + /** * Replace a range of this array with another subarray. - * @param thisStart the start index (inclusive) of the subarray in this + * @param thisStart the start index (inclusive) of the subarray in this * array to be replaced - * @param thisStop the stop index (exclusive) of the subarray in this + * @param thisStop the stop index (exclusive) of the subarray in this * array to be replaced * @param srcArray the source array from which to copy * @param srcStart the start index (inclusive) of the replacement subarray * @param srcStop the stop index (exclusive) of the replacement subarray */ - public void replaceSubArray(int thisStart, int thisStop, Object srcArray, + public void replaceSubArray(int thisStart, int thisStop, Object srcArray, int srcStart, int srcStop) { - + this.modCountIncr = 0; - if (!srcArray.getClass().isArray()) { - throw new IllegalArgumentException("'array' must be an array type"); - } - + Preconditions.checkArgument(srcArray.getClass().isArray(), "'array' must be an array type"); + int replacedLen = thisStop - thisStart; if (thisStart < 0 || replacedLen < 0 || thisStop > this.size) { String message = null; if (thisStart < 0) { message = "thisStart < 0 (thisStart = " + thisStart + ")"; } else if (replacedLen < 0) { - message = "thisStart > thistStop (thisStart = " + thisStart + + message = "thisStart > thistStop (thisStart = " + thisStart + ", thisStop = " + thisStop + ")"; } else if (thisStop > this.size) { - message = "thisStop > size (thisStop = " + thisStop + + message = "thisStop > size (thisStop = " + thisStop + ", size = " + this.size + ")"; } else { throw new InternalError("Incorrect validation logic"); } - + throw new ArrayIndexOutOfBoundsException(message); } - + int srcLen = Array.getLength(srcArray); int replacementLen = srcStop - srcStart; if (srcStart < 0 || replacementLen < 0 || srcStop > srcLen) { @@ -444,38 +443,39 @@ if (srcStart < 0) { message = "srcStart < 0 (srcStart = " + srcStart +")"; } else if (replacementLen < 0) { - message = "srcStart > srcStop (srcStart = " + srcStart + + message = "srcStart > srcStop (srcStart = " + srcStart + ", srcStop = " + srcStop + ")"; } else if (srcStop > srcLen) { - message = "srcStop > srcArray length (srcStop = " + srcStop + + message = "srcStop > srcArray length (srcStop = " + srcStop + ", srcArray length = " +srcLen + ")"; } else { throw new InternalError("Incorrect validation logic"); } - + throw new IllegalArgumentException("start, stop and array must follow:\n\t" + "0 <= start <= stop <= array length\nBut found\n\t" + message); } - + int lengthChange = replacementLen - replacedLen; - + // Adjust array size if needed. if (lengthChange < 0) { remove(thisStop + lengthChange, thisStop); } else if (lengthChange > 0) { makeInsertSpace(thisStop, lengthChange); } - + try { this.modCountIncr = 1; System.arraycopy(srcArray, srcStart, getArray(), thisStart, replacementLen); } catch (ArrayStoreException e) { - throw new IllegalArgumentException("'ofArrayType' must be compatible with existing array type of " + - getArray().getClass().getName() + "\tsee java.lang.Class.getName()."); + throw new IllegalArgumentException( + "'ofArrayType' must be compatible with existing array type of " + + getArray().getClass().getName() + "\tsee java.lang.Class.getName()."); } } - + /** * Set the backing array. This method is used by the type-agnostic base * class code to set the array used for type-specific storage by the @@ -513,7 +513,7 @@ if (count > this.capacity) { ensureCapacity(count); } else if (count < this.size) { - clearRange(count, this.size); + clearRange(count, this.size); } this.size = count; } @@ -585,9 +585,9 @@ public int getModCountIncr() { return this.modCountIncr; } - + /** * @return an array of the given size for the type used by this abstract array. - */ + */ protected abstract Object createArray(int size); } Modified: branches/customizable-proxymaker/src/org/python/core/FilelikeInputStream.java =================================================================== --- branches/customizable-proxymaker/src/org/python/core/FilelikeInputStream.java 2009-09-06 00:24:01 UTC (rev 6758) +++ branches/customizable-proxymaker/src/org/python/core/FilelikeInputStream.java 2009-09-06 07:34:32 UTC (rev 6759) @@ -4,6 +4,7 @@ import java.io.InputStream; import org.python.core.util.StringUtil; +import org.python.util.Preconditions; public class FilelikeInputStream extends InputStream { @@ -23,9 +24,8 @@ } public int read(byte b[], int off, int len) throws IOException { - if(b == null) { - throw new NullPointerException(); - } else if((off < 0) || (off > b.length) || (len < 0) + Preconditions.checkNotNull(b, "Can't be given null array to read into"); + if((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if(len == 0) { Modified: branches/customizable-proxymaker/src/org/python/core/PyList.java =================================================================== --- branches/customizable-proxymaker/src/org/python/core/PyList.java 2009-09-06 00:24:01 UTC (rev 6758) +++ branches/customizable-proxymaker/src/org/python/core/PyList.java 2009-09-06 07:34:32 UTC (rev 6759) @@ -142,7 +142,7 @@ } if (value instanceof PyList) { if (value == this) { // copy - value = new PyList((PySequence) value); + value = new PyList(value); } setslicePyList(start, stop, step, (PyList) value); } else if (value instanceof PySequence) { Modified: branches/customizable-proxymaker/src/org/python/core/PyString.java =================================================================== --- branches/customizable-proxymaker/src/org/python/core/PyString.java 2009-09-06 00:24:01 UTC (rev 6758) +++ branches/customizable-proxymaker/src/org/python/core/PyString.java 2009-09-06 07:34:32 UTC (rev 6759) @@ -9,6 +9,7 @@ import org.python.expose.ExposedNew; import org.python.expose.ExposedType; import org.python.expose.MethodType; +import org.python.util.Preconditions; /** * A builtin python string. @@ -27,10 +28,7 @@ public PyString(PyType subType, String string) { super(subType); - if (string == null) { - throw new IllegalArgumentException( - "Cannot create PyString from null!"); - } + Preconditions.checkNotNull(string, "Cannot create PyString from null!"); this.string = string; } @@ -45,7 +43,7 @@ PyString(StringBuilder buffer) { this(TYPE, new String(buffer)); } - + /** * Creates a PyString from an already interned String. Just means it won't * be reinterned if used in a place that requires interned Strings. @@ -82,16 +80,16 @@ } return codePoints; } - + public String substring(int start, int end) { return string.substring(start, end); } - + public PyString __str__() { return str___str__(); } - @ExposedMethod(doc = BuiltinDocs.str___str___doc) + @ExposedMethod(doc = BuiltinDocs.str___str___doc) final PyString str___str__() { if (getClass() == PyString.class) { return this; @@ -212,7 +210,7 @@ private static ucnhashAPI pucnHash = null; - + public static String decode_UnicodeEscape(String str, int start, int end, @@ -468,7 +466,7 @@ } return ret; } - + //XXX: need doc @ExposedMethod(defaults = "null") final PyObject str___getslice__(PyObject start, PyObject stop, PyObject step) { @@ -511,7 +509,7 @@ return null; return string.equals(s) ? Py.False : Py.True; } - + public PyObject __lt__(PyObject other) { return str___lt__(other); } @@ -633,8 +631,8 @@ protected PyString createInstance(String str, boolean isBasic) { // ignore isBasic, doesn't apply to PyString, just PyUnicode return new PyString(str); - } - + } + public boolean __contains__(PyObject o) { return str___contains__(o); } @@ -678,7 +676,7 @@ } return repeat(o.asIndex(Py.OverflowError)); } - + @Override public PyObject __rmul__(PyObject o) { return str___rmul__(o); @@ -695,7 +693,7 @@ public PyObject __add__(PyObject other) { return str___add__(other); } - + @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.str___add___doc) final PyObject str___add__(PyObject other) { if (other instanceof PyUnicode) { @@ -720,7 +718,7 @@ public PyObject __mod__(PyObject other) { return str___mod__(other); } - + @ExposedMethod(doc = BuiltinDocs.str___mod___doc) public PyObject str___mod__(PyObject other){ StringFormatter fmt = new StringFormatter(string, false); @@ -892,7 +890,7 @@ public String lower() { return str_lower(); } - + @ExposedMethod(doc = BuiltinDocs.str_lower_doc) final String str_lower() { return string.toLowerCase(); @@ -993,7 +991,7 @@ public String lstrip() { return str_lstrip(null); } - + public String lstrip(String sep) { return str_lstrip(sep); } @@ -1016,7 +1014,7 @@ public String rstrip(String sep) { return str_rstrip(sep); } - + @ExposedMethod(defaults = "null", doc = BuiltinDocs.str_rstrip_doc) final String str_rstrip(String sep) { char[] chars = string.toCharArray(); @@ -1415,7 +1413,7 @@ public int count(String sub, int start, int end) { return str_count(sub, start, Py.newInteger(end)); } - + @ExposedMethod(defaults = {"0", "null"}, doc = BuiltinDocs.str_count_doc) final int str_count(String sub, int start, PyObject end) { int[] indices = translateIndices(start, end); @@ -1506,7 +1504,7 @@ if (lowSval.equals("nan")) return Double.NaN; else if (lowSval.equals("inf")) return Double.POSITIVE_INFINITY; else if (lowSval.equals("-inf")) return Double.NEGATIVE_INFINITY; - + if (lowSval.endsWith("d") || lowSval.endsWith("f")) { throw new NumberFormatException("format specifiers not allowed"); } @@ -1628,10 +1626,10 @@ // if the base >= 22, then an 'l' or 'L' is a digit! if (base < 22 && e > b && (str.charAt(e-1) == 'L' || str.charAt(e-1) == 'l')) e--; - + if (b > 0 || e < str.length()) str = str.substring(b, e); - + try { java.math.BigInteger bi = null; if (sign == '-') @@ -1670,7 +1668,7 @@ } return fillchar.charAt(0); } - + public String ljust(int width) { return str_ljust(width, null); } @@ -1678,7 +1676,7 @@ public String ljust(int width, String padding) { return str_ljust(width, padding); } - + @ExposedMethod(defaults="null", doc = BuiltinDocs.str_ljust_doc) final String str_ljust(int width, String fillchar) { char pad = parse_fillchar("ljust", fillchar); @@ -1714,7 +1712,7 @@ int half = n/2; if (n%2 > 0 && width%2 > 0) half += 1; - + return padding(half, pad)+string+padding(n-half, pad); } @@ -1803,7 +1801,7 @@ return replace((PyString)oldPiece, (PyString)newPiece, maxsplit == null ? -1 : maxsplit.asInt()); } - + protected PyString replace(PyString oldPiece, PyString newPiece, int maxsplit) { int len = string.length(); int old_len = oldPiece.string.length(); @@ -1813,7 +1811,7 @@ } return createInstance(string, true); } - + if (old_len == 0 && newPiece.string.length() != 0 && maxsplit !=0) { // old="" and new != "", interleave new piece with each char in original, taking in effect maxsplit StringBuilder buffer = new StringBuilder(); @@ -1826,7 +1824,7 @@ buffer.append(string.substring(i)); return createInstance(buffer.toString(), true); } - + if(maxsplit == -1) { if(old_len == 0) { maxsplit = len + 1; @@ -1834,7 +1832,7 @@ maxsplit = len; } } - + return newPiece.join(splitfields(oldPiece.string, maxsplit)); } @@ -1979,16 +1977,16 @@ @ExposedMethod(defaults = {"0", "null"}, doc = BuiltinDocs.str_startswith_doc) final boolean str_startswith(PyObject prefix, int start, PyObject end) { int[] indices = translateIndices(start, end); - + if (prefix instanceof PyString) { String strPrefix = ((PyString)prefix).string; if (indices[1] - indices[0] < strPrefix.length()) return false; - + return string.startsWith(strPrefix, indices[0]); } else if (prefix instanceof PyTuple) { PyObject[] prefixes = ((PyTuple)prefix).getArray(); - + for (int i = 0 ; i < prefixes.length ; i++) { if (!(prefixes[i] instanceof PyString)) throw Py.TypeError("expected a character buffer object"); @@ -1996,7 +1994,7 @@ String strPrefix = ((PyString)prefixes[i]).string; if (indices[1] - indices[0] < strPrefix.length()) continue; - + if (string.startsWith(strPrefix, indices[0])) return true; } @@ -2027,7 +2025,7 @@ return substr.endsWith(((PyString)suffix).string); } else if (suffix instanceof PyTuple) { PyObject[] suffixes = ((PyTuple)suffix).getArray(); - + for (int i = 0 ; i < suffixes.length ; i++) { if (!(suffixes[i] instanceof PyString)) throw Py.TypeError("expected a character buffer object"); @@ -2039,16 +2037,16 @@ } else { throw Py.TypeError("expected a character buffer object or tuple"); } - } + } /** * Turns the possibly negative Python slice start and end into valid indices * into this string. - * + * * @return a 2 element array of indices into this string describing a * substring from [0] to [1]. [0] <= [1], [0] >= 0 and [1] <= * string.length() - * + * */ protected int[] translateIndices(int start, PyObject end) { int iEnd; @@ -2569,7 +2567,7 @@ // A magic number. Larger than in CPython. throw Py.OverflowError("formatted " + type + " is too long (precision too long?)"); } - + } private String formatLong(PyObject arg, char type, boolean altFlag) { @@ -2955,7 +2953,7 @@ string = formatFloatExponential(arg, c, false); break; case 'f': - case 'F': + case 'F': string = formatFloatDecimal(arg, false); // if (altFlag && string.indexOf('.') == -1) // string += '.'; Modified: branches/customizable-proxymaker/src/org/python/core/PyTuple.java =================================================================== --- branches/customizable-proxymaker/src/org/python/core/PyTuple.java 2009-09-06 00:24:01 UTC (rev 6758) +++ branches/customizable-proxymaker/src/org/python/core/PyTuple.java 2009-09-06 07:34:32 UTC (rev 6759) @@ -13,6 +13,7 @@ import org.python.expose.ExposedNew; import org.python.expose.ExposedType; import org.python.expose.MethodType; +import org.python.util.Preconditions; /** * A builtin python tuple. @@ -326,10 +327,9 @@ } public List subList(int fromIndex, int toIndex) { + Preconditions.checkArgument(fromIndex <= toIndex, "to can't be greater than from"); if (fromIndex < 0 || toIndex > size()) { throw new IndexOutOfBoundsException(); - } else if (fromIndex > toIndex) { - throw new IllegalArgumentException(); } PyObject elements[] = new PyObject[toIndex - fromIndex]; for (int i = 0, j = fromIndex; i < elements.length; i++, j++) { Modified: branches/customizable-proxymaker/src/org/python/core/io/TextIOInputStream.java =================================================================== --- branches/customizable-proxymaker/src/org/python/core/io/TextIOInputStream.java 2009-09-06 00:24:01 UTC (rev 6758) +++ branches/customizable-proxymaker/src/org/python/core/io/TextIOInputStream.java 2009-09-06 07:34:32 UTC (rev 6759) @@ -1,9 +1,11 @@ /* Copyright (c) Jython Developers */ package org.python.core.io; +import java.io.IOException; import java.io.InputStream; -import java.io.IOException; +import org.python.util.Preconditions; + /** * An InputStream tie-in to a TextIOBase. */ @@ -26,14 +28,13 @@ if (result.length() == 0) { return -1; } - return (int)result.charAt(0); + return result.charAt(0); } @Override public int read(byte[] b, int off, int len) throws IOException { - if (b == null) { - throw new NullPointerException(); - } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) + Preconditions.checkNotNull(b, "Can't be given null array to read into"); + if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { Modified: branches/customizable-proxymaker/src/org/python/expose/generate/Exposer.java =================================================================== --- branches/customizable-proxymaker/src/org/python/expose/generate/Exposer.java 2009-09-06 00:24:01 UTC (rev 6758) +++ branches/customizable-proxymaker/src/org/python/expose/generate/Exposer.java 2009-09-06 07:34:32 UTC (rev 6759) @@ -10,11 +10,12 @@ import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import org.python.core.BytecodeLoader; +import org.python.util.Preconditions; /** * Base class that handles the basics of generating a single class with asm. Subclass to supply the * actual functionality of the generated class. - * + * */ public abstract class Exposer implements Opcodes, PyTypes { @@ -29,7 +30,7 @@ /** The type that will be generated. */ protected Type thisType; - + protected Type[] interfacesImplemented; /** Maps from a primitive type to its wrapper */ @@ -125,11 +126,9 @@ * Push args onto the stack corresponding to the types passed to the constructor. */ public void pushArgs() { - if(types.length > 0) { - throw new IllegalStateException("If the constuctor takes types as indicated by " - + "passing their types to Instantiator, pushArgs must be overriden to put " - + "those args on the stack before the call"); - } + Preconditions.checkState(types.length == 0, "If the constuctor takes types as " + + "indicated by passing their types to Instantiator, pushArgs must be overriden to " + + "put those args on the stack before the call"); }; public Type[] getTypes() { Modified: branches/customizable-proxymaker/src/org/python/jsr223/PyScriptEngine.java =================================================================== --- branches/customizable-proxymaker/src/org/python/jsr223/PyScriptEngine.java 2009-09-06 00:24:01 UTC (rev 6758) +++ branches/customizable-proxymaker/src/org/python/jsr223/PyScriptEngine.java 2009-09-06 07:34:32 UTC (rev 6759) @@ -15,6 +15,8 @@ import javax.script.ScriptEngineFactory; import javax.script.ScriptException; import javax.script.SimpleBindings; + +import org.python.util.Preconditions; import org.python.util.PythonInterpreter; public class PyScriptEngine extends AbstractScriptEngine implements Compilable, Invocable { @@ -120,12 +122,8 @@ } public <T> T getInterface(Object obj, Class<T> clazz) { - if (obj == null) { - throw new IllegalArgumentException("object expected"); - } - if (clazz == null || !clazz.isInterface()) { - throw new IllegalArgumentException("interface expected"); - } + Preconditions.checkNotNull(obj, "object expected"); + Preconditions.checkArgument(clazz != null && clazz.isInterface(), "interface expected"); final PyObject thiz = Py.java2py(obj); @SuppressWarnings("unchecked") T proxy = (T) Proxy.newProxyInstance( Modified: branches/customizable-proxymaker/src/org/python/modules/sre/SRE_STATE.java =================================================================== --- branches/customizable-proxymaker/src/org/python/modules/sre/SRE_STATE.java 2009-09-06 00:24:01 UTC (rev 6758) +++ branches/customizable-proxymaker/src/org/python/modules/sre/SRE_STATE.java 2009-09-06 07:34:32 UTC (rev 6759) @@ -17,18 +17,19 @@ package org.python.modules.sre; import org.python.core.PyString; +import org.python.util.Preconditions; public class SRE_STATE { - + /* * Generated from Python-2.4.5 like 'python headerToJava.py < Modules/sre_constants.h' - * where headerToJava.py contains the following code + * where headerToJava.py contains the following code import sys for line in sys.stdin: if line.startswith('#define'): line = line.replace('#define', 'public static final int').strip() segs = line.split(' ') - print '%s = %s;' % (' '.join(segs[:-1]), segs[-1]) + print '%s = %s;' % (' '.join(segs[:-1]), segs[-1]) */ //BEGIN generated code public static final int SRE_MAGIC = 20031017; @@ -108,7 +109,7 @@ //From here we're including things from _sre.c in the order they're defined there public static final int USE_RECURSION_LIMIT = 5000; - + /* error codes */ public static final int SRE_ERROR_ILLEGAL = -1; public static final int SRE_ERROR_STATE = -2; @@ -188,7 +189,7 @@ return false; } } - + final boolean sre_category(int category, int ch) { switch (category) { @@ -287,7 +288,7 @@ } private void mark_restore(int lo, int hi, int mark_stack_base) { - + if (hi <= lo) return; @@ -299,7 +300,7 @@ System.arraycopy(mark_stack, this.mark_stack_base, mark, lo, size); } - + final boolean SRE_AT(int ptr, int at) { /* check if pointer is at given position. */ @@ -370,7 +371,7 @@ case SRE_OP_FAILURE: TRACE(setidx, ch, "CHARSET FAILURE"); return !ok; - + case SRE_OP_LITERAL: TRACE(setidx, ch, "CHARSET LITERAL " + set[setidx]); /* <LITERAL> <code> */ @@ -378,7 +379,7 @@ return ok; setidx++; break; - + case SRE_OP_CATEGORY: /* <CATEGORY> <code> */ TRACE(setidx, ch, "CHARSET CHARSET " + set[setidx]); @@ -394,13 +395,13 @@ // (set[setidx + (ch >> 4)] & (1 << (ch & 15))) != 0) // return ok; // setidx += 16; - + /* <CHARSET> <bitmap> (32 bits per code word) */ if (ch < 256 && (set[setidx + (ch >> 5)] & (1 << (ch & 31))) != 0) return ok; setidx += 8; break; - + case SRE_OP_RANGE: /* <RANGE> <lower> <upper> */ TRACE(setidx, ch, "CHARSET RANGE " + set[setidx] + " " + set[setidx+1]); @@ -413,11 +414,11 @@ TRACE(setidx, ch, "CHARSET NEGATE"); ok = !ok; break; - + case SRE_OP_BIGCHARSET: /* <BIGCHARSET> <blockcount> <256 blockindices> <blocks> */ TRACE(setidx, ch, "CHARSET BIGCHARSET "); - + // count = *(set++); // if (!(ch & ~65535)) // block = ((unsigned char*)set)[ch >> 8]; @@ -428,7 +429,7 @@ // (set[block*8 + ((ch & 255)>>5)] & (1 << (ch & 31)))) // return ok; // set += count*8; - + int count = set[setidx++]; int block; if (ch < 65536) @@ -438,7 +439,7 @@ setidx += 64; if (block >= 0 && (set[setidx + block*8 + ((ch & 255)>>5)] & (1 << (ch & 31))) != 0) return ok; - setidx += count * 8; + setidx += count * 8; break; default: @@ -449,7 +450,7 @@ } } } - + private int SRE_COUNT(int[] pattern, int pidx, int maxcount, int level) { int chr; int ptr = this.ptr; @@ -468,7 +469,7 @@ while (ptr < end && SRE_CHARSET(pattern, pidx + 2, str[ptr])) ptr++; break; - + case SRE_OP_ANY: /* repeated dot wildcard. */ TRACE(pidx, ptr, "COUNT ANY"); @@ -594,7 +595,7 @@ pidx++; ptr++; break; - + case SRE_OP_SUCCESS: /* end of pattern */ TRACE(pidx, ptr, "SUCCESS"); @@ -752,7 +753,7 @@ } lastmark = this.lastmark; lastindex = this.lastindex; - + if (pattern[pidx + pattern[pidx]] == SRE_OP_LITERAL) { /* tail starts with a literal. skip positions where the rest of the pattern cannot possibly match */ @@ -790,7 +791,7 @@ } } return 0; - + case SRE_OP_MIN_REPEAT_ONE: /* match repeated sequence (minimizing regexp) */ @@ -845,9 +846,7 @@ return c; if (c == 0) break; - if(c != 1){ - throw new IllegalStateException("c should be 1!"); - } + Preconditions.checkState(c == 1, "c should be 1!"); ptr++; count++; LASTMARK_RESTORE(lastmark, lastindex); @@ -956,7 +955,7 @@ this.ptr = ptr; return 0; } - + lastmark = this.lastmark; lastindex = this.lastindex; @@ -983,7 +982,7 @@ this.ptr = ptr; return 0; - + case SRE_OP_GROUPREF: /* match backreference */ i = pattern[pidx]; @@ -1017,7 +1016,7 @@ } pidx++; break; - + case SRE_OP_GROUPREF_EXISTS: i = pattern[pidx]; TRACE(pidx, ptr, "GROUPREF_EXISTS " + i); @@ -1029,7 +1028,7 @@ } pidx += 2; break; - + case SRE_OP_ASSERT: /* assert subpattern */ /* args: <skip> <back> <pattern> */ @@ -1058,7 +1057,7 @@ } pidx += pattern[pidx]; break; - + case SRE_OP_FAILURE: /* immediate failure */ TRACE(pidx, ptr, "FAILURE"); @@ -1081,7 +1080,7 @@ this.lastindex = lastindex; } } - + int SRE_SEARCH(int[] pattern, int pidx) { int ptr = this.start; int end = this.end; @@ -1282,7 +1281,7 @@ } // XXX - this is not UTF-16 compliant; also depends on whether from PyString or PyUnicode - + String getslice(int index, String string, boolean empty) { int i, j; Modified: branches/customizable-proxymaker/src/org/python/util/Generic.java =================================================================== --- branches/customizable-proxymaker/src/org/python/util/Generic.java 2009-09-06 00:24:01 UTC (rev 6758) +++ branches/customizable-proxymaker/src/org/python/util/Generic.java 2009-09-06 07:34:32 UTC (rev 6759) @@ -33,6 +33,7 @@ public static <T> List<T> list() { return new ArrayList<T>(); } + /** * Makes a List with its generic type inferred from whatever it's being assigned to filled with * the items in <code>contents</code>. Added: branches/customizable-proxymaker/src/org/python/util/Preconditions.java =================================================================== --- branches/customizable-proxymaker/src/org/python/util/Preconditions.java (rev 0) +++ branches/customizable-proxymaker/src/org/python/util/Preconditions.java 2009-09-06 07:34:32 UTC (rev 6759) @@ -0,0 +1,53 @@ +package org.python.util; + +/** + * Static methods to be called at the beginning of a method to verify arguments and state. Inspired + * by <a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Preconditions.html"> + * Google Collections</a>. + */ +public class Preconditions { + + /** + * Ensures the truth of an expression involving one or more parameters to the calling method. + * + * @param errorMessage + * - the exception message to use if the check fails; will be converted to a string + * using {@link String#valueOf}. + * @throws IllegalArgumentException - if <code>expression</code> is false. + */ + public static void checkArgument(boolean expression, Object errorMessage) { + if (!expression) { + throw new IllegalArgumentException(String.valueOf(errorMessage)); + } + } + + /** + * Ensures that a reference is not to null. + * + * @param errorMessage + * - the exception message to use if the check fails; will be converted to a string + * using {@link String#valueOf}. + * @throws NullPointerException - if <code>toCheck</code> is null. + */ + public static void checkNotNull(Object toCheck, Object errorMessage) { + if (toCheck == null) { + throw new NullPointerException(errorMessage.toString()); + } + } + + /** + *Ensures the truth of an expression involving the state of the calling instance, but not + * involving any parameters to the calling method. + * + * @param errorMessage + * - the exception message to use if the check fails; will be converted to a string + * using {@link String#valueOf}. + * @throws IllegalStateException + * - if <code>expression</code> is false. + */ + public static void checkState(boolean expression, Object errorMessage) { + if (!expression) { + throw new IllegalStateException(errorMessage.toString()); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-09-06 00:24:07
|
Revision: 6758 http://jython.svn.sourceforge.net/jython/?rev=6758&view=rev Author: cgroves Date: 2009-09-06 00:24:01 +0000 (Sun, 06 Sep 2009) Log Message: ----------- Add a comment to APIVersion explaining why it's accessed through getAPIVersion Modified Paths: -------------- branches/customizable-proxymaker/src/org/python/core/imp.java Modified: branches/customizable-proxymaker/src/org/python/core/imp.java =================================================================== --- branches/customizable-proxymaker/src/org/python/core/imp.java 2009-09-05 23:50:14 UTC (rev 6757) +++ branches/customizable-proxymaker/src/org/python/core/imp.java 2009-09-06 00:24:01 UTC (rev 6758) @@ -21,6 +21,12 @@ private static final String UNKNOWN_SOURCEFILE = "<unknown>"; + /** + * The version of compiled python source encoded into created bytecode. This is private and + * accessed externally through {@link #getAPIVersion()} as javac will hardcode the value of this + * in other classes that reference it, but won't update those classes if the version changes + * here. + */ private static final int APIVersion = 24; public static final int NO_MTIME = -1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-09-05 23:50:20
|
Revision: 6757 http://jython.svn.sourceforge.net/jython/?rev=6757&view=rev Author: cgroves Date: 2009-09-05 23:50:14 +0000 (Sat, 05 Sep 2009) Log Message: ----------- Use imp.NO_MTIME instead of returning -1 directly Modified Paths: -------------- branches/customizable-proxymaker/src/org/python/core/ClasspathPyImporter.java branches/customizable-proxymaker/src/org/python/core/PyProxy.java branches/customizable-proxymaker/src/org/python/core/imp.java branches/customizable-proxymaker/src/org/python/core/util/importer.java branches/customizable-proxymaker/src/org/python/modules/zipimport/zipimporter.java Modified: branches/customizable-proxymaker/src/org/python/core/ClasspathPyImporter.java =================================================================== --- branches/customizable-proxymaker/src/org/python/core/ClasspathPyImporter.java 2009-09-05 23:48:38 UTC (rev 6756) +++ branches/customizable-proxymaker/src/org/python/core/ClasspathPyImporter.java 2009-09-05 23:50:14 UTC (rev 6757) @@ -65,8 +65,7 @@ @Override protected long getSourceMtime(String path) { - // Can't determine this easily - return -1; + return imp.NO_MTIME; // Can't determine this from the information exposed by the classpath } @Override Modified: branches/customizable-proxymaker/src/org/python/core/PyProxy.java =================================================================== --- branches/customizable-proxymaker/src/org/python/core/PyProxy.java 2009-09-05 23:48:38 UTC (rev 6756) +++ branches/customizable-proxymaker/src/org/python/core/PyProxy.java 2009-09-05 23:50:14 UTC (rev 6757) @@ -3,14 +3,14 @@ /** * Common methods for all generated proxy classes. + * <p> * * Proxy classes are created whenever a python class inherits from a java class. Instances of such a * python class consists of two objects: * <ul> - * <li>An instance of the proxy class. The _getPyInstance() will return a reference to the - * PyInstance. - * <li>An instance of PyInstance. The PyInstance.javaProxy contains a reference to the proxy class - * instance. + * <li>An instance of the proxy class. {@link #_getPyInstance()} will return a reference to the + * PyObject. + * <li>An instance of PyObject. {@link PyObject#getJavaProxy} returns the proxy class instance. * </ul> * * All proxy classes implement this interface. Modified: branches/customizable-proxymaker/src/org/python/core/imp.java =================================================================== --- branches/customizable-proxymaker/src/org/python/core/imp.java 2009-09-05 23:48:38 UTC (rev 6756) +++ branches/customizable-proxymaker/src/org/python/core/imp.java 2009-09-05 23:50:14 UTC (rev 6757) @@ -163,8 +163,7 @@ } } if (testing && mtime != NO_MTIME) { - long time = ar.getMTime(); - if (mtime != time) { + if (mtime != ar.getMTime()) { return null; } } Modified: branches/customizable-proxymaker/src/org/python/core/util/importer.java =================================================================== --- branches/customizable-proxymaker/src/org/python/core/util/importer.java 2009-09-05 23:48:38 UTC (rev 6756) +++ branches/customizable-proxymaker/src/org/python/core/util/importer.java 2009-09-05 23:50:14 UTC (rev 6757) @@ -133,7 +133,7 @@ * matching .py file. * * @param path to the compiled file - * @return long mtime of the .py, or -1 if no source is available + * @return long mtime of the .py, or {@link imp#NO_MTIME} if no source is available */ protected abstract long getSourceMtime(String path); @@ -189,15 +189,12 @@ boolean isPackage = entry.type.contains(EntryType.IS_PACKAGE); boolean isBytecode = entry.type.contains(EntryType.IS_BYTECODE); - long mtime = -1; - if (isBytecode) { - mtime = getSourceMtime(searchPath); - } Bundle bundle = makeBundle(searchPath, tocEntry); byte[] codeBytes; try { if (isBytecode) { + long mtime = getSourceMtime(searchPath); try { codeBytes = imp.readCode(fullname, bundle.inputStream, true, mtime); } catch (IOException ioe) { Modified: branches/customizable-proxymaker/src/org/python/modules/zipimport/zipimporter.java =================================================================== --- branches/customizable-proxymaker/src/org/python/modules/zipimport/zipimporter.java 2009-09-05 23:48:38 UTC (rev 6756) +++ branches/customizable-proxymaker/src/org/python/modules/zipimport/zipimporter.java 2009-09-05 23:50:14 UTC (rev 6757) @@ -20,6 +20,7 @@ import org.python.core.PySystemState; import org.python.core.PyTuple; import org.python.core.PyType; +import org.python.core.imp; import org.python.core.util.FileUtil; import org.python.core.util.StringUtil; import org.python.core.util.importer; @@ -305,7 +306,7 @@ String sourcePath = path.substring(0, path.length() - 9) + ".py"; PyObject sourceTocEntry = files.__finditem__(sourcePath); if (sourceTocEntry == null) { - return -1; + return imp.NO_MTIME; } int time; @@ -317,8 +318,8 @@ if (!pye.match(Py.TypeError)) { throw pye; } - time = -1; - date = -1; + time = imp.NO_MTIME; + date = imp.NO_MTIME; } return dosTimeToEpoch(time, date); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-09-05 23:48:47
|
Revision: 6756 http://jython.svn.sourceforge.net/jython/?rev=6756&view=rev Author: cgroves Date: 2009-09-05 23:48:38 +0000 (Sat, 05 Sep 2009) Log Message: ----------- There's no reason to set the nextVisit booleans in visit as visitAnnotation will set both of them before every call to visit, and the wrong boolean was being set for mtime anyway. Bring things into line with the coding standards while I'm in here. Modified Paths: -------------- branches/customizable-proxymaker/src/org/python/core/AnnotationReader.java Modified: branches/customizable-proxymaker/src/org/python/core/AnnotationReader.java =================================================================== --- branches/customizable-proxymaker/src/org/python/core/AnnotationReader.java 2009-09-05 10:54:53 UTC (rev 6755) +++ branches/customizable-proxymaker/src/org/python/core/AnnotationReader.java 2009-09-05 23:48:38 UTC (rev 6756) @@ -11,21 +11,21 @@ import org.objectweb.asm.commons.EmptyVisitor; /** - * This class reads a classfile from a byte array and pulls out the value of the class annotation - * for APIVersion, which can then be retrieved by a call to getVersion(). - * - * Hopefully the use of ClassReader in this implementation is not too expensive. I suspect it is not + * Reads the bytecode of a compiled Python source file and pulls out the values of the class + * annotations for APIVersion and MTime. + */ +/* Hopefully the use of ClassReader in this implementation is not too expensive. I suspect it is not * since EmptyVisitor is just a bag of empty methods so shouldn't cost too much. If it turns out to * cost too much, we will want to implement a special purpose ClassReader that only reads out the * APIVersion annotation I think. */ public class AnnotationReader extends EmptyVisitor { - private boolean nextVisitIsVersion = false; - private boolean nextVisitIsMTime = false; + private boolean nextVisitIsVersion; + private boolean nextVisitIsMTime; - private int version = -1; - private long mtime = -1; + private int version; + private long mtime; /** * Reads the classfile bytecode in data and to extract the version. @@ -44,19 +44,19 @@ r.accept(this, 0); } + @Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { nextVisitIsVersion = desc.equals("Lorg/python/compiler/APIVersion;"); nextVisitIsMTime = desc.equals("Lorg/python/compiler/MTime;"); return this; } + @Override public void visit(String name, Object value) { if (nextVisitIsVersion) { version = (Integer)value; - nextVisitIsVersion = false; } else if (nextVisitIsMTime) { mtime = (Long)value; - nextVisitIsVersion = false; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wme...@us...> - 2009-09-05 10:55:01
|
Revision: 6755 http://jython.svn.sourceforge.net/jython/?rev=6755&view=rev Author: wmeissner Date: 2009-09-05 10:54:53 +0000 (Sat, 05 Sep 2009) Log Message: ----------- Treat None as a VOID type Modified Paths: -------------- branches/ctypes-jffi/src/org/python/modules/jffi/CType.java Modified: branches/ctypes-jffi/src/org/python/modules/jffi/CType.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/CType.java 2009-09-05 10:46:25 UTC (rev 6754) +++ branches/ctypes-jffi/src/org/python/modules/jffi/CType.java 2009-09-05 10:54:53 UTC (rev 6755) @@ -95,6 +95,8 @@ static CType typeOf(PyObject obj) { if (obj instanceof CType) { return (CType) obj; + } else if (obj == Py.None) { + return CType.VOID; } PyObject jffi_type = obj.__getattr__("_jffi_type"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wme...@us...> - 2009-09-05 10:46:31
|
Revision: 6754 http://jython.svn.sourceforge.net/jython/?rev=6754&view=rev Author: wmeissner Date: 2009-09-05 10:46:25 +0000 (Sat, 05 Sep 2009) Log Message: ----------- Implement Function.errcheck= Modified Paths: -------------- branches/ctypes-jffi/src/org/python/modules/jffi/Function.java Modified: branches/ctypes-jffi/src/org/python/modules/jffi/Function.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/Function.java 2009-09-05 05:45:36 UTC (rev 6753) +++ branches/ctypes-jffi/src/org/python/modules/jffi/Function.java 2009-09-05 10:46:25 UTC (rev 6754) @@ -27,6 +27,9 @@ private Invoker invoker = null; @ExposedGet + public PyObject errcheck = Py.None; + + @ExposedGet public final String name; Function(PyType type, Pointer address) { @@ -137,6 +140,11 @@ } } + @ExposedSet(name = "errcheck") + public void errcheck(PyObject errcheck) { + this.invoker = null; // invalidate old invoker + this.errcheck = errcheck; + } @Override public boolean __nonzero__() { return !getMemory().isNull(); @@ -161,12 +169,43 @@ } com.kenai.jffi.Function jffiFunction = new com.kenai.jffi.Function(getMemory().getAddress(), jffiReturnType, jffiParamTypes); + Invoker i; if (FastIntInvokerFactory.getFactory().isFastIntMethod(restype, argtypes)) { - invoker = FastIntInvokerFactory.getFactory().createInvoker(jffiFunction, restype, argtypes); + i = FastIntInvokerFactory.getFactory().createInvoker(jffiFunction, restype, argtypes); } else { - invoker = DefaultInvokerFactory.getFactory().createInvoker(jffiFunction, restype, argtypes); + i = DefaultInvokerFactory.getFactory().createInvoker(jffiFunction, restype, argtypes); } - - return invoker; + + return invoker = errcheck != Py.None ? new ErrCheckInvoker(i, errcheck) : i; } + + private static final class ErrCheckInvoker implements Invoker { + private final Invoker invoker; + private final PyObject errcheck; + + public ErrCheckInvoker(Invoker invoker, PyObject errcheck) { + this.invoker = invoker; + this.errcheck = errcheck; + } + + public PyObject invoke(PyObject[] args) { + return errcheck.__call__(invoker.invoke(args)); + } + + public PyObject invoke() { + return errcheck.__call__(invoker.invoke()); + } + + public PyObject invoke(PyObject arg1) { + return errcheck.__call__(invoker.invoke(arg1)); + } + + public PyObject invoke(PyObject arg1, PyObject arg2) { + return errcheck.__call__(invoker.invoke(arg1, arg2)); + } + + public PyObject invoke(PyObject arg1, PyObject arg2, PyObject arg3) { + return errcheck.__call__(invoker.invoke(arg1, arg2, arg3)); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wme...@us...> - 2009-09-05 05:45:44
|
Revision: 6753 http://jython.svn.sourceforge.net/jython/?rev=6753&view=rev Author: wmeissner Date: 2009-09-05 05:45:36 +0000 (Sat, 05 Sep 2009) Log Message: ----------- Hoist argtypes and restype up into jffi.Function, since the extra type info is going to be needed Modified Paths: -------------- branches/ctypes-jffi/Lib/ctypes/__init__.py branches/ctypes-jffi/src/org/python/modules/jffi/DefaultInvokerFactory.java branches/ctypes-jffi/src/org/python/modules/jffi/FastIntInvokerFactory.java branches/ctypes-jffi/src/org/python/modules/jffi/Function.java Modified: branches/ctypes-jffi/Lib/ctypes/__init__.py =================================================================== --- branches/ctypes-jffi/Lib/ctypes/__init__.py 2009-09-05 01:28:02 UTC (rev 6752) +++ branches/ctypes-jffi/Lib/ctypes/__init__.py 2009-09-05 05:45:36 UTC (rev 6753) @@ -240,27 +240,7 @@ _restype = c_int _argtypes = None - def set_restype(self, restype): - self._jffi_restype = restype._jffi_type - self._restype = restype - def get_restype(self): - return self._restype - - def set_argtypes(self, argtypes): - jffi_types = [] - for t in argtypes: - jffi_types.append(t._jffi_type) - self._jffi_argtypes = jffi_types - self._argtypes = argtypes - - def get_argtypes(self): - return self._argtypes - - restype = property(get_restype, set_restype) - argtypes = property(get_argtypes, set_argtypes) - - class CDLL: DEFAULT_MODE = jffi.RTLD_GLOBAL | jffi.RTLD_LAZY Modified: branches/ctypes-jffi/src/org/python/modules/jffi/DefaultInvokerFactory.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/DefaultInvokerFactory.java 2009-09-05 01:28:02 UTC (rev 6752) +++ branches/ctypes-jffi/src/org/python/modules/jffi/DefaultInvokerFactory.java 2009-09-05 05:45:36 UTC (rev 6753) @@ -19,6 +19,16 @@ private DefaultInvokerFactory() {} + final Invoker createInvoker(com.kenai.jffi.Function function, PyObject returnType, PyObject[] parameterTypes) { + ParameterMarshaller[] marshallers = new ParameterMarshaller[parameterTypes.length]; + + for (int i = 0; i < marshallers.length; ++i) { + marshallers[i] = getMarshaller(parameterTypes[i]); + } + + return createInvoker(function, returnType, marshallers); + } + final Invoker createInvoker(com.kenai.jffi.Function function, CType[] parameterTypes, CType returnType) { ParameterMarshaller[] marshallers = new ParameterMarshaller[parameterTypes.length]; @@ -26,9 +36,12 @@ marshallers[i] = getMarshaller(parameterTypes[i]); } - - if (returnType instanceof CType.Builtin) { - switch (returnType.getNativeType()) { + return createInvoker(function, returnType, marshallers); + } + final Invoker createInvoker(com.kenai.jffi.Function function, PyObject returnType, ParameterMarshaller[] marshallers) { + CType cReturnType = CType.typeOf(returnType); + if (cReturnType instanceof CType.Builtin) { + switch (cReturnType.getNativeType()) { case VOID: return new VoidInvoker(function, marshallers); @@ -141,6 +154,10 @@ } } + private static final ParameterMarshaller getMarshaller(PyObject type) { + return getMarshaller(CType.typeOf(type)); + } + private static interface ParameterMarshaller { void marshal(HeapInvocationBuffer buffer, PyObject arg); } Modified: branches/ctypes-jffi/src/org/python/modules/jffi/FastIntInvokerFactory.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/FastIntInvokerFactory.java 2009-09-05 01:28:02 UTC (rev 6752) +++ branches/ctypes-jffi/src/org/python/modules/jffi/FastIntInvokerFactory.java 2009-09-05 05:45:36 UTC (rev 6753) @@ -3,6 +3,7 @@ import com.kenai.jffi.Function; import com.kenai.jffi.Platform; +import com.kenai.jffi.Type; import org.python.core.Py; import org.python.core.PyObject; @@ -63,6 +64,23 @@ } /** + * Tests if a combination of result and parameter types can be called using + * an {@link Invoker} created by this factory. + * + * @param returnType The return type of the native function. + * @param parameterTypes The parameter types of the native function. + * @return <tt>true</tt> if the method can be handled as a fast int method. + */ + final boolean isFastIntMethod(PyObject returnType, PyObject[] parameterTypes) { + for (int i = 0; i < parameterTypes.length; ++i) { + if (!isFastIntParam(parameterTypes[i])) { + return false; + } + } + return parameterTypes.length <= 3 && isFastIntResult(returnType); + } + + /** * Tests if the type can be returned as an integer result. * * @param type The result type. @@ -95,6 +113,15 @@ return false; } + /** + * Tests if the type can be returned as an integer result. + * + * @param type The result type. + * @return <tt>true</tt> if <tt>type</tt> can be returned as an integer. + */ + final boolean isFastIntResult(PyObject type) { + return isFastIntResult(CType.typeOf(type)); + } /** * Tests if the type can be passed as an integer parameter. @@ -125,6 +152,15 @@ return false; } + /** + * Tests if the type can be passed as an integer parameter. + * + * @param type The parameter type. + * @return <tt>true</tt> if <tt>type</tt> can be passed as an integer. + */ + final boolean isFastIntParam(PyObject paramType) { + return isFastIntParam(CType.typeOf(paramType)); + } /** * Creates a new <tt>Invoker</tt> instance for the given function, with the @@ -142,33 +178,66 @@ parameterConverters[i] = getIntParameterConverter(parameterTypes[i]); } if (returnType.nativeType == NativeType.FLOAT) { - switch (parameterTypes.length) { - case 0: - return new FastFloatInvokerZero(function, null, parameterConverters); - case 1: - return new FastFloatInvokerOne(function, null, parameterConverters); - case 2: - return new FastFloatInvokerTwo(function, null, parameterConverters); - case 3: - return new FastFloatInvokerThree(function, null, parameterConverters); - } + return createFloatInvoker(function, null, parameterConverters); } else { - IntResultConverter resultConverter = getIntResultConverter(returnType); - switch (parameterTypes.length) { - case 0: - return new FastIntInvokerZero(function, resultConverter, parameterConverters); - case 1: - return new FastIntInvokerOne(function, resultConverter, parameterConverters); - case 2: - return new FastIntInvokerTwo(function, resultConverter, parameterConverters); - case 3: - return new FastIntInvokerThree(function, resultConverter, parameterConverters); - } + return createIntInvoker(function, getIntResultConverter(returnType), parameterConverters); } - throw Py.RuntimeError("Fast Integer invoker does not support functions with arity=" + parameterTypes.length); } /** + * Creates a new <tt>Invoker</tt> instance for the given function, with the + * given parameter types and return type. + * + * @param function The JFFI function to wrap + * @param parameterTypes The parameter types the function will be called with + * @param returnType The result type the function will return + * @return A new {@link Invoker} instance. + */ + final Invoker createInvoker(Function function, PyObject returnType, PyObject[] parameterTypes) { + IntParameterConverter[] parameterConverters = new IntParameterConverter[parameterTypes.length]; + + for (int i = 0; i < parameterConverters.length; ++i) { + parameterConverters[i] = getIntParameterConverter(parameterTypes[i]); + } + + if (function.getReturnType().equals(Type.FLOAT)) { + return createFloatInvoker(function, null, parameterConverters); + } else { + return createIntInvoker(function, getIntResultConverter(returnType), parameterConverters); + } + } + + + final Invoker createFloatInvoker(Function function, IntResultConverter resultConverter, IntParameterConverter[] parameterConverters) { + switch (parameterConverters.length) { + case 0: + return new FastFloatInvokerZero(function, null, parameterConverters); + case 1: + return new FastFloatInvokerOne(function, null, parameterConverters); + case 2: + return new FastFloatInvokerTwo(function, null, parameterConverters); + case 3: + return new FastFloatInvokerThree(function, null, parameterConverters); + } + throw Py.RuntimeError("fast int invoker does not support functions with arity=" + parameterConverters.length); + } + + final Invoker createIntInvoker(Function function, IntResultConverter resultConverter, IntParameterConverter[] parameterConverters) { + switch (parameterConverters.length) { + case 0: + return new FastIntInvokerZero(function, resultConverter, parameterConverters); + case 1: + return new FastIntInvokerOne(function, resultConverter, parameterConverters); + case 2: + return new FastIntInvokerTwo(function, resultConverter, parameterConverters); + case 3: + return new FastIntInvokerThree(function, resultConverter, parameterConverters); + } + throw Py.RuntimeError("fast int invoker does not support functions with arity=" + parameterConverters.length); + } + + + /** * Gets a python object to integer parameter converter. * * @param type The python C type @@ -181,6 +250,15 @@ throw Py.TypeError("cannot convert objects of type " + type + " to int"); } + /** + * Gets a python object to integer parameter converter. + * + * @param type The python C type + * @return An <tt>IntParameterConverter</tt> instance. + */ + final IntParameterConverter getIntParameterConverter(PyObject type) { + return getIntParameterConverter(CType.typeOf(type)); + } /** * Gets a python object to integer parameter converter. @@ -240,6 +318,16 @@ * @param type The object type. * @return An <tt>IntResultConverter</tt> instance. */ + final IntResultConverter getIntResultConverter(PyObject type) { + return getIntResultConverter(CType.typeOf(type)); + } + + /** + * Gets a int to python object result converter for the type. + * + * @param type The object type. + * @return An <tt>IntResultConverter</tt> instance. + */ final IntResultConverter getIntResultConverter(CType type) { return type instanceof CType.Builtin ? getIntResultConverter(type.getNativeType()) : null; } Modified: branches/ctypes-jffi/src/org/python/modules/jffi/Function.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/Function.java 2009-09-05 01:28:02 UTC (rev 6752) +++ branches/ctypes-jffi/src/org/python/modules/jffi/Function.java 2009-09-05 05:45:36 UTC (rev 6753) @@ -5,6 +5,7 @@ import org.python.core.PyList; import org.python.core.PyNewWrapper; import org.python.core.PyObject; +import org.python.core.PySequenceList; import org.python.core.PyStringMap; import org.python.core.PyType; import org.python.expose.ExposedGet; @@ -20,23 +21,20 @@ private final DynamicLibrary library; private final PyStringMap dict = new PyStringMap(); - - private volatile CType returnType = CType.INT; - private volatile CType[] parameterTypes = null; + + private volatile PyObject restype = Py.None; + private volatile PyObject[] argtypes = null; private Invoker invoker = null; @ExposedGet public final String name; - - @ExposedGet - @ExposedSet - public PyObject restype; - + Function(PyType type, Pointer address) { super(type); this.library = null; this.name = "<anonymous>"; this.pointer = address; + this.restype = type.__getattr__("_restype"); } Function(PyType type, DynamicLibrary.Symbol sym) { @@ -44,6 +42,7 @@ this.library = sym.library; this.name = sym.name; this.pointer = sym; + this.restype = type.__getattr__("_restype"); } @ExposedNew @@ -101,51 +100,41 @@ } - @ExposedGet(name = "_jffi_restype") - public PyObject getReturnType() { - return this.returnType; + @ExposedGet(name = "restype") + public PyObject getResultType() { + return this.restype; } - - @ExposedSet(name = "_jffi_restype") - public void setReturnType(PyObject returnType) { - if (!(returnType instanceof CType)) { - throw Py.TypeError("wrong argument type (expected jffi.Type)"); - } - + @ExposedSet(name = "restype") + public void setResultType(PyObject restype) { this.invoker = null; // invalidate old invoker - this.returnType = (CType) returnType; + this.restype = restype; } - - @ExposedGet(name = "_jffi_argtypes") - public PyObject getParameterTypes() { - return new PyList(parameterTypes != null ? parameterTypes : new CType[0]); + + @ExposedGet(name = "argtypes") + public PyObject getArgTypes() { + return new PyList(argtypes != null ? argtypes : new PyObject[0]); } - @ExposedSet(name = "_jffi_argtypes") - public void setParameterTypes(PyObject parameterTypes) { + @ExposedSet(name = "argtypes") + public void setArgTypes(PyObject parameterTypes) { this.invoker = null; // invalidate old invoker // Removing the parameter types defaults back to varargs if (parameterTypes == Py.None) { - this.parameterTypes = null; + this.argtypes = null; return; } - if (!(parameterTypes instanceof PyList)) { - throw Py.TypeError("wrong argument type (expected list of jffi.Type)"); + if (!(parameterTypes instanceof PySequenceList)) { + throw Py.TypeError("wrong argument type (expected list or tuple)"); } - CType[] paramTypes = new CType[((PyList) parameterTypes).size()]; - for (int i = 0; i < paramTypes.length; ++i) { - PyObject t = ((PyList) parameterTypes).pyget(i); - if (!(t instanceof CType)) { - throw Py.TypeError(String.format("wrong argument type for parameter %d (expected jffi.Type)", i)); - } - paramTypes[i] = (CType) t; + PySequenceList paramList = (PySequenceList) parameterTypes; + argtypes = new PyObject[paramList.size()]; + for (int i = 0; i < argtypes.length; ++i) { + argtypes[i] = paramList.pyget(i); } - - this.parameterTypes = paramTypes; } @Override @@ -157,25 +146,25 @@ if (invoker != null) { return invoker; } - return createInvoker(getMemory().getAddress(), returnType, parameterTypes); + return createInvoker(); } - private synchronized final Invoker createInvoker(long address, CType returnType, CType[] parameterTypes) { - if (parameterTypes == null) { + private synchronized final Invoker createInvoker() { + if (argtypes == null) { throw Py.NotImplementedError("variadic functions not supported yet; specify a parameter list"); } - com.kenai.jffi.Type jffiReturnType = NativeType.jffiType(returnType.nativeType); - com.kenai.jffi.Type[] jffiParamTypes = new com.kenai.jffi.Type[parameterTypes.length]; + com.kenai.jffi.Type jffiReturnType = CType.typeOf(restype).jffiType; + com.kenai.jffi.Type[] jffiParamTypes = new com.kenai.jffi.Type[argtypes.length]; for (int i = 0; i < jffiParamTypes.length; ++i) { - jffiParamTypes[i] = NativeType.jffiType(parameterTypes[i].nativeType); + jffiParamTypes[i] = CType.typeOf(argtypes[i]).jffiType; } - com.kenai.jffi.Function jffiFunction = new com.kenai.jffi.Function(address, jffiReturnType, jffiParamTypes); + com.kenai.jffi.Function jffiFunction = new com.kenai.jffi.Function(getMemory().getAddress(), jffiReturnType, jffiParamTypes); - if (FastIntInvokerFactory.getFactory().isFastIntMethod(returnType, parameterTypes)) { - invoker = FastIntInvokerFactory.getFactory().createInvoker(jffiFunction, parameterTypes, returnType); + if (FastIntInvokerFactory.getFactory().isFastIntMethod(restype, argtypes)) { + invoker = FastIntInvokerFactory.getFactory().createInvoker(jffiFunction, restype, argtypes); } else { - invoker = DefaultInvokerFactory.getFactory().createInvoker(jffiFunction, parameterTypes, returnType); + invoker = DefaultInvokerFactory.getFactory().createInvoker(jffiFunction, restype, argtypes); } return invoker; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wme...@us...> - 2009-09-05 01:28:09
|
Revision: 6752 http://jython.svn.sourceforge.net/jython/?rev=6752&view=rev Author: wmeissner Date: 2009-09-05 01:28:02 +0000 (Sat, 05 Sep 2009) Log Message: ----------- Fix Union hierarchy Modified Paths: -------------- branches/ctypes-jffi/Lib/ctypes/__init__.py Modified: branches/ctypes-jffi/Lib/ctypes/__init__.py =================================================================== --- branches/ctypes-jffi/Lib/ctypes/__init__.py 2009-09-04 14:41:21 UTC (rev 6751) +++ branches/ctypes-jffi/Lib/ctypes/__init__.py 2009-09-05 01:28:02 UTC (rev 6752) @@ -118,14 +118,14 @@ def __new__(cls, name, bases, dict): return _AggregateMetaClass.__new_aggregate__(cls, name, bases, dict, union = False) -class _UnionMetaClass(type): +class _UnionMetaClass(_AggregateMetaClass): def __new__(cls, name, bases, dict): return _AggregateMetaClass.__new_aggregate__(cls, name, bases, dict, union = True) class Structure(jffi.Structure, _CData): __metaclass__ = _StructMetaClass -class Union(jffi.Structure): +class Union(jffi.Structure, _CData): __metaclass__ = _UnionMetaClass def sizeof(type): @@ -165,7 +165,7 @@ return ptype class c_bool(_ScalarCData): - _type_ = "?" + _type_ = '?' _jffi_type = jffi.Type.BOOL class c_byte(_ScalarCData): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wme...@us...> - 2009-09-04 14:41:30
|
Revision: 6751 http://jython.svn.sourceforge.net/jython/?rev=6751&view=rev Author: wmeissner Date: 2009-09-04 14:41:21 +0000 (Fri, 04 Sep 2009) Log Message: ----------- Implement Structure._fields_=, and raise errors if _pack_ or _anonymous_ are set Modified Paths: -------------- branches/ctypes-jffi/Lib/ctypes/__init__.py Modified: branches/ctypes-jffi/Lib/ctypes/__init__.py =================================================================== --- branches/ctypes-jffi/Lib/ctypes/__init__.py 2009-09-04 13:50:18 UTC (rev 6750) +++ branches/ctypes-jffi/Lib/ctypes/__init__.py 2009-09-04 14:41:21 UTC (rev 6751) @@ -88,9 +88,32 @@ # make all fields accessible via .foo for f in dict['_fields_']: dict[f[0]] = layout[f[0]] + dict['__fields_'] = dict['_fields_'] + else: + dict['__fields_'] = [] + if dict.has_key('_pack_'): + raise NotImplementedError("struct packing not implemented") + if dict.has_key('_anonymous_'): + raise NotImplementedError("anonymous fields not implemented") return type.__new__(cls, name, bases, dict) + def get_fields(self): + return self.__fields_ + + def set_fields(self, fields): + layout = _StructLayoutBuilder(union = issubclass(Union, self)).add_fields(fields).build() + self.__fields_ = fields + self._jffi_type = layout + # make all fields accessible via .foo + for f in fields: + setattr(self, f[0], layout[f[0]]) + + _fields_ = property(get_fields, set_fields) + # Make _pack_ and _anonymous_ throw errors if anyone tries to use them + _pack_ = property(None) + _anonymous_ = property(None) + class _StructMetaClass(_AggregateMetaClass): def __new__(cls, name, bases, dict): return _AggregateMetaClass.__new_aggregate__(cls, name, bases, dict, union = False) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wme...@us...> - 2009-09-04 13:50:28
|
Revision: 6750 http://jython.svn.sourceforge.net/jython/?rev=6750&view=rev Author: wmeissner Date: 2009-09-04 13:50:18 +0000 (Fri, 04 Sep 2009) Log Message: ----------- Implement from_address and in_dll for scalar, pointer, string and struct types Modified Paths: -------------- branches/ctypes-jffi/Lib/ctypes/__init__.py branches/ctypes-jffi/src/org/python/modules/jffi/CData.java branches/ctypes-jffi/src/org/python/modules/jffi/DynamicLibrary.java branches/ctypes-jffi/src/org/python/modules/jffi/PointerCData.java branches/ctypes-jffi/src/org/python/modules/jffi/ScalarCData.java branches/ctypes-jffi/src/org/python/modules/jffi/StringCData.java branches/ctypes-jffi/src/org/python/modules/jffi/Structure.java branches/ctypes-jffi/src/org/python/modules/jffi/Util.java Modified: branches/ctypes-jffi/Lib/ctypes/__init__.py =================================================================== --- branches/ctypes-jffi/Lib/ctypes/__init__.py 2009-09-04 13:44:07 UTC (rev 6749) +++ branches/ctypes-jffi/Lib/ctypes/__init__.py 2009-09-04 13:50:18 UTC (rev 6750) @@ -27,14 +27,19 @@ dict = { '_jffi_type': jffi.Type.Array(self, len) } return type("%s_%d" % (self.__name__, len), (_ArrayCData,), dict) -class _ScalarCData(jffi.ScalarCData): - __metaclass__ = _CTypeMetaClass +class _CData(object): + @classmethod + def in_dll(self, lib, name): + return self.from_address(lib[name]) + @classmethod def size(self): return self._jffi_type.size - size = classmethod(size) +class _ScalarCData(jffi.ScalarCData, _CData): + __metaclass__ = _CTypeMetaClass + class _ArrayCData(object): def __init__(self, *args): raise NotImplementedError("instantiating arrays is not implemented yet") @@ -76,6 +81,7 @@ return jffi.StructLayout(fields = self.fields, union = self.union) class _AggregateMetaClass(type): + @staticmethod def __new_aggregate__(cls, name, bases, dict, union = False): if dict.has_key('_fields_'): layout = dict['_jffi_type'] = _StructLayoutBuilder(union).add_fields(dict['_fields_']).build() @@ -85,8 +91,6 @@ return type.__new__(cls, name, bases, dict) - __new_aggregate__ = staticmethod(__new_aggregate__) - class _StructMetaClass(_AggregateMetaClass): def __new__(cls, name, bases, dict): return _AggregateMetaClass.__new_aggregate__(cls, name, bases, dict, union = False) @@ -95,7 +99,7 @@ def __new__(cls, name, bases, dict): return _AggregateMetaClass.__new_aggregate__(cls, name, bases, dict, union = True) -class Structure(jffi.Structure): +class Structure(jffi.Structure, _CData): __metaclass__ = _StructMetaClass class Union(jffi.Structure): @@ -133,7 +137,7 @@ name = mod.__name__ dict["__module__"] = name - ptype = type("LP_%s" % (ctype.__name__,), (jffi.PointerCData,), dict) + ptype = type("LP_%s" % (ctype.__name__,), (jffi.PointerCData, _CData), dict) _pointer_type_cache[ctype] = ptype return ptype @@ -201,7 +205,7 @@ c_size_t = c_ulong c_ssize_t = c_long -class c_char_p(jffi.StringCData): +class c_char_p(jffi.StringCData, _CData): _type_ = 'z' _jffi_type = jffi.Type.STRING Modified: branches/ctypes-jffi/src/org/python/modules/jffi/CData.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/CData.java 2009-09-04 13:44:07 UTC (rev 6749) +++ branches/ctypes-jffi/src/org/python/modules/jffi/CData.java 2009-09-04 13:50:18 UTC (rev 6750) @@ -2,6 +2,8 @@ package org.python.modules.jffi; import org.python.core.Py; +import org.python.core.PyInteger; +import org.python.core.PyLong; import org.python.core.PyObject; import org.python.core.PyType; import org.python.expose.ExposedMethod; @@ -15,10 +17,14 @@ private DirectMemory referenceMemory; - CData(PyType subtype, CType type) { + CData(PyType subtype, CType ctype) { + this(subtype, ctype, null); + } + + CData(PyType subtype, CType ctype, DirectMemory memory) { super(subtype); - this.ctype = type; - this.referenceMemory = null; + this.ctype = ctype; + this.referenceMemory = memory; } /** @@ -86,4 +92,15 @@ } protected abstract void initReferenceMemory(Memory m); + + + + protected static final DirectMemory findInDll(PyObject lib, PyObject name) { + if (!(lib instanceof DynamicLibrary)) { + throw Py.TypeError("expected library, not " + lib.getType().fastGetName()); + } + DynamicLibrary.Symbol sym = (DynamicLibrary.Symbol) ((DynamicLibrary) lib).find_symbol(name); + + return sym.getMemory(); + } } Modified: branches/ctypes-jffi/src/org/python/modules/jffi/DynamicLibrary.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/DynamicLibrary.java 2009-09-04 13:44:07 UTC (rev 6749) +++ branches/ctypes-jffi/src/org/python/modules/jffi/DynamicLibrary.java 2009-09-04 13:50:18 UTC (rev 6750) @@ -79,13 +79,22 @@ public static final class TextSymbol extends Symbol implements ExposeAsSuperclass { public TextSymbol(DynamicLibrary lib, String name, long address) { - super(lib, name, new NativeMemory(address)); + super(lib, name, new SymbolMemory(lib, address)); } } public static final class DataSymbol extends Symbol implements ExposeAsSuperclass { public DataSymbol(DynamicLibrary lib, String name, long address) { - super(lib, name, new NativeMemory(address)); + super(lib, name, new SymbolMemory(lib, address)); } } + + private static final class SymbolMemory extends NativeMemory { + private final DynamicLibrary library; // backlink to keep library alive + + public SymbolMemory(DynamicLibrary library, long address) { + super(address); + this.library = library; + } + } } Modified: branches/ctypes-jffi/src/org/python/modules/jffi/PointerCData.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/PointerCData.java 2009-09-04 13:44:07 UTC (rev 6749) +++ branches/ctypes-jffi/src/org/python/modules/jffi/PointerCData.java 2009-09-04 13:50:18 UTC (rev 6750) @@ -5,6 +5,7 @@ import org.python.core.PyNewWrapper; import org.python.core.PyObject; import org.python.core.PyType; +import org.python.expose.ExposedClassMethod; import org.python.expose.ExposedGet; import org.python.expose.ExposedNew; import org.python.expose.ExposedSet; @@ -25,14 +26,8 @@ public static PyObject PointerCData_new(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords) { - PyObject jffi_type = subtype.__getattr__("_jffi_type"); + CType.Pointer pointerType = getPointerType(subtype); - if (!(jffi_type instanceof CType.Pointer)) { - throw Py.TypeError("invalid _jffi_type for " + subtype.getName()); - } - - CType.Pointer pointerType = (CType.Pointer) jffi_type; - // No args == create NULL pointer if (args.length == 0) { return new PointerCData(subtype, pointerType, NullMemory.INSTANCE, pointerType.componentMemoryOp); @@ -48,6 +43,27 @@ } } + static final CType.Pointer getPointerType(PyType subtype) { + PyObject jffi_type = subtype.__getattr__("_jffi_type"); + + if (!(jffi_type instanceof CType.Pointer)) { + throw Py.TypeError("invalid _jffi_type for " + subtype.getName()); + } + + return (CType.Pointer) jffi_type; + } + + @ExposedClassMethod(names= { "from_address" }) + public static final PyObject from_address(PyType subtype, PyObject address) { + + CType.Pointer pointerType = getPointerType(subtype); + DirectMemory m = Util.getMemoryForAddress(address); + PointerCData cdata = new PointerCData(subtype, pointerType, m.getMemory(0), pointerType.componentMemoryOp); + cdata.setReferenceMemory(m); + + return cdata; + } + @ExposedGet(name="contents") public PyObject getContents() { return componentMemoryOp.get(getMemory(), 0); @@ -57,4 +73,5 @@ public void setContents(PyObject value) { componentMemoryOp.put(getMemory(), 0, value); } + } Modified: branches/ctypes-jffi/src/org/python/modules/jffi/ScalarCData.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/ScalarCData.java 2009-09-04 13:44:07 UTC (rev 6749) +++ branches/ctypes-jffi/src/org/python/modules/jffi/ScalarCData.java 2009-09-04 13:50:18 UTC (rev 6750) @@ -3,10 +3,13 @@ import org.python.core.Py; import org.python.core.PyFloat; +import org.python.core.PyInteger; +import org.python.core.PyLong; import org.python.core.PyNewWrapper; import org.python.core.PyObject; import org.python.core.PyObject.ConversionException; import org.python.core.PyType; +import org.python.expose.ExposedClassMethod; import org.python.expose.ExposedGet; import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; @@ -16,31 +19,46 @@ @ExposedType(name = "jffi.ScalarCData", base = CData.class) public class ScalarCData extends CData { public static final PyType TYPE = PyType.fromClass(ScalarCData.class); - + static { +// TYPE.fastGetDict().__setitem__("in_dll", new InDll()); + } private PyObject value = Py.None; @ExposedNew public static PyObject ScalarCData_new(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords) { - PyObject jffi_type = subtype.__getattr__("_jffi_type"); + ScalarCData cdata = new ScalarCData(subtype, getScalarType(subtype)); - if (!(jffi_type instanceof CType.Builtin)) { - throw Py.TypeError("invalid _jffi_type for " + subtype.getName()); - } - - ScalarCData cdata = new ScalarCData(subtype, (CType.Builtin) jffi_type); - // If an initial value was supplied, use it, else default to zero cdata.setValue(args.length > 0 ? args[0] : Py.newInteger(0)); return cdata; } + + @ExposedClassMethod(names= { "from_address" }) + public static final PyObject from_address(PyType subtype, PyObject address) { + return new ScalarCData(subtype, getScalarType(subtype), Util.getMemoryForAddress(address)); + } + + static final CType.Builtin getScalarType(PyType subtype) { + PyObject jffi_type = subtype.__getattr__("_jffi_type"); + + if (!(jffi_type instanceof CType.Builtin)) { + throw Py.TypeError("invalid _jffi_type for " + subtype.getName()); + } + return (CType.Builtin) jffi_type; + } + ScalarCData(PyType pytype, CType.Builtin ctype) { super(pytype, ctype); } + ScalarCData(PyType pytype, CType.Builtin ctype, DirectMemory m) { + super(pytype, ctype, m); + } + protected final void initReferenceMemory(Memory m) { getMemoryOp().put(m, 0, value); } Modified: branches/ctypes-jffi/src/org/python/modules/jffi/StringCData.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/StringCData.java 2009-09-04 13:44:07 UTC (rev 6749) +++ branches/ctypes-jffi/src/org/python/modules/jffi/StringCData.java 2009-09-04 13:50:18 UTC (rev 6750) @@ -5,6 +5,7 @@ import org.python.core.PyNewWrapper; import org.python.core.PyObject; import org.python.core.PyType; +import org.python.expose.ExposedClassMethod; import org.python.expose.ExposedGet; import org.python.expose.ExposedNew; import org.python.expose.ExposedSet; @@ -33,6 +34,16 @@ return new StringCData(subtype, CType.typeOf(subtype), m); } + @ExposedClassMethod(names= { "from_address" }) + public static final PyObject from_address(PyType subtype, PyObject address) { + + DirectMemory m = Util.getMemoryForAddress(address); + StringCData cdata = new StringCData(subtype, CType.typeOf(subtype), m.getMemory(0)); + cdata.setReferenceMemory(m); + + return cdata; + } + @ExposedGet(name = "value") public PyObject getValue() { Memory m = getMemory(); Modified: branches/ctypes-jffi/src/org/python/modules/jffi/Structure.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/Structure.java 2009-09-04 13:44:07 UTC (rev 6749) +++ branches/ctypes-jffi/src/org/python/modules/jffi/Structure.java 2009-09-04 13:50:18 UTC (rev 6750) @@ -1,13 +1,12 @@ package org.python.modules.jffi; -import java.lang.reflect.Field; import java.util.List; -import org.python.core.ArgParser; import org.python.core.Py; import org.python.core.PyNewWrapper; import org.python.core.PyObject; import org.python.core.PyType; +import org.python.expose.ExposedClassMethod; import org.python.expose.ExposedNew; import org.python.expose.ExposedType; @@ -33,12 +32,7 @@ public static PyObject Structure_new(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords) { - PyObject jffi_type = subtype.__getattr__("_jffi_type"); - if (!(jffi_type instanceof StructLayout)) { - throw Py.TypeError("invalid _jffi_type for " + subtype.fastGetName() + "; should be instance of jffi.StructLayout"); - } - - StructLayout layout = (StructLayout) jffi_type; + StructLayout layout = getStructLayout(subtype); Structure s = new Structure(subtype, layout); if (args.length > 0) { int n = args.length - keywords.length; @@ -59,6 +53,20 @@ return s; } + static final StructLayout getStructLayout(PyType subtype) { + PyObject jffi_type = subtype.__getattr__("_jffi_type"); + if (!(jffi_type instanceof StructLayout)) { + throw Py.TypeError("invalid _jffi_type for " + subtype.fastGetName() + "; should be instance of jffi.StructLayout"); + } + + return (StructLayout) jffi_type; + } + + @ExposedClassMethod(names= { "from_address" }) + public static final PyObject from_address(PyType subtype, PyObject address) { + return new Structure(subtype, getStructLayout(subtype), Util.getMemoryForAddress(address)); + } + protected final void initReferenceMemory(Memory m) { throw Py.RuntimeError("reference memory already initialized"); } Modified: branches/ctypes-jffi/src/org/python/modules/jffi/Util.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/Util.java 2009-09-04 13:44:07 UTC (rev 6749) +++ branches/ctypes-jffi/src/org/python/modules/jffi/Util.java 2009-09-04 13:50:18 UTC (rev 6750) @@ -129,4 +129,15 @@ + off + " size=" + len + " is out of bounds"); } } + + static final DirectMemory getMemoryForAddress(PyObject address) { + if (address instanceof Pointer) { + return ((Pointer) address).getMemory(); + } else if (address instanceof PyInteger) { + return new NativeMemory(address.asInt()); + } else if (address instanceof PyLong) { + return new NativeMemory(((PyLong) address).getValue().longValue()); + } + throw Py.TypeError("invalid address"); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-04 13:44:18
|
Revision: 6749 http://jython.svn.sourceforge.net/jython/?rev=6749&view=rev Author: fwierzbicki Date: 2009-09-04 13:44:07 +0000 (Fri, 04 Sep 2009) Log Message: ----------- Removed pbvcm branch dep. Property Changed: ---------------- branches/indy/ Property changes on: branches/indy ___________________________________________________________________ Modified: svnmerge-integrated - /branches/pbcvm:1-6045 /trunk/jython:1-6660 + /trunk/jython:1-6660 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |