From: Lyle Johnson Date: 2002-04-05T02:52:17+09:00 Subject: Re: Help: Ruby<->C++ callbacks > Also, now that I knew what to look for, I noticed that SWIG doesn't pass > the "mark" function to Data_Wrap_Struct, only the "free" function... > Lyle, are you reading? Can we do something about this? Or should I inject > the relevant code by hand, instead of relying upon SWIG_NewPointerObj? Actually, I added this feature to SWIG 1.3.12 (i.e. the CVS development version) awhile back and have been meaning to get around to documenting it ;) You can use SWIG's %markfunc directive to specify the name of a "mark" function for a class: %markfunc RubyCallback "RubyCallback_markfunc"; %{ static void RubyCallback_markfunc(void *ptr) { RubyCallback *callback = static_cast(ptr); rb_gc_mark(callback->p_); } %} class RubyCallback { // whatever }; For this example, SWIG should pass the function name "RubyCallback_markfunc" to Data_Wrap_Struct() when it calls that. I'm using this all over the place in FXRuby. Let me know if you run into any trouble with it.