[pypy-svn] r78256 - in pypy/branch/fast-forward/pypy/objspace/flow: . test

afa at codespeak.net afa at codespeak.net
Mon Oct 25 14:13:51 CEST 2010


Author: afa
Date: Mon Oct 25 14:13:50 2010
New Revision: 78256

Modified:
   pypy/branch/fast-forward/pypy/objspace/flow/flowcontext.py
   pypy/branch/fast-forward/pypy/objspace/flow/test/test_objspace.py
Log:
Another R to RPython: __exit__ must not return True to swallow exceptions.
This fixes constructs like::

    with c:
        res = fn()
    return res

otherwise the flow space finds a path where no exception is raised,
but 'res' is not initialized.


Modified: pypy/branch/fast-forward/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/flow/flowcontext.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/flow/flowcontext.py	Mon Oct 25 14:13:50 2010
@@ -445,5 +445,8 @@
             # Replace it with an object which will break translation when used
             # (except maybe with 'exc_typ is None')
             w_typ = self.space.wrap(self.space)
-        return self.space.call_function(w_func, w_typ, w_val, w_tb)
+        self.space.call_function(w_func, w_typ, w_val, w_tb)
+        # Return None so that the flow space statically knows that we didn't
+        # swallow the exception
+        return self.space.w_None
 

Modified: pypy/branch/fast-forward/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/flow/test/test_objspace.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/flow/test/test_objspace.py	Mon Oct 25 14:13:50 2010
@@ -841,12 +841,13 @@
         def g(): pass
         def f(c, x):
             with x:
-                g()
+                res = g()
+            return res
         graph = self.codetest(f)
         assert self.all_operations(graph) == {
             'getattr': 2,     # __enter__ and __exit__
             'simple_call': 4, # __enter__, g and 2 possible calls to __exit__
-            'is_true': 1}     # check the result of __exit__()
+            }
 
     def monkey_patch_code(self, code, stacksize, flags, codestring, names, varnames):
         c = code



More information about the Pypy-commit mailing list