From: Luigi Ballabio Date: 2002-04-05T00:42:14+09:00 Subject: Re: Help: Ruby<->C++ callbacks Guy, thanks a lot for the reply. The scaffolding is not a big problem: I'm using SWIG to export the stuff, so the class destructor is automatically passed to Data_[Wrap|Make]_Struct as the mark function, so I can put there a call to rb_gc_mark for the proc. What I'm concerned about is the following scenario: // the Callback constructor makes a copy of the VALUE pointing to // the proc and stores it away, but the Ruby interpreter doesn't know. irb> c = Callback.new(proc { puts "Hello World!" }) // for all I know, here the interpreter could decide to gc the // proc object since the only reference that it saw is already // out of scope // therefore, the following call could try to use a pointer to // a gc'ed object and fail spectacularly. irb> c.doit Goodbye, cruel world. The question really was, how do I tell the interpreter that I'm holding a reference to a Ruby object from C++? Thanks again, Luigi