[pypy-svn] r45997 - in pypy/branch/pypy-more-rtti-inprogress: rpython/lltypesystem translator/backendopt translator/backendopt/test translator/c/test

pedronis at codespeak.net pedronis at codespeak.net
Sun Aug 26 18:13:28 CEST 2007


Author: pedronis
Date: Sun Aug 26 18:13:26 2007
New Revision: 45997

Modified:
   pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/rffi.py
   pypy/branch/pypy-more-rtti-inprogress/translator/backendopt/canraise.py
   pypy/branch/pypy-more-rtti-inprogress/translator/backendopt/test/test_canraise.py
   pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_exceptiontransform.py
Log:
llexternals typically should not raise. have a canraise flag on them for the benefit of the raise analyzer and exception transform.

this changeset will be fun to merge because on the trunk the exception transform has been generalized to work with ootype
and has moved. be careful.



Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/rffi.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/rffi.py	Sun Aug 26 18:13:26 2007
@@ -22,7 +22,8 @@
         return self.TP
 
 def llexternal(name, args, result, _callable=None, sources=[], includes=[],
-               libraries=[], include_dirs=[], sandboxsafe=False):
+               libraries=[], include_dirs=[], sandboxsafe=False,
+               canraise=False):
     ext_type = lltype.FuncType(args, result)
     if _callable is None:
         _callable = ll2ctypes.LL2CtypesCallable(ext_type)
@@ -33,7 +34,8 @@
                                  include_dirs=tuple(include_dirs),
                                  _callable=_callable,
                                  _safe_not_sandboxed=sandboxsafe,
-                                 _debugexc=True)  # on top of llinterp
+                                 _debugexc=True, # on top of llinterp
+                                 canraise=canraise)  
     if isinstance(_callable, ll2ctypes.LL2CtypesCallable):
         _callable.funcptr = funcptr
     return funcptr

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/backendopt/canraise.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/backendopt/canraise.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/backendopt/canraise.py	Sun Aug 26 18:13:26 2007
@@ -16,6 +16,12 @@
             log.WARNING("Unknown operation: %s" % op.opname)
             return True
 
+
+    def analyze_external_call(self, op):
+        deref = self.translator.rtyper.type_system_deref
+        fnobj = deref(op.args[0].value)
+        return getattr(fnobj, 'canraise', True)
+
     def analyze_exceptblock(self, block, seen=None):
         return True
 

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/backendopt/test/test_canraise.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/backendopt/test/test_canraise.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/backendopt/test/test_canraise.py	Sun Aug 26 18:13:26 2007
@@ -64,13 +64,29 @@
     result = ra.can_raise(hgraph.startblock.operations[0])
     assert result
 
-def test_external():
-    import os.path
+def test_llexternal():
+    from pypy.rpython.lltypesystem.rffi import llexternal
+    from pypy.rpython.lltypesystem import lltype
+    z = llexternal('z', [lltype.Signed], lltype.Signed)
     def f(x):
-        return os.path.isdir(str(x))
+        return z(x)
     t, ra = translate(f, [int])
     fgraph = graphof(t, f)
+
+    assert fgraph.startblock.operations[0].opname == 'direct_call'
+
     result = ra.can_raise(fgraph.startblock.operations[0])
+    assert not result
+
+    z = llexternal('z', [lltype.Signed], lltype.Signed, canraise=True)
+    def g(x):
+        return z(x)
+    t, ra = translate(g, [int])
+    ggraph = graphof(t, g)
+
+    assert ggraph.startblock.operations[0].opname == 'direct_call'
+
+    result = ra.can_raise(ggraph.startblock.operations[0])
     assert result
 
 def test_instantiate():

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_exceptiontransform.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_exceptiontransform.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_exceptiontransform.py	Sun Aug 26 18:13:26 2007
@@ -204,7 +204,6 @@
 
 
 def test_llexternal():
-    py.test.skip("WIP")
     from pypy.rpython.lltypesystem.rffi import llexternal
     from pypy.rpython.lltypesystem import lltype
     z = llexternal('z', [lltype.Signed], lltype.Signed)



More information about the Pypy-commit mailing list