[pypy-commit] pypy py3k: Fix fcntl module

amauryfa noreply at buildbot.pypy.org
Wed Oct 19 23:11:08 CEST 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r48235:059c4d141093
Date: 2011-10-19 22:31 +0200
http://bitbucket.org/pypy/pypy/changeset/059c4d141093/

Log:	Fix fcntl module

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
@@ -123,17 +123,22 @@
     except OperationError, e:
         if not e.match(space, space.w_TypeError):
             raise
-    else:
-        ll_arg = rffi.str2charp(arg)
-        rv = fcntl_str(fd, op, ll_arg)
-        arg = rffi.charpsize2str(ll_arg, len(arg))
-        lltype.free(ll_arg, flavor='raw')
-        if rv < 0:
-            raise _get_error(space, "fcntl")
-        return space.wrap(arg)
+        try:
+            arg = space.str_w(w_arg)
+        except OperationError, e:
+            if not e.match(space, space.w_TypeError):
+                raise
+            raise OperationError(space.w_TypeError, space.wrap(
+                    "int or string or buffer required"))
 
-    raise OperationError(space.w_TypeError,
-                         space.wrap("int or string or buffer required"))
+    ll_arg = rffi.str2charp(arg)
+    rv = fcntl_str(fd, op, ll_arg)
+    arg = rffi.charpsize2str(ll_arg, len(arg))
+    lltype.free(ll_arg, flavor='raw')
+    if rv < 0:
+        raise _get_error(space, "fcntl")
+    return space.wrapbytes(arg)
+
 
 @unwrap_spec(op=int)
 def flock(space, w_fd, op):
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
@@ -32,8 +32,8 @@
         raises(TypeError, fcntl.fcntl, f, "foo")
         raises((IOError, ValueError), fcntl.fcntl, -1, 1, 0)
         assert fcntl.fcntl(f, 1, 0) == 0
-        assert fcntl.fcntl(f, 2, "foo") == "foo"
-        assert fcntl.fcntl(f, 2, buffer("foo")) == "foo"
+        assert fcntl.fcntl(f, 2, "foo") == b"foo"
+        assert fcntl.fcntl(f, 2, buffer(b"foo")) == b"foo"
 
         try:
             os.O_LARGEFILE


More information about the pypy-commit mailing list