[pypy-svn] r48915 - in pypy/dist/pypy: rlib rpython/lltypesystem translator/sandbox/test

arigo at codespeak.net arigo at codespeak.net
Thu Nov 22 10:25:42 CET 2007


Author: arigo
Date: Thu Nov 22 10:25:41 2007
New Revision: 48915

Modified:
   pypy/dist/pypy/rlib/rposix.py
   pypy/dist/pypy/rpython/lltypesystem/rffi.py
   pypy/dist/pypy/translator/sandbox/test/test_sandbox.py
Log:
Fix the sandboxing handling of errno.  Add a test.


Modified: pypy/dist/pypy/rlib/rposix.py
==============================================================================
--- pypy/dist/pypy/rlib/rposix.py	(original)
+++ pypy/dist/pypy/rlib/rposix.py	Thu Nov 22 10:25:41 2007
@@ -16,5 +16,5 @@
         ll2ctypes.TLS.errno = value
 
 get_errno, set_errno = CExternVariable(lltype.Signed, 'errno', CConstantErrno,
-                                       includes=['errno.h'])
+                                       includes=['errno.h'], sandboxsafe=True)
 

Modified: pypy/dist/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rffi.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rffi.py	Thu Nov 22 10:25:41 2007
@@ -242,7 +242,8 @@
 def COpaquePtr(*args, **kwds):
     return lltype.Ptr(COpaque(*args, **kwds))
 
-def CExternVariable(TYPE, name, _CConstantClass=CConstant, includes=[], include_dirs=[]):
+def CExternVariable(TYPE, name, _CConstantClass=CConstant, includes=[],
+                    include_dirs=[], sandboxsafe=False):
     """Return a pair of functions - a getter and a setter - to access
     the given global C variable.
     """
@@ -269,7 +270,7 @@
     sources = ('\n'.join(lines),)
 
     kwds = {'includes': includes, 'sources':sources,
-            'include_dirs':include_dirs}
+            'include_dirs':include_dirs, 'sandboxsafe': sandboxsafe}
     getter = llexternal(getter_name, [], TYPE, **kwds)
     setter = llexternal(setter_name, [TYPE], lltype.Void, **kwds)
     return getter, setter

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 Nov 22 10:25:41 2007
@@ -160,6 +160,21 @@
             return 0
         self.run(entry_point, ["3.011"], "2 4 13 75 2 1 3\n")
 
+    def test_safefuncs_exception(self):
+        import math
+        def entry_point(argv):
+            a = float(argv[1])
+            x = math.log(a)
+            print int(x * 100.0)
+            try:
+                math.log(-a)
+            except ValueError:
+                print 'as expected, got a ValueError'
+            else:
+                print 'did not get a ValueError!'
+            return 0
+        self.run(entry_point, ["3.011"], "110\nas expected, got a ValueError\n")
+
     def test_os_path_safe(self):
         def entry_point(argv):
             print os.path.join('tmp', argv[1])



More information about the Pypy-commit mailing list