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

fijal at codespeak.net fijal at codespeak.net
Thu Jun 28 10:46:53 CEST 2007


Author: fijal
Date: Thu Jun 28 10:46:52 2007
New Revision: 44582

Modified:
   pypy/dist/pypy/rpython/module/ll_os.py
   pypy/dist/pypy/rpython/module/test/test_ll_os.py
Log:
* separators
* add os.ttyname
* few clarifications


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	Thu Jun 28 10:46:52 2007
@@ -32,13 +32,11 @@
 from pypy.rpython.lltypesystem import rffi
 from pypy.rpython.lltypesystem import lltype
 
+# ------------------------------- os.execv ------------------------------
+
 if hasattr(os, 'execv'):
 
-    if os.name == 'nt':
-        name = '_execv'
-    else:
-        name = 'execv'
-    os_execv = rffi.llexternal(name, [rffi.CCHARP, rffi.CCHARPP],
+    os_execv = rffi.llexternal('execv', [rffi.CCHARP, rffi.CCHARPP],
                                lltype.Signed)
 
     def execv_lltypeimpl(path, args):
@@ -52,12 +50,9 @@
     register_external(os.execv, [str, [str]], s_ImpossibleValue, llimpl=
                       execv_lltypeimpl, export_name="ll_os.ll_os_execv")
 
-if os.name == 'nt':
-    name = '_dup'
-else:
-    name = 'dup'
+# ------------------------------- os.dup --------------------------------
 
-os_dup = rffi.llexternal(name, [lltype.Signed], lltype.Signed,
+os_dup = rffi.llexternal('dup', [lltype.Signed], lltype.Signed,
                          _callable=os.dup)
 
 def dup_lltypeimpl(fd):
@@ -68,11 +63,9 @@
 register_external(os.dup, [int], int, llimpl=dup_lltypeimpl,
                   export_name="ll_os.ll_os_dup", oofakeimpl=os.dup)
 
-if os.name == 'nt':
-    name = '_dup2'
-else:
-    name = 'dup2'
-os_dup2 = rffi.llexternal(name, [lltype.Signed, lltype.Signed], lltype.Signed)
+# ------------------------------- os.dup2 -------------------------------
+
+os_dup2 = rffi.llexternal('dup2', [lltype.Signed, lltype.Signed], lltype.Signed)
 
 def dup2_lltypeimpl(fd, newfd):
     error = os_dup2(fd, newfd)
@@ -81,6 +74,7 @@
 register_external(os.dup2, [int, int], s_None, llimpl=dup2_lltypeimpl,
                   export_name="ll_os.ll_os_dup2")
 
+# ------------------------------- os.utime ------------------------------
 
 UTIMEBUFP = rffi.CStruct('utimbuf', ('actime', rffi.SIZE_T),
                          ('modtime', rffi.SIZE_T))
@@ -111,7 +105,9 @@
     if error == -1:
         raise OSError(rffi.c_errno, "utime_tuple failed")
 register_external(ros.utime_tuple, [str, (float, float)], s_None, "ll_os.utime_tuple",
-                  llimpl=utime_tuple_lltypeimpl)    
+                  llimpl=utime_tuple_lltypeimpl)
+
+# ------------------------------- os.open -------------------------------
 
 def fake_os_open(l_path, flags, mode):
     path = rffi.charp2str(l_path)
@@ -140,6 +136,9 @@
 register_external(os.open, [str, int, int], int, "ll_os.ll_os_open",
                   llimpl=os_open_lltypeimpl, oofakeimpl=os_open_oofakeimpl)
 
+# ------------------------------- os.WIFSIGNALED ------------------------
+# XXX this needs to be generated automatically for all os.W*
+
 if hasattr(os, 'WIFSIGNALED'):
     def fake_WIFSIGNALED(status):
         return int(os.WIFSIGNALED(status))
@@ -154,6 +153,24 @@
     register_external(os.WIFSIGNALED, [int], bool, "ll_os.WIFSIGNALED",
                       llimpl=WIFSIGNALED_lltypeimpl)
 
+# ------------------------------- os.ttyname ----------------------------
+
+if hasattr(os, 'ttyname'):
+    def fake_ttyname(fd):
+        return rffi.str2charp(os.ttyname(fd))
+    
+    os_ttyname = rffi.llexternal('ttyname', [lltype.Signed], rffi.CCHARP,
+                                 _callable=fake_ttyname)
+
+    def ttyname_lltypeimpl(fd):
+        l_name = os_ttyname(fd)
+        if not l_name:
+            raise OSError(rffi.c_errno, "ttyname raised")
+        return rffi.charp2str(l_name)
+
+    register_external(os.ttyname, [int], str, "ll_os.ttyname",
+                      llimpl=ttyname_lltypeimpl)
+
 class BaseOS:
     __metaclass__ = ClassMethods
 
@@ -221,14 +238,6 @@
         return os.system(cls.from_rstr(cmd))
     ll_os_system.suggested_primitive = True
 
-    #def ll_os_execv(cls, cmd, args):
-    #    os.execv(cmd, args)
-    #ll_os_execv.suggested_primitive = True
-
-    #def ll_os_execve(cls, cmd, args, env):
-    #    env_list = from_rdict(env)
-    #    ll_execve(cmd, args, env_list)
-
     def ll_os_unlink(cls, path):
         os.unlink(cls.from_rstr(path))
     ll_os_unlink.suggested_primitive = True

Modified: pypy/dist/pypy/rpython/module/test/test_ll_os.py
==============================================================================
--- pypy/dist/pypy/rpython/module/test/test_ll_os.py	(original)
+++ pypy/dist/pypy/rpython/module/test/test_ll_os.py	Thu Jun 28 10:46:52 2007
@@ -109,3 +109,24 @@
     fn = compile(fun, [int])
     assert fn(0) == False
     assert fn(1) == True
+
+class ExpectTestOs:
+    def setup_class(cls):
+        if not hasattr(os, 'ttyname'):
+            py.test.skip("no ttyname")
+    
+    def test_ttyname(self):
+        import os
+        import py
+        from pypy.translator.c.test.test_genc import compile
+        def f(num):
+            try:
+                return os.ttyname(num)
+            except OSError:
+                return ''
+
+        fn = compile(f, [int])
+        assert f(0) == fn(0)
+        assert fn(338) == ''
+
+    



More information about the Pypy-commit mailing list