From: <zy...@us...> - 2009-02-07 06:29:41
|
Revision: 6019 http://jython.svn.sourceforge.net/jython/?rev=6019&view=rev Author: zyasoft Date: 2009-02-07 06:29:37 +0000 (Sat, 07 Feb 2009) Log Message: ----------- Fixed IMPORT_STAR for nested modules. sys.exc_info now returns Py.None for the traceback (this fixes an issue in PBC where null is being used as both a sentinel value by __getitem__ AND an actual value for exception handling). Modified Paths: -------------- branches/pbcvm/src/org/python/core/PyBytecode.java branches/pbcvm/src/org/python/core/PySystemState.java branches/pbcvm/src/org/python/core/imp.java Modified: branches/pbcvm/src/org/python/core/PyBytecode.java =================================================================== --- branches/pbcvm/src/org/python/core/PyBytecode.java 2009-02-07 04:04:54 UTC (rev 6018) +++ branches/pbcvm/src/org/python/core/PyBytecode.java 2009-02-07 06:29:37 UTC (rev 6019) @@ -9,7 +9,7 @@ // for debugging private int count = 0; // total number of opcodes run - private int maxCount = 10000; // less than my buffer on iterm + private int maxCount = -1; // less than my buffer on iterm private static PyObject opname; public static boolean defaultDebug = false; @@ -263,7 +263,7 @@ f.f_savedlocals = null; } - while (!debug || (count < maxCount)) { // XXX - replace with while(true) + while (!debug || (maxCount == -1 || count < maxCount)) { // XXX - replace with while(true) try { @@ -870,7 +870,7 @@ } case Opcode.IMPORT_STAR: { - String module = stack.pop().toString(); + PyObject module = stack.pop(); imp.importAll(module, f); break; } @@ -1109,9 +1109,11 @@ if (b.b_type == Opcode.SETUP_EXCEPT) { exc.normalize(); } - stack.push(new PyStackException(exc)); - stack.dup(); // x3 to conform with CPython's calling convention, which - stack.dup(); // stores the type, val, tb separately on the stack + stack.push(exc.traceback); + stack.push(exc.value); + stack.push(new PyStackException(exc)); // instead of stack.push(exc.type);, like CPython +// stack.dup(); // x3 to conform with CPython's calling convention, which +// stack.dup(); // stores the type, val, tb separately on the stack } else { if (why == Why.RETURN || why == Why.CONTINUE) { stack.push(retval); Modified: branches/pbcvm/src/org/python/core/PySystemState.java =================================================================== --- branches/pbcvm/src/org/python/core/PySystemState.java 2009-02-07 04:04:54 UTC (rev 6018) +++ branches/pbcvm/src/org/python/core/PySystemState.java 2009-02-07 06:29:37 UTC (rev 6019) @@ -1027,7 +1027,8 @@ PyException exc = Py.getThreadState().exception; if(exc == null) return new PyTuple(Py.None, Py.None, Py.None); - return new PyTuple(exc.type, exc.value, exc.traceback); + PyObject tb = exc.traceback; + return new PyTuple(exc.type, exc.value, tb == null ? Py.None : tb); } public static void exc_clear() { Modified: branches/pbcvm/src/org/python/core/imp.java =================================================================== --- branches/pbcvm/src/org/python/core/imp.java 2009-02-07 04:04:54 UTC (rev 6018) +++ branches/pbcvm/src/org/python/core/imp.java 2009-02-07 06:29:37 UTC (rev 6019) @@ -827,22 +827,15 @@ return submods; } - private static PyTuple all = null; + private final static PyTuple all = new PyTuple(Py.newString('*')); - private synchronized static PyTuple getStarArg() { - if (all == null) { - all = new PyTuple(Py.newString('*')); - } - return all; - } - /** * Called from jython generated code when a statement like "from spam.eggs * import *" is executed. */ public static void importAll(String mod, PyFrame frame) { PyObject module = __builtin__.__import__(mod, frame.f_globals, frame - .getLocals(), getStarArg()); + .getLocals(), all); PyObject names; boolean filter = true; if (module instanceof PyJavaPackage) { @@ -860,6 +853,27 @@ loadNames(names, module, frame.getLocals(), filter); } + public static void importAll(PyObject module, PyFrame frame) { + PyObject names; + boolean filter = true; + if (module instanceof PyJavaPackage) { + names = ((PyJavaPackage) module).fillDir(); + } else { + PyObject __all__ = module.__findattr__("__all__"); + if (__all__ != null) { + names = __all__; + filter = false; + } else { + names = module.__dir__(); + } + } + + loadNames(names, module, frame.getLocals(), filter); + } + + + + /** * From a module, load the attributes found in <code>names</code> into * locals. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |