[pypy-svn] r22206 - in pypy/dist/pypy/translator/backendopt: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Jan 16 10:34:51 CET 2006


Author: cfbolz
Date: Mon Jan 16 10:34:49 2006
New Revision: 22206

Modified:
   pypy/dist/pypy/translator/backendopt/escape.py
   pypy/dist/pypy/translator/backendopt/test/test_escape.py
Log:
don't just give up on external functions that take arguments that are on the heap


Modified: pypy/dist/pypy/translator/backendopt/escape.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/escape.py	(original)
+++ pypy/dist/pypy/translator/backendopt/escape.py	Mon Jan 16 10:34:49 2006
@@ -280,11 +280,16 @@
     def direct_call(self, op, function, *args):
         graph = get_graph(op.args[0], self.translation_context)
         if graph is None:
-            if len(filter(None, args)):
+            if isonheap(op.result):
                 raise NotImplementedError, "can't handle call %s" % (op, )
-            else:
-                result = None
-                funcargs = [None] * len(args)
+            for arg in args:
+                if arg is None:
+                    continue
+                # an external function can change every parameter:
+                changed = arg.setchanges()
+                self.handle_changed(changed)
+            result = None
+            funcargs = [None] * len(args)
         else:
             result, funcargs = self.schedule_function(graph)
         assert len(args) == len(funcargs)
@@ -292,7 +297,8 @@
             if localarg is None:
                 assert funcarg is None
                 continue
-            self.register_state_dependency(localarg, funcarg)
+            if funcarg is not None:
+                self.register_state_dependency(localarg, funcarg)
         if isonheap(op.result):
             # assume that a call creates a new value
             return VarState(self.get_creationpoint(op.result, "direct_call"))

Modified: pypy/dist/pypy/translator/backendopt/test/test_escape.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_escape.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_escape.py	Mon Jan 16 10:34:49 2006
@@ -323,6 +323,17 @@
     # does not crash
     t, adi, graph = build_adi(entrypoint, [int])
 
+def test_extfunc_onheaparg():
+    import os
+    def f(i):
+        s = str(i)
+        os.write(2, s)
+        return len(s)
+    t, adi, graph = build_adi(f, [int])
+    svar = graph.startblock.operations[0].result
+    state = adi.getstate(svar)
+    assert not state.does_escape()
+    assert state.does_change()
  
 #__________________________________________________________
 # malloc removal tests



More information about the Pypy-commit mailing list