Author: Matti Picus <matti.pi...@gmail.com> Branch: Changeset: r92928:9d22ff3be2ae Date: 2017-11-04 20:07 +0200 http://bitbucket.org/pypy/pypy/changeset/9d22ff3be2ae/
Log: graft parts of 287c9946859b that provide rposix.lockf in rpython diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py --- a/rpython/rlib/rposix.py +++ b/rpython/rlib/rposix.py @@ -276,6 +276,10 @@ SCHED_OTHER = rffi_platform.DefinedConstantInteger('SCHED_OTHER') SCHED_BATCH = rffi_platform.DefinedConstantInteger('SCHED_BATCH') O_NONBLOCK = rffi_platform.DefinedConstantInteger('O_NONBLOCK') + F_LOCK = rffi_platform.DefinedConstantInteger('F_LOCK') + F_TLOCK = rffi_platform.DefinedConstantInteger('F_TLOCK') + F_ULOCK = rffi_platform.DefinedConstantInteger('F_ULOCK') + F_TEST = rffi_platform.DefinedConstantInteger('F_TEST') OFF_T = rffi_platform.SimpleType('off_t') OFF_T_SIZE = rffi_platform.SizeOf('off_t') @@ -548,6 +552,14 @@ if error != 0: raise OSError(error, 'posix_fadvise failed') + c_lockf = external('lockf', + [rffi.INT, rffi.INT , OFF_T], rffi.INT, + save_err=rffi.RFFI_SAVE_ERRNO) + @enforceargs(int, None, None) + def lockf(fd, cmd, length): + validate_fd(fd) + return handle_posix_error('lockf', c_lockf(fd, cmd, length)) + c_ftruncate = external('ftruncate', [rffi.INT, rffi.LONGLONG], rffi.INT, macro=_MACRO_ON_POSIX, save_err=rffi.RFFI_SAVE_ERRNO) c_fsync = external('fsync' if not _WIN32 else '_commit', [rffi.INT], rffi.INT, diff --git a/rpython/rlib/test/test_rposix.py b/rpython/rlib/test/test_rposix.py --- a/rpython/rlib/test/test_rposix.py +++ b/rpython/rlib/test/test_rposix.py @@ -816,3 +816,14 @@ if sys.platform != 'win32': rposix.sched_yield() +@rposix_requires('lockf') +def test_os_lockf(): + fname = str(udir.join('os_test.txt')) + fd = os.open(fname, os.O_WRONLY | os.O_CREAT, 0777) + try: + os.write(fd, b'test') + os.lseek(fd, 0, 0) + rposix.lockf(fd, rposix.F_LOCK, 4) + rposix.lockf(fd, rposix.F_ULOCK, 4) + finally: + os.close(fd) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit