From: Kent Sibilev Date: 2007-04-08T02:08:52+09:00 Subject: Re: rb_yield(), break, and C extensions On 4/7/07, Noah Easterly wrote: > So, I'm working on a C extension. > > One of my C functions uses a callback function, so when I wrap that > function in a method, I pass it a callback function that just wraps a > call to rb_yield(). > > This works great, except that when the block passed to the method > includes a 'break' statement, the end of the C function is bypassed, > and so it can't do its own cleanup. You should wrap your rb_yield call with rb_ensure. From README.EXT: VALUE rb_ensure(VALUE (*func1)(), void *arg1, void (*func2)(), void *arg2) Calls the function func1 with arg1 as the argument, then calls func2 with arg2 if execution terminated. The return value from rb_ensure() is that of func1. -- Kent --- http://www.datanoise.com