[pypy-commit] pypy ffistruct: don't track the allocation of ffistruct, on cpython it might go to gc.garbage
antocuni
noreply at buildbot.pypy.org
Tue May 15 14:45:02 CEST 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: ffistruct
Changeset: r55102:b88f00a63c19
Date: 2012-05-15 12:22 +0200
http://bitbucket.org/pypy/pypy/changeset/b88f00a63c19/
Log: don't track the allocation of ffistruct, on cpython it might go to
gc.garbage
diff --git a/pypy/module/_ffi/interp_struct.py b/pypy/module/_ffi/interp_struct.py
--- a/pypy/module/_ffi/interp_struct.py
+++ b/pypy/module/_ffi/interp_struct.py
@@ -51,7 +51,7 @@
@must_be_light_finalizer
def __del__(self):
if self.ffistruct:
- lltype.free(self.ffistruct, flavor='raw')
+ lltype.free(self.ffistruct, flavor='raw', track_allocation=True)
class W__StructDescr(Wrappable):
@@ -79,7 +79,12 @@
for w_field in fields_w:
field_types.append(w_field.w_ffitype.get_ffitype())
self.name2w_field[w_field.name] = w_field
- ffistruct = clibffi.make_struct_ffitype_e(size, alignment, field_types)
+ #
+ # on CPython, the FFIStructOwner might go into gc.garbage and thus the
+ # __del__ never be called. Thus, we don't track the allocation of the
+ # malloc done inside this function, else the leakfinder might complain
+ ffistruct = clibffi.make_struct_ffitype_e(size, alignment, field_types,
+ track_allocation=False)
self.w_ffitype.set_ffitype(ffistruct.ffistruct)
self._ffistruct_owner = FFIStructOwner(ffistruct)
diff --git a/pypy/rlib/clibffi.py b/pypy/rlib/clibffi.py
--- a/pypy/rlib/clibffi.py
+++ b/pypy/rlib/clibffi.py
@@ -347,11 +347,12 @@
('ffistruct', FFI_TYPE_P.TO),
('members', lltype.Array(FFI_TYPE_P))))
-def make_struct_ffitype_e(size, aligment, field_types):
+def make_struct_ffitype_e(size, aligment, field_types, track_allocation=True):
"""Compute the type of a structure. Returns a FFI_STRUCT_P out of
which the 'ffistruct' member is a regular FFI_TYPE.
"""
- tpe = lltype.malloc(FFI_STRUCT_P.TO, len(field_types)+1, flavor='raw')
+ tpe = lltype.malloc(FFI_STRUCT_P.TO, len(field_types)+1, flavor='raw',
+ track_allocation=track_allocation)
tpe.ffistruct.c_type = rffi.cast(rffi.USHORT, FFI_TYPE_STRUCT)
tpe.ffistruct.c_size = rffi.cast(rffi.SIZE_T, size)
tpe.ffistruct.c_alignment = rffi.cast(rffi.USHORT, aligment)
More information about the pypy-commit
mailing list