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

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Jan 12 19:40:33 CET 2007


Author: cfbolz
Date: Fri Jan 12 19:40:18 2007
New Revision: 36613

Modified:
   pypy/dist/pypy/rpython/module/ll_os.py
   pypy/dist/pypy/rpython/module/test/test_ll_os.py
   pypy/dist/pypy/rpython/module/test/test_posix.py
Log:
adapt dup and dup2 to the new new style and fix the tests


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 Jan 12 19:40:18 2007
@@ -57,32 +57,24 @@
 os_dup.argtypes = [ctypes.c_int]
 os_dup.restype = ctypes.c_int
 
-class DupFuncEntry(ExtFuncEntry):
-    _about_ = os.dup
-    name = "ll_os.ll_os_dup"
-    signature_args = [SomeInteger()]
-    signature_result = SomeInteger()
-
-    def lltypeimpl(fd):
-        newfd = os_dup(fd)
-        if newfd == -1:
-            raise OSError(geterrno(), "dup failed")
-        return newfd
+def dup_lltypeimpl(fd):
+    newfd = os_dup(fd)
+    if newfd == -1:
+        raise OSError(geterrno(), "dup failed")
+    return newfd
+register_external(os.dup, [int], int, llimpl=dup_lltypeimpl,
+                  export_name="ll_os.ll_os_dup")
 
 os_dup2 = libc.dup2
 os_dup2.argtypes = [ctypes.c_int, ctypes.c_int]
 os_dup2.restype = ctypes.c_int
 
-class Dup2FuncEntry(ExtFuncEntry):
-    _about_ = os.dup2
-    name = "ll_os.ll_os_dup2"
-    signature_args = [SomeInteger(), SomeInteger()]
-    signature_result = s_None
-
-    def lltypeimpl(fd, newfd):
-        error = os_dup2(fd, newfd)
-        if error == -1:
-            raise OSError(geterrno(), "dup2 failed")
+def dup2_lltypeimpl(fd, newfd):
+    error = os_dup2(fd, newfd)
+    if error == -1:
+        raise OSError(geterrno(), "dup2 failed")
+register_external(os.dup2, [int, int], s_None, llimpl=dup2_lltypeimpl,
+                  export_name="ll_os.ll_os_dup2")
 
 class BaseOS:
     __metaclass__ = ClassMethods

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	Fri Jan 12 19:40:18 2007
@@ -131,3 +131,19 @@
         else:
             os.waitpid(pid, 0)
         assert open(filename).read() == "1"
+
+def test_dup():
+    from pypy.rpython.extregistry import lookup
+    os_dup = lookup(os.dup).lltypeimpl.im_func
+    testf = udir.join('test.txt')
+    testf.write("foo")
+    path = testf.strpath
+
+    def ff(fi):
+        g = os_dup(fi)
+        return g
+    fi = os.open(path,os.O_RDONLY,0755)
+    g = ff(fi)
+    assert os.fstat(g) == os.fstat(fi)
+
+

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 Jan 12 19:40:18 2007
@@ -22,14 +22,6 @@
         func = self.interpret(f,[])
         assert type(func) == int
 
-    def test_dup(self):
-        def ff(fi):
-            g = posix.dup(fi)
-            return g
-        fi = os.open(path,os.O_RDONLY,0755)
-        g = self.interpret(ff,[fi])
-        assert os.fstat(g) == os.fstat(fi)
-
     def test_fstat(self):
         def fo(fi):
             g = posix.fstat(fi)



More information about the Pypy-commit mailing list