[pypy-svn] r50348 - in pypy/branch/applevel-ctypes/pypy/module/_ffi: . test

fijal at codespeak.net fijal at codespeak.net
Sat Jan 5 11:24:19 CET 2008


Author: fijal
Date: Sat Jan  5 11:24:19 2008
New Revision: 50348

Modified:
   pypy/branch/applevel-ctypes/pypy/module/_ffi/structure.py
   pypy/branch/applevel-ctypes/pypy/module/_ffi/test/test__ffi.py
Log:
Insert an explicit keepalive of objects passed as arguments to structure
init.


Modified: pypy/branch/applevel-ctypes/pypy/module/_ffi/structure.py
==============================================================================
--- pypy/branch/applevel-ctypes/pypy/module/_ffi/structure.py	(original)
+++ pypy/branch/applevel-ctypes/pypy/module/_ffi/structure.py	Sat Jan  5 11:24:19 2008
@@ -114,8 +114,11 @@
             self.ll_buffer = lltype.malloc(rffi.VOIDP.TO, shape.size, flavor='raw',
                                            zero=True)
         if fieldinits_w:
+            self.fieldinits_w = fieldinits_w
             for field, w_value in fieldinits_w.iteritems():
                 self.setattr(space, field, w_value)
+        else:
+            self.fieldinits_w = None
 
     def getindex(self, space, attr):
         try:

Modified: pypy/branch/applevel-ctypes/pypy/module/_ffi/test/test__ffi.py
==============================================================================
--- pypy/branch/applevel-ctypes/pypy/module/_ffi/test/test__ffi.py	(original)
+++ pypy/branch/applevel-ctypes/pypy/module/_ffi/test/test__ffi.py	Sat Jan  5 11:24:19 2008
@@ -210,9 +210,7 @@
         lib = _ffi.CDLL(self.lib_name)
         inner = lib.ptr("inner_struct_elem", ['P'], 'c')
         X = _ffi.Structure([('x1', 'i'), ('x2', 'h'), ('x3', 'c'), ('next', 'P')])
-        y = X(next=None, x3='x')
-        x = X(next=y, x1=1, x2=2, x3='x')
-        assert inner(x) == 'x'
+        x = X(next=X(next=None, x3='x'), x1=1, x2=2, x3='x')
         assert X(x.next).x3 == 'x'
         create_double_struct = lib.ptr("create_double_struct", [], 'P')
         x = create_double_struct()


More information about the pypy-svn mailing list