Skip to content

Commit

Permalink
cffilib: Get rid of __del__ and use ffi.gc instead, see Issue #8
Browse files Browse the repository at this point in the history
  • Loading branch information
lazka committed Aug 6, 2014
1 parent 60a5144 commit 0506eca
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pgi/cffilib/gir/gibaseinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

0 comments on commit 0506eca

Please sign in to comment.