[pypy-svn] pypy default: Remove helper function from fcntl which at some point became a space method.

alex_gaynor commits-noreply at bitbucket.org
Sun Mar 6 03:36:27 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r42439:496a59afa455
Date: 2011-03-05 18:35 -0800
http://bitbucket.org/pypy/pypy/changeset/496a59afa455/

Log:	Remove helper function from fcntl which at some point became a space
	method.

diff --git a/pypy/module/fcntl/app_fcntl.py b/pypy/module/fcntl/app_fcntl.py
--- a/pypy/module/fcntl/app_fcntl.py
+++ b/pypy/module/fcntl/app_fcntl.py
@@ -1,12 +1,3 @@
-
-def _conv_descriptor(f):
-    if hasattr(f, "fileno"):
-        return f.fileno()
-    elif isinstance(f, (int, long)):
-        return f
-    else:
-        raise TypeError, "argument must be an int, or have a fileno() method."
-
 __doc__ = """This module performs file control and I/O control on file
 descriptors.  It is an interface to the fcntl() and ioctl() Unix
 routines.  File descriptors can be obtained with the fileno() method of

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
@@ -15,19 +15,19 @@
         ('l_pid', rffi.LONG), ('l_type', rffi.SHORT),
         ('l_whence', rffi.SHORT)])
     has_flock = platform.Has('flock')
-    
+
 # constants, look in fcntl.h and platform docs for the meaning
-# some constants are linux only so they will be correctly exposed outside 
+# some constants are linux only so they will be correctly exposed outside
 # depending on the OS
 constants = {}
 constant_names = ['LOCK_SH', 'LOCK_EX', 'LOCK_NB', 'LOCK_UN', 'F_DUPFD',
     'F_GETFD', 'F_SETFD', 'F_GETFL', 'F_SETFL', 'F_UNLCK', 'FD_CLOEXEC',
-    'LOCK_MAND', 'LOCK_READ', 'LOCK_WRITE', 'LOCK_RW', 'F_GETSIG', 'F_SETSIG', 
+    'LOCK_MAND', 'LOCK_READ', 'LOCK_WRITE', 'LOCK_RW', 'F_GETSIG', 'F_SETSIG',
     'F_GETLK64', 'F_SETLK64', 'F_SETLKW64', 'F_GETLK', 'F_SETLK', 'F_SETLKW',
     'F_GETOWN', 'F_SETOWN', 'F_RDLCK', 'F_WRLCK', 'F_SETLEASE', 'F_GETLEASE',
     'F_NOTIFY', 'F_EXLCK', 'F_SHLCK', 'DN_ACCESS', 'DN_MODIFY', 'DN_CREATE',
     'DN_DELETE', 'DN_RENAME', 'DN_ATTRIB', 'DN_MULTISHOT', 'I_NREAD',
-    'I_PUSH', 'I_POP', 'I_LOOK', 'I_FLUSH', 'I_SRDOPT', 'I_GRDOPT', 'I_STR', 
+    'I_PUSH', 'I_POP', 'I_LOOK', 'I_FLUSH', 'I_SRDOPT', 'I_GRDOPT', 'I_STR',
     'I_SETSIG', 'I_GETSIG', 'I_FIND', 'I_LINK', 'I_UNLINK', 'I_PEEK',
     'I_FDINSERT', 'I_SENDFD', 'I_RECVFD', 'I_SWROPT', 'I_LIST', 'I_PLINK',
     'I_PUNLINK', 'I_FLUSHBAND', 'I_CKBAND', 'I_GETBAND', 'I_ATMARK',
@@ -79,12 +79,6 @@
     w_obj = space.getattr(w_module, space.wrap(obj_name))
     return w_obj
 
-def _conv_descriptor(space, w_f):
-    w_conv_descriptor = _get_module_object(space, "_conv_descriptor")
-    w_fd = space.call_function(w_conv_descriptor, w_f)
-    fd = space.int_w(w_fd)
-    return rffi.cast(rffi.INT, fd)     # C long => C int
-
 def _check_flock_op(space, op):
 
     if op == LOCK_UN:
@@ -114,7 +108,7 @@
     integer corresponding to the return value of the fcntl call in the C code.
     """
 
-    fd = _conv_descriptor(space, w_fd)
+    fd = space.c_filedescriptor_w(w_fd)
     op = rffi.cast(rffi.INT, op)        # C long => C int
 
     try:
@@ -154,7 +148,7 @@
     manual flock(3) for details.  (On some systems, this function is
     emulated using fcntl().)"""
 
-    fd = _conv_descriptor(space, w_fd)
+    fd = space.c_filedescriptor_w(w_fd)
 
     if has_flock:
         rv = c_flock(fd, op)
@@ -196,7 +190,7 @@
     1 - relative to the current buffer position (SEEK_CUR)
     2 - relative to the end of the file (SEEK_END)"""
 
-    fd = _conv_descriptor(space, w_fd)
+    fd = space.c_filedescriptor_w(w_fd)
 
     l = _check_flock_op(space, op)
     if start:
