[pypy-svn] r79991 - in pypy/branch/more-posix/pypy: rpython/module translator/c/test

arigo at codespeak.net arigo at codespeak.net
Sat Dec 11 17:55:45 CET 2010


Author: arigo
Date: Sat Dec 11 17:55:44 2010
New Revision: 79991

Modified:
   pypy/branch/more-posix/pypy/rpython/module/ll_os.py
   pypy/branch/more-posix/pypy/translator/c/test/test_extfunc.py
Log:
Translation of os.nice().

Modified: pypy/branch/more-posix/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/more-posix/pypy/rpython/module/ll_os.py	(original)
+++ pypy/branch/more-posix/pypy/rpython/module/ll_os.py	Sat Dec 11 17:55:44 2010
@@ -1471,6 +1471,25 @@
         return extdef([int], s_None, llimpl=_exit_llimpl,
                       export_name="ll_os.ll_os__exit")
 
+    @registering_if(os, 'nice')
+    def register_os_nice(self):
+        os_nice = self.llexternal('nice', [rffi.INT], rffi.INT)
+
+        def nice_llimpl(inc):
+            # Assume that the system provides a standard-compliant version
+            # of nice() that returns the new priority.  Nowadays, FreeBSD
+            # might be the last major non-compliant system (xxx check me).
+            rposix.set_errno(0)
+            res = rffi.cast(lltype.Signed, os_nice(inc))
+            if res == -1:
+                err = rposix.get_errno()
+                if err != 0:
+                    raise OSError(err, "os_nice failed")
+            return res
+
+        return extdef([int], int, llimpl=nice_llimpl,
+                      export_name="ll_os.ll_os_nice")
+
 # --------------------------- os.stat & variants ---------------------------
 
     @registering(os.fstat)

Modified: pypy/branch/more-posix/pypy/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/branch/more-posix/pypy/translator/c/test/test_extfunc.py	(original)
+++ pypy/branch/more-posix/pypy/translator/c/test/test_extfunc.py	Sat Dec 11 17:55:44 2010
@@ -4,6 +4,7 @@
 from pypy.tool.udir import udir
 from pypy.rlib.rarithmetic import r_longlong
 from pypy.translator.c.test.test_genc import compile
+from pypy.translator.c.test.test_standalone import StandaloneTests
 posix = __import__(os.name)
 
 # note: clock synchronizes itself!
@@ -805,3 +806,19 @@
         finally:
             os.chdir(localdir)
         assert res == True
+
+# ____________________________________________________________
+
+
+class TestExtFuncStandalone(StandaloneTests):
+
+    if hasattr(os, 'nice'):
+        def test_os_nice(self):
+            def does_stuff(argv):
+                res =  os.nice(3)
+                print 'os.nice returned', res
+                return 0
+            t, cbuilder = self.compile(does_stuff)
+            data = cbuilder.cmdexec('')
+            res = os.nice(0) + 3
+            assert data.startswith('os.nice returned %d\n' % res)



More information about the Pypy-commit mailing list