overload rb_protect

  • Thread starter Thomas Sondergaard
  • Start date
T

Thomas Sondergaard

To use rb_protect you have to wrap the function you want to protect so it
accepts a single VALUE parameter. Would it not make sense to overload
rb_protect, so it could protect the three normal signatures for ruby
methods, ie:

1) VALUE func(VALUE self[, VALUE arg1, VALUE arg2, ...]);
2) VALUE func(int argc, VALUE *argv, VALUE self);
3) VALUE func(VALUE self, VALUE args);

The existing rb_protect(VALUE (*proc)(VALUE), VALUE data, int *state)
matches the third of the common signatures, so if

VALUE rb_protect2(int *state, VALUE (*proc)(ANYARGS), VALUE self, ...);

and

VALUE rb_protect3(int *state, VALUE (*proc)(int, VALUE*, VALUE), int argc,
VALUE *argv, VALUE self);

were added it would be easier to do exception handling in C. Doesn't that
make good sense? Or maybe rb_protect could be macroized, so you could do
something like

RB_EXCEPTION_INIT // declare int exception_state among other things
RB_TRY
... do something that you want to protect here
RB_RESCUE
... examine exception_state here

Hm, okay, maybe not :)

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,135
Messages
2,570,783
Members
47,341
Latest member
hanifree

Latest Threads

Top