Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: llimpl
Changeset: r82247:44df4ef6c185
Date: 2016-02-14 16:39 +0000
http://bitbucket.org/pypy/pypy/changeset/44df4ef6c185/

Log:    Fix --sandbox translation

diff --git a/rpython/annotator/policy.py b/rpython/annotator/policy.py
--- a/rpython/annotator/policy.py
+++ b/rpython/annotator/policy.py
@@ -3,6 +3,9 @@
 from rpython.annotator.specialize import (
     specialize_argvalue, specialize_argtype, specialize_arglistitemtype,
     specialize_arg_or_var, memo, specialize_call_location)
+from rpython.flowspace.operation import op
+from rpython.flowspace.model import Constant
+from rpython.annotator.model import SomeTuple
 
 
 class AnnotatorPolicy(object):
@@ -64,7 +67,35 @@
         return LowLevelAnnotatorPolicy.specialize__ll_and_arg(*args)
 
     def no_more_blocks_to_annotate(pol, annotator):
+        bk = annotator.bookkeeper
         # hint to all pending specializers that we are done
-        for callback in annotator.bookkeeper.pending_specializations:
+        for callback in bk.pending_specializations:
             callback()
-        del annotator.bookkeeper.pending_specializations[:]
+        del bk.pending_specializations[:]
+        if annotator.added_blocks is not None:
+            all_blocks = annotator.added_blocks
+        else:
+            all_blocks = annotator.annotated
+        for block in list(all_blocks):
+            for i, instr in enumerate(block.operations):
+                if not isinstance(instr, (op.simple_call, op.call_args)):
+                    continue
+                v_func = instr.args[0]
+                s_func = annotator.annotation(v_func)
+                if not hasattr(s_func, 'needs_sandboxing'):
+                    continue
+                key = ('sandboxing', s_func.const)
+                if key not in bk.emulated_pbc_calls:
+                    entry = s_func.entry
+                    params_s = entry.signature_args
+                    s_result = entry.signature_result
+                    from rpython.translator.sandbox.rsandbox import 
make_sandbox_trampoline
+                    sandbox_trampoline = make_sandbox_trampoline(
+                        entry.name, params_s, s_result)
+                    sandbox_trampoline._signature_ = 
[SomeTuple(items=params_s)], s_result
+                    bk.emulate_pbc_call(key, 
bk.immutablevalue(sandbox_trampoline), params_s)
+                else:
+                    s_trampoline = bk.emulated_pbc_calls[key][0]
+                    sandbox_trampoline = s_trampoline.const
+                new = instr.replace({instr.args[0]: 
Constant(sandbox_trampoline)})
+                block.operations[i] = new
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -113,8 +113,9 @@
 
 @op.simple_call.register(SomeObject)
 def simple_call_SomeObject(annotator, func, *args):
-    return annotator.annotation(func).call(
-        simple_args([annotator.annotation(arg) for arg in args]))
+    s_func = annotator.annotation(func)
+    argspec = simple_args([annotator.annotation(arg) for arg in args])
+    return s_func.call(argspec)
 
 @op.call_args.register_transform(SomeObject)
 def transform_varargs(annotator, v_func, v_shape, *data_v):
diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py
--- a/rpython/rtyper/extfunc.py
+++ b/rpython/rtyper/extfunc.py
@@ -25,13 +25,12 @@
         return self.signature_result
 
     def compute_annotation(self):
+        s_result = super(ExtFuncEntry, self).compute_annotation()
         if (self.bookkeeper.annotator.translator.config.translation.sandbox
                 and not self.safe_not_sandboxed):
-            from rpython.translator.sandbox.rsandbox import 
make_sandbox_trampoline
-            impl = make_sandbox_trampoline(self.name, self.signature_args,
-                self.signature_result)
-            return self.bookkeeper.immutablevalue(impl)
-        return super(ExtFuncEntry, self).compute_annotation()
+            s_result.needs_sandboxing = True
+            s_result.entry = self
+        return s_result
 
     def specialize_call(self, hop):
         rtyper = hop.rtyper
diff --git a/rpython/translator/sandbox/test/test_sandbox.py 
b/rpython/translator/sandbox/test/test_sandbox.py
--- a/rpython/translator/sandbox/test/test_sandbox.py
+++ b/rpython/translator/sandbox/test/test_sandbox.py
@@ -292,6 +292,21 @@
     rescode = pipe.wait()
     assert rescode == 0
 
+def test_environ_items():
+    def entry_point(argv):
+        print os.environ.items()
+        return 0
+
+    exe = compile(entry_point)
+    g, f = run_in_subprocess(exe)
+    expect(f, g, "ll_os.ll_os_envitems", (), [])
+    expect(f, g, "ll_os.ll_os_write", (1, "[]\n"), 3)
+    g.close()
+    tail = f.read()
+    f.close()
+    assert tail == ""
+
+
 class TestPrintedResults:
 
     def run(self, entry_point, args, expected):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to