[pypy-svn] r45717 - in pypy/branch/pypy-more-rtti-inprogress: rpython rpython/module translator/c translator/c/src translator/c/test

arigo at codespeak.net arigo at codespeak.net
Thu Aug 16 14:08:16 CEST 2007


Author: arigo
Date: Thu Aug 16 14:08:13 2007
New Revision: 45717

Modified:
   pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py
   pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py
   pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py
   pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h
   pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py
Log:
os.ftruncate().  Test large files when translated to C too.


Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py	Thu Aug 16 14:08:13 2007
@@ -151,8 +151,6 @@
 # external function declarations
 posix = __import__(os.name)
 declare(os.isatty   , bool          , 'll_os/isatty')
-if hasattr(posix, 'ftruncate'):
-    declare(os.ftruncate, noneannotation, 'll_os/ftruncate')
 declare(os.system   , int           , 'll_os/system')
 declare(os.strerror , str           , 'll_os/strerror')
 declare(os.unlink   , noneannotation, 'll_os/unlink')

Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py	Thu Aug 16 14:08:13 2007
@@ -372,6 +372,22 @@
                       export_name = "ll_os.ll_os_lseek",
                       oofakeimpl = os_lseek_oofakeimpl)
 
+    if hasattr(os, 'ftruncate'):
+        @registering(os.ftruncate)
+        def register_os_ftruncate(self):
+            os_ftruncate = rffi.llexternal('ftruncate',
+                                           [rffi.INT, rffi.LONGLONG], rffi.INT)
+
+            def ftruncate_lltypeimpl(fd, length):
+                res = os_ftruncate(rffi.cast(rffi.INT, fd),
+                                   rffi.cast(rffi.LONGLONG, length))
+                if res < 0:
+                    raise OSError(rffi.get_errno(), "os_lseek failed")
+
+            self.register(os.ftruncate, [int, r_longlong], s_None,
+                          llimpl = ftruncate_lltypeimpl,
+                          export_name = "ll_os.ll_os_ftruncate")
+
     @registering(os.access)
     def register_os_access(self):
         os_access = rffi.llexternal('access',
@@ -682,10 +698,6 @@
         return os.isatty(fd)
     ll_os_isatty.suggested_primitive = True
 
-    def ll_os_ftruncate(cls, fd,len):
-        return os.ftruncate(fd,len)
-    ll_os_ftruncate.suggested_primitive = True
-
     def ll_os_strerror(cls, errnum):
         return cls.to_rstr(os.strerror(errnum))
     ll_os_strerror.suggested_primitive = True

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py	Thu Aug 16 14:08:13 2007
@@ -21,7 +21,6 @@
 
 EXTERNALS = {
     impl.ll_os_isatty.im_func:  'LL_os_isatty',
-    impl.ll_os_ftruncate.im_func:'LL_os_ftruncate',
     impl.ll_os_strerror.im_func: 'LL_os_strerror',
     impl.ll_os_system.im_func:  'LL_os_system',
     impl.ll_os_unlink.im_func:  'LL_os_unlink',

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h	Thu Aug 16 14:08:13 2007
@@ -73,16 +73,6 @@
     return isatty((int)fd);
 }
 
-#ifdef HAVE_FTRUNCATE
-void LL_os_ftruncate(long fd, long length) { /*XXX add longfile support */
-    int res;
-    res = ftruncate((int)fd, (off_t)length);
-    if (res < 0) {
-	RPYTHON_RAISE_OSERROR(errno);
-    }
-}
-#endif
-
 RPyString *LL_os_strerror(int errnum) {
 	char *res;
 	res = strerror(errnum);

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/test/test_extfunc.py	Thu Aug 16 14:08:13 2007
@@ -2,6 +2,7 @@
 import py
 import os, time, sys
 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.extfunc import EXTERNALS
 posix = __import__(os.name)
@@ -120,6 +121,35 @@
     f1()
     os.unlink(filename)
 
+def test_largefile():
+    if not hasattr(os, 'ftruncate'):
+        py.test.skip("this os has no ftruncate :-(")
+    if os.name == 'nt':
+        py.test.skip("no sparse files on Windows")
+    filename = str(udir.join('test_largefile'))
+    r4800000000  = r_longlong(4800000000L)
+    r4900000000  = r_longlong(4900000000L)
+    r5000000000  = r_longlong(5000000000L)
+    r5200000000  = r_longlong(5200000000L)
+    r9900000000  = r_longlong(9900000000L)
+    r10000000000 = r_longlong(10000000000L)
+    def does_stuff():
+        fd = os.open(filename, os.O_RDWR | os.O_CREAT, 0666)
+        os.ftruncate(fd, r10000000000)
+        res = os.lseek(fd, r9900000000, 0)
+        assert res == r9900000000
+        res = os.lseek(fd, -r5000000000, 1)
+        assert res == r4900000000
+        res = os.lseek(fd, -r5200000000, 2)
+        assert res == r4800000000
+        os.close(fd)
+        st = os.stat(filename)
+        assert st.st_size == r10000000000
+    does_stuff()
+    os.unlink(filename)
+    f1 = compile(does_stuff, [])
+    f1()
+    os.unlink(filename)
 
 def test_os_access():
     filename = str(py.magic.autopath())



More information about the Pypy-commit mailing list