From: <cg...@us...> - 2007-03-09 17:26:21
|
Revision: 3138 http://svn.sourceforge.net/jython/?rev=3138&view=rev Author: cgroves Date: 2007-03-09 09:26:17 -0800 (Fri, 09 Mar 2007) Log Message: ----------- patch #1634405 from leouser to fix bug #1605847. Makes co_filename set in PyFrames from bytecode match the actual loaded location. Modified Paths: -------------- trunk/jython/src/org/python/compiler/Module.java trunk/jython/src/org/python/core/BytecodeLoader.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/imp.java Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2007-03-09 17:24:51 UTC (rev 3137) +++ trunk/jython/src/org/python/compiler/Module.java 2007-03-09 17:26:17 UTC (rev 3138) @@ -252,7 +252,7 @@ CodeCompiler.makeStrings(c, null, 0); } - c.ldc(((PyStringConstant)module.filename).value); + c.aload(1); c.ldc(co_name); c.iconst(co_firstlineno); @@ -538,12 +538,12 @@ //This block of code writes out the various standard methods public void addInit() throws IOException { - Code c = classfile.addMethod("<init>", "()V", ClassFile.PUBLIC); + Code c = classfile.addMethod("<init>", "(Ljava/lang/String;)V", ClassFile.PUBLIC); c.aload(0); c.invokespecial(c.pool.Methodref("org/python/core/PyFunctionTable", "<init>", "()V")); - c.return_(); + addConstants(c); } public void addRunnable() throws IOException { @@ -571,14 +571,10 @@ c.return_(); } - public void addConstants() throws IOException { - Code c = classfile.addMethod("<clinit>", "()V", ClassFile.STATIC); - + public void addConstants(Code c) throws IOException { classfile.addField("self", "L"+classfile.name+";", ClassFile.STATIC|ClassFile.FINAL); - c.new_(c.pool.Class(classfile.name)); - c.dup(); - c.invokespecial(c.pool.Methodref(classfile.name, "<init>", "()V")); + c.aload(0); c.putstatic(c.pool.Fieldref(classfile.name, "self", "L"+classfile.name+";")); @@ -638,7 +634,6 @@ addRunnable(); //addMain(); - addConstants(); addFunctions(); classfile.addInterface("org/python/core/PyRunnable"); Modified: trunk/jython/src/org/python/core/BytecodeLoader.java =================================================================== --- trunk/jython/src/org/python/core/BytecodeLoader.java 2007-03-09 17:24:51 UTC (rev 3137) +++ trunk/jython/src/org/python/core/BytecodeLoader.java 2007-03-09 17:26:17 UTC (rev 3138) @@ -95,11 +95,13 @@ * @param name the name of the class * @param data the java byte code. */ - public static PyCode makeCode(String name, byte[] data) { + public static PyCode makeCode(String name, byte[] data, String filename) { try { Class c = makeClass(name, null, data); - return ((PyRunnable) c.newInstance()).getMain(); - } catch (Exception e) { + Object o = c.getConstructor(new Class[] {String.class}) + .newInstance(new Object[] {filename}); + return ((PyRunnable)o).getMain(); + } catch(Exception e) { throw Py.JavaError(e); } } Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2007-03-09 17:24:51 UTC (rev 3137) +++ trunk/jython/src/org/python/core/Py.java 2007-03-09 17:26:17 UTC (rev 3138) @@ -1657,7 +1657,7 @@ saveClassFile(name, ostream); - return BytecodeLoader.makeCode(name, ostream.toByteArray()); + return BytecodeLoader.makeCode(name, ostream.toByteArray(), filename); } catch (Throwable t) { throw parser.fixParseError(null, t, filename); } Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2007-03-09 17:24:51 UTC (rev 3137) +++ trunk/jython/src/org/python/core/imp.java 2007-03-09 17:26:17 UTC (rev 3138) @@ -94,7 +94,7 @@ } PyCode code; try { - code = BytecodeLoader.makeCode(name + "$py", data); + code = BytecodeLoader.makeCode(name + "$py", data, fileName); } catch (Throwable t) { if (testing) { return null; @@ -206,7 +206,7 @@ Py.writeComment(IMPORT_LOG, "'" + name + "' as " + filename); - PyCode code = BytecodeLoader.makeCode(name + "$py", bytes); + PyCode code = BytecodeLoader.makeCode(name + "$py", bytes, filename); return createFromCode(name, code, filename); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |