[pypy-commit] pypy ctypes-byref: test and fix for getting ctypes.byref contents

kostialopuhin noreply at buildbot.pypy.org
Tue Jun 4 11:19:22 CEST 2013


Author: Konstantin Lopuhin <kostia.lopuhin at gmail.com>
Branch: ctypes-byref
Changeset: r64747:3404eb318128
Date: 2013-05-20 00:23 +0400
http://bitbucket.org/pypy/pypy/changeset/3404eb318128/

Log:	test and fix for getting ctypes.byref contents

diff --git a/lib_pypy/_ctypes/pointer.py b/lib_pypy/_ctypes/pointer.py
--- a/lib_pypy/_ctypes/pointer.py
+++ b/lib_pypy/_ctypes/pointer.py
@@ -120,6 +120,7 @@
         return self._buffer[0] != 0
 
     contents = property(getcontents, setcontents)
+    _obj = property(getcontents) # byref interface
 
     def _as_ffi_pointer_(self, ffitype):
         return as_ffi_pointer(self, ffitype)
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_pointers.py b/pypy/module/test_lib_pypy/ctypes_tests/test_pointers.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_pointers.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_pointers.py
@@ -108,6 +108,13 @@
 
             py.test.raises(TypeError, delitem, p, 0)
 
+    def test_byref(self):
+        for ct, pt in zip(ctype_types, python_types):
+            i = ct(42)
+            p = byref(i)
+            assert type(p._obj) is ct
+            assert p._obj.value == 42
+
     def test_pointer_to_pointer(self):
         x = c_int(32)
         y = c_int(42)


More information about the pypy-commit mailing list