On Wed, 2011-06-22 at 08:19 +0200, Jakub Jelinek wrote: > Hi! > > On Tue, Jun 21, 2011 at 07:52:27PM -0400, David Malcolm wrote: > > I'm not yet familiar with the details of the gcc GC, but it appears that > > GTY() annotations are preprocessed to generate traversal code used by a > > mark-and-sweep algorithm. > > > > Python's own GC allows for classes to opt-in as reference-owners; > > instances of such classes get tracked within linked lists (one per > > generation of Python's GC). This is intended for use for tracking > > PyObject* references, but I may be able to piggy-back off of this - if I > > add the relevant flag to my wrapper classes then they get tracked in > > these linked lists. I can then register a callback to > > PLUGIN_GGC_MARKING that uses this to locate the subset of all PyObject* > > objects that wrap GCC objects. This could then mark all of the wrapped > > GCC objects referenced from Python. That way all of the Python wrapper > > objects can be found as roots within a GCC GC, and thus not have their > > wrapped GCC objects deleted "from under them" (traversing any refs they > > in turn keep alive, of course). > > You could just: > #include "ggc.h" > > static void my_walker (void *arg ATTRIBUTE_UNUSED) > { > /* Ignore argument, as it is dummy */ > /* Walk all the still live python objects here and if they reference > GCC GC objects, call > ggc_test_and_set_mark (ptr); > on each of them. */ > } > > static struct ggc_root_tab myroot = { "", 1, 1, my_walker, NULL }; > > ... > init_plugin (...) > { > ... > ggc_register_root_tab (&myroot); > ... > } > > No need for gengtype for this, unless you want to use GTY(()) markup > inside of your plugin.
[replying to 6-month old thread about integrating the Python plugin with GCC's garbage collector] Thanks. FWIW, I implemented something like this in http://git.fedorahosted.org/git/?p=gcc-python-plugin.git;a=commitdiff;h=58d65a1b353220efbcf8d908b0946ef5d1c4fafd which iterates over all live wrapper objects calling gt_ggc_mx_NAME_OF_TYPE() on each wrapped object, which I hope is the correct approach [it seems to work: the selftest puts the machinery into verbose mode, and then verifies this log: http://git.fedorahosted.org/git/?p=gcc-python-plugin.git;a=blob;f=tests/plugin/gc/_gc_selftest/stdout.txt;hb=HEAD ] Hope this is helpful Dave