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-22 18:02:54
|
Revision: 6803 http://jython.svn.sourceforge.net/jython/?rev=6803&view=rev Author: fwierzbicki Date: 2009-09-22 18:00:39 +0000 (Tue, 22 Sep 2009) Log Message: ----------- null MethodHandles as placeholders. Modified Paths: -------------- trunk/sandbox/wierzbicki/indy_jython/IndyDump.java trunk/sandbox/wierzbicki/indy_jython/indy Modified: trunk/sandbox/wierzbicki/indy_jython/IndyDump.java =================================================================== --- trunk/sandbox/wierzbicki/indy_jython/IndyDump.java 2009-09-22 17:17:27 UTC (rev 6802) +++ trunk/sandbox/wierzbicki/indy_jython/IndyDump.java 2009-09-22 18:00:39 UTC (rev 6803) @@ -11,7 +11,7 @@ MethodVisitor mv; AnnotationVisitor av0; -cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "Hello", null, "org/python/core/PyFunctionTable", new String[] { "org/python/core/PyRunnable" }); +cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "Hello", null, "org/python/core/IndyFunctionTable", new String[] { "org/python/core/PyRunnable" }); { av0 = cw.visitAnnotation("Lorg/python/compiler/APIVersion;", true); @@ -112,7 +112,7 @@ mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(Ljava/lang/String;)V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); -mv.visitMethodInsn(INVOKESPECIAL, "org/python/core/PyFunctionTable", "<init>", "()V"); +mv.visitMethodInsn(INVOKESPECIAL, "org/python/core/IndyFunctionTable", "<init>", "()V"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(PUTSTATIC, "Hello", "self", "LHello;"); mv.visitLdcInsn("Frank"); @@ -135,12 +135,15 @@ mv.visitInsn(ICONST_0); mv.visitInsn(ICONST_0); mv.visitFieldInsn(GETSTATIC, "Hello", "self", "LHello;"); -mv.visitInsn(ICONST_0); + mv.visitInsn(ACONST_NULL); +////mv.visitInsn(ICONST_0); + mv.visitInsn(ACONST_NULL); +mv.visitInsn(ACONST_NULL); mv.visitInsn(ICONST_0); mv.visitIntInsn(SIPUSH, 4096); -mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "newCode", "(I[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZLorg/python/core/PyFunctionTable;I[Ljava/lang/String;[Ljava/lang/String;II)Lorg/python/core/PyCode;"); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "newCode", "(I[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZLorg/python/core/IndyFunctionTable;Ljava/dyn/MethodHandle;[Ljava/lang/String;[Ljava/lang/String;II)Lorg/python/core/PyCode;"); mv.visitFieldInsn(PUTSTATIC, "Hello", "f$0", "Lorg/python/core/PyCode;"); mv.visitInsn(ICONST_1); mv.visitInsn(ICONST_1); @@ -157,12 +160,15 @@ mv.visitInsn(ICONST_0); mv.visitInsn(ICONST_0); mv.visitFieldInsn(GETSTATIC, "Hello", "self", "LHello;"); -mv.visitInsn(ICONST_1); + mv.visitInsn(ACONST_NULL); +////mv.visitInsn(ICONST_1); + mv.visitInsn(ACONST_NULL); +mv.visitInsn(ACONST_NULL); mv.visitInsn(ICONST_0); mv.visitIntInsn(SIPUSH, 4097); -mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "newCode", "(I[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZLorg/python/core/PyFunctionTable;I[Ljava/lang/String;[Ljava/lang/String;II)Lorg/python/core/PyCode;"); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "newCode", "(I[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZLorg/python/core/IndyFunctionTable;Ljava/dyn/MethodHandle;[Ljava/lang/String;[Ljava/lang/String;II)Lorg/python/core/PyCode;"); mv.visitFieldInsn(PUTSTATIC, "Hello", "greet$1", "Lorg/python/core/PyCode;"); mv.visitInsn(RETURN); mv.visitMaxs(13, 3); Modified: trunk/sandbox/wierzbicki/indy_jython/indy =================================================================== --- trunk/sandbox/wierzbicki/indy_jython/indy 2009-09-22 17:17:27 UTC (rev 6802) +++ trunk/sandbox/wierzbicki/indy_jython/indy 2009-09-22 18:00:39 UTC (rev 6803) @@ -1,5 +1,8 @@ -JYTHON_HOME=/Users/frank/svn/jython/trunk/jython +JYTHON_HOME=/Users/frank/svn/jython/branches/indy +JAVA_HOME=/Users/frank/work/davinci/sources/build/bsd-i586 -$JAVA_HOME/bin/javac -classpath $JYTHON_HOME/extlibs/asm-3.1.jar:asm-util-3.1.jar:. IndyDump.java -$JAVA_HOME/bin/java -classpath $JYTHON_HOME/extlibs/asm-3.1.jar:asm-util-3.1.jar:. IndyDump -$JAVA_HOME/bin/java -classpath $JYTHON_HOME/extlibs/asm-3.1.jar:asm-util-3.1.jar:$JYTHON_HOME/dist/jython.jar:. Hello +JARS=$JYTHON_HOME/dist/jython-dev.jar:$JYTHON_HOME/extlibs/antlr-runtime-3.1.3.jar:$JYTHON_HOME/extlibs/constantine-0.4.jar:$JYTHON_HOME/extlibs/jna-posix.jar:$JYTHON_HOME/extlibs/jna.jar:$JYTHON_HOME/extlibs/asm-all-3.2.jar + +$JAVA_HOME/bin/javac -classpath $JARS:. IndyDump.java +$JAVA_HOME/bin/java -classpath $JARS:. IndyDump +$JAVA_HOME/bin/java -classpath $JARS:. Hello This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-22 17:17:44
|
Revision: 6802 http://jython.svn.sourceforge.net/jython/?rev=6802&view=rev Author: fwierzbicki Date: 2009-09-22 17:17:27 +0000 (Tue, 22 Sep 2009) Log Message: ----------- IndyDump stub Added Paths: ----------- trunk/sandbox/wierzbicki/indy_jython/IndyDump.java trunk/sandbox/wierzbicki/indy_jython/indy Added: trunk/sandbox/wierzbicki/indy_jython/IndyDump.java =================================================================== --- trunk/sandbox/wierzbicki/indy_jython/IndyDump.java (rev 0) +++ trunk/sandbox/wierzbicki/indy_jython/IndyDump.java 2009-09-22 17:17:27 UTC (rev 6802) @@ -0,0 +1,247 @@ +import java.io.*; +import java.util.*; +import org.objectweb.asm.*; +//import org.objectweb.asm.attrs.*; +public class IndyDump implements Opcodes { + +public static byte[] dump () throws Exception { + +ClassWriter cw = new ClassWriter(0); +FieldVisitor fv; +MethodVisitor mv; +AnnotationVisitor av0; + +cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "Hello", null, "org/python/core/PyFunctionTable", new String[] { "org/python/core/PyRunnable" }); + +{ +av0 = cw.visitAnnotation("Lorg/python/compiler/APIVersion;", true); +av0.visit("value", new Integer(26)); +av0.visitEnd(); +} +{ +av0 = cw.visitAnnotation("Lorg/python/compiler/MTime;", true); +av0.visit("value", new Long(1253627083000L)); +av0.visitEnd(); +} +{ +fv = cw.visitField(ACC_FINAL + ACC_STATIC, "self", "LHello;", null, null); +fv.visitEnd(); +} +{ +fv = cw.visitField(ACC_FINAL + ACC_STATIC, "_2", "Lorg/python/core/PyString;", null, null); +fv.visitEnd(); +} +{ +fv = cw.visitField(ACC_FINAL + ACC_STATIC, "_1", "Lorg/python/core/PyString;", null, null); +fv.visitEnd(); +} +{ +fv = cw.visitField(ACC_FINAL + ACC_STATIC, "_0", "Lorg/python/core/PyString;", null, null); +fv.visitEnd(); +} +{ +fv = cw.visitField(ACC_FINAL + ACC_STATIC, "f$0", "Lorg/python/core/PyCode;", null, null); +fv.visitEnd(); +} +{ +fv = cw.visitField(ACC_FINAL + ACC_STATIC, "greet$1", "Lorg/python/core/PyCode;", null, null); +fv.visitEnd(); +} +{ +mv = cw.visitMethod(ACC_PUBLIC, "f$0", "(Lorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;", null, null); +mv.visitCode(); +mv.visitVarInsn(ALOAD, 1); +mv.visitInsn(ICONST_1); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "setline", "(I)V"); +mv.visitFieldInsn(GETSTATIC, "org/python/core/Py", "EmptyObjects", "[Lorg/python/core/PyObject;"); +mv.visitVarInsn(ASTORE, 3); +mv.visitTypeInsn(NEW, "org/python/core/PyFunction"); +mv.visitInsn(DUP); +mv.visitVarInsn(ALOAD, 1); +mv.visitFieldInsn(GETFIELD, "org/python/core/PyFrame", "f_globals", "Lorg/python/core/PyObject;"); +mv.visitVarInsn(ALOAD, 3); +mv.visitFieldInsn(GETSTATIC, "Hello", "greet$1", "Lorg/python/core/PyCode;"); +mv.visitInsn(ACONST_NULL); +mv.visitMethodInsn(INVOKESPECIAL, "org/python/core/PyFunction", "<init>", "(Lorg/python/core/PyObject;[Lorg/python/core/PyObject;Lorg/python/core/PyCode;Lorg/python/core/PyObject;)V"); +mv.visitVarInsn(ASTORE, 3); +mv.visitVarInsn(ALOAD, 1); +mv.visitLdcInsn("greet"); +mv.visitVarInsn(ALOAD, 3); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "setlocal", "(Ljava/lang/String;Lorg/python/core/PyObject;)V"); +mv.visitInsn(ACONST_NULL); +mv.visitVarInsn(ASTORE, 3); +mv.visitVarInsn(ALOAD, 1); +mv.visitInsn(ICONST_4); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "setline", "(I)V"); +mv.visitVarInsn(ALOAD, 1); +mv.visitLdcInsn("greet"); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "getname", "(Ljava/lang/String;)Lorg/python/core/PyObject;"); +mv.visitVarInsn(ALOAD, 2); +mv.visitFieldInsn(GETSTATIC, "Hello", "_2", "Lorg/python/core/PyString;"); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "__call__", "(Lorg/python/core/ThreadState;Lorg/python/core/PyObject;)Lorg/python/core/PyObject;"); +mv.visitInsn(POP); +mv.visitVarInsn(ALOAD, 1); +mv.visitInsn(ICONST_M1); +mv.visitFieldInsn(PUTFIELD, "org/python/core/PyFrame", "f_lasti", "I"); +mv.visitFieldInsn(GETSTATIC, "org/python/core/Py", "None", "Lorg/python/core/PyObject;"); +mv.visitInsn(ARETURN); +mv.visitMaxs(6, 4); +mv.visitEnd(); +} +{ +mv = cw.visitMethod(ACC_PUBLIC, "greet$1", "(Lorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;", null, null); +mv.visitCode(); +mv.visitVarInsn(ALOAD, 1); +mv.visitInsn(ICONST_2); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "setline", "(I)V"); +mv.visitFieldInsn(GETSTATIC, "Hello", "_1", "Lorg/python/core/PyString;"); +mv.visitVarInsn(ALOAD, 1); +mv.visitInsn(ICONST_0); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "getlocal", "(I)Lorg/python/core/PyObject;"); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "_mod", "(Lorg/python/core/PyObject;)Lorg/python/core/PyObject;"); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "println", "(Lorg/python/core/PyObject;)V"); +mv.visitVarInsn(ALOAD, 1); +mv.visitInsn(ICONST_M1); +mv.visitFieldInsn(PUTFIELD, "org/python/core/PyFrame", "f_lasti", "I"); +mv.visitFieldInsn(GETSTATIC, "org/python/core/Py", "None", "Lorg/python/core/PyObject;"); +mv.visitInsn(ARETURN); +mv.visitMaxs(3, 3); +mv.visitEnd(); +} +{ +mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(Ljava/lang/String;)V", null, null); +mv.visitCode(); +mv.visitVarInsn(ALOAD, 0); +mv.visitMethodInsn(INVOKESPECIAL, "org/python/core/PyFunctionTable", "<init>", "()V"); +mv.visitVarInsn(ALOAD, 0); +mv.visitFieldInsn(PUTSTATIC, "Hello", "self", "LHello;"); +mv.visitLdcInsn("Frank"); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/PyString", "fromInterned", "(Ljava/lang/String;)Lorg/python/core/PyString;"); +mv.visitFieldInsn(PUTSTATIC, "Hello", "_2", "Lorg/python/core/PyString;"); +mv.visitLdcInsn("hello, %s"); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/PyString", "fromInterned", "(Ljava/lang/String;)Lorg/python/core/PyString;"); +mv.visitFieldInsn(PUTSTATIC, "Hello", "_1", "Lorg/python/core/PyString;"); +mv.visitLdcInsn("/Users/frank/svn/jython/trunk/sandbox/wierzbicki/indy_jython/./hello.py"); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/PyString", "fromInterned", "(Ljava/lang/String;)Lorg/python/core/PyString;"); +mv.visitFieldInsn(PUTSTATIC, "Hello", "_0", "Lorg/python/core/PyString;"); +mv.visitInsn(ICONST_0); +mv.visitInsn(ICONST_0); +mv.visitTypeInsn(ANEWARRAY, "java/lang/String"); +mv.visitVarInsn(ASTORE, 2); +mv.visitVarInsn(ALOAD, 2); +mv.visitVarInsn(ALOAD, 1); +mv.visitLdcInsn("<module>"); +mv.visitInsn(ICONST_0); +mv.visitInsn(ICONST_0); +mv.visitInsn(ICONST_0); +mv.visitFieldInsn(GETSTATIC, "Hello", "self", "LHello;"); +mv.visitInsn(ICONST_0); +mv.visitInsn(ACONST_NULL); +mv.visitInsn(ACONST_NULL); +mv.visitInsn(ICONST_0); +mv.visitIntInsn(SIPUSH, 4096); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "newCode", "(I[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZLorg/python/core/PyFunctionTable;I[Ljava/lang/String;[Ljava/lang/String;II)Lorg/python/core/PyCode;"); +mv.visitFieldInsn(PUTSTATIC, "Hello", "f$0", "Lorg/python/core/PyCode;"); +mv.visitInsn(ICONST_1); +mv.visitInsn(ICONST_1); +mv.visitTypeInsn(ANEWARRAY, "java/lang/String"); +mv.visitVarInsn(ASTORE, 2); +mv.visitVarInsn(ALOAD, 2); +mv.visitInsn(ICONST_0); +mv.visitLdcInsn("name"); +mv.visitInsn(AASTORE); +mv.visitVarInsn(ALOAD, 2); +mv.visitVarInsn(ALOAD, 1); +mv.visitLdcInsn("greet"); +mv.visitInsn(ICONST_1); +mv.visitInsn(ICONST_0); +mv.visitInsn(ICONST_0); +mv.visitFieldInsn(GETSTATIC, "Hello", "self", "LHello;"); +mv.visitInsn(ICONST_1); +mv.visitInsn(ACONST_NULL); +mv.visitInsn(ACONST_NULL); +mv.visitInsn(ICONST_0); +mv.visitIntInsn(SIPUSH, 4097); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "newCode", "(I[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZLorg/python/core/PyFunctionTable;I[Ljava/lang/String;[Ljava/lang/String;II)Lorg/python/core/PyCode;"); +mv.visitFieldInsn(PUTSTATIC, "Hello", "greet$1", "Lorg/python/core/PyCode;"); +mv.visitInsn(RETURN); +mv.visitMaxs(13, 3); +mv.visitEnd(); +} +{ +mv = cw.visitMethod(ACC_PUBLIC, "getMain", "()Lorg/python/core/PyCode;", null, null); +mv.visitCode(); +mv.visitFieldInsn(GETSTATIC, "Hello", "f$0", "Lorg/python/core/PyCode;"); +mv.visitInsn(ARETURN); +mv.visitMaxs(1, 1); +mv.visitEnd(); +} +{ +mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); +mv.visitCode(); +mv.visitTypeInsn(NEW, "Hello"); +mv.visitInsn(DUP); +mv.visitLdcInsn("Hello"); +mv.visitMethodInsn(INVOKESPECIAL, "Hello", "<init>", "(Ljava/lang/String;)V"); +mv.visitMethodInsn(INVOKEVIRTUAL, "Hello", "getMain", "()Lorg/python/core/PyCode;"); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/CodeLoader", "createSimpleBootstrap", "(Lorg/python/core/PyCode;)Lorg/python/core/CodeBootstrap;"); +mv.visitVarInsn(ALOAD, 0); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "runMain", "(Lorg/python/core/CodeBootstrap;[Ljava/lang/String;)V"); +mv.visitInsn(RETURN); +mv.visitMaxs(3, 1); +mv.visitEnd(); +} +{ +mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "getCodeBootstrap", "()Lorg/python/core/CodeBootstrap;", null, null); +mv.visitCode(); +mv.visitLdcInsn(Type.getType("LHello;")); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/PyRunnableBootstrap", "getFilenameConstructorReflectionBootstrap", "(Ljava/lang/Class;)Lorg/python/core/CodeBootstrap;"); +mv.visitInsn(ARETURN); +mv.visitMaxs(1, 0); +mv.visitEnd(); +} +{ +mv = cw.visitMethod(ACC_PUBLIC, "call_function", "(ILorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;", null, null); +mv.visitCode(); +mv.visitFrame(Opcodes.F_NEW, 0, new Object[] {}, 0, new Object[] {}); +mv.visitVarInsn(ALOAD, 0); +mv.visitVarInsn(ALOAD, 2); +mv.visitVarInsn(ALOAD, 3); +mv.visitVarInsn(ILOAD, 1); +Label l0 = new Label(); +Label l1 = new Label(); +Label l2 = new Label(); +mv.visitTableSwitchInsn(0, 1, l2, new Label[] { l0, l1 }); +mv.visitLabel(l0); +mv.visitFrame(Opcodes.F_NEW, 4, new Object[] {"Hello", Opcodes.INTEGER, "org/python/core/PyFrame", "org/python/core/ThreadState"}, 3, new Object[] {"Hello", "org/python/core/PyFrame", "org/python/core/ThreadState"}); +mv.visitMethodInsn(INVOKEVIRTUAL, "Hello", "f$0", "(Lorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;"); +mv.visitInsn(ARETURN); +mv.visitLabel(l1); +mv.visitFrame(Opcodes.F_NEW, 4, new Object[] {"Hello", Opcodes.INTEGER, "org/python/core/PyFrame", "org/python/core/ThreadState"}, 3, new Object[] {"Hello", "org/python/core/PyFrame", "org/python/core/ThreadState"}); +mv.visitMethodInsn(INVOKEVIRTUAL, "Hello", "greet$1", "(Lorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;"); +mv.visitInsn(ARETURN); +mv.visitLabel(l2); +mv.visitFrame(Opcodes.F_NEW, 4, new Object[] {"Hello", Opcodes.INTEGER, "org/python/core/PyFrame", "org/python/core/ThreadState"}, 3, new Object[] {"Hello", "org/python/core/PyFrame", "org/python/core/ThreadState"}); +mv.visitInsn(ACONST_NULL); +mv.visitInsn(ARETURN); +mv.visitMaxs(4, 4); +mv.visitEnd(); +} +cw.visitEnd(); + +return cw.toByteArray(); +} + +public static void main(String args[]) throws Exception { + byte[] ba = dump(); + File file = new File("Hello.class"); + try { + FileOutputStream o = new FileOutputStream(file); + o.write(ba); + o.close(); + } catch (Throwable t) { + t.printStackTrace(); + } + +} +} Property changes on: trunk/sandbox/wierzbicki/indy_jython/IndyDump.java ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/sandbox/wierzbicki/indy_jython/indy =================================================================== --- trunk/sandbox/wierzbicki/indy_jython/indy (rev 0) +++ trunk/sandbox/wierzbicki/indy_jython/indy 2009-09-22 17:17:27 UTC (rev 6802) @@ -0,0 +1,5 @@ +JYTHON_HOME=/Users/frank/svn/jython/trunk/jython + +$JAVA_HOME/bin/javac -classpath $JYTHON_HOME/extlibs/asm-3.1.jar:asm-util-3.1.jar:. IndyDump.java +$JAVA_HOME/bin/java -classpath $JYTHON_HOME/extlibs/asm-3.1.jar:asm-util-3.1.jar:. IndyDump +$JAVA_HOME/bin/java -classpath $JYTHON_HOME/extlibs/asm-3.1.jar:asm-util-3.1.jar:$JYTHON_HOME/dist/jython.jar:. Hello Property changes on: trunk/sandbox/wierzbicki/indy_jython/indy ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-22 17:01:19
|
Revision: 6801 http://jython.svn.sourceforge.net/jython/?rev=6801&view=rev Author: fwierzbicki Date: 2009-09-22 17:01:13 +0000 (Tue, 22 Sep 2009) Log Message: ----------- Playground code for indy. Added Paths: ----------- trunk/sandbox/wierzbicki/indy_jython/ trunk/sandbox/wierzbicki/indy_jython/HelloDump.java trunk/sandbox/wierzbicki/indy_jython/dump trunk/sandbox/wierzbicki/indy_jython/hello.py Added: trunk/sandbox/wierzbicki/indy_jython/HelloDump.java =================================================================== --- trunk/sandbox/wierzbicki/indy_jython/HelloDump.java (rev 0) +++ trunk/sandbox/wierzbicki/indy_jython/HelloDump.java 2009-09-22 17:01:13 UTC (rev 6801) @@ -0,0 +1,247 @@ +import java.io.*; +import java.util.*; +import org.objectweb.asm.*; +//import org.objectweb.asm.attrs.*; +public class HelloDump implements Opcodes { + +public static byte[] dump () throws Exception { + +ClassWriter cw = new ClassWriter(0); +FieldVisitor fv; +MethodVisitor mv; +AnnotationVisitor av0; + +cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, "Hello", null, "org/python/core/PyFunctionTable", new String[] { "org/python/core/PyRunnable" }); + +{ +av0 = cw.visitAnnotation("Lorg/python/compiler/APIVersion;", true); +av0.visit("value", new Integer(26)); +av0.visitEnd(); +} +{ +av0 = cw.visitAnnotation("Lorg/python/compiler/MTime;", true); +av0.visit("value", new Long(1253627083000L)); +av0.visitEnd(); +} +{ +fv = cw.visitField(ACC_FINAL + ACC_STATIC, "self", "LHello;", null, null); +fv.visitEnd(); +} +{ +fv = cw.visitField(ACC_FINAL + ACC_STATIC, "_2", "Lorg/python/core/PyString;", null, null); +fv.visitEnd(); +} +{ +fv = cw.visitField(ACC_FINAL + ACC_STATIC, "_1", "Lorg/python/core/PyString;", null, null); +fv.visitEnd(); +} +{ +fv = cw.visitField(ACC_FINAL + ACC_STATIC, "_0", "Lorg/python/core/PyString;", null, null); +fv.visitEnd(); +} +{ +fv = cw.visitField(ACC_FINAL + ACC_STATIC, "f$0", "Lorg/python/core/PyCode;", null, null); +fv.visitEnd(); +} +{ +fv = cw.visitField(ACC_FINAL + ACC_STATIC, "greet$1", "Lorg/python/core/PyCode;", null, null); +fv.visitEnd(); +} +{ +mv = cw.visitMethod(ACC_PUBLIC, "f$0", "(Lorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;", null, null); +mv.visitCode(); +mv.visitVarInsn(ALOAD, 1); +mv.visitInsn(ICONST_1); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "setline", "(I)V"); +mv.visitFieldInsn(GETSTATIC, "org/python/core/Py", "EmptyObjects", "[Lorg/python/core/PyObject;"); +mv.visitVarInsn(ASTORE, 3); +mv.visitTypeInsn(NEW, "org/python/core/PyFunction"); +mv.visitInsn(DUP); +mv.visitVarInsn(ALOAD, 1); +mv.visitFieldInsn(GETFIELD, "org/python/core/PyFrame", "f_globals", "Lorg/python/core/PyObject;"); +mv.visitVarInsn(ALOAD, 3); +mv.visitFieldInsn(GETSTATIC, "Hello", "greet$1", "Lorg/python/core/PyCode;"); +mv.visitInsn(ACONST_NULL); +mv.visitMethodInsn(INVOKESPECIAL, "org/python/core/PyFunction", "<init>", "(Lorg/python/core/PyObject;[Lorg/python/core/PyObject;Lorg/python/core/PyCode;Lorg/python/core/PyObject;)V"); +mv.visitVarInsn(ASTORE, 3); +mv.visitVarInsn(ALOAD, 1); +mv.visitLdcInsn("greet"); +mv.visitVarInsn(ALOAD, 3); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "setlocal", "(Ljava/lang/String;Lorg/python/core/PyObject;)V"); +mv.visitInsn(ACONST_NULL); +mv.visitVarInsn(ASTORE, 3); +mv.visitVarInsn(ALOAD, 1); +mv.visitInsn(ICONST_4); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "setline", "(I)V"); +mv.visitVarInsn(ALOAD, 1); +mv.visitLdcInsn("greet"); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "getname", "(Ljava/lang/String;)Lorg/python/core/PyObject;"); +mv.visitVarInsn(ALOAD, 2); +mv.visitFieldInsn(GETSTATIC, "Hello", "_2", "Lorg/python/core/PyString;"); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "__call__", "(Lorg/python/core/ThreadState;Lorg/python/core/PyObject;)Lorg/python/core/PyObject;"); +mv.visitInsn(POP); +mv.visitVarInsn(ALOAD, 1); +mv.visitInsn(ICONST_M1); +mv.visitFieldInsn(PUTFIELD, "org/python/core/PyFrame", "f_lasti", "I"); +mv.visitFieldInsn(GETSTATIC, "org/python/core/Py", "None", "Lorg/python/core/PyObject;"); +mv.visitInsn(ARETURN); +mv.visitMaxs(6, 4); +mv.visitEnd(); +} +{ +mv = cw.visitMethod(ACC_PUBLIC, "greet$1", "(Lorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;", null, null); +mv.visitCode(); +mv.visitVarInsn(ALOAD, 1); +mv.visitInsn(ICONST_2); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "setline", "(I)V"); +mv.visitFieldInsn(GETSTATIC, "Hello", "_1", "Lorg/python/core/PyString;"); +mv.visitVarInsn(ALOAD, 1); +mv.visitInsn(ICONST_0); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "getlocal", "(I)Lorg/python/core/PyObject;"); +mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "_mod", "(Lorg/python/core/PyObject;)Lorg/python/core/PyObject;"); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "println", "(Lorg/python/core/PyObject;)V"); +mv.visitVarInsn(ALOAD, 1); +mv.visitInsn(ICONST_M1); +mv.visitFieldInsn(PUTFIELD, "org/python/core/PyFrame", "f_lasti", "I"); +mv.visitFieldInsn(GETSTATIC, "org/python/core/Py", "None", "Lorg/python/core/PyObject;"); +mv.visitInsn(ARETURN); +mv.visitMaxs(3, 3); +mv.visitEnd(); +} +{ +mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(Ljava/lang/String;)V", null, null); +mv.visitCode(); +mv.visitVarInsn(ALOAD, 0); +mv.visitMethodInsn(INVOKESPECIAL, "org/python/core/PyFunctionTable", "<init>", "()V"); +mv.visitVarInsn(ALOAD, 0); +mv.visitFieldInsn(PUTSTATIC, "Hello", "self", "LHello;"); +mv.visitLdcInsn("Frank"); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/PyString", "fromInterned", "(Ljava/lang/String;)Lorg/python/core/PyString;"); +mv.visitFieldInsn(PUTSTATIC, "Hello", "_2", "Lorg/python/core/PyString;"); +mv.visitLdcInsn("hello, %s"); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/PyString", "fromInterned", "(Ljava/lang/String;)Lorg/python/core/PyString;"); +mv.visitFieldInsn(PUTSTATIC, "Hello", "_1", "Lorg/python/core/PyString;"); +mv.visitLdcInsn("/Users/frank/svn/jython/trunk/sandbox/wierzbicki/indy_jython/./hello.py"); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/PyString", "fromInterned", "(Ljava/lang/String;)Lorg/python/core/PyString;"); +mv.visitFieldInsn(PUTSTATIC, "Hello", "_0", "Lorg/python/core/PyString;"); +mv.visitInsn(ICONST_0); +mv.visitInsn(ICONST_0); +mv.visitTypeInsn(ANEWARRAY, "java/lang/String"); +mv.visitVarInsn(ASTORE, 2); +mv.visitVarInsn(ALOAD, 2); +mv.visitVarInsn(ALOAD, 1); +mv.visitLdcInsn("<module>"); +mv.visitInsn(ICONST_0); +mv.visitInsn(ICONST_0); +mv.visitInsn(ICONST_0); +mv.visitFieldInsn(GETSTATIC, "Hello", "self", "LHello;"); +mv.visitInsn(ICONST_0); +mv.visitInsn(ACONST_NULL); +mv.visitInsn(ACONST_NULL); +mv.visitInsn(ICONST_0); +mv.visitIntInsn(SIPUSH, 4096); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "newCode", "(I[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZLorg/python/core/PyFunctionTable;I[Ljava/lang/String;[Ljava/lang/String;II)Lorg/python/core/PyCode;"); +mv.visitFieldInsn(PUTSTATIC, "Hello", "f$0", "Lorg/python/core/PyCode;"); +mv.visitInsn(ICONST_1); +mv.visitInsn(ICONST_1); +mv.visitTypeInsn(ANEWARRAY, "java/lang/String"); +mv.visitVarInsn(ASTORE, 2); +mv.visitVarInsn(ALOAD, 2); +mv.visitInsn(ICONST_0); +mv.visitLdcInsn("name"); +mv.visitInsn(AASTORE); +mv.visitVarInsn(ALOAD, 2); +mv.visitVarInsn(ALOAD, 1); +mv.visitLdcInsn("greet"); +mv.visitInsn(ICONST_1); +mv.visitInsn(ICONST_0); +mv.visitInsn(ICONST_0); +mv.visitFieldInsn(GETSTATIC, "Hello", "self", "LHello;"); +mv.visitInsn(ICONST_1); +mv.visitInsn(ACONST_NULL); +mv.visitInsn(ACONST_NULL); +mv.visitInsn(ICONST_0); +mv.visitIntInsn(SIPUSH, 4097); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "newCode", "(I[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZLorg/python/core/PyFunctionTable;I[Ljava/lang/String;[Ljava/lang/String;II)Lorg/python/core/PyCode;"); +mv.visitFieldInsn(PUTSTATIC, "Hello", "greet$1", "Lorg/python/core/PyCode;"); +mv.visitInsn(RETURN); +mv.visitMaxs(13, 3); +mv.visitEnd(); +} +{ +mv = cw.visitMethod(ACC_PUBLIC, "getMain", "()Lorg/python/core/PyCode;", null, null); +mv.visitCode(); +mv.visitFieldInsn(GETSTATIC, "Hello", "f$0", "Lorg/python/core/PyCode;"); +mv.visitInsn(ARETURN); +mv.visitMaxs(1, 1); +mv.visitEnd(); +} +{ +mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); +mv.visitCode(); +mv.visitTypeInsn(NEW, "Hello"); +mv.visitInsn(DUP); +mv.visitLdcInsn("Hello"); +mv.visitMethodInsn(INVOKESPECIAL, "Hello", "<init>", "(Ljava/lang/String;)V"); +mv.visitMethodInsn(INVOKEVIRTUAL, "Hello", "getMain", "()Lorg/python/core/PyCode;"); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/CodeLoader", "createSimpleBootstrap", "(Lorg/python/core/PyCode;)Lorg/python/core/CodeBootstrap;"); +mv.visitVarInsn(ALOAD, 0); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "runMain", "(Lorg/python/core/CodeBootstrap;[Ljava/lang/String;)V"); +mv.visitInsn(RETURN); +mv.visitMaxs(3, 1); +mv.visitEnd(); +} +{ +mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "getCodeBootstrap", "()Lorg/python/core/CodeBootstrap;", null, null); +mv.visitCode(); +mv.visitLdcInsn(Type.getType("LHello;")); +mv.visitMethodInsn(INVOKESTATIC, "org/python/core/PyRunnableBootstrap", "getFilenameConstructorReflectionBootstrap", "(Ljava/lang/Class;)Lorg/python/core/CodeBootstrap;"); +mv.visitInsn(ARETURN); +mv.visitMaxs(1, 0); +mv.visitEnd(); +} +{ +mv = cw.visitMethod(ACC_PUBLIC, "call_function", "(ILorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;", null, null); +mv.visitCode(); +mv.visitFrame(Opcodes.F_NEW, 0, new Object[] {}, 0, new Object[] {}); +mv.visitVarInsn(ALOAD, 0); +mv.visitVarInsn(ALOAD, 2); +mv.visitVarInsn(ALOAD, 3); +mv.visitVarInsn(ILOAD, 1); +Label l0 = new Label(); +Label l1 = new Label(); +Label l2 = new Label(); +mv.visitTableSwitchInsn(0, 1, l2, new Label[] { l0, l1 }); +mv.visitLabel(l0); +mv.visitFrame(Opcodes.F_NEW, 4, new Object[] {"Hello", Opcodes.INTEGER, "org/python/core/PyFrame", "org/python/core/ThreadState"}, 3, new Object[] {"Hello", "org/python/core/PyFrame", "org/python/core/ThreadState"}); +mv.visitMethodInsn(INVOKEVIRTUAL, "Hello", "f$0", "(Lorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;"); +mv.visitInsn(ARETURN); +mv.visitLabel(l1); +mv.visitFrame(Opcodes.F_NEW, 4, new Object[] {"Hello", Opcodes.INTEGER, "org/python/core/PyFrame", "org/python/core/ThreadState"}, 3, new Object[] {"Hello", "org/python/core/PyFrame", "org/python/core/ThreadState"}); +mv.visitMethodInsn(INVOKEVIRTUAL, "Hello", "greet$1", "(Lorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;"); +mv.visitInsn(ARETURN); +mv.visitLabel(l2); +mv.visitFrame(Opcodes.F_NEW, 4, new Object[] {"Hello", Opcodes.INTEGER, "org/python/core/PyFrame", "org/python/core/ThreadState"}, 3, new Object[] {"Hello", "org/python/core/PyFrame", "org/python/core/ThreadState"}); +mv.visitInsn(ACONST_NULL); +mv.visitInsn(ARETURN); +mv.visitMaxs(4, 4); +mv.visitEnd(); +} +cw.visitEnd(); + +return cw.toByteArray(); +} + +public static void main(String args[]) throws Exception { + byte[] ba = dump(); + File file = new File("Hello.class"); + try { + FileOutputStream o = new FileOutputStream(file); + o.write(ba); + o.close(); + } catch (Throwable t) { + t.printStackTrace(); + } + +} +} Property changes on: trunk/sandbox/wierzbicki/indy_jython/HelloDump.java ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/sandbox/wierzbicki/indy_jython/dump =================================================================== --- trunk/sandbox/wierzbicki/indy_jython/dump (rev 0) +++ trunk/sandbox/wierzbicki/indy_jython/dump 2009-09-22 17:01:13 UTC (rev 6801) @@ -0,0 +1,5 @@ +JYTHON_HOME=/Users/frank/svn/jython/trunk/jython + +$JAVA_HOME/bin/javac -classpath $JYTHON_HOME/extlibs/asm-3.1.jar:asm-util-3.1.jar:. HelloDump.java +$JAVA_HOME/bin/java -classpath $JYTHON_HOME/extlibs/asm-3.1.jar:asm-util-3.1.jar:. HelloDump +$JAVA_HOME/bin/java -classpath $JYTHON_HOME/extlibs/asm-3.1.jar:asm-util-3.1.jar:$JYTHON_HOME/dist/jython.jar:. Hello Property changes on: trunk/sandbox/wierzbicki/indy_jython/dump ___________________________________________________________________ Added: svn:executable + * Added: svn:eol-style + native Added: trunk/sandbox/wierzbicki/indy_jython/hello.py =================================================================== --- trunk/sandbox/wierzbicki/indy_jython/hello.py (rev 0) +++ trunk/sandbox/wierzbicki/indy_jython/hello.py 2009-09-22 17:01:13 UTC (rev 6801) @@ -0,0 +1,4 @@ +def greet(name): + print "hello, %s" % name + +greet('Frank') Property changes on: trunk/sandbox/wierzbicki/indy_jython/hello.py ___________________________________________________________________ Added: svn:keywords + Id Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-17 04:14:13
|
Revision: 6800 http://jython.svn.sourceforge.net/jython/?rev=6800&view=rev Author: fwierzbicki Date: 2009-09-17 04:14:04 +0000 (Thu, 17 Sep 2009) Log Message: ----------- Remove modules that now have modified versions living in our Lib/ Modified Paths: -------------- trunk/jython/CPythonLib.includes Modified: trunk/jython/CPythonLib.includes =================================================================== --- trunk/jython/CPythonLib.includes 2009-09-16 11:57:28 UTC (rev 6799) +++ trunk/jython/CPythonLib.includes 2009-09-17 04:14:04 UTC (rev 6800) @@ -55,17 +55,14 @@ dummy_thread.py dummy_threading.py exceptions.py -fileinput.py fnmatch.py formatter.py fpformat.py ftplib.py functools.py getopt.py -gettext.py glob.py gopherlib.py -gzip.py hashlib.py heapq.py hmac.py @@ -76,13 +73,11 @@ ihooks.py imaplib.py imghdr.py -inspect.py keyword.py linecache.py locale.py macpath.py macurl2path.py -mailbox.py mailcap.py markupbase.py md5.py @@ -94,9 +89,7 @@ modulefinder.py multifile.py mutex.py -netrc.py nntplib.py -ntpath.py nturl2path.py opcode.py optparse.py @@ -104,15 +97,12 @@ pickle.py pickletools.py pipes.py -pkgutil.py -platform.py poplib.py posixfile.py pprint.py profile.py pstats.py pyclbr.py -pydoc.py Queue.py quopri.py random.py @@ -130,9 +120,7 @@ shelve.py shlex.py shutil.py -SimpleHTTPServer.py SimpleXMLRPCServer.py -site.py site-packages/README smtpd.py smtplib.py @@ -145,26 +133,20 @@ symbol.py tabnanny.py this.py -threading.py textwrap.py -timeit.py token.py tokenize.py trace.py traceback.py tzparse.py unittest.py -urllib.py urllib2.py urlparse.py user.py UserDict.py UserList.py UserString.py -uu.py uuid.py -warnings.py -weakref.py whichdb.py whrandom.py wsgiref.egg-info @@ -172,4 +154,3 @@ xdrlib.py xmllib.py xmlrpclib.py -zipfile.py This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-09-14 02:26:19
|
Revision: 6797 http://jython.svn.sourceforge.net/jython/?rev=6797&view=rev Author: pjenvey Date: 2009-09-14 01:49:05 +0000 (Mon, 14 Sep 2009) Log Message: ----------- actually test 'a+' Modified Paths: -------------- trunk/jython/Lib/test/test_file_jy.py Modified: trunk/jython/Lib/test/test_file_jy.py =================================================================== --- trunk/jython/Lib/test/test_file_jy.py 2009-09-14 01:05:23 UTC (rev 6796) +++ trunk/jython/Lib/test/test_file_jy.py 2009-09-14 01:49:05 UTC (rev 6797) @@ -21,9 +21,9 @@ def _test_append(self, mode): # http://bugs.jython.org/issue1466 - fp1 = open(test_support.TESTFN, 'ab') + fp1 = open(test_support.TESTFN, mode) fp1.write('test1\n') - fp2 = open(test_support.TESTFN, 'ab') + fp2 = open(test_support.TESTFN, mode) fp2.write('test2\n') fp1.close() fp2.close() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-09-14 01:05:42
|
Revision: 6796 http://jython.svn.sourceforge.net/jython/?rev=6796&view=rev Author: pjenvey Date: 2009-09-14 01:05:23 +0000 (Mon, 14 Sep 2009) Log Message: ----------- force real O_APPEND for files' 'a' mode by going through FileOutputStream, otherwise emulate it with a performance hit for 'a+' mode fixes #1466 Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/core/io/FileIO.java Added Paths: ----------- trunk/jython/Lib/test/test_file_jy.py Added: trunk/jython/Lib/test/test_file_jy.py =================================================================== --- trunk/jython/Lib/test/test_file_jy.py (rev 0) +++ trunk/jython/Lib/test/test_file_jy.py 2009-09-14 01:05:23 UTC (rev 6796) @@ -0,0 +1,39 @@ +"""Misc file tests. + +Made for Jython. +""" +from __future__ import with_statement +import os +import unittest +from test import test_support + +class FileTestCase(unittest.TestCase): + + def tearDown(self): + if os.path.exists(test_support.TESTFN): + os.remove(test_support.TESTFN) + + def test_append(self): + self._test_append('ab') + + def test_appendplus(self): + self._test_append('a+') + + def _test_append(self, mode): + # http://bugs.jython.org/issue1466 + fp1 = open(test_support.TESTFN, 'ab') + fp1.write('test1\n') + fp2 = open(test_support.TESTFN, 'ab') + fp2.write('test2\n') + fp1.close() + fp2.close() + with open(test_support.TESTFN) as fp: + self.assertEqual('test1\ntest2\n', fp.read()) + + +def test_main(): + test_support.run_unittest(FileTestCase) + + +if __name__ == '__main__': + test_main() Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-09-13 23:30:43 UTC (rev 6795) +++ trunk/jython/NEWS 2009-09-14 01:05:23 UTC (rev 6796) @@ -1,5 +1,9 @@ Jython NEWS +Jython 2.5.1rc3 + Bugs Fixed + - [ 1466 ] wrong handling of append only files + Jython 2.5.1rc2 New Features - zxJDBC supports the with-statement: connections are committed or rollbacked; cursors are closed Modified: trunk/jython/src/org/python/core/io/FileIO.java =================================================================== --- trunk/jython/src/org/python/core/io/FileIO.java 2009-09-13 23:30:43 UTC (rev 6795) +++ trunk/jython/src/org/python/core/io/FileIO.java 2009-09-14 01:05:23 UTC (rev 6796) @@ -3,6 +3,7 @@ import java.io.File; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -28,21 +29,27 @@ /** The underlying file channel */ private FileChannel fileChannel; - /** The underlying file (if known) */ + /** The underlying RandomAccessFile, if known. May be null */ private RandomAccessFile file; + /** The underlying FileOutputStream, if known. May be null */ + private FileOutputStream fileOutputStream; + /** true if the file is opened for reading ('r') */ - private boolean reading = false; + private boolean reading; /** true if the file is opened for writing ('w', 'a', or '+') */ - private boolean writing = false; + private boolean writing; /** true if the file is in appending mode ('a') */ - private boolean appending = false; + private boolean appending; /** true if the file is opened for reading and writing ('+') */ - private boolean plus = false; + private boolean plus; + /** true if write will emulate O_APPEND mode */ + private boolean emulateAppend; + /** * Construct a FileIO instance for the specified file name. * @@ -55,21 +62,21 @@ */ public FileIO(String name, String mode) { parseMode(mode); + File absPath = new RelativeFile(name); - File fullPath = new RelativeFile(name); - String rafMode = "r" + (writing ? "w" : ""); try { - if (plus && reading && !fullPath.isFile()) { - writing = false; // suppress "permission denied" - throw new FileNotFoundException(""); + if (appending && !reading) { + // Take advantage of FileOutputStream's append mode + fromFileOutputStream(absPath); + } else { + fromRandomAccessFile(absPath); + emulateAppend = appending; } - file = new RandomAccessFile(fullPath, rafMode); - fileChannel = file.getChannel(); } catch (FileNotFoundException fnfe) { - if (fullPath.isDirectory()) { + if (absPath.isDirectory()) { throw Py.IOError(Errno.EISDIR, name); } - if ((writing && !fullPath.canWrite()) + if ((writing && !absPath.canWrite()) || fnfe.getMessage().endsWith("(Permission denied)")) { throw Py.IOError(Errno.EACCES, name); } @@ -144,6 +151,34 @@ } /** + * Open the underlying FileChannel from a RandomAccessFile. + * + * @param absPath The absolute path File to open + */ + private void fromRandomAccessFile(File absPath) throws FileNotFoundException { + String rafMode = "r" + (writing ? "w" : ""); + if (plus && reading && !absPath.isFile()) { + // suppress "permission denied" + writing = false; + throw new FileNotFoundException(""); + } + file = new RandomAccessFile(absPath, rafMode); + fileChannel = file.getChannel(); + } + + /** + * Open the underlying FileChannel from a FileOutputStream in append mode, as opposed + * to a RandomAccessFile, for the use of the OS's underlying O_APPEND mode. This can + * only be used by 'a' (not 'a+') mode. + * + * @param absPath The absolute path File to open + */ + private void fromFileOutputStream(File absPath) throws FileNotFoundException { + fileOutputStream = new FileOutputStream(absPath, true); + fileChannel = fileOutputStream.getChannel(); + } + + /** * Raise a value error due to a mode string not containing exactly * one r/w/a/+ character. * @@ -183,11 +218,11 @@ @Override public boolean isatty() { checkClosed(); - if (file == null) { + if (file == null || fileOutputStream == null) { return false; } try { - return FileUtil.isatty(file.getFD()); + return FileUtil.isatty(file != null ? file.getFD() : fileOutputStream.getFD()); } catch (IOException e) { return false; } @@ -259,7 +294,8 @@ checkClosed(); checkWritable(); try { - return fileChannel.write(buf); + return !emulateAppend ? fileChannel.write(buf) : + fileChannel.write(buf, fileChannel.position()); } catch (IOException ioe) { throw Py.IOError(ioe); } @@ -277,12 +313,33 @@ checkClosed(); checkWritable(); try { - return fileChannel.write(bufs); + return !emulateAppend ? fileChannel.write(bufs) : writeAppend(bufs); } catch (IOException ioe) { throw Py.IOError(ioe); } } + /** + * Write multiple ByteBuffers while emulating O_APPEND mode. + * + * @param bufs an array of ByteBuffers + * @return the number of bytes written as a long + */ + private long writeAppend(ByteBuffer[] bufs) throws IOException { + long count = 0; + int bufCount; + for (ByteBuffer buf : bufs) { + if (!buf.hasRemaining()) { + continue; + } + if ((bufCount = fileChannel.write(buf, fileChannel.position())) == 0) { + break; + } + count += bufCount; + } + return count; + } + @Override public long seek(long pos, int whence) { checkClosed(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-09-13 23:31:02
|
Revision: 6795 http://jython.svn.sourceforge.net/jython/?rev=6795&view=rev Author: pjenvey Date: 2009-09-13 23:30:43 +0000 (Sun, 13 Sep 2009) Log Message: ----------- add @Overrides Modified Paths: -------------- trunk/jython/src/org/python/core/io/FileIO.java Modified: trunk/jython/src/org/python/core/io/FileIO.java =================================================================== --- trunk/jython/src/org/python/core/io/FileIO.java 2009-09-13 16:26:28 UTC (rev 6794) +++ trunk/jython/src/org/python/core/io/FileIO.java 2009-09-13 23:30:43 UTC (rev 6795) @@ -211,6 +211,7 @@ * @param bufs {@inheritDoc} * @return {@inheritDoc} */ + @Override public long readinto(ByteBuffer[] bufs) { checkClosed(); checkReadable(); @@ -229,6 +230,7 @@ * * @return {@inheritDoc} */ + @Override public ByteBuffer readall() { checkClosed(); checkReadable(); @@ -270,6 +272,7 @@ * @param bufs {@inheritDoc} * @return {@inheritDoc} */ + @Override public long write(ByteBuffer[] bufs) { checkClosed(); checkWritable(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-09-13 16:26:37
|
Revision: 6794 http://jython.svn.sourceforge.net/jython/?rev=6794&view=rev Author: thobes Date: 2009-09-13 16:26:28 +0000 (Sun, 13 Sep 2009) Log Message: ----------- Preparing SoC code submission. Modified Paths: -------------- trunk/sandbox/tobias/README.txt trunk/sandbox/tobias/build.xml Property Changed: ---------------- trunk/sandbox/tobias/ Property changes on: trunk/sandbox/tobias ___________________________________________________________________ Modified: svn:externals - jython https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython frame https://kenai.com/svn/jvm-frame-introspect~svn/frame ssa https://kenai.com/svn/ssa-compiler~svn-temprep/trunk + jython https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython frame https://kenai.com/svn/jvm-frame-introspect~svn/frame ssa https://kenai.com/svn/ssa-compiler~svn-temprep/trunk mlvm https://kenai.com/svn/jvm-frame-introspect~svn/mlvm/ Modified: trunk/sandbox/tobias/README.txt =================================================================== --- trunk/sandbox/tobias/README.txt 2009-09-13 10:00:14 UTC (rev 6793) +++ trunk/sandbox/tobias/README.txt 2009-09-13 16:26:28 UTC (rev 6794) @@ -1,5 +1,8 @@ This sandbox contains Tobias projects. Most notably the "advanced" compiler. +The most recent version can be found at: + https://jython.svn.sourceforge.net/svnroot/jython/trunk/sandbox/tobias + Here double version control systems are used. Subversion is used at the base. All sub projects are managed in subversion. The main Jython code is linked using svn:externals. Modified: trunk/sandbox/tobias/build.xml =================================================================== --- trunk/sandbox/tobias/build.xml 2009-09-13 10:00:14 UTC (rev 6793) +++ trunk/sandbox/tobias/build.xml 2009-09-13 16:26:28 UTC (rev 6794) @@ -1,8 +1,5 @@ <project name="advanced" default="all" basedir="."> <target name="all" depends="jython,compiler,frame,util,bytecode,agent"/> - <target name="version"> - <echo message="${ant.version.minor}"/> - </target> <property name="target.dir" location="${basedir}/target"/> @@ -54,6 +51,32 @@ </target> <target name="source dist"> + <tar destfile="${target.dir}/Tobias_Ivarsson.tar.gz" compression="gzip"> + <tarfileset dir="${basedir}"> + <not> + <filename name="**/.svn/**" /> + </not> + <or> + <!-- files --> + <filename name="README.txt" /> + <filename name="bootstrap" /> + <filename name="build.xml" /> + <!-- subdirectories --> + <filename name="agent/**" /> + <filename name="bytecode/**" /> + <filename name="compiler/**" /> + <filename name="frame/**" /> + <filename name="lib/**" /> + <filename name="mlvm/**" /> + <filename name="ssa/**" /> + <filename name="tests/**" /> + <filename name="util/**" /> + </or> + </tarfileset> + <tarfileset dir="${basedir}/.hg/patches" prefix="patches/"> + <filename name="*.patch" /> + </tarfileset> + </tar> </target> <target name="setup target"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-09-13 10:00:27
|
Revision: 6793 http://jython.svn.sourceforge.net/jython/?rev=6793&view=rev Author: cgroves Date: 2009-09-13 10:00:14 +0000 (Sun, 13 Sep 2009) Log Message: ----------- Extend MethodAdapter rather than doing the exact same thing ourselves Modified Paths: -------------- branches/customizable-proxymaker/src/org/python/compiler/Code.java Modified: branches/customizable-proxymaker/src/org/python/compiler/Code.java =================================================================== --- branches/customizable-proxymaker/src/org/python/compiler/Code.java 2009-09-12 21:32:08 UTC (rev 6792) +++ branches/customizable-proxymaker/src/org/python/compiler/Code.java 2009-09-13 10:00:14 UTC (rev 6793) @@ -3,26 +3,23 @@ import java.util.BitSet; import java.util.Vector; -import org.objectweb.asm.AnnotationVisitor; -import org.objectweb.asm.Attribute; import org.objectweb.asm.Label; +import org.objectweb.asm.MethodAdapter; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; -public class Code implements MethodVisitor, Opcodes { - MethodVisitor mv; - String sig; +public class Code extends MethodAdapter implements Opcodes { + String locals[]; int nlocals; int argcount; int returnLocal; - BitSet finallyLocals = new java.util.BitSet(); + BitSet finallyLocals = new BitSet(); //XXX: I'd really like to get sig and access out of here since MethodVistitor // should already have this information. public Code(MethodVisitor mv, String sig, int access) { - this.mv = mv; - this.sig = sig; + super(mv); nlocals = -sigSize(sig, false); if ((access & ACC_STATIC) != ACC_STATIC) nlocals = nlocals+1; argcount = nlocals; @@ -83,102 +80,6 @@ return ret; } - public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) { - return mv.visitAnnotation(arg0, arg1); - } - - public AnnotationVisitor visitAnnotationDefault() { - return mv.visitAnnotationDefault(); - } - - public void visitAttribute(Attribute arg0) { - mv.visitAttribute(arg0); - } - - public void visitCode() { - mv.visitCode(); - } - - public void visitEnd() { - mv.visitEnd(); - } - - public void visitFieldInsn(int arg0, String arg1, String arg2, String arg3) { - mv.visitFieldInsn(arg0, arg1, arg2, arg3); - } - - public void visitFrame(int arg0, int arg1, Object[] arg2, int arg3, Object[] arg4) { - mv.visitFrame(arg0, arg1, arg2, arg3, arg4); - } - - public void visitIincInsn(int arg0, int arg1) { - mv.visitIincInsn(arg0, arg1); - } - - public void visitInsn(int arg0) { - mv.visitInsn(arg0); - } - - public void visitIntInsn(int arg0, int arg1) { - mv.visitIntInsn(arg0, arg1); - } - - public void visitJumpInsn(int arg0, Label arg1) { - mv.visitJumpInsn(arg0, arg1); - } - - public void visitLabel(Label arg0) { - mv.visitLabel(arg0); - } - - public void visitLdcInsn(Object arg0) { - mv.visitLdcInsn(arg0); - } - - public void visitLineNumber(int arg0, Label arg1) { - mv.visitLineNumber(arg0, arg1); - } - - public void visitLocalVariable(String arg0, String arg1, String arg2, Label arg3, Label arg4, int arg5) { - mv.visitLocalVariable(arg0, arg1, arg2, arg3, arg4, arg5); - } - - public void visitLookupSwitchInsn(Label arg0, int[] arg1, Label[] arg2) { - mv.visitLookupSwitchInsn(arg0, arg1, arg2); - } - - public void visitMaxs(int arg0, int arg1) { - mv.visitMaxs(arg0, arg1); - } - - public void visitMethodInsn(int arg0, String arg1, String arg2, String arg3) { - mv.visitMethodInsn(arg0, arg1, arg2, arg3); - } - - public void visitMultiANewArrayInsn(String arg0, int arg1) { - mv.visitMultiANewArrayInsn(arg0, arg1); - } - - public AnnotationVisitor visitParameterAnnotation(int arg0, String arg1, boolean arg2) { - return mv.visitParameterAnnotation(arg0, arg1, arg2); - } - - public void visitTableSwitchInsn(int arg0, int arg1, Label arg2, Label[] arg3) { - mv.visitTableSwitchInsn(arg0, arg1, arg2, arg3); - } - - public void visitTryCatchBlock(Label arg0, Label arg1, Label arg2, String arg3) { - mv.visitTryCatchBlock(arg0, arg1, arg2, arg3); - } - - public void visitTypeInsn(int arg0, String arg1) { - mv.visitTypeInsn(arg0, arg1); - } - - public void visitVarInsn(int arg0, int arg1) { - mv.visitVarInsn(arg0, arg1); - } - @SuppressWarnings("fallthrough") private int sigSize(String sig, boolean includeReturn) { int stack = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-12 18:38:19
|
Revision: 6790 http://jython.svn.sourceforge.net/jython/?rev=6790&view=rev Author: fwierzbicki Date: 2009-09-12 18:38:10 +0000 (Sat, 12 Sep 2009) Log Message: ----------- tag rc2. Added Paths: ----------- tags/Release_2_5_1rc2/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-12 18:14:26
|
Revision: 6789 http://jython.svn.sourceforge.net/jython/?rev=6789&view=rev Author: fwierzbicki Date: 2009-09-12 18:14:14 +0000 (Sat, 12 Sep 2009) Log Message: ----------- Update versions. Modified Paths: -------------- trunk/jython/README.txt trunk/jython/build.xml Modified: trunk/jython/README.txt =================================================================== --- trunk/jython/README.txt 2009-09-12 02:24:31 UTC (rev 6788) +++ trunk/jython/README.txt 2009-09-12 18:14:14 UTC (rev 6789) @@ -1,9 +1,9 @@ -Welcome to Jython 2.5.1rc1 +Welcome to Jython 2.5.1rc2 ========================== -This is the first release candidate of the 2.5.1 version of Jython. This +This is the second 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 +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: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2009-09-12 02:24:31 UTC (rev 6788) +++ trunk/jython/build.xml 2009-09-12 18:14:14 UTC (rev 6789) @@ -130,7 +130,7 @@ <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"/> + <property name="jython.release_serial" value="2"/> <condition property="do.snapshot.build"> <isset property="snapshot.revision" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-09-12 02:24:41
|
Revision: 6788 http://jython.svn.sourceforge.net/jython/?rev=6788&view=rev Author: zyasoft Date: 2009-09-12 02:24:31 +0000 (Sat, 12 Sep 2009) Log Message: ----------- Updated NEWS re zxJDBC support of with-statement Modified Paths: -------------- trunk/jython/NEWS Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-09-12 01:10:11 UTC (rev 6787) +++ trunk/jython/NEWS 2009-09-12 02:24:31 UTC (rev 6788) @@ -1,6 +1,8 @@ Jython NEWS Jython 2.5.1rc2 + New Features + - zxJDBC supports the with-statement: connections are committed or rollbacked; cursors are closed Bugs Fixed - [ 1079 ] fixed regression on issue: twisted.python.threadable module: missing attribute '_RLock' - [ 1461 ] assert statement should lookup AssertionError using getglobal This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wme...@us...> - 2009-09-12 01:10:24
|
Revision: 6787 http://jython.svn.sourceforge.net/jython/?rev=6787&view=rev Author: wmeissner Date: 2009-09-12 01:10:11 +0000 (Sat, 12 Sep 2009) Log Message: ----------- Implement some parts of ctypes Array Modified Paths: -------------- branches/ctypes-jffi/CoreExposed.includes branches/ctypes-jffi/Lib/ctypes/__init__.py branches/ctypes-jffi/src/org/python/modules/jffi/CType.java branches/ctypes-jffi/src/org/python/modules/jffi/jffi.java Added Paths: ----------- branches/ctypes-jffi/src/org/python/modules/jffi/ArrayCData.java Modified: branches/ctypes-jffi/CoreExposed.includes =================================================================== --- branches/ctypes-jffi/CoreExposed.includes 2009-09-11 11:39:00 UTC (rev 6786) +++ branches/ctypes-jffi/CoreExposed.includes 2009-09-12 01:10:11 UTC (rev 6787) @@ -52,6 +52,7 @@ org/python/modules/_csv/PyWriter.class org/python/modules/_functools/PyPartial.class org/python/modules/_hashlib$Hash.class +org/python/modules/jffi/ArrayCData.class org/python/modules/jffi/ByReference.class org/python/modules/jffi/CData.class org/python/modules/jffi/CType.class Modified: branches/ctypes-jffi/Lib/ctypes/__init__.py =================================================================== --- branches/ctypes-jffi/Lib/ctypes/__init__.py 2009-09-11 11:39:00 UTC (rev 6786) +++ branches/ctypes-jffi/Lib/ctypes/__init__.py 2009-09-12 01:10:11 UTC (rev 6787) @@ -25,8 +25,17 @@ def __mul__(self, len): dict = { '_jffi_type': jffi.Type.Array(self, len) } - return type("%s_%d" % (self.__name__, len), (_ArrayCData,), dict) + # Look back up the stack frame to find out the module this new type is declared in + import inspect + mod = inspect.getmodule(inspect.stack()[1][0]) + if mod is None: + name = "__main__" + else: + name = mod.__name__ + dict["__module__"] = name + return type("%s_Array_%d" % (self.__name__, len), (jffi.ArrayCData, _ArrayCData, _CData), dict) + class _CData(object): @classmethod def in_dll(self, lib, name): @@ -41,9 +50,6 @@ class _ArrayCData(object): - def __init__(self, *args): - raise NotImplementedError("instantiating arrays is not implemented yet") - def __len__(self): return self._jffi_type.length Added: branches/ctypes-jffi/src/org/python/modules/jffi/ArrayCData.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/ArrayCData.java (rev 0) +++ branches/ctypes-jffi/src/org/python/modules/jffi/ArrayCData.java 2009-09-12 01:10:11 UTC (rev 6787) @@ -0,0 +1,175 @@ + +package org.python.modules.jffi; + +import org.python.core.Py; +import org.python.core.PyIterator; +import org.python.core.PyList; +import org.python.core.PyNewWrapper; +import org.python.core.PyObject; +import org.python.core.PySequenceList; +import org.python.core.PyType; +import org.python.core.SequenceIndexDelegate; +import org.python.expose.ExposedClassMethod; +import org.python.expose.ExposedNew; +import org.python.expose.ExposedType; + +@ExposedType(name = "jffi.ArrayCData", base = CData.class) +public class ArrayCData extends CData implements Pointer { + public static final PyType TYPE = PyType.fromClass(ArrayCData.class); + + final CType.Array arrayType; + final CType componentType; + final MemoryOp componentMemoryOp; + + ArrayCData(PyType subtype, CType.Array arrayType, DirectMemory memory, MemoryOp componentMemoryOp) { + super(subtype, arrayType, memory); + this.arrayType = arrayType; + this.componentType = arrayType.componentType; + this.componentMemoryOp = componentMemoryOp; + } + + @ExposedNew + public static PyObject ArrayCData_new(PyNewWrapper new_, boolean init, PyType subtype, + PyObject[] args, String[] keywords) { + + CType.Array arrayType = getArrayType(subtype); + + // Only clear the array if it is not going to be completely filled + boolean clear = args.length < arrayType.length; + DirectMemory memory = AllocatedNativeMemory.allocateAligned(arrayType.componentType.size() * arrayType.length, + arrayType.componentType.alignment(), clear); + int offset = 0; + for (PyObject value : args) { + arrayType.componentMemoryOp.put(memory, offset, value); + offset += arrayType.componentType.size(); + } + return new ArrayCData(subtype, arrayType, memory, arrayType.componentMemoryOp); + } + + static final CType.Array getArrayType(PyType subtype) { + PyObject jffi_type = subtype.__getattr__("_jffi_type"); + + if (!(jffi_type instanceof CType.Array)) { + throw Py.TypeError("invalid _jffi_type for " + subtype.getName()); + } + + return (CType.Array) jffi_type; + } + + @ExposedClassMethod(names= { "from_address" }) + public static final PyObject from_address(PyType subtype, PyObject address) { + + CType.Array arrayType = getArrayType(subtype); + DirectMemory m = Util.getMemoryForAddress(address); + PointerCData cdata = new PointerCData(subtype, arrayType, m.getMemory(0), arrayType.componentMemoryOp); + cdata.setReferenceMemory(m); + + return cdata; + } + + public final DirectMemory getMemory() { + return getReferenceMemory(); + } + + protected final void initReferenceMemory(Memory m) { + // Nothing to do, since the reference memory was initialized during construction + } + + @Override + public PyObject __finditem__(int index) { + return delegator.checkIdxAndFindItem(index); + } + + @Override + public PyObject __getitem__(PyObject index) { + return delegator.checkIdxAndGetItem(index); + } + + @Override + public void __setitem__(int index, PyObject value) { + delegator.checkIdxAndSetItem(index, value); + } + + @Override + public void __setitem__(PyObject index, PyObject value) { + delegator.checkIdxAndSetItem(index, value); + } + + @Override + public void __delitem__(PyObject key) { + throw Py.TypeError("Array does not support item deletion"); + } + + + @Override + public PyObject __iter__() { + return new ArrayIter(); + } + + protected final SequenceIndexDelegate delegator = new SequenceIndexDelegate() { + + @Override + public String getTypeName() { + return getType().fastGetName(); + } + + @Override + public void setItem(int idx, PyObject value) { + componentMemoryOp.put(getReferenceMemory(), idx * componentType.size(), value); + } + + @Override + public void setSlice(int start, int stop, int step, PyObject value) { + if (!(value instanceof PySequenceList)) { + throw Py.TypeError("expected list or tuple"); + } + PySequenceList list = (PySequenceList) value; + for (int i = 0; i < stop - start; ++i) { + setItem(start + i, list.pyget(i)); + } + } + + @Override + public int len() { + return arrayType.length; + } + + @Override + public void delItem(int idx) { + throw Py.TypeError("Array does not support item deletion"); + } + + @Override + public void delItems(int start, int stop) { + throw Py.TypeError("Array does not support item deletion"); + } + + + @Override + public PyObject getItem(int idx) { + return componentMemoryOp.get(getReferenceMemory(), idx * componentType.size()); + } + + @Override + public PyObject getSlice(int start, int stop, int step) { + PyObject[] result = new PyObject[stop - start]; + for (int i = 0; i < result.length; ++i) { + result[i] = getItem(start + i); + } + return new PyList(result); + } + }; + + public class ArrayIter extends PyIterator { + + private int index = 0; + + public PyObject __iternext__() { + if (index >= arrayType.length) { + return null; + } + return componentMemoryOp.get(getReferenceMemory(), index++ * componentType.size()); + } + } + +} Modified: branches/ctypes-jffi/src/org/python/modules/jffi/CType.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/CType.java 2009-09-11 11:39:00 UTC (rev 6786) +++ branches/ctypes-jffi/src/org/python/modules/jffi/CType.java 2009-09-12 01:10:11 UTC (rev 6787) @@ -110,15 +110,17 @@ static final class Array extends CType { public static final PyType TYPE = PyType.fromClass(Array.class); final CType componentType; - final PyObject pyComponentType; + final PyType pyComponentType; + final MemoryOp componentMemoryOp; @ExposedGet public final int length; - public Array(PyObject pyComponentType, CType componentType, int length) { + public Array(PyType pyComponentType, CType componentType, int length) { super(NativeType.ARRAY, new com.kenai.jffi.Array(componentType.jffiType, length), null); this.pyComponentType = pyComponentType; this.componentType = componentType; + this.componentMemoryOp = getComponentMemoryOp((PyType) pyComponentType, componentType); this.length = length; } @@ -130,7 +132,11 @@ throw Py.TypeError(String.format("__init__() takes exactly 2 arguments (%d given)", args.length)); } - return new Array(args[0], typeOf(args[0]), args[1].asInt()); + if (!(args[0] instanceof PyType)) { + throw Py.TypeError("invalid component type"); + } + + return new Array((PyType) args[0], typeOf(args[0]), args[1].asInt()); } @Override @@ -142,8 +148,20 @@ public final String toString() { return String.format("<ctypes.Array elem_type=%s length=%d>", pyComponentType.toString(), length); } + + static final MemoryOp getComponentMemoryOp(PyType pyComponentType, CType componentType) { + if (pyComponentType.isSubType(ScalarCData.TYPE)) { + return componentType.getMemoryOp(); + } else if (pyComponentType.isSubType(Structure.TYPE)) { + return new MemoryOp.StructOp(pyComponentType); + } else { + throw Py.TypeError("only scalar and struct types supported"); + } + } } + + @ExposedType(name = "jffi.Type.Pointer", base = CType.class) final static class Pointer extends CType { public static final PyType TYPE = PyType.fromClass(Pointer.class); @@ -166,7 +184,7 @@ } else { throw Py.TypeError("pointer only supported for scalar types"); } - + } @ExposedNew @@ -196,7 +214,7 @@ public final String toString() { return String.format("<jffi.Type.Pointer component_type=%s>", componentType.toString()); } - + private static final class ScalarOp extends MemoryOp { private final MemoryOp op; private final PyType type; @@ -217,12 +235,12 @@ // update the same memory this pointer points to // if (result instanceof ScalarCData) { - ((ScalarCData) result).setReferenceMemory(mem); + ((ScalarCData) result).setReferenceMemory(mem); } return result; } } - + } } Modified: branches/ctypes-jffi/src/org/python/modules/jffi/jffi.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/jffi.java 2009-09-11 11:39:00 UTC (rev 6786) +++ branches/ctypes-jffi/src/org/python/modules/jffi/jffi.java 2009-09-12 01:10:11 UTC (rev 6787) @@ -23,6 +23,7 @@ dict.__setitem__("Type", CType.TYPE); dict.__setitem__("Function", Function.TYPE); dict.__setitem__("CData", CData.TYPE); + dict.__setitem__("ArrayCData", ArrayCData.TYPE); dict.__setitem__("PointerCData", PointerCData.TYPE); dict.__setitem__("ScalarCData", ScalarCData.TYPE); dict.__setitem__("StringCData", StringCData.TYPE); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wme...@us...> - 2009-09-11 11:39:11
|
Revision: 6786 http://jython.svn.sourceforge.net/jython/?rev=6786&view=rev Author: wmeissner Date: 2009-09-11 11:39:00 +0000 (Fri, 11 Sep 2009) Log Message: ----------- Implement memset & memmove 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/jffi.java Modified: branches/ctypes-jffi/Lib/ctypes/__init__.py =================================================================== --- branches/ctypes-jffi/Lib/ctypes/__init__.py 2009-09-11 06:55:34 UTC (rev 6785) +++ branches/ctypes-jffi/Lib/ctypes/__init__.py 2009-09-11 11:39:00 UTC (rev 6786) @@ -137,12 +137,18 @@ def alignment(type): return type._jffi_type.alignment -def byref(cdata): - return cdata.byref() +def addressof(cdata): + return cdata.address() +def byref(cdata, offset = 0): + return cdata.byref(offset) + def pointer(cdata): return cdata.pointer(POINTER(cdata.__class__)) +memmove = jffi.memmove +memset = jffi.memset + _pointer_type_cache = {} def POINTER(ctype): # If a pointer class for the C type has been created, re-use it Modified: branches/ctypes-jffi/src/org/python/modules/jffi/CData.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/CData.java 2009-09-11 06:55:34 UTC (rev 6785) +++ branches/ctypes-jffi/src/org/python/modules/jffi/CData.java 2009-09-11 11:39:00 UTC (rev 6786) @@ -2,8 +2,6 @@ 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; @@ -34,8 +32,8 @@ * @return A ByReference instance pointing to this object's native memory. */ @ExposedMethod(names= { "byref" }) - public PyObject byref() { - return new ByReference(ctype, getReferenceMemory()); + public PyObject byref(PyObject offset) { + return new ByReference(ctype, (DirectMemory) getReferenceMemory().slice(offset.asInt())); } @ExposedMethod(names= { "pointer" }) @@ -47,6 +45,11 @@ return new PointerCData((PyType) pytype, CType.typeOf(pytype), getReferenceMemory(), getMemoryOp()); } + @ExposedMethod(names = { "address" }) + public PyObject address() { + return Py.newInteger(getReferenceMemory().getAddress()); + } + final CType getCType() { return ctype; } Modified: branches/ctypes-jffi/src/org/python/modules/jffi/jffi.java =================================================================== --- branches/ctypes-jffi/src/org/python/modules/jffi/jffi.java 2009-09-11 06:55:34 UTC (rev 6785) +++ branches/ctypes-jffi/src/org/python/modules/jffi/jffi.java 2009-09-11 11:39:00 UTC (rev 6786) @@ -4,6 +4,8 @@ import com.kenai.jffi.Library; import org.python.core.ClassDictInit; import org.python.core.Py; +import org.python.core.PyInteger; +import org.python.core.PyLong; import org.python.core.PyObject; @@ -54,4 +56,30 @@ public static PyObject POINTER(PyObject type) { return type; } + + private static long getMemoryAddress(PyObject obj) { + if (obj instanceof Pointer) { + return ((Pointer) obj).getMemory().getAddress(); + } else if (obj instanceof CData) { + return ((CData) obj).getReferenceMemory().getAddress(); + } else if (obj instanceof PyInteger) { + return obj.asInt(); + } else if (obj instanceof PyLong) { + return ((PyLong) obj).asLong(0); + } else { + throw Py.TypeError("invalid memory address"); + } + } + + public static PyObject memmove(PyObject dst, PyObject src, PyObject length) { + com.kenai.jffi.MemoryIO.getInstance().copyMemory(getMemoryAddress(src), + getMemoryAddress(dst), length.asInt()); + + return Py.None; + } + + public static PyObject memset(PyObject dst, PyObject value, PyObject length) { + com.kenai.jffi.MemoryIO.getInstance().setMemory(getMemoryAddress(dst), length.asInt(), (byte) value.asInt()); + return Py.None; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-09-11 06:55:49
|
Revision: 6785 http://jython.svn.sourceforge.net/jython/?rev=6785&view=rev Author: cgroves Date: 2009-09-11 06:55:34 +0000 (Fri, 11 Sep 2009) Log Message: ----------- Use the builtin codecs when nothing is found in the registry. Fixes issue 1458. Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/core/codecs.java Added Paths: ----------- trunk/jython/Lib/test/print_sans_lib.py trunk/jython/Lib/test/test_codecs_jy.py Added: trunk/jython/Lib/test/print_sans_lib.py =================================================================== --- trunk/jython/Lib/test/print_sans_lib.py (rev 0) +++ trunk/jython/Lib/test/print_sans_lib.py 2009-09-11 06:55:34 UTC (rev 6785) @@ -0,0 +1,4 @@ +import sys +sys.path = [path for path in sys.path if not path.startswith('/')] +encoded = u'hi'.encode("utf-8") +encoded.decode('utf-8') Added: trunk/jython/Lib/test/test_codecs_jy.py =================================================================== --- trunk/jython/Lib/test/test_codecs_jy.py (rev 0) +++ trunk/jython/Lib/test/test_codecs_jy.py 2009-09-11 06:55:34 UTC (rev 6785) @@ -0,0 +1,19 @@ +import subprocess +import sys +import test_support +import unittest + +class AccessBuiltinCodecs(unittest.TestCase): + def test_print_sans_lib(self): + '''Encodes and decodes using utf-8 after in an environment without the standard library + + Checks that the builtin utf-8 codec is always available: http://bugs.jython.org/issue1458''' + subprocess.call([sys.executable, "-J-Dpython.cachedir.skip=true", + "-J-Dpython.security.respectJavaAccessibility=false", + test_support.findfile('print_sans_lib.py')]) + +def test_main(): + test_support.run_unittest(AccessBuiltinCodecs) + +if __name__ == "__main__": + test_main() Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-09-11 06:44:19 UTC (rev 6784) +++ trunk/jython/NEWS 2009-09-11 06:55:34 UTC (rev 6785) @@ -9,6 +9,7 @@ - [ 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') + - [ 1458 ] Builtin codecs aren't available without standard lib Jython 2.5.1rc1 New Features Modified: trunk/jython/src/org/python/core/codecs.java =================================================================== --- trunk/jython/src/org/python/core/codecs.java 2009-09-11 06:44:19 UTC (rev 6784) +++ trunk/jython/src/org/python/core/codecs.java 2009-09-11 06:55:34 UTC (rev 6785) @@ -9,6 +9,7 @@ import java.nio.ByteBuffer; import java.nio.charset.Charset; + import java.util.ArrayList; import java.util.Iterator; @@ -113,8 +114,7 @@ } } - public static PyObject decode(PyString v, String encoding, - String errors) { + public static PyObject decode(PyString v, String encoding, String errors) { if (encoding == null) { encoding = getDefaultEncoding(); } else { @@ -127,11 +127,27 @@ /* Shortcut for ascii encoding */ if (encoding.equals("ascii")) { - return new PyUnicode(PyUnicode_DecodeASCII(v.toString(), v.__len__(), errors), true); + return wrapDecodeResult(PyUnicode_DecodeASCII(v.toString(), v.__len__(), errors)); } /* Decode via the codec registry */ - PyObject decoder = lookup(encoding).__getitem__(1); + PyObject decoder; + try { + decoder = lookup(encoding).__getitem__(1); + } catch (PyException ex) { + if (ex.match(Py.LookupError)) { + // If we couldn't find an encoding, see if we have a builtin + if (encoding.equals("utf-8")) { + return wrapDecodeResult(PyUnicode_DecodeUTF8(v.toString(), errors)); + } else if(encoding.equals("utf-7")) { + return wrapDecodeResult(PyUnicode_DecodeUTF7(v.toString(), errors)); + } else if(encoding.equals("latin-1")) { + return wrapDecodeResult(PyUnicode_DecodeLatin1(v.toString(), v.__len__(), + errors)); + } + } + throw ex; + } PyObject result; if (errors != null) { result = decoder.__call__(v, new PyString(errors)); @@ -145,6 +161,10 @@ return result.__getitem__(0); } + private static PyUnicode wrapDecodeResult(String result) { + return new PyUnicode(result, true); + } + public static String encode(PyString v, String encoding, String errors) { if (encoding == null) { @@ -165,8 +185,21 @@ return PyUnicode_EncodeASCII(v.toString(), v.__len__(), errors); } - /* Decode via the codec registry */ - PyObject encoder = lookup(encoding).__getitem__(0); + /* Encode via the codec registry */ + PyObject encoder; + try { + encoder = lookup(encoding).__getitem__(0); + } catch (PyException ex) { + if (ex.match(Py.LookupError)) { + // If we couldn't find an encoding, see if we have a builtin + if (encoding.equals("utf-8")) { + return PyUnicode_EncodeUTF8(v.toString(), errors); + } else if(encoding.equals("utf-7")) { + return codecs.PyUnicode_EncodeUTF7(v.toString(), false, false, errors); + } + } + throw ex; + } PyObject result; if (errors != null) { result = encoder.__call__(v, new PyString(errors)); @@ -181,7 +214,7 @@ if (encoded instanceof PyString) { return encoded.toString(); } else { - throw Py.TypeError("decoder did not return a string/unicode object (type=" + throw Py.TypeError("encoder did not return a string/unicode object (type=" + encoded.getType().fastGetName() + ")"); } } @@ -415,8 +448,7 @@ // note that we follow CPython 2.5 exactly here - it does not support surrogates, // but has to process as-if they are there for replacement purposes // fortunately no one really cares about utf-7 - public static String PyUnicode_DecodeUTF7(String str, - String errors) { + public static String PyUnicode_DecodeUTF7(String str, String errors) { int s = 0; int e = str.length(); boolean inShift = false; @@ -551,9 +583,9 @@ } public static String PyUnicode_EncodeUTF7(String str, - boolean encodeSetO, - boolean encodeWhiteSpace, - String errors) { + boolean encodeSetO, + boolean encodeWhiteSpace, + String errors) { int size = str.length(); if (size == 0) { @@ -786,13 +818,11 @@ return v.toString(); } - public static String PyUnicode_DecodeASCII(String str, int size, - String errors) { + public static String PyUnicode_DecodeASCII(String str, int size, String errors) { return PyUnicode_DecodeIntLimited(str, size, errors, "ascii", 128); } - public static String PyUnicode_DecodeLatin1(String str, int size, - String errors) { + public static String PyUnicode_DecodeLatin1(String str, int size, String errors) { return PyUnicode_DecodeIntLimited(str, size, errors, "latin-1", 256); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-09-11 06:44:28
|
Revision: 6784 http://jython.svn.sourceforge.net/jython/?rev=6784&view=rev Author: zyasoft Date: 2009-09-11 06:44:19 +0000 (Fri, 11 Sep 2009) Log Message: ----------- Added with-statement support to zxJDBC: * PyConnection - commit if no exception, otherwise rollback * PyCursor - always close this resource Modified Paths: -------------- trunk/jython/src/com/ziclix/python/sql/PyConnection.java trunk/jython/src/com/ziclix/python/sql/PyCursor.java Modified: trunk/jython/src/com/ziclix/python/sql/PyConnection.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/PyConnection.java 2009-09-11 05:52:44 UTC (rev 6783) +++ trunk/jython/src/com/ziclix/python/sql/PyConnection.java 2009-09-11 06:44:19 UTC (rev 6784) @@ -17,6 +17,7 @@ import org.python.core.ClassDictInit; import org.python.core.Py; import org.python.core.PyBuiltinMethodSet; +import org.python.core.PyException; import org.python.core.PyInteger; import org.python.core.PyList; import org.python.core.PyObject; @@ -24,7 +25,10 @@ import org.python.core.PyUnicode; import com.ziclix.python.sql.util.PyArgParser; +import org.python.core.ContextManager; +import org.python.core.ThreadState; + /** * A connection to the database. * @@ -32,7 +36,7 @@ * @author last revised by $Author$ * @version $Revision$ */ -public class PyConnection extends PyObject implements ClassDictInit { +public class PyConnection extends PyObject implements ClassDictInit, ContextManager { /** True if closed. */ protected boolean closed; @@ -137,6 +141,8 @@ zxJDBC.getString("rollback"))); dict.__setitem__("nativesql", new ConnectionFunc("nativesql", 4, 1, 1, zxJDBC.getString("nativesql"))); + dict.__setitem__("__enter__", new ConnectionFunc("__enter__", 5, 0, 0, "__enter__")); + dict.__setitem__("__exit__", new ConnectionFunc("__exit__", 6, 3, 3, "__exit__")); // hide from python dict.__setitem__("initModule", null); @@ -421,6 +427,33 @@ } return this.statements.contains(statement); } + + public PyObject __enter__(ThreadState ts) { + return this; + } + + public PyObject __enter__() { + return this; + } + + public boolean __exit__(ThreadState ts, PyException exception) { + if (exception == null) { + commit(); + } else { + rollback(); + } + return false; + } + + public boolean __exit__(PyObject type, PyObject value, PyObject traceback) { + if (type == null || type == Py.None) { + commit(); + } else { + rollback(); + } + return false; + } + } class ConnectionFunc extends PyBuiltinMethodSet { @@ -444,6 +477,8 @@ case 3: c.rollback(); return Py.None; + case 5: + return c.__enter__(); default: throw info.unexpectedCall(0, false); } @@ -468,6 +503,8 @@ switch (index) { case 2: return c.cursor(arg1.__nonzero__(), arg2, arg3); + case 6: + return Py.newBoolean(c.__exit__(arg1, arg2, arg3)); default: throw info.unexpectedCall(3, false); } Modified: trunk/jython/src/com/ziclix/python/sql/PyCursor.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/PyCursor.java 2009-09-11 05:52:44 UTC (rev 6783) +++ trunk/jython/src/com/ziclix/python/sql/PyCursor.java 2009-09-11 06:44:19 UTC (rev 6784) @@ -26,7 +26,10 @@ import org.python.core.PyUnicode; import com.ziclix.python.sql.util.PyArgParser; +import org.python.core.ContextManager; +import org.python.core.ThreadState; + /** * These objects represent a database cursor, which is used to manage the * context of a fetch operation. @@ -35,7 +38,7 @@ * @author last revised by $Author$ * @version $Revision$ */ -public class PyCursor extends PyObject implements ClassDictInit, WarningListener { +public class PyCursor extends PyObject implements ClassDictInit, WarningListener, ContextManager { /** Field fetch */ protected Fetch fetch; @@ -260,6 +263,8 @@ dict.__setitem__("scroll", new CursorFunc("scroll", 10, 1, 2, "scroll the cursor in the result set to a new position according to mode")); dict.__setitem__("write", new CursorFunc("write", 11, 1, "execute the sql written to this file-like object")); dict.__setitem__("prepare", new CursorFunc("prepare", 12, 1, "prepare the sql statement for later execution")); + dict.__setitem__("__enter__", new CursorFunc("__enter__", 13, 0, 0, "__enter__")); + dict.__setitem__("__exit__", new CursorFunc("__exit__", 14, 3, 3, "__exit__")); // hide from python dict.__setitem__("classDictInit", null); @@ -884,6 +889,24 @@ throw zxJDBC.makeException(zxJDBC.ProgrammingError, "cursor is closed"); } } + + public PyObject __enter__(ThreadState ts) { + return this; + } + + public PyObject __enter__() { + return this; + } + + public boolean __exit__(ThreadState ts, PyException exception) { + close(); + return false; + } + + public boolean __exit__(PyObject type, PyObject value, PyObject traceback) { + close(); + return false; + } } class CursorFunc extends PyBuiltinMethodSet { @@ -911,6 +934,8 @@ return cursor.fetchone(); case 4 : return cursor.nextset(); + case 13 : + return cursor.__enter__(); default : throw info.unexpectedCall(0, false); } @@ -983,6 +1008,8 @@ case 9 : cursor.executemany(arga, argb, argc, Py.None); return Py.None; + case 14 : + return Py.newBoolean(cursor.__exit__(arga, argc, argc)); default : throw info.unexpectedCall(3, false); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-09-11 05:53:03
|
Revision: 6783 http://jython.svn.sourceforge.net/jython/?rev=6783&view=rev Author: pjenvey Date: 2009-09-11 05:52:44 +0000 (Fri, 11 Sep 2009) Log Message: ----------- cleanup Modified Paths: -------------- trunk/jython/Lib/test/test_seq_jy.py Modified: trunk/jython/Lib/test/test_seq_jy.py =================================================================== --- trunk/jython/Lib/test/test_seq_jy.py 2009-09-11 05:34:56 UTC (rev 6782) +++ trunk/jython/Lib/test/test_seq_jy.py 2009-09-11 05:52:44 UTC (rev 6783) @@ -28,11 +28,12 @@ self.assertFalse(eq_called) def test_seq_equality(self): + class Foo(object): + def __eq__(self, other): + return True + foo = [Foo()] for type2test in self.types2test: - class Foo(object): - def __eq__(self, other): - return True - self.assertTrue(type2test() in [Foo()]) + self.assertTrue(type2test() in foo) def test_seq_subclass_equality(self): # Various combinations of PyObject._eq, overriden Object.equals, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-09-11 05:35:02
|
Revision: 6782 http://jython.svn.sourceforge.net/jython/?rev=6782&view=rev Author: pjenvey Date: 2009-09-11 05:34:56 +0000 (Fri, 11 Sep 2009) Log Message: ----------- o fix PyTuple/List.equals not trying rich comparison (_eq) to all other PyObjects like PyObject.equals does o no need to synchronize all of PyList.equals Modified Paths: -------------- trunk/jython/Lib/test/test_seq_jy.py trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PyTuple.java Modified: trunk/jython/Lib/test/test_seq_jy.py =================================================================== --- trunk/jython/Lib/test/test_seq_jy.py 2009-09-11 05:22:00 UTC (rev 6781) +++ trunk/jython/Lib/test/test_seq_jy.py 2009-09-11 05:34:56 UTC (rev 6782) @@ -27,6 +27,13 @@ self.assertTrue(foo in seq1) self.assertFalse(eq_called) + def test_seq_equality(self): + for type2test in self.types2test: + class Foo(object): + def __eq__(self, other): + return True + self.assertTrue(type2test() in [Foo()]) + def test_seq_subclass_equality(self): # Various combinations of PyObject._eq, overriden Object.equals, # and cmp implementations Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2009-09-11 05:22:00 UTC (rev 6781) +++ trunk/jython/src/org/python/core/PyList.java 2009-09-11 05:34:56 UTC (rev 6782) @@ -953,16 +953,21 @@ } @Override - public synchronized boolean equals(Object other) { + public boolean equals(Object other) { if (this == other) { return true; } - if (other instanceof PyList) { - return _eq((PyList)other).__nonzero__(); - } else if (other instanceof List && !(other instanceof PyTuple)) { - List otherList = (List)other; - return list.equals(otherList); + + if (other instanceof PyObject) { + synchronized (this) { + return _eq((PyObject)other).__nonzero__(); + } } + if (other instanceof List) { + synchronized (this) { + return list.equals(other); + } + } return false; } Modified: trunk/jython/src/org/python/core/PyTuple.java =================================================================== --- trunk/jython/src/org/python/core/PyTuple.java 2009-09-11 05:22:00 UTC (rev 6781) +++ trunk/jython/src/org/python/core/PyTuple.java 2009-09-11 05:34:56 UTC (rev 6782) @@ -476,9 +476,11 @@ if (this == other) { return true; } - if (other instanceof PyTuple) { - return _eq((PyTuple)other).__nonzero__(); - } else if (other instanceof List && !(other instanceof PyList)) { + + if (other instanceof PyObject) { + return _eq((PyObject)other).__nonzero__(); + } + if (other instanceof List) { return other.equals(this); } return false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-09-11 05:22:08
|
Revision: 6781 http://jython.svn.sourceforge.net/jython/?rev=6781&view=rev Author: cgroves Date: 2009-09-11 05:22:00 +0000 (Fri, 11 Sep 2009) Log Message: ----------- Widening, standards Modified Paths: -------------- trunk/jython/src/org/python/core/codecs.java Modified: trunk/jython/src/org/python/core/codecs.java =================================================================== --- trunk/jython/src/org/python/core/codecs.java 2009-09-11 03:35:35 UTC (rev 6780) +++ trunk/jython/src/org/python/core/codecs.java 2009-09-11 05:22:00 UTC (rev 6781) @@ -71,42 +71,34 @@ public static PyTuple lookup(String encoding) { registry_init(); PyString v = new PyString(normalizestring(encoding)); - PyObject result = searchCache.__finditem__(v); - if (result != null) { - return (PyTuple) result; + PyObject cached = searchCache.__finditem__(v); + if (cached != null) { + return (PyTuple)cached; } if (searchPath.__len__() == 0) { throw new PyException(Py.LookupError, - "no codec search functions registered: " + - "can't find encoding '" + encoding + "'"); + "no codec search functions registered: can't find encoding '" + encoding + "'"); } - PyObject iter = searchPath.__iter__(); - PyObject func = null; - while ((func = iter.__iternext__()) != null) { - result = func.__call__(v); - if (result == Py.None) { + for (PyObject func : searchPath.asIterable()) { + PyObject created = func.__call__(v); + if (created == Py.None) { continue; } - if (!(result instanceof PyTuple) || result.__len__() != 4) { - throw Py.TypeError("codec search functions must " + - "return 4-tuples"); + if (!(created instanceof PyTuple) || created.__len__() != 4) { + throw Py.TypeError("codec search functions must return 4-tuples"); } - break; + searchCache.__setitem__(v, created); + return (PyTuple)created; } - if (func == null) { - throw new PyException(Py.LookupError, "unknown encoding '" + - encoding + "'"); - } - searchCache.__setitem__(v, result); - return (PyTuple) result; + throw new PyException(Py.LookupError, "unknown encoding '" + encoding + "'"); } private static String normalizestring(String string) { return string.toLowerCase().replace(' ', '-'); } - private static boolean import_encodings_called = false; + private static boolean import_encodings_called; private static void import_encodings() { if (!import_encodings_called) { @@ -135,14 +127,12 @@ /* Shortcut for ascii encoding */ if (encoding.equals("ascii")) { - return new PyUnicode( - PyUnicode_DecodeASCII(v.toString(), v.__len__(), errors), - true); + return new PyUnicode(PyUnicode_DecodeASCII(v.toString(), v.__len__(), errors), true); } /* Decode via the codec registry */ - PyObject decoder = getDecoder(encoding); - PyObject result = null; + PyObject decoder = lookup(encoding).__getitem__(1); + PyObject result; if (errors != null) { result = decoder.__call__(v, new PyString(errors)); } else { @@ -150,17 +140,11 @@ } if (!(result instanceof PyTuple) || result.__len__() != 2) { - throw Py.TypeError("decoder must return a tuple " + - "(object,integer)"); + throw Py.TypeError("decoder must return a tuple (object,integer)"); } return result.__getitem__(0); } - private static PyObject getDecoder(String encoding) { - PyObject codecs = lookup(encoding); - return codecs.__getitem__(1); - } - public static String encode(PyString v, String encoding, String errors) { if (encoding == null) { @@ -174,18 +158,16 @@ } /* Shortcuts for common default encodings. latin-1 must not use the - * lookup registry for the encodigs module to work correctly */ + * lookup registry for the encodings module to work correctly */ if (encoding.equals("latin-1")) { return PyUnicode_EncodeLatin1(v.toString(), v.__len__(), errors); - } else if (encoding.equals("ascii")) { - return PyUnicode_EncodeASCII(v.toString(), - v.__len__(), errors); + return PyUnicode_EncodeASCII(v.toString(), v.__len__(), errors); } /* Decode via the codec registry */ - PyObject encoder = getEncoder(encoding); - PyObject result = null; + PyObject encoder = lookup(encoding).__getitem__(0); + PyObject result; if (errors != null) { result = encoder.__call__(v, new PyString(errors)); } else { @@ -193,23 +175,17 @@ } if (!(result instanceof PyTuple) || result.__len__() != 2) { - throw Py.TypeError("encoder must return a tuple " + - "(object,integer)"); + throw Py.TypeError("encoder must return a tuple (object,integer)"); } PyObject encoded = result.__getitem__(0); if (encoded instanceof PyString) { return encoded.toString(); } else { - throw Py.TypeError("decoder did not return a string/unicode object (type=" + - encoded.getType().fastGetName() + ")"); + throw Py.TypeError("decoder did not return a string/unicode object (type=" + + encoded.getType().fastGetName() + ")"); } } - private static PyObject getEncoder(String encoding) { - PyObject codecs = lookup(encoding); - return codecs.__getitem__(0); - } - public static PyObject strict_errors(PyObject[] args, String[] kws) { ArgParser ap = new ArgParser("strict_errors", args, kws, "exc"); PyObject exc = ap.getPyObject(0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-09-11 03:35:56
|
Revision: 6780 http://jython.svn.sourceforge.net/jython/?rev=6780&view=rev Author: pjenvey Date: 2009-09-11 03:35:35 +0000 (Fri, 11 Sep 2009) Log Message: ----------- support multiple ResultSets via cursor.nextset. to accommodate this staticFetch Statements are no longer immediately closed after execute (unless an exception was thrown), like dynamicFetch Modified Paths: -------------- trunk/jython/src/com/ziclix/python/sql/PyConnection.java trunk/jython/src/com/ziclix/python/sql/PyCursor.java Modified: trunk/jython/src/com/ziclix/python/sql/PyConnection.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/PyConnection.java 2009-09-09 17:59:05 UTC (rev 6779) +++ trunk/jython/src/com/ziclix/python/sql/PyConnection.java 2009-09-11 03:35:35 UTC (rev 6780) @@ -40,6 +40,9 @@ /** Whether transactions are supported. */ protected boolean supportsTransactions; + /** Whether multiple ResultSets are supported. */ + protected boolean supportsMultipleResultSets; + /** The underlying java.sql.Connection. */ protected Connection connection; @@ -90,6 +93,8 @@ this.connection = connection; this.statements = new HashSet<PyStatement>(); this.supportsTransactions = this.connection.getMetaData().supportsTransactions(); + this.supportsMultipleResultSets = + this.connection.getMetaData().supportsMultipleResultSets(); if (this.supportsTransactions) { this.connection.setAutoCommit(false); Modified: trunk/jython/src/com/ziclix/python/sql/PyCursor.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/PyCursor.java 2009-09-09 17:59:05 UTC (rev 6779) +++ trunk/jython/src/com/ziclix/python/sql/PyCursor.java 2009-09-11 03:35:35 UTC (rev 6780) @@ -482,15 +482,11 @@ throw zxJDBC.makeException(zxJDBC.NotSupportedError, zxJDBC.getString("noStoredProc")); } - } catch (PyException e) { - throw e; - } catch (Throwable e) { - throw zxJDBC.makeException(e); - } finally { - if (this.statement != null) { - // close what we opened - this.statement.close(); + } catch (Throwable t) { + if (statement != null) { + statement.close(); } + throw zxJDBC.makeException(t); } } @@ -584,17 +580,12 @@ this.execute(Py.None, Py.None); } } - } catch (PyException e) { - throw e; - } catch (Throwable e) { - throw zxJDBC.makeException(zxJDBC.Error, e, rowIndex); - } finally { - if (this.statement != null) { + } catch (Throwable t) { + if (statement != null && !(sql instanceof PyStatement)) { // only close static, single-use statements - if (!(sql instanceof PyStatement) && !this.dynamicFetch) { - this.statement.close(); - } + statement.close(); } + throw zxJDBC.makeException(zxJDBC.Error, t, rowIndex); } } @@ -605,18 +596,12 @@ protected void execute(PyObject params, PyObject bindings) { try { Statement stmt = this.statement.statement; - this.datahandler.preExecute(stmt); // this performs the SQL execution and fetch per the Statement type this.statement.execute(this, params, bindings); - this.lastrowid = this.datahandler.getRowId(stmt); - - int uc = stmt.getUpdateCount(); - - this.updatecount = uc < 0 ? Py.None : Py.newInteger(uc); - + this.updateAttributes(stmt.getUpdateCount()); warning(new WarningEvent(this, stmt.getWarnings())); this.datahandler.postExecute(stmt); } catch (PyException e) { @@ -627,6 +612,17 @@ } /** + * Update the cursor's lastrowid and updatecount. + * + * @param updateCount The int value of updatecount + * @throws SQLException + */ + private void updateAttributes(int updateCount) throws SQLException { + lastrowid = datahandler.getRowId(statement.statement); + updatecount = updateCount < 0 ? Py.None : Py.newInteger(updateCount); + } + + /** * Fetch the next row of a query result set, returning a single sequence, * or None when no more data is available. * @@ -691,7 +687,28 @@ */ public PyObject nextset() { ensureOpen(); - return this.fetch.nextset(); + PyObject nextset = fetch.nextset(); + + // If the fetch is exhausted and multiple ResultSets are supported, try addding a + // next ResultSet. XXX: DynamicFetch currently isn't so tailored for this + if (!nextset.__nonzero__() && connection.supportsMultipleResultSets && !dynamicFetch) { + Statement stmt = statement.statement; + try { + boolean hasMoreResults; + int updateCount = -1; + if ((hasMoreResults = stmt.getMoreResults()) + || (updateCount = stmt.getUpdateCount()) != -1) { + // Only call getUpdateCount once, per its docs + updateAttributes(!hasMoreResults ? updateCount : stmt.getUpdateCount()); + fetch.add(stmt.getResultSet()); + nextset = Py.One; + } + } catch (SQLException sqle) { + throw zxJDBC.makeException(sqle); + } + } + + return nextset; } /** @@ -784,12 +801,9 @@ } if (this.statement != null) { - // we can't close a dynamic fetch statement until everything has been - // consumed so the only time we can clean up is now - // but if this is a previously prepared statement we don't want to close - // it underneath someone; we can check this by looking in the set + // Finally done with the Statement: only close it if we created it try { - if (this.dynamicFetch && !this.connection.contains(this.statement)) { + if (!this.connection.contains(this.statement)) { this.statement.close(); } } finally { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-09 17:59:13
|
Revision: 6779 http://jython.svn.sourceforge.net/jython/?rev=6779&view=rev Author: fwierzbicki Date: 2009-09-09 17:59:05 +0000 (Wed, 09 Sep 2009) Log Message: ----------- Also test the toArray() bugs fixed by Andrea's patch applied by Tobias. Modified Paths: -------------- trunk/jython/tests/java/org/python/core/PyListTest.java trunk/jython/tests/java/org/python/core/PyTupleTest.java Modified: trunk/jython/tests/java/org/python/core/PyListTest.java =================================================================== --- trunk/jython/tests/java/org/python/core/PyListTest.java 2009-09-09 17:47:39 UTC (rev 6778) +++ trunk/jython/tests/java/org/python/core/PyListTest.java 2009-09-09 17:59:05 UTC (rev 6779) @@ -7,21 +7,34 @@ */ public class PyListTest extends TestCase { + private PyList p = null; + @Override protected void setUp() throws Exception { + p = new PyList(); + p.add("foo"); + p.add("bar"); } @Override protected void tearDown() throws Exception { + p = null; } // Test for http://bugs.jython.org/issue1419 // "Bug in PyTuple.indexOf and PyList.indexOf" public void testIndexOf() { - PyList p = new PyList(); - p.add("foo"); - p.add("bar"); assertEquals(0, p.indexOf("foo")); assertEquals(1, p.indexOf("bar")); } + + public void testToArray() { + // In Jython 2.5.0 if an array was passed into toArray() that was + // too short, an Object[] was always returned instead of an array + // of the proper type. + Object[] test = new String[1]; + String[] s = (String[])p.toArray(test); + assertEquals(s[0], "foo"); + assertEquals(s[1], "bar"); + } } Modified: trunk/jython/tests/java/org/python/core/PyTupleTest.java =================================================================== --- trunk/jython/tests/java/org/python/core/PyTupleTest.java 2009-09-09 17:47:39 UTC (rev 6778) +++ trunk/jython/tests/java/org/python/core/PyTupleTest.java 2009-09-09 17:59:05 UTC (rev 6779) @@ -7,12 +7,16 @@ */ public class PyTupleTest extends TestCase { + private PyTuple p = null; + @Override protected void setUp() throws Exception { + p = new PyTuple(new PyString("foo"), new PyString("bar")); } @Override protected void tearDown() throws Exception { + p = null; } // Test for http://bugs.jython.org/issue1419 @@ -22,5 +26,14 @@ assertEquals(0, p.indexOf("foo")); assertEquals(1, p.indexOf("bar")); } - + + public void testToArray() { + // In Jython 2.5.0 if an array was passed into toArray() that was + // too short, an Object[] was always returned instead of an array + // of the proper type. + Object[] test = new String[1]; + String[] s = (String[])p.toArray(test); + assertEquals(s[0], "foo"); + assertEquals(s[1], "bar"); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-09 17:47:47
|
Revision: 6778 http://jython.svn.sourceforge.net/jython/?rev=6778&view=rev Author: fwierzbicki Date: 2009-09-09 17:47:39 +0000 (Wed, 09 Sep 2009) Log Message: ----------- Give tests non-stupid names. Modified Paths: -------------- trunk/jython/tests/java/org/python/core/PyListTest.java trunk/jython/tests/java/org/python/core/PyTupleTest.java Modified: trunk/jython/tests/java/org/python/core/PyListTest.java =================================================================== --- trunk/jython/tests/java/org/python/core/PyListTest.java 2009-09-09 17:35:38 UTC (rev 6777) +++ trunk/jython/tests/java/org/python/core/PyListTest.java 2009-09-09 17:47:39 UTC (rev 6778) @@ -17,7 +17,7 @@ // Test for http://bugs.jython.org/issue1419 // "Bug in PyTuple.indexOf and PyList.indexOf" - public void testFoo() { + public void testIndexOf() { PyList p = new PyList(); p.add("foo"); p.add("bar"); Modified: trunk/jython/tests/java/org/python/core/PyTupleTest.java =================================================================== --- trunk/jython/tests/java/org/python/core/PyTupleTest.java 2009-09-09 17:35:38 UTC (rev 6777) +++ trunk/jython/tests/java/org/python/core/PyTupleTest.java 2009-09-09 17:47:39 UTC (rev 6778) @@ -17,9 +17,10 @@ // Test for http://bugs.jython.org/issue1419 // "Bug in PyTuple.indexOf and PyTuple.indexOf" - public void testFoo() { + public void testIndexOf() { PyTuple p = new PyTuple(new PyString("foo"), new PyString("bar")); assertEquals(0, p.indexOf("foo")); assertEquals(1, p.indexOf("bar")); } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-09 17:35:47
|
Revision: 6777 http://jython.svn.sourceforge.net/jython/?rev=6777&view=rev Author: fwierzbicki Date: 2009-09-09 17:35:38 +0000 (Wed, 09 Sep 2009) Log Message: ----------- Test PyTuple for http://bugs.jython.org/issue1419 "Bug in PyTuple.indexOf and PyList.indexOf". Added Paths: ----------- trunk/jython/tests/java/org/python/core/PyTupleTest.java Added: trunk/jython/tests/java/org/python/core/PyTupleTest.java =================================================================== --- trunk/jython/tests/java/org/python/core/PyTupleTest.java (rev 0) +++ trunk/jython/tests/java/org/python/core/PyTupleTest.java 2009-09-09 17:35:38 UTC (rev 6777) @@ -0,0 +1,25 @@ +package org.python.core; + +import junit.framework.TestCase; + +/** + * Tests for PyTuple as Java Tuple. + */ +public class PyTupleTest extends TestCase { + + @Override + protected void setUp() throws Exception { + } + + @Override + protected void tearDown() throws Exception { + } + + // Test for http://bugs.jython.org/issue1419 + // "Bug in PyTuple.indexOf and PyTuple.indexOf" + public void testFoo() { + PyTuple p = new PyTuple(new PyString("foo"), new PyString("bar")); + assertEquals(0, p.indexOf("foo")); + assertEquals(1, p.indexOf("bar")); + } +} Property changes on: trunk/jython/tests/java/org/python/core/PyTupleTest.java ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-09 17:28:42
|
Revision: 6776 http://jython.svn.sourceforge.net/jython/?rev=6776&view=rev Author: fwierzbicki Date: 2009-09-09 17:28:32 +0000 (Wed, 09 Sep 2009) Log Message: ----------- Add PyList testing for http://bugs.jython.org/issue1419, but it will also be a good place for testing the Java List interface of PyList in the future. Added Paths: ----------- trunk/jython/tests/java/org/python/core/PyListTest.java Added: trunk/jython/tests/java/org/python/core/PyListTest.java =================================================================== --- trunk/jython/tests/java/org/python/core/PyListTest.java (rev 0) +++ trunk/jython/tests/java/org/python/core/PyListTest.java 2009-09-09 17:28:32 UTC (rev 6776) @@ -0,0 +1,27 @@ +package org.python.core; + +import junit.framework.TestCase; + +/** + * Tests for PyList as Java List. + */ +public class PyListTest extends TestCase { + + @Override + protected void setUp() throws Exception { + } + + @Override + protected void tearDown() throws Exception { + } + + // Test for http://bugs.jython.org/issue1419 + // "Bug in PyTuple.indexOf and PyList.indexOf" + public void testFoo() { + PyList p = new PyList(); + p.add("foo"); + p.add("bar"); + assertEquals(0, p.indexOf("foo")); + assertEquals(1, p.indexOf("bar")); + } +} Property changes on: trunk/jython/tests/java/org/python/core/PyListTest.java ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-09-09 16:59:28
|
Revision: 6775 http://jython.svn.sourceforge.net/jython/?rev=6775&view=rev Author: fwierzbicki Date: 2009-09-09 16:59:20 +0000 (Wed, 09 Sep 2009) Log Message: ----------- Cleanup. 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 12:11:47 UTC (rev 6774) +++ trunk/jython/src/org/python/antlr/PythonTree.java 2009-09-09 16:59:20 UTC (rev 6775) @@ -16,22 +16,10 @@ private int charStartIndex = -1; private int charStopIndex = -1; private CommonTree node; - private PythonTree parent; - - /** 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; - /** 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; - + private PythonTree parent; + public PythonTree() { node = new CommonTree(); } @@ -291,8 +279,6 @@ * 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) } @@ -329,7 +315,6 @@ 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 */ @@ -371,11 +356,6 @@ * 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"); } @@ -428,7 +408,6 @@ } freshenParentAndChildIndexes(startChildIndex); } - //System.out.println("out="+toStringTree()); } /** Override in a subclass to change the impl of children list */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |