Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r57374:d3f714e26354
Date: 2012-09-18 16:01 +0200
http://bitbucket.org/pypy/pypy/changeset/d3f714e26354/

Log:    Test and fix. That took far too long to find :-(((

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
@@ -81,7 +81,9 @@
         addr = self._buffer[0]
         if addr == 0:
             raise ValueError("NULL pointer access")
-        return self._type_.from_address(addr)
+        instance = self._type_.from_address(addr)
+        instance.__dict__['_base'] = self
+        return instance
 
     def setcontents(self, value):
         if not isinstance(value, self._type_):
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py 
b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py
@@ -433,6 +433,14 @@
         obj = X()
         assert isinstance(obj.items, Array)
 
+    def test_b_base(self):
+        # _b_base_ used to be None here in PyPy
+        class X(Structure):
+            _fields_ = [('x', c_int)]
+        obj = X()
+        p = pointer(obj)
+        assert p.contents._b_base_ is p
+
 class TestPointerMember(BaseCTypesTestChecker):
 
     def test_1(self):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to