[pypy-commit] pypy cffi-1.0: Grumble, figured out that the reason we get sometimes unexpected objects
arigo
noreply at buildbot.pypy.org
Fri May 8 15:57:34 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r77211:8d28e47f70b9
Date: 2015-05-08 15:57 +0200
http://bitbucket.org/pypy/pypy/changeset/8d28e47f70b9/
Log: Grumble, figured out that the reason we get sometimes unexpected
objects staying alive is that there is a cycle involving
W_FFIObject. As it also has a destructor, on CPython it ends up in
gc.garbage.
diff --git a/pypy/module/_cffi_backend/ffi_obj.py b/pypy/module/_cffi_backend/ffi_obj.py
--- a/pypy/module/_cffi_backend/ffi_obj.py
+++ b/pypy/module/_cffi_backend/ffi_obj.py
@@ -24,22 +24,27 @@
return w_ffitype.getdictvalue(space, 'error')
+class FreeCtxObj(object):
+ def __init__(self, ctxobj):
+ self.ctxobj = ctxobj
+ @rgc.must_be_light_finalizer
+ def __del__(self):
+ parse_c_type.free_ctxobj(self.ctxobj)
+
+
class W_FFIObject(W_Root):
def __init__(self, space, src_ctx=parse_c_type.NULL_CTX):
self.space = space
self.types_dict = {}
self.ctxobj = parse_c_type.allocate_ctxobj(src_ctx)
+ self._finalizer = FreeCtxObj(self.ctxobj)
if src_ctx:
self.cached_types = [None] * parse_c_type.get_num_types(src_ctx)
else:
self.cached_types = None
self.w_FFIError = get_ffi_error(space)
- @rgc.must_be_light_finalizer
- def __del__(self):
- parse_c_type.free_ctxobj(self.ctxobj)
-
@jit.elidable
def parse_string_to_type(self, string, flags):
try:
diff --git a/pypy/module/_cffi_backend/newtype.py b/pypy/module/_cffi_backend/newtype.py
--- a/pypy/module/_cffi_backend/newtype.py
+++ b/pypy/module/_cffi_backend/newtype.py
@@ -45,6 +45,7 @@
return x
def _clean_cache(space):
+ "NOT_RPYTHON"
space.fromcache(UniqueCache).__init__(space)
# ____________________________________________________________
More information about the pypy-commit
mailing list