How is rb_protect supposed to work?


(Jens Nissen) #1

I have embedded Ruby into my application and got the following problem:
I have a Script
which calls "load"
the loaded Script calls my C-Extension-Function foo,
which calls with rb_protect a Ruby function.
This Ruby-function throws an exception and
C-function returns nicely because rb_protect handles it.
script terminates
(“load”) rb_load terminates and throws the exception again (!!! surprise
!!!)
because it was stored in the global variable ruby_errinfo

Quote from rb_load(fname, wrap) in eval.c:
if (!NIL_P(ruby_errinfo)) /* exception during load */
rb_exc_raise(ruby_errinfo);

(a) Is this intentional?
(a1) If so, what else can I call instead of rb_protect, which clears the
error!?

(b) Did I do something wrong with my embedding of Ruby, some PUSH_TAG
or whatever, so that this problem is only in “my” extended Ruby?

Kind regards to all,

Jens


(Yukihiro Matsumoto) #2

Hi,

I have embedded Ruby into my application and got the following problem:
I have a Script
which calls "load"
the loaded Script calls my C-Extension-Function foo,
which calls with rb_protect a Ruby function.
This Ruby-function throws an exception and
C-function returns nicely because rb_protect handles it.

         put "ruby_errinfo = Qnil;" here to clear.
  script terminates

(“load”) rb_load terminates and throws the exception again (!!! surprise
!!!)
because it was stored in the global variable ruby_errinfo

rb_protect() is a primitive. rb_rescue() clears ruby_errinfo
automagically.

						matz.
···

In message “How is rb_protect supposed to work?” on 02/06/18, “Jens Nissen” frodo.hobbit@gmx.net writes: