From: <zy...@us...> - 2009-02-14 09:24:01
|
Revision: 6026 http://jython.svn.sourceforge.net/jython/?rev=6026&view=rev Author: zyasoft Date: 2009-02-14 09:23:58 +0000 (Sat, 14 Feb 2009) Log Message: ----------- Now interns names in co_names, etc., when unmarshalling, which fixes equality tests on special case like __class__, __dict__, etc. Fix instanceof test in eval and exec so that it looks at PyBaseCode, not PyTableCode. Also, exec cannot be called with Py.None instead of null. Fixes test_scope. Modified Paths: -------------- branches/pbcvm/src/org/python/core/Py.java branches/pbcvm/src/org/python/core/PyBaseCode.java branches/pbcvm/src/org/python/core/PyBytecode.java branches/pbcvm/src/org/python/core/__builtin__.java branches/pbcvm/src/org/python/modules/_marshal.java Modified: branches/pbcvm/src/org/python/core/Py.java =================================================================== --- branches/pbcvm/src/org/python/core/Py.java 2009-02-12 04:38:04 UTC (rev 6025) +++ branches/pbcvm/src/org/python/core/Py.java 2009-02-14 09:23:58 UTC (rev 6026) @@ -1211,14 +1211,14 @@ int flags = 0; if (o instanceof PyCode) { code = (PyCode) o; - if (locals == null && o instanceof PyTableCode && ((PyTableCode) o).hasFreevars()) { + if (locals == null && o instanceof PyBaseCode && ((PyBaseCode) o).hasFreevars()) { throw Py.TypeError("code object passed to exec may not contain free variables"); } } else { String contents = null; if (o instanceof PyString) { if (o instanceof PyUnicode) { - flags |= PyTableCode.PyCF_SOURCE_IS_UTF8; + flags |= PyBaseCode.PyCF_SOURCE_IS_UTF8; } contents = o.toString(); } else if (o instanceof PyFile) { Modified: branches/pbcvm/src/org/python/core/PyBaseCode.java =================================================================== --- branches/pbcvm/src/org/python/core/PyBaseCode.java 2009-02-12 04:38:04 UTC (rev 6025) +++ branches/pbcvm/src/org/python/core/PyBaseCode.java 2009-02-14 09:23:58 UTC (rev 6026) @@ -18,7 +18,7 @@ public boolean varargs, varkwargs; final public static int CO_OPTIMIZED = 0x0001; - //final public static int CO_NEWLOCALS = 0x0002 + final public static int CO_NEWLOCALS = 0x0002; final public static int CO_VARARGS = 0x0004; final public static int CO_VARKEYWORDS = 0x0008; final public static int CO_GENERATOR = 0x0020; Modified: branches/pbcvm/src/org/python/core/PyBytecode.java =================================================================== --- branches/pbcvm/src/org/python/core/PyBytecode.java 2009-02-12 04:38:04 UTC (rev 6025) +++ branches/pbcvm/src/org/python/core/PyBytecode.java 2009-02-14 09:23:58 UTC (rev 6026) @@ -44,7 +44,7 @@ public final PyObject[] co_consts; public final String[] co_names; public final int co_stacksize; // XXX - use to convert PyStack to use PyObject[] instead of ArrayList<PyObject> - public final String co_lnotab; // ignored for now + public final String co_lnotab; private final static int CALL_FLAG_VAR = 1; private final static int CALL_FLAG_KW = 2; @@ -686,7 +686,7 @@ PyObject locals = stack.pop(); PyObject globals = stack.pop(); PyObject code = stack.pop(); - Py.exec(code, globals, locals); + Py.exec(code, globals==Py.None ? null : globals, locals==Py.None ? null : locals); break; } @@ -711,10 +711,6 @@ why = Why.RERAISE; } else if (v instanceof PyString) { - if (debug) { - System.err.println("ts.exception=" + ts.exception + ", v=" + v); -// ts.exception = new PyException(v); // XXX - what do I do about string exceptions??!!! - } why = Why.RERAISE; } else if (v != Py.None) { throw Py.SystemError("'finally' pops bad exception"); @@ -794,8 +790,9 @@ } else { name = co_cellvars[oparg]; } -// System.err.println("Loading closure: " + name); - // XXX - consider some efficient lookup mechanism, like a hash + // XXX - consider some efficient lookup mechanism, like a hash :), + // at least if co_varnames is much greater than say a certain + // size (but i would think, it's not going to happen in real code. profile?) if (f.f_fastlocals != null) { int i = 0; boolean matched = false; Modified: branches/pbcvm/src/org/python/core/__builtin__.java =================================================================== --- branches/pbcvm/src/org/python/core/__builtin__.java 2009-02-12 04:38:04 UTC (rev 6025) +++ branches/pbcvm/src/org/python/core/__builtin__.java 2009-02-14 09:23:58 UTC (rev 6026) @@ -506,7 +506,7 @@ } public static PyObject eval(PyObject o) { - if (o instanceof PyTableCode && ((PyTableCode) o).hasFreevars()) { + if (o instanceof PyBaseCode && ((PyBaseCode) o).hasFreevars()) { throw Py.TypeError("code object passed to eval() may not contain free variables"); } return eval(o, null, null); Modified: branches/pbcvm/src/org/python/modules/_marshal.java =================================================================== --- branches/pbcvm/src/org/python/modules/_marshal.java 2009-02-12 04:38:04 UTC (rev 6025) +++ branches/pbcvm/src/org/python/modules/_marshal.java 2009-02-14 09:23:58 UTC (rev 6026) @@ -235,7 +235,7 @@ write_strings(code.co_cellvars, depth + 1); write_object(Py.newString(code.co_name), depth + 1); write_int(code.co_firstlineno); - write_object(new PyTuple(code.co_lnotab), depth + 1); + write_object(Py.newString(new String(code.co_lnotab)), depth + 1); } else { write_byte(TYPE_UNKNOWN); } @@ -353,7 +353,7 @@ String some_strings[] = new String[t.__len__()]; int i = 0; for (PyObject item : t.asIterable()) { - some_strings[i++] = item.toString(); + some_strings[i++] = item.toString().intern(); } return some_strings; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |