Author: Ronan Lamy <[email protected]>
Branch: exctrans
Changeset: r81686:eddfb3e100dd
Date: 2016-01-12 17:43 +0000
http://bitbucket.org/pypy/pypy/changeset/eddfb3e100dd/
Log: Split get_external_function_sandbox_graph() and kill force_stub flag
diff --git a/rpython/translator/c/node.py b/rpython/translator/c/node.py
--- a/rpython/translator/c/node.py
+++ b/rpython/translator/c/node.py
@@ -916,15 +916,15 @@
def sandbox_stub(fnobj, db):
# unexpected external function for --sandbox translation: replace it
# with a "Not Implemented" stub.
- graph = rsandbox.get_external_function_sandbox_graph(fnobj, db,
- force_stub=True)
+ graph = rsandbox.get_sandbox_stub(fnobj, db.translator.rtyper)
return make_funcgen(graph, db)
def sandbox_transform(fnobj, db):
# for --sandbox: replace a function like os_open_llimpl() with
# code that communicates with the external process to ask it to
# perform the operation.
- graph = rsandbox.get_external_function_sandbox_graph(fnobj, db)
+ graph = rsandbox.get_external_function_sandbox_graph(
+ fnobj, db.translator.rtyper)
return make_funcgen(graph, db)
def need_sandboxing(fnobj):
diff --git a/rpython/translator/sandbox/rsandbox.py
b/rpython/translator/sandbox/rsandbox.py
--- a/rpython/translator/sandbox/rsandbox.py
+++ b/rpython/translator/sandbox/rsandbox.py
@@ -108,10 +108,24 @@
execute.__name__ = 'sandboxed_%s' % (fnname,)
return execute
+def sig_ll(fnobj):
+ FUNCTYPE = lltype.typeOf(fnobj)
+ args_s = [lltype_to_annotation(ARG) for ARG in FUNCTYPE.ARGS]
+ s_result = lltype_to_annotation(FUNCTYPE.RESULT)
+ return args_s, s_result
+
dump_string = rmarshal.get_marshaller(str)
load_int = rmarshal.get_loader(int)
-def get_external_function_sandbox_graph(fnobj, db, force_stub=False):
+def get_sandbox_stub(fnobj, rtyper):
+ """Build always-raising graph for unsupported external function."""
+ fnname = fnobj._name
+ args_s, s_result = sig_ll(fnobj)
+ msg = "Not implemented: sandboxing for external function '%s'" % (fnname,)
+ execute = make_stub(fnname, msg)
+ return _annotate(rtyper, execute, args_s, s_result)
+
+def get_external_function_sandbox_graph(fnobj, rtyper):
"""Build the graph of a helper trampoline function to be used
in place of real calls to the external function 'fnobj'. The
trampoline marshals its input arguments, dumps them to STDOUT,
@@ -129,34 +143,28 @@
else:
# pure external function - fall back to the annotations
# corresponding to the ll types
- FUNCTYPE = lltype.typeOf(fnobj)
- args_s = [lltype_to_annotation(ARG) for ARG in FUNCTYPE.ARGS]
- s_result = lltype_to_annotation(FUNCTYPE.RESULT)
+ args_s, s_result = sig_ll(fnobj)
- if force_stub: # old case - don't try to support suggested_primitive
- msg = "Not implemented: sandboxing for external function '%s'" %
(fnname,)
+ try:
+ dump_arguments = rmarshal.get_marshaller(tuple(args_s))
+ load_result = rmarshal.get_loader(s_result)
+ except (rmarshal.CannotMarshal, rmarshal.CannotUnmarshall) as e:
+ msg = "Cannot sandbox function '%s': %s" % (fnname, e)
execute = make_stub(fnname, msg)
else:
- try:
- dump_arguments = rmarshal.get_marshaller(tuple(args_s))
- load_result = rmarshal.get_loader(s_result)
- except (rmarshal.CannotMarshal, rmarshal.CannotUnmarshall) as e:
- msg = "Cannot sandbox function '%s': %s" % (fnname, e)
- execute = make_stub(fnname, msg)
- else:
- def execute(*args):
- # marshal the function name and input arguments
- buf = []
- dump_string(buf, fnname)
- dump_arguments(buf, args)
- # send the buffer and wait for the answer
- loader = sandboxed_io(buf)
- # decode the answer
- result = load_result(loader)
- loader.check_finished()
- return result
- execute.__name__ = 'sandboxed_%s' % (fnname,)
- return _annotate(db.translator.rtyper, execute, args_s, s_result)
+ def execute(*args):
+ # marshal the function name and input arguments
+ buf = []
+ dump_string(buf, fnname)
+ dump_arguments(buf, args)
+ # send the buffer and wait for the answer
+ loader = sandboxed_io(buf)
+ # decode the answer
+ result = load_result(loader)
+ loader.check_finished()
+ return result
+ execute.__name__ = 'sandboxed_%s' % (fnname,)
+ return _annotate(rtyper, execute, args_s, s_result)
def _annotate(rtyper, f, args_s, s_result):
ann = MixLevelHelperAnnotator(rtyper)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit