[pypy-svn] r45462 - in pypy/dist/pypy: rpython translator/sandbox/test
arigo at codespeak.net
arigo at codespeak.net
Thu Aug 2 19:17:24 CEST 2007
Author: arigo
Date: Thu Aug 2 19:17:24 2007
New Revision: 45462
Modified:
pypy/dist/pypy/rpython/extfunc.py
pypy/dist/pypy/rpython/extfuncregistry.py
pypy/dist/pypy/translator/sandbox/test/test_sandbox.py
Log:
Mark the math.*() functions as sandbox-safe, i.e. they are kept unmodified
in executables even if they are built with the --sandbox option.
Modified: pypy/dist/pypy/rpython/extfunc.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunc.py (original)
+++ pypy/dist/pypy/rpython/extfunc.py Thu Aug 2 19:17:24 2007
@@ -76,6 +76,8 @@
annotation(self.instance.result, self.bookkeeper))
class ExtFuncEntry(ExtRegistryEntry):
+ safe_not_sandboxed = False
+
def compute_result_annotation(self, *args_s):
if hasattr(self, 'ann_hook'):
self.ann_hook()
@@ -117,7 +119,8 @@
impl, self.signature_args, hop.s_result)
else:
obj = rtyper.type_system.getexternalcallable(args_ll, ll_result,
- name, _external_name=self.name, _callable=fakeimpl)
+ name, _external_name=self.name, _callable=fakeimpl,
+ _safe_not_sandboxed=self.safe_not_sandboxed)
vlist = [hop.inputconst(typeOf(obj), obj)] + hop.inputargs(*args_r)
hop.exception_is_here()
return hop.genop('direct_call', vlist, r_result)
@@ -125,7 +128,8 @@
def _register_external(function, args, result=None, export_name=None,
llimpl=None, ooimpl=None,
llfakeimpl=None, oofakeimpl=None,
- annotation_hook=None):
+ annotation_hook=None,
+ sandboxsafe=False):
"""
function: the RPython function that will be rendered as an external function (e.g.: math.floor)
args: a list containing the annotation of the arguments
@@ -134,10 +138,12 @@
llimpl, ooimpl: optional; if provided, these RPython functions are called instead of the target function
llfakeimpl, oofakeimpl: optional; if provided, they are called by the llinterpreter
annotationhook: optional; a callable that is called during annotation, useful for genc hacks
+ sandboxsafe: use True if the function performs no I/O (safe for --sandbox)
"""
class FunEntry(ExtFuncEntry):
_about_ = function
+ safe_not_sandboxed = sandboxsafe
if args is None:
signature_args = None
else:
Modified: pypy/dist/pypy/rpython/extfuncregistry.py
==============================================================================
--- pypy/dist/pypy/rpython/extfuncregistry.py (original)
+++ pypy/dist/pypy/rpython/extfuncregistry.py Thu Aug 2 19:17:24 2007
@@ -24,7 +24,8 @@
'floor', 'log', 'log10', 'sin', 'sinh', 'sqrt', 'tan', 'tanh'
]
for name in simple_math_functions:
- _register_external(getattr(math, name), [float], float, "ll_math.ll_math_%s" % name)
+ _register_external(getattr(math, name), [float], float, "ll_math.ll_math_%s" % name,
+ sandboxsafe=True)
def frexp_hook():
from pypy.rpython.extfunctable import record_call
@@ -54,7 +55,8 @@
oofake = getattr(oo_math, 'll_math_%s' % name, None)
_register_external(func, args, res, 'll_math.ll_math_%s' % name,
llfakeimpl=llfake, oofakeimpl=oofake,
- annotation_hook = hook)
+ annotation_hook = hook,
+ sandboxsafe=True)
# ___________________________
Modified: pypy/dist/pypy/translator/sandbox/test/test_sandbox.py
==============================================================================
--- pypy/dist/pypy/translator/sandbox/test/test_sandbox.py (original)
+++ pypy/dist/pypy/translator/sandbox/test/test_sandbox.py Thu Aug 2 19:17:24 2007
@@ -130,3 +130,26 @@
tail = f.read()
f.close()
assert tail == ""
+
+class TestPrintedResults:
+
+ def run(self, entry_point, args, expected):
+ t = Translation(entry_point, backend='c', standalone=True,
+ sandbox=True)
+ exe = t.compile()
+ from pypy.translator.sandbox.sandlib import SimpleIOSandboxedProc
+ proc = SimpleIOSandboxedProc([exe] + args)
+ output, error = proc.communicate()
+ assert error == ''
+ assert output == expected
+
+ def test_safefuncs(self):
+ import math
+ def entry_point(argv):
+ a = float(argv[1])
+ print int(math.floor(a - 0.2)),
+ print int(math.ceil(a)),
+ print int(100.0 * math.sin(a)),
+ print
+ return 0
+ self.run(entry_point, ["3.011"], "2 4 13\n")
More information about the Pypy-commit
mailing list