Author: Armin Rigo <[email protected]>
Branch: sandbox-2
Changeset: r97071:2b1d31cf3e3e
Date: 2019-08-06 15:34 +0200
http://bitbucket.org/pypy/pypy/changeset/2b1d31cf3e3e/

Log:    Remove support for the outdated register_external(sandboxsafe=False)

diff --git a/rpython/annotator/policy.py b/rpython/annotator/policy.py
--- a/rpython/annotator/policy.py
+++ b/rpython/annotator/policy.py
@@ -72,29 +72,3 @@
         for callback in bk.pending_specializations:
             callback()
         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:
-                    params_s = s_func.args_s
-                    s_result = s_func.s_result
-                    from rpython.translator.sandbox.rsandbox import 
make_sandbox_trampoline
-                    sandbox_trampoline = make_sandbox_trampoline(
-                        s_func.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/rlib/debug.py b/rpython/rlib/debug.py
--- a/rpython/rlib/debug.py
+++ b/rpython/rlib/debug.py
@@ -6,7 +6,6 @@
 from rpython.rtyper.extregistry import ExtRegistryEntry
 from rpython.rlib.objectmodel import we_are_translated, always_inline
 from rpython.rlib.rarithmetic import is_valid_int, r_longlong
-from rpython.rtyper.extfunc import register_external
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rtyper.lltypesystem import rffi
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
@@ -460,7 +459,10 @@
 
 
 def attach_gdb():
-    import pdb; pdb.set_trace()
+    if not we_are_translated():
+        import pdb; pdb.set_trace()
+    else:
+        impl_attach_gdb()
 
 if not sys.platform.startswith('win'):
     if sys.platform.startswith('linux'):
@@ -586,11 +588,8 @@
         d['separate_module_files'] = [cppfile]
         return ExternalCompilationInfo(**d)
 
-    ll_attach = rffi.llexternal("AttachToVS", [], lltype.Void,
-                                compilation_info=make_vs_attach_eci())
+    #ll_attach = rffi.llexternal("AttachToVS", [], lltype.Void,
+    #                            compilation_info=make_vs_attach_eci())
     def impl_attach_gdb():
         #ll_attach()
         print "AttachToVS is disabled at the moment (compilation failure)"
-
-register_external(attach_gdb, [], result=None,
-                  export_name="impl_attach_gdb", llimpl=impl_attach_gdb)
diff --git a/rpython/rlib/rfloat.py b/rpython/rlib/rfloat.py
--- a/rpython/rlib/rfloat.py
+++ b/rpython/rlib/rfloat.py
@@ -5,7 +5,6 @@
 
 from rpython.annotator.model import SomeString, SomeChar
 from rpython.rlib import objectmodel, unroll
-from rpython.rtyper.extfunc import register_external
 from rpython.rtyper.tool import rffi_platform
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 from rpython.rlib.objectmodel import not_rpython
diff --git a/rpython/rlib/rposix_environ.py b/rpython/rlib/rposix_environ.py
--- a/rpython/rlib/rposix_environ.py
+++ b/rpython/rlib/rposix_environ.py
@@ -5,7 +5,6 @@
 from rpython.rlib.objectmodel import enforceargs
 # importing rposix here creates a cycle on Windows
 from rpython.rtyper.controllerentry import Controller
-from rpython.rtyper.extfunc import register_external
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 
@@ -97,9 +96,6 @@
 # Lower-level interface: dummy placeholders and external registations
 
 def r_envkeys():
-    just_a_placeholder
-
-def envkeys_llimpl():
     environ = os_get_environ()
     result = []
     i = 0
@@ -111,10 +107,6 @@
         i += 1
     return result
 
-register_external(r_envkeys, [], [str0],   # returns a list of strings
-                  export_name='ll_os.ll_os_envkeys',
-                  llimpl=envkeys_llimpl)
-
 # ____________________________________________________________
 
 def r_envitems():
@@ -190,18 +182,7 @@
 
     return envitems_llimpl, getenv_llimpl, putenv_llimpl
 
-envitems_llimpl, getenv_llimpl, putenv_llimpl = make_env_impls()
-
-register_external(r_envitems, [], [(str0, str0)],
-                  export_name='ll_os.ll_os_envitems',
-                  llimpl=envitems_llimpl)
-register_external(r_getenv, [str0],
-                  annmodel.SomeString(can_be_None=True, no_nul=True),
-                  export_name='ll_os.ll_os_getenv',
-                  llimpl=getenv_llimpl)
-register_external(r_putenv, [str0, str0], annmodel.s_None,
-                  export_name='ll_os.ll_os_putenv',
-                  llimpl=putenv_llimpl)
+r_envitems, r_getenv, r_putenv = make_env_impls()
 
 # ____________________________________________________________
 
@@ -215,7 +196,7 @@
     os_unsetenv = llexternal('unsetenv', [rffi.CCHARP], rffi.INT,
                                   save_err=rffi.RFFI_SAVE_ERRNO)
 
-    def unsetenv_llimpl(name):
+    def r_unsetenv(name):
         with rffi.scoped_str2charp(name) as l_name:
             error = rffi.cast(lltype.Signed, os_unsetenv(l_name))
         if error:
@@ -229,7 +210,4 @@
             del envkeepalive.byname[name]
             rffi.free_charp(l_oldstring)
 
-    register_external(r_unsetenv, [str0], annmodel.s_None,
-                      export_name='ll_os.ll_os_unsetenv',
-                      llimpl=unsetenv_llimpl)
     REAL_UNSETENV = True
diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py
--- a/rpython/rtyper/extfunc.py
+++ b/rpython/rtyper/extfunc.py
@@ -95,9 +95,7 @@
     def compute_annotation(self):
         s_result = SomeExternalFunction(
             self.name, self.signature_args, self.signature_result)
-        if (self.bookkeeper.annotator.translator.config.translation.sandbox
-                and not self.safe_not_sandboxed):
-            s_result.needs_sandboxing = True
+        assert self.safe_not_sandboxed
         return s_result
 
 
@@ -113,6 +111,12 @@
     sandboxsafe: use True if the function performs no I/O (safe for --sandbox)
     """
 
+    if not sandboxsafe:
+        raise Exception("Don't use the outdated register_external() protocol "
+                        "to invoke external function; use instead "
+                        "rffi.llexternal().  The old register_external() is "
+                        "now only supported with safeboxsafe=True.")
+
     if export_name is None:
         export_name = function.__name__
     params_s = [annotation(arg) for arg in args]
diff --git a/rpython/rtyper/test/test_extfunc.py 
b/rpython/rtyper/test/test_extfunc.py
--- a/rpython/rtyper/test/test_extfunc.py
+++ b/rpython/rtyper/test/test_extfunc.py
@@ -18,7 +18,7 @@
             "NOT_RPYTHON"
             return eval("x+40")
 
-        register_external(b, [int], result=int)
+        register_external(b, [int], result=int, sandboxsafe=True)
 
         def f():
             return b(2)
@@ -42,7 +42,7 @@
             return y + x
 
         register_external(c, [int, int], result=int, llimpl=llimpl,
-                          export_name='ccc')
+                          export_name='ccc', sandboxsafe=True)
 
         def f():
             return c(3, 4)
@@ -62,7 +62,8 @@
             tuple as an argument so that register_external's behavior for
             tuple-taking functions can be verified.
             """
-        register_external(function_with_tuple_arg, [(int,)], int)
+        register_external(function_with_tuple_arg, [(int,)], int,
+                          sandboxsafe=True)
 
         def f():
             return function_with_tuple_arg((1,))
@@ -82,11 +83,11 @@
         """
         def function_with_list():
             pass
-        register_external(function_with_list, [[int]], int)
+        register_external(function_with_list, [[int]], int, sandboxsafe=True)
 
         def function_returning_list():
             pass
-        register_external(function_returning_list, [], [int])
+        register_external(function_returning_list, [], [int], sandboxsafe=True)
 
         def f():
             return function_with_list(function_returning_list())
@@ -100,7 +101,7 @@
         str0 = SomeString(no_nul=True)
         def os_open(s):
             pass
-        register_external(os_open, [str0], None)
+        register_external(os_open, [str0], None, sandboxsafe=True)
         def f(s):
             return os_open(s)
         policy = AnnotatorPolicy()
@@ -121,7 +122,7 @@
         def os_execve(l):
             pass
 
-        register_external(os_execve, [[str0]], None)
+        register_external(os_execve, [[str0]], None, sandboxsafe=True)
 
         def f(l):
             return os_execve(l)
@@ -149,7 +150,7 @@
         def a_llfakeimpl(i):
             return i * 3
         register_external(a, [int], int, llimpl=a_llimpl,
-                          llfakeimpl=a_llfakeimpl)
+                          llfakeimpl=a_llfakeimpl, sandboxsafe=True)
         def f(i):
             return a(i)
 
diff --git a/rpython/rtyper/test/test_llinterp.py 
b/rpython/rtyper/test/test_llinterp.py
--- a/rpython/rtyper/test/test_llinterp.py
+++ b/rpython/rtyper/test/test_llinterp.py
@@ -584,7 +584,8 @@
     def raising():
         raise OSError(15, "abcd")
 
-    ext = register_external(external, [], llimpl=raising, llfakeimpl=raising)
+    ext = register_external(external, [], llimpl=raising, llfakeimpl=raising,
+                            sandboxsafe=True)
 
     def f():
         # this is a useful llfakeimpl that raises an exception
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to