[pypy-commit] pypy default: A ll2ctypes bug that depends on the order of the fields in the structure.
amauryfa
noreply at buildbot.pypy.org
Fri Sep 9 01:27:32 CEST 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r47177:d5b0b000a97e
Date: 2011-09-09 01:11 +0200
http://bitbucket.org/pypy/pypy/changeset/d5b0b000a97e/
Log: A ll2ctypes bug that depends on the order of the fields in the
structure. Found while trying to implement PyHeapTypeObject in
cpyext, the equivalent of CPython:: PyHeapTypeObject *type =
malloc(); type->ht_type.tp_as_number = &type->as_number;
diff --git a/pypy/rpython/lltypesystem/test/test_ll2ctypes.py b/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
--- a/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
+++ b/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
@@ -81,6 +81,26 @@
lltype.free(s, flavor='raw')
assert not ALLOCATED # detects memory leaks in the test
+ def test_get_pointer(self):
+ py.test.skip("FIXME")
+ # Equivalent of the C code::
+ # struct S1 { struct S2 *ptr; struct S2 buf; };
+ # struct S1 s1;
+ # s1.ptr = & s1.buf;
+ S2 = lltype.Struct('S2', ('y', lltype.Signed))
+ S1 = lltype.Struct('S',
+ ('sub', lltype.Struct('SUB',
+ ('ptr', lltype.Ptr(S2)))),
+ ('ptr', lltype.Ptr(S2)),
+ ('buf', S2), # Works when this field is first!
+ )
+ s1 = lltype.malloc(S1, flavor='raw')
+ s1.ptr = s1.buf
+ s1.sub.ptr = s1.buf
+
+ x = rffi.cast(rffi.CCHARP, s1)
+ lltype.free(s1, flavor='raw')
+
def test_struct_ptrs(self):
S2 = lltype.Struct('S2', ('y', lltype.Signed))
S1 = lltype.Struct('S', ('x', lltype.Signed), ('p', lltype.Ptr(S2)))
More information about the pypy-commit
mailing list