@@ -230,8 +224,8 @@
 
     # XXX this function's interface is a mess.
     # We try to emulate the behavior of Python >= 2.5 w.r.t. mutate_flag
-    
-    fd = _conv_descriptor(space, w_fd)
+
+    fd = space.c_filedescriptor_w(w_fd)
     op = rffi.cast(rffi.INT, op)        # C long => C int
 
     if mutate_flag != 0:

diff --git a/pypy/module/fcntl/test/test_fcntl.py b/pypy/module/fcntl/test/test_fcntl.py
--- a/pypy/module/fcntl/test/test_fcntl.py
+++ b/pypy/module/fcntl/test/test_fcntl.py
@@ -18,32 +18,14 @@
         tmpprefix = str(udir.ensure('test_fcntl', dir=1).join('tmp_'))
         cls.w_tmp = space.wrap(tmpprefix)
 
-    def test_conv_descriptor(self):
-        import fcntl
-        if not hasattr(fcntl, '_conv_descriptor'):
-            skip("PyPy only")
-        
-        f = open(self.tmp + "a", "w+")
-        
-        raises(TypeError, fcntl._conv_descriptor, "foo")
-        raises(TypeError, fcntl._conv_descriptor, 2.0)
-        import cStringIO
-        raises(TypeError, fcntl._conv_descriptor, cStringIO.StringIO())
-        res = fcntl._conv_descriptor(10)
-        res_1 = fcntl._conv_descriptor(f)
-        assert res == 10
-        assert res_1 == f.fileno()
-        
-        f.close()
-
     def test_fcntl(self):
         import fcntl
         import os
         import sys
         import struct
-        
+
         f = open(self.tmp + "b", "w+")
-        
+
         fcntl.fcntl(f, 1, 0)
         fcntl.fcntl(f, 1)
         raises(TypeError, fcntl.fcntl, "foo")
@@ -52,7 +34,7 @@
         assert fcntl.fcntl(f, 1, 0) == 0
         assert fcntl.fcntl(f, 2, "foo") == "foo"
         assert fcntl.fcntl(f, 2, buffer("foo")) == "foo"
-        
+
         try:
             os.O_LARGEFILE
         except AttributeError:
@@ -60,7 +42,7 @@
         else:
             start_len = "qq"
 
-        if sys.platform in ('netbsd1', 'netbsd2', 'netbsd3', 
+        if sys.platform in ('netbsd1', 'netbsd2', 'netbsd3',
                             'Darwin1.2', 'darwin',
                             'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
                             'freebsd6', 'freebsd7', 'freebsd8', 'freebsd9',
@@ -118,15 +100,15 @@
             # with "Inappropriate ioctl for device"
             raises(IOError, fcntl.fcntl, f, fcntl.F_GETOWN)
             raises(IOError, fcntl.fcntl, f, fcntl.F_SETOWN, 20)
-        
+
         f.close()
 
     def test_flock(self):
         import fcntl
         import sys
-        
+
         f = open(self.tmp + "c", "w+")
-        
+
         raises(TypeError, fcntl.flock, "foo")
         raises(TypeError, fcntl.flock, f, "foo")
         fcntl.flock(f, fcntl.LOCK_SH)
@@ -134,22 +116,22 @@
         # LOCK_NB flag was selected.
         raises(IOError, fcntl.flock, f, fcntl.LOCK_NB)
         fcntl.flock(f, fcntl.LOCK_UN)
-        
+
         f.close()
 
     def test_lockf(self):
         import fcntl
-        
+
         f = open(self.tmp + "d", "w+")
-        
+
         raises(TypeError, fcntl.lockf, f, "foo")
         raises(TypeError, fcntl.lockf, f, fcntl.LOCK_UN, "foo")
         raises(ValueError, fcntl.lockf, f, -256)
         raises(ValueError, fcntl.lockf, f, 256)
-        
+
         fcntl.lockf(f, fcntl.LOCK_SH)
         fcntl.lockf(f, fcntl.LOCK_UN)
-        
+
         f.close()
 
     def test_ioctl(self):
@@ -163,7 +145,7 @@
             TIOCGPGRP = 0x40047477
         else:
             skip("don't know how to test ioctl() on this platform")
-        
+
         raises(TypeError, fcntl.ioctl, "foo")
         raises(TypeError, fcntl.ioctl, 0, "foo")
         #raises(TypeError, fcntl.ioctl, 0, TIOCGPGRP, float(0))

diff --git a/pypy/module/fcntl/__init__.py b/pypy/module/fcntl/__init__.py
--- a/pypy/module/fcntl/__init__.py
+++ b/pypy/module/fcntl/__init__.py
@@ -10,10 +10,9 @@
     }
 
     appleveldefs = {
-        '_conv_descriptor': 'app_fcntl._conv_descriptor',
         '__doc__': 'app_fcntl.__doc__'
     }
-    
+
     def buildloaders(cls):
         from pypy.module.fcntl import interp_fcntl
         for constant, value in interp_fcntl.constants.iteritems():


More information about the Pypy-commit mailing list