From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-04-11T01:05:08+09:00 Subject: Re: embedding ruby with swig On Thu, 10 Apr 2003 08:33:10 +0000, Steve Hart wrote: > Thanks for the reply - sorry if I kept you up! The hardest part of my day is when I have to move myself from the computer over to my bed (2 meters). I hate sleeping :-) > I think I've sussed the problem and oh dear, how stupid could I be! > The problem I had was that even though the mark function gets called > so does free immediately afterwards. This is because i declare tObj > once, pass a reference to rb_gc_register_address and then next time > round the loop just overwrite it. I am not sure about the purpose of your code. guess: an experiment to see what happens when GC kicks in. Thats a rather complicated proof of concept you have. I have done some experiments too, try http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/metaeditor/experiments/cpp_embed_ruby/test/garbage/ maybe I should add it to the tutorial ??? [snip maip.cpp] variable-declarations = street-respect :-) I think you have gotton out on a off-track. Both malloc/free and marking is unnecessary. I know you really want to use rb_gc_mark(), but you are not in the situation where its necessary to mark your children. You are using it to mark non-children...mark is not supposed to be used in that way. > I'm a bit doubtful about the malloc - should I do something different > here? > It all works though > I also had to change the mark and free functions in swig to: [snip swig.i] > I'm also unsure regarding the static_cast. I've seen examples using > static_cast,dynamic_cast,reinterpret_cast and no cast at all. http://cpptips.hyperformix.com/cpptips/cast_overview > I'm still unclear on one issue though. I supply a mark function for > swig and > sure enough this gets called now, so why do I have to register the > object (tObj) on the c++ side? I think you should see the example that mentioned earlier, this should hopefully make it a bit more clear for you. -- Simon Strandgaard