From: Nobuyoshi Nakada Date: 2007-04-10T09:29:20+09:00 Subject: Re: rb_yield(), break, and C extensions Hi, At Mon, 9 Apr 2007 09:40:07 +0900, Noah Easterly wrote in [ruby-talk:247204]: > So the original definition of func (which allocated memory, used the > callback, freed memory, and didn't use ruby.h) won't work, I need to > divide that into 3 parts (one to alloc, one that uses the callback, > and one to free), and do something like: You can use rb_protect() and rb_jump_tag() too. > static VALUE > my_meth(VALUE self) > { > MyType * my_type = AllocMyType(); int status; VALUE result = rb_protect(DoStuff, (VALUE)my_type, &status); FreeMyType(my_type); if (status) rb_jump_tag(status); return result; > } The way to do all in one function is not provieded. -- Nobu Nakada