From: <th...@us...> - 2008-09-24 22:12:32
|
Revision: 5346 http://jython.svn.sourceforge.net/jython/?rev=5346&view=rev Author: thobes Date: 2008-09-24 22:12:23 +0000 (Wed, 24 Sep 2008) Log Message: ----------- Fixed the bug of the __exit__ method not being invoked on the outer context manager in the case of nested with statements. The problem was that the exception handlers were not properly sorted. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-09-24 21:05:39 UTC (rev 5345) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-09-24 22:12:23 UTC (rev 5346) @@ -2090,7 +2090,7 @@ // mgr = (EXPR) visit(node.context_expr); - int mgr_tmp = code.getLocal("org/python/core/PyObject"); + int mgr_tmp = code.getLocal("org/python/core/PyObject"); code.astore(mgr_tmp); // exit = mgr.__exit__ # Not calling it yet, so storing in the frame @@ -2113,7 +2113,10 @@ // exc = True # not necessary, since we don't exec finally if exception // try-catch block here - code.trycatch(label_body_start, label_body_end, label_catch, "java/lang/Throwable"); + //code.trycatch(label_body_start, label_body_end, label_catch, "java/lang/Throwable"); + ExceptionHandler handler = new ExceptionHandler(); + handler.exceptionStarts.addElement(label_body_start); + exceptionHandlers.push(handler); // VAR = value # Only if "as VAR" is present code.label(label_body_start); @@ -2124,8 +2127,10 @@ // BLOCK suite(node.body); + exceptionHandlers.pop(); code.goto_(label_finally); code.label(label_body_end); + handler.exceptionEnds.addElement(label_body_end); // CATCH code.label(label_catch); @@ -2162,6 +2167,8 @@ code.athrow(); code.freeLocal(ts_tmp); + + handler.addExceptionHandlers(label_catch); // FINALLY // ordinarily with a finally, we need to duplicate the code. that's not the case here This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |