[pypy-svn] r64479 - in pypy/trunk/pypy: rpython/module rpython/tool translator/c/test

tismer at codespeak.net tismer at codespeak.net
Mon Apr 20 20:37:33 CEST 2009


Author: tismer
Date: Mon Apr 20 20:37:32 2009
New Revision: 64479

Modified:
   pypy/trunk/pypy/rpython/module/ll_os.py
   pypy/trunk/pypy/rpython/tool/rffi_platform.py
   pypy/trunk/pypy/translator/c/test/test_extfunc.py
Log:
generalized implementation of os.setpgrp and os.getpgrp. The latter is not really tested, because on OSX getpgrp seems to take no argument. It is probably not worse than before now

Modified: pypy/trunk/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/trunk/pypy/rpython/module/ll_os.py	(original)
+++ pypy/trunk/pypy/rpython/module/ll_os.py	Mon Apr 20 20:37:32 2009
@@ -83,6 +83,11 @@
     def __init__(self):
         self.configure(CConfig)
 
+        if hasattr(os, 'getpgrp'):
+            self.GETPGRP_HAVE_ARG = platform.checkcompiles("getpgrp(0)", "#include <unistd.h>")
+        if hasattr(os, 'setpgrp'):
+            self.SETPGRP_HAVE_ARG = platform.checkcompiles("setpgrp(0,0)", "#include <unistd.h>")
+
         # we need an indirection via c functions to get macro calls working on llvm XXX still?
         if hasattr(os, 'WCOREDUMP'):
             decl_snippet = """
@@ -533,12 +538,26 @@
 
     @registering_if(os, 'getpgrp')
     def register_os_getpgrp(self):
-        return self.extdef_for_os_function_returning_int('getpgrp')
+        name = 'getpgrp'
+        if self.GETPGRP_HAVE_ARG:
+            c_func = self.llexternal(name, [rffi.INT], rffi.INT)
+            def c_func_llimpl():
+                res = rffi.cast(rffi.LONG, c_func(0))
+                if res == -1:
+                    raise OSError(rposix.get_errno(), "%s failed" % name)
+                return res
+
+            c_func_llimpl.func_name = name + '_llimpl'
+
+            return extdef([], int, llimpl=c_func_llimpl,
+                          export_name='ll_os.ll_os_' + name)
+        else:
+            return self.extdef_for_os_function_returning_int('getpgrp')
 
     @registering_if(os, 'setpgrp')
     def register_os_setpgrp(self):
         name = 'setpgrp'
-        if sys.platform.startswith('freebsd') or sys.platform == 'darwin':
+        if self.SETPGRP_HAVE_ARG:
             c_func = self.llexternal(name, [rffi.INT, rffi.INT], rffi.INT)
             def c_func_llimpl():
                 res = rffi.cast(rffi.LONG, c_func(0, 0))

Modified: pypy/trunk/pypy/rpython/tool/rffi_platform.py
==============================================================================
--- pypy/trunk/pypy/rpython/tool/rffi_platform.py	(original)
+++ pypy/trunk/pypy/rpython/tool/rffi_platform.py	Mon Apr 20 20:37:32 2009
@@ -56,7 +56,11 @@
         _compilation_info_ = eci
         WORKS = Works()
     configure(CConfig)
-
+    
+def checkcompiles(expression, c_header_source):
+    """Check if expression compiles. If not, returns False"""
+    return has(expression, c_header_source)
+    
 def sizeof(name, eci, **kwds):
     class CConfig:
         _compilation_info_ = eci
@@ -150,7 +154,7 @@
     def ask_gcc(self, question):
         self.start_main()
         self.f.write(question + "\n")
-        self.close()
+        self.close()	
         eci = self.config._compilation_info_
         try_compile_cache([self.path], eci)
 

Modified: pypy/trunk/pypy/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/trunk/pypy/translator/c/test/test_extfunc.py	(original)
+++ pypy/trunk/pypy/translator/c/test/test_extfunc.py	Mon Apr 20 20:37:32 2009
@@ -502,6 +502,14 @@
         res = f1()
         assert res == os.getpid()
         
+if hasattr(os, 'getpgrp'):
+    def test_os_getpgrp():
+        def does_stuff():
+            return os.getpgrp()
+        f1 = compile(does_stuff, [])
+        res = f1()
+        assert res == os.getpgrp()
+
 if hasattr(os, 'setpgrp'):
     def test_os_setpgrp():
         def does_stuff():



More information about the Pypy-commit mailing list