>>>>> "T" == Tobin Baker <senderista / hotmail.com> writes:

T> I'm trying to solve the problem of how to trap a Ruby exception from a
T> C call to a Ruby method.

 Probably I've not understood what you want to do, but I'll write something
 like this

T> static VALUE
T> rorbit_apply_try(VALUE packed_args)
T> {
T>     int argc;
T>     VALUE *argv;
T>     VALUE recv;
T>     VALUE sym;
T>     VALUE args;

T>     Check_Type(packed_args, T_ARRAY);
T>     argc = RARRAY(packed_args)->len;
T>     argv = RARRAY(packed_args)->ptr;
T>     rb_scan_args(argc, argv, "3", &recv, &sym, &args);
T>     Check_Type(args, T_ARRAY);
T>     return rb_apply(recv, SYM2ID(sym), args);
T> }

[...]

T> // use rb_rescue to catch exception
T>     VALUE packed_args = rb_ary_new3(3, servant->impl,
T> ID2SYM(rb_intern(name)), args);

       VALUE result;
       VALUE packed_args = 
          rb_ary_new3(3, servant->impl, ID2SYM(rb_intern(name)), args);
       int state = 0;

       result = rb_protect(rorbit_apply_try, packed_args, &state);
       if (state) {
          result = rb_gv_get("$!");
          /* do what you want */
       }


Guy Decoux