From 13423bbbafc823740126e90ef0d7ca6e76fc7341 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sun, 21 Jun 2009 19:47:31 +0200 Subject: python: Make all CppOwnedPyObjects and similar support garbage collection. If you want to subclass apt_pkg.Cache() and create an apt_pkg.DepCache() object in it (e.g. as self.depcache) this is needed because otherwise, Python would not know about the cyclic dependency and refuse to free any of them. This also changes apt_pkg.Cache to the standard deallocation schema, because the underlying CacheFile deletes its pointers automatically on deletion. Thus a second call is not needed. --- python/depcache.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'python/depcache.cc') diff --git a/python/depcache.cc b/python/depcache.cc index 7cf8e0a2..d0b233b8 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -677,10 +677,11 @@ PyTypeObject PkgDepCacheType = 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags - Py_TPFLAGS_BASETYPE), + Py_TPFLAGS_BASETYPE | + Py_TPFLAGS_HAVE_GC), doc_PkgDepCache, // tp_doc - 0, // tp_traverse - 0, // tp_clear + CppOwnedTraverse, // tp_traverse + CppOwnedClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -866,10 +867,11 @@ PyTypeObject PkgProblemResolverType = 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags - Py_TPFLAGS_BASETYPE), + Py_TPFLAGS_BASETYPE | + Py_TPFLAGS_HAVE_GC), "ProblemResolver Object", // tp_doc - 0, // tp_traverse - 0, // tp_clear + CppOwnedTraverse, // tp_traverse + CppOwnedClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -984,10 +986,11 @@ PyTypeObject PkgActionGroupType = 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags - Py_TPFLAGS_BASETYPE), + Py_TPFLAGS_BASETYPE | + Py_TPFLAGS_HAVE_GC), doc_PkgActionGroup, // tp_doc - 0, // tp_traverse - 0, // tp_clear + CppOwnedTraverse, // tp_traverse + CppOwnedClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset 0, // tp_iter @@ -1002,7 +1005,7 @@ PyTypeObject PkgActionGroupType = 0, // tp_dictoffset 0, // tp_init 0, // tp_alloc - PkgActionGroupNew, // tp_new + PkgActionGroupNew, // tp_new }; #ifdef COMPAT_0_7 -- cgit v1.2.3