[pypy-commit] pypy default: cleanup fcntl.flock and fix fcntl.lockf ignoring return value
bdkearns
noreply at buildbot.pypy.org
Sat Dec 15 13:50:10 CET 2012
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r59442:c1024ee7bb9c
Date: 2012-12-13 22:50 -0500
http://bitbucket.org/pypy/pypy/changeset/c1024ee7bb9c/
Log: cleanup fcntl.flock and fix fcntl.lockf ignoring return value
diff --git a/pypy/module/fcntl/interp_fcntl.py b/pypy/module/fcntl/interp_fcntl.py
--- a/pypy/module/fcntl/interp_fcntl.py
+++ b/pypy/module/fcntl/interp_fcntl.py
@@ -74,21 +74,6 @@
return wrap_oserror(space, OSError(errno, funcname),
exception_name = 'w_IOError')
-def _check_flock_op(space, op):
-
- if op == LOCK_UN:
- l_type = F_UNLCK
- elif op & LOCK_SH:
- l_type = F_RDLCK
- elif op & LOCK_EX:
- l_type = F_WRLCK
- else:
- raise OperationError(space.w_ValueError,
- space.wrap("unrecognized flock argument"))
- l = lltype.malloc(_flock.TO, flavor='raw')
- l.c_l_type = rffi.cast(rffi.SHORT, l_type)
- return l
-
@unwrap_spec(op=int, w_arg=WrappedDefault(0))
def fcntl(space, w_fd, op, w_arg):
"""fcntl(fd, op, [arg])
@@ -143,21 +128,14 @@
manual flock(3) for details. (On some systems, this function is
emulated using fcntl().)"""
- fd = space.c_filedescriptor_w(w_fd)
-
if has_flock:
+ fd = space.c_filedescriptor_w(w_fd)
+ op = rffi.cast(rffi.INT, op) # C long => C int
rv = c_flock(fd, op)
if rv < 0:
raise _get_error(space, "flock")
else:
- l = _check_flock_op(space, op)
- rffi.setintfield(l, 'c_l_whence', 0)
- rffi.setintfield(l, 'c_l_start', 0)
- rffi.setintfield(l, 'c_l_len', 0)
- op = [F_SETLKW, F_SETLK][int(bool(op & LOCK_NB))]
- op = rffi.cast(rffi.INT, op) # C long => C int
- fcntl_flock(fd, op, l)
- lltype.free(l, flavor='raw')
+ lockf(space, w_fd, op)
@unwrap_spec(op=int, length=int, start=int, whence=int)
def lockf(space, w_fd, op, length=0, start=0, whence=0):
@@ -187,22 +165,28 @@
fd = space.c_filedescriptor_w(w_fd)
- l = _check_flock_op(space, op)
- if start:
+ if op == LOCK_UN:
+ l_type = F_UNLCK
+ elif op & LOCK_SH:
+ l_type = F_RDLCK
+ elif op & LOCK_EX:
+ l_type = F_WRLCK
+ else:
+ raise OperationError(space.w_ValueError,
+ space.wrap("unrecognized lock operation"))
+
+ op = [F_SETLKW, F_SETLK][int(bool(op & LOCK_NB))]
+ op = rffi.cast(rffi.INT, op) # C long => C int
+
+ l = lltype.malloc(_flock.TO, flavor='raw')
+ try:
+ rffi.setintfield(l, 'c_l_type', l_type)
rffi.setintfield(l, 'c_l_start', int(start))
- else:
- rffi.setintfield(l, 'c_l_start', 0)
- if len:
rffi.setintfield(l, 'c_l_len', int(length))
- else:
- rffi.setintfield(l, 'c_l_len', 0)
-
- l.c_l_whence = rffi.cast(rffi.SHORT, whence)
-
- try:
- op = [F_SETLKW, F_SETLK][int(bool(op & LOCK_NB))]
- op = rffi.cast(rffi.INT, op) # C long => C int
- fcntl_flock(fd, op, l)
+ rffi.setintfield(l, 'c_l_whence', int(whence))
+ rv = fcntl_flock(fd, op, l)
+ if rv < 0:
+ raise _get_error(space, "fcntl")
finally:
lltype.free(l, flavor='raw')
More information about the pypy-commit
mailing list