Author: Amaury Forgeot d'Arc <[email protected]>
Branch: more-rposix
Changeset: r74387:aaf7d91a3993
Date: 2014-11-07 21:26 +0100
http://bitbucket.org/pypy/pypy/changeset/aaf7d91a3993/
Log: os.ftruncate(), os.fsync()
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -409,6 +409,26 @@
how = SEEK_END
return handle_posix_error('lseek', c_lseek(fd, pos, how))
+c_ftruncate = external('ftruncate', [rffi.INT, rffi.LONGLONG], rffi.INT,
+ macro=True)
+c_fsync = external('fsync' if not _WIN32 else '_commit', [rffi.INT], rffi.INT)
+c_fdatasync = external('fdatasync', [rffi.INT], rffi.INT)
+
+@replace_os_function('ftruncate')
+def ftruncate(fd, length):
+ validate_fd(fd)
+ handle_posix_error('ftruncate', c_ftruncate(fd, length))
+
+@replace_os_function('fsync')
+def fsync(fd):
+ validate_fd(fd)
+ handle_posix_error('fsync', c_fsync(fd))
+
+@replace_os_function('fdatasync')
+def fdatasync(fd):
+ rposix.validate_fd(fd)
+ handle_posix_error('fdatasync', c_fdatasync(fd))
+
#___________________________________________________________________
c_execv = external('execv', [rffi.CCHARP, rffi.CCHARPP], rffi.INT)
diff --git a/rpython/rtyper/module/ll_os.py b/rpython/rtyper/module/ll_os.py
--- a/rpython/rtyper/module/ll_os.py
+++ b/rpython/rtyper/module/ll_os.py
@@ -173,116 +173,6 @@
separate_module_sources = ["\n".join(defs)]
))
- # a simple, yet useful factory
- def extdef_for_os_function_returning_int(self, name, **kwds):
- c_func = self.llexternal(name, [], rffi.INT, **kwds)
- def c_func_llimpl():
- res = rffi.cast(rffi.SIGNED, c_func())
- if res == -1:
- raise OSError(rposix.get_errno(), "%s failed" % name)
- return res
- c_func_llimpl.func_name = name + '_llimpl'
-
- return extdef([], int, llimpl=c_func_llimpl,
- export_name='ll_os.ll_os_' + name)
-
- def extdef_for_os_function_accepting_int(self, name, **kwds):
- c_func = self.llexternal(name, [rffi.INT], rffi.INT, **kwds)
- def c_func_llimpl(arg):
- res = rffi.cast(rffi.SIGNED, c_func(arg))
- if res == -1:
- raise OSError(rposix.get_errno(), "%s failed" % name)
-
- c_func_llimpl.func_name = name + '_llimpl'
-
- return extdef([int], None, llimpl=c_func_llimpl,
- export_name='ll_os.ll_os_' + name)
-
- def extdef_for_os_function_accepting_2int(self, name, **kwds):
- c_func = self.llexternal(name, [rffi.INT, rffi.INT], rffi.INT, **kwds)
- def c_func_llimpl(arg, arg2):
- res = rffi.cast(rffi.SIGNED, c_func(arg, arg2))
- if res == -1:
- raise OSError(rposix.get_errno(), "%s failed" % name)
-
- c_func_llimpl.func_name = name + '_llimpl'
-
- return extdef([int, int], None, llimpl=c_func_llimpl,
- export_name='ll_os.ll_os_' + name)
-
- def extdef_for_os_function_accepting_0int(self, name, **kwds):
- c_func = self.llexternal(name, [], rffi.INT, **kwds)
- def c_func_llimpl():
- res = rffi.cast(rffi.SIGNED, c_func())
- if res == -1:
- raise OSError(rposix.get_errno(), "%s failed" % name)
-
- c_func_llimpl.func_name = name + '_llimpl'
-
- return extdef([], None, llimpl=c_func_llimpl,
- export_name='ll_os.ll_os_' + name)
-
- def extdef_for_os_function_int_to_int(self, name, **kwds):
- c_func = self.llexternal(name, [rffi.INT], rffi.INT, **kwds)
- def c_func_llimpl(arg):
- res = rffi.cast(rffi.SIGNED, c_func(arg))
- if res == -1:
- raise OSError(rposix.get_errno(), "%s failed" % name)
- return res
-
- c_func_llimpl.func_name = name + '_llimpl'
-
- return extdef([int], int, llimpl=c_func_llimpl,
- export_name='ll_os.ll_os_' + name)
-
-# ------------------------------- os.read -------------------------------
-
- @registering_if(os, 'ftruncate')
- def register_os_ftruncate(self):
- os_ftruncate = self.llexternal('ftruncate',
- [rffi.INT, rffi.LONGLONG], rffi.INT,
macro=True)
-
- def ftruncate_llimpl(fd, length):
- rposix.validate_fd(fd)
- res = rffi.cast(rffi.LONG,
- os_ftruncate(rffi.cast(rffi.INT, fd),
- rffi.cast(rffi.LONGLONG, length)))
- if res < 0:
- raise OSError(rposix.get_errno(), "os_ftruncate failed")
-
- return extdef([int, r_longlong], s_None,
- llimpl = ftruncate_llimpl,
- export_name = "ll_os.ll_os_ftruncate")
-
- @registering_if(os, 'fsync')
- def register_os_fsync(self):
- if not _WIN32:
- os_fsync = self.llexternal('fsync', [rffi.INT], rffi.INT)
- else:
- os_fsync = self.llexternal('_commit', [rffi.INT], rffi.INT)
-
- def fsync_llimpl(fd):
- rposix.validate_fd(fd)
- res = rffi.cast(rffi.SIGNED, os_fsync(rffi.cast(rffi.INT, fd)))
- if res < 0:
- raise OSError(rposix.get_errno(), "fsync failed")
- return extdef([int], s_None,
- llimpl=fsync_llimpl,
- export_name="ll_os.ll_os_fsync")
-
- @registering_if(os, 'fdatasync')
- def register_os_fdatasync(self):
- os_fdatasync = self.llexternal('fdatasync', [rffi.INT], rffi.INT)
-
- def fdatasync_llimpl(fd):
- rposix.validate_fd(fd)
- res = rffi.cast(rffi.SIGNED, os_fdatasync(rffi.cast(rffi.INT, fd)))
- if res < 0:
- raise OSError(rposix.get_errno(), "fdatasync failed")
- return extdef([int], s_None,
- llimpl=fdatasync_llimpl,
- export_name="ll_os.ll_os_fdatasync")
-
@registering_if(os, 'fchdir')
def register_os_fchdir(self):
os_fchdir = self.llexternal('fchdir', [rffi.INT], rffi.INT)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit