[pypy-svn] r36569 - in pypy/dist/pypy: rpython rpython/module translator/c translator/c/src

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Jan 12 14:05:53 CET 2007


Author: cfbolz
Date: Fri Jan 12 14:05:52 2007
New Revision: 36569

Modified:
   pypy/dist/pypy/rpython/extfunctable.py
   pypy/dist/pypy/rpython/module/ll_os.py
   pypy/dist/pypy/translator/c/extfunc.py
   pypy/dist/pypy/translator/c/src/ll_os.h
Log:
rewrite dup and dup2 in the new style


Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py	(original)
+++ pypy/dist/pypy/rpython/extfunctable.py	Fri Jan 12 14:05:52 2007
@@ -195,8 +195,6 @@
 declare(os.read     , str           , 'll_os/read')
 declare(os.write    , posannotation , 'll_os/write')
 declare(os.close    , noneannotation, 'll_os/close')
-declare(os.dup      , int           , 'll_os/dup')
-declare(os.dup2     , noneannotation, 'll_os/dup2')
 declare(os.access   , int           , 'll_os/access')
 declare(os.lseek    , r_longlong    , 'll_os/lseek')
 declare(os.isatty   , bool          , 'll_os/isatty')

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 14:05:52 2007
@@ -21,7 +21,8 @@
 from pypy.tool.staticmethods import ClassMethods
 import stat
 from pypy.rpython.extfunc import ExtFuncEntry
-from pypy.annotation.model import SomeString, s_ImpossibleValue
+from pypy.annotation.model import SomeString, SomeInteger, s_ImpossibleValue, \
+    s_None
 from pypy.annotation.listdef import s_list_of_strings
 import ctypes
 import pypy.rpython.rctypes.implementation
@@ -55,6 +56,37 @@
             os_execv(path, array)
             raise OSError(geterrno(), "execv failed")
 
+os_dup = libc.dup
+os_dup.argtypes = [ctypes.c_int]
+os_dup.restype = ctypes.c_int
+
+class DupFuncEntry(ExtFuncEntry):
+    _about_ = os.dup
+    name = "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
+
+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_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")
+
 class BaseOS:
     __metaclass__ = ClassMethods
 

Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/extfunc.py	Fri Jan 12 14:05:52 2007
@@ -28,8 +28,6 @@
     impl.ll_read_into:          'LL_read_into', # it's a staticmethod
     impl.ll_os_write.im_func:   'LL_os_write',
     impl.ll_os_close.im_func:   'LL_os_close',
-    impl.ll_os_dup.im_func:     'LL_os_dup',
-    impl.ll_os_dup2.im_func:    'LL_os_dup2',
     impl.ll_os_access.im_func:  'LL_os_access',
     impl.ll_os_stat.im_func:    'LL_os_stat',
     impl.ll_os_fstat.im_func:   'LL_os_fstat',

Modified: pypy/dist/pypy/translator/c/src/ll_os.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/ll_os.h	(original)
+++ pypy/dist/pypy/translator/c/src/ll_os.h	Fri Jan 12 14:05:52 2007
@@ -55,8 +55,6 @@
 long LL_read_into(int fd, RPyString *buffer);
 long LL_os_write(int fd, RPyString *buffer);
 void LL_os_close(int fd);
-int LL_os_dup(int fd);
-void LL_os_dup2(int old_fd, int new_fd);
 int LL_os_access(RPyString *filename, int mode);
 RPySTAT_RESULT* _stat_construct_result_helper(STRUCT_STAT st);
 RPySTAT_RESULT* LL_os_stat(RPyString * fname);
@@ -136,21 +134,6 @@
 		RPYTHON_RAISE_OSERROR(errno);
 }
 
-int LL_os_dup(int fd)
-{
-	fd = dup(fd);
-	if (fd < 0)
-		RPYTHON_RAISE_OSERROR(errno);
-	return fd;
-}
-
-void LL_os_dup2(int old_fd, int new_fd)
-{
-	new_fd = dup2(old_fd, new_fd);
-	if (new_fd < 0)
-		RPYTHON_RAISE_OSERROR(errno);
-}
-
 int LL_os_access(RPyString *filename, int mode) {
 	int n = access(RPyString_AsString(filename), mode);
 	return (n == 0);



More information about the Pypy-commit mailing list