From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-07-24T00:05:52+09:00 Subject: Re: Embedding problem - SEGV On Thu, 24 Jul 2003 00:49:04 +0900, Brian Candler wrote: > On Wed, Jul 23, 2003 at 10:58:55PM +0900, Brian Candler wrote: >> If I still want a regular Ruby exception report printed, after catching it, >> is there a function I can call? I don't know if this can be useful to you ? http://metaeditor.sourceforge.net/embed/#id2841406 [snip] > It looks like I'm going to have to split all these functions into two: one > to do the Ruby work, and one to call it using rb_protect (and pass a struct* > between the two if there's more than one argument), purely to prevent the > coredumps. This is pretty nasty. Before now, it was looking that back-ruby > was going to be much cleaner than back-perl :-( You could do like this C++ code: /* ------------------------------ wrap rb_funcall ------------------------------ */ struct Arguments { VALUE recv; ID id; int n; VALUE *argv; Arguments(VALUE recv, ID id, int n, VALUE *argv) : recv(recv), id(id), n(n), argv(argv) { } }; VALUE FuncallWrap(VALUE arg) { Arguments &a = *reinterpret_cast(arg); return rb_funcall2(a.recv, a.id, a.n, a.argv); } /* purpose: call a ruby function in a safe way. translate ruby errors into c++ exceptions. VALUE Unsafe() { return rb_funcall( self, rb_intern("test"), 1, INT2NUM(42) ); } VALUE Safe() { return RUBY_CPP::Funcall( self, rb_intern("test"), 1, INT2NUM(42) ); } */ VALUE Funcall(VALUE recv, ID id, int n, ...) { VALUE *argv = 0; if (n > 0) { argv = ALLOCA_N(VALUE, n); va_list ar; va_start(ar, n); int i; for(i=0;i(&arg), &error); if(error) throw RubyError::Create("cannot invoke ruby-function"); return result; } -- Simon Strandgaard