[pypy-svn] r49001 - in pypy/dist/pypy/rpython/module: . test

xoraxax at codespeak.net xoraxax at codespeak.net
Fri Nov 23 19:21:14 CET 2007


Author: xoraxax
Date: Fri Nov 23 19:21:14 2007
New Revision: 49001

Modified:
   pypy/dist/pypy/rpython/module/ll_os.py
   pypy/dist/pypy/rpython/module/test/test_posix.py
Log:
(xoraxax, fijal and rxe around): Wrap the os.W* macros in functions, add a test for them. In the end, it allows LLVM to use these.

Modified: pypy/dist/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_os.py	(original)
+++ pypy/dist/pypy/rpython/module/ll_os.py	Fri Nov 23 19:21:14 2007
@@ -17,6 +17,8 @@
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.tool import rffi_platform as platform
 from pypy.rlib import rposix
+from pypy.tool.udir import udir
+
 posix = __import__(os.name)
 
 if sys.platform.startswith('win'):
@@ -52,6 +54,7 @@
                            ('tms_cstime', rffi.INT)])
     else:
         _includes_ += ['sys/utime.h']
+    _include_dirs_ = [str(udir)]
 
     SEEK_SET = platform.DefinedConstantInteger('SEEK_SET')
     SEEK_CUR = platform.DefinedConstantInteger('SEEK_CUR')
@@ -67,6 +70,25 @@
     def __init__(self):
         self.configure(CConfig)
 
+        # we need an indirection via c functions to get macro calls working on llvm
+        decl_snippet = """
+            %(ret_type)s pypy_%(name)s (int status);
+        """
+        def_snippet = """
+            %(ret_type)s pypy_%(name)s (int status) {
+                return %(name)s(status);
+            }
+        """
+        decls = []
+        defs = []
+        for name in self.w_star:
+            data = {'ret_type': 'int', 'name': name}
+            decls.append(decl_snippet % data)
+            defs.append(def_snippet % data)
+        h_source = ['#include "sys/wait.h"'] + decls + ["#ifndef PYPY_NOT_MAIN_FILE"] + defs + ["#endif"]
+        h_file = udir.join("pypy_os_macros.h")
+        h_file.write("\n".join(h_source))
+
     # a simple, yet usefull factory
     def extdef_for_os_function_returning_int(self, name, **kwds):
         c_func = self.llexternal(name, [], rffi.INT, **kwds)
@@ -1069,16 +1091,20 @@
     # last 3 are returning int
     w_star_returning_int = dict.fromkeys(w_star[-3:])
 
+
+
     def declare_new_w_star(self, name):
         """ stupid workaround for the python late-binding
         'feature'
         """
+
         def fake(status):
             return int(getattr(os, name)(status))
         fake.func_name = 'fake_' + name
 
-        os_c_func = self.llexternal(name, [lltype.Signed],
-                                    lltype.Signed, _callable=fake)
+        os_c_func = self.llexternal("pypy_" + name, [lltype.Signed],
+                                    lltype.Signed, includes=['pypy_os_macros.h'],
+                                    _callable=fake)
     
         if name in self.w_star_returning_int:
             def llimpl(status):
@@ -1089,7 +1115,7 @@
                 return bool(os_c_func(status))
             resulttype = bool
         llimpl.func_name = name + '_llimpl'
-        return extdef([int], resulttype, "ll_os."+name,
+        return extdef([int], resulttype, "ll_os." + name,
                       llimpl=llimpl)
 
     for name in w_star:

Modified: pypy/dist/pypy/rpython/module/test/test_posix.py
==============================================================================
--- pypy/dist/pypy/rpython/module/test/test_posix.py	(original)
+++ pypy/dist/pypy/rpython/module/test/test_posix.py	Fri Nov 23 19:21:14 2007
@@ -122,17 +122,6 @@
                 return os.getgid()
             assert self.interpret(f, []) == f()
 
-    def test_os_wstar(self):
-        from pypy.rpython.module.ll_os import RegisterOs
-        for name in RegisterOs.w_star:
-            if not hasattr(os, name):
-                continue
-            def fun(s):
-                return getattr(os, name)(s)
-
-            for value in [0, 1, 127, 128, 255]:
-                res = self.interpret(fun, [value])
-                assert res == fun(value)
 
     if hasattr(os, 'setuid'):
         def test_os_setuid(self):
@@ -148,3 +137,18 @@
     def test_fstat(self):
         py.test.skip("ootypesystem does not support os.fstat")
 
+
+def test_os_wstar():
+    from pypy.rpython.module.ll_os import RegisterOs
+    from pypy.translator.c.test.test_genc import compile
+    for name in RegisterOs.w_star:
+        if not hasattr(os, name):
+            continue
+        def fun(s):
+            return getattr(os, name)(s)
+
+        fun_c = compile(fun, [int])
+        for value in [0, 1, 127, 128, 255]:
+            res = fun_c(value)
+            assert res == fun(value)
+



More information about the Pypy-commit mailing list