From 0506eca5911592da6f273cc14e51597c5ecae31f Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Wed, 6 Aug 2014 14:42:58 +0200 Subject: [PATCH] cffilib: Get rid of __del__ and use ffi.gc instead, see Issue #8 --- pgi/cffilib/gir/gibaseinfo.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pgi/cffilib/gir/gibaseinfo.py b/pgi/cffilib/gir/gibaseinfo.py index 4870b6c..ba5a7a3 100644 --- a/pgi/cffilib/gir/gibaseinfo.py +++ b/pgi/cffilib/gir/gibaseinfo.py @@ -25,12 +25,24 @@ def _g_info_type_to_string(self): GIInfoType.string = property(_g_info_type_to_string) +def _destructor(cdata): + if cdata: + lib.g_base_info_unref(cdata) + + class GIBaseInfo(object): __types = {} - def __init__(self, ptr, unref=True): + def __init__(self, ptr, take_ownership=True): self._ptr = ptr - self._unref = unref + + if take_ownership: + self._gc = ffi.gc(ptr, self._destructor) + + @staticmethod + def _destructor(cdata): + if cdata: + lib.g_base_info_unref(cdata) @classmethod def _register(cls, info_type): @@ -117,7 +129,3 @@ def __neq__(self, other): def __repr__(self): return "<%s namespace=%r name=%r>" % ( type(self).__name__, self.namespace, self.name) - - def __del__(self): - if self._ptr and self._unref: - self.unref()