Project

General

Profile

Bug #17305 ยป 0001-Fix-rb_rescue2-when-called-with-non-module.patch

jeremyevans0 (Jeremy Evans), 11/17/2020 02:29 AM

View differences:

eval.c
}
}
/*! An equivalent of \c rescue clause.
*
* Equivalent to <code>begin .. rescue err_type .. end</code>
*
* \param[in] b_proc a function which potentially raises an exception.
* \param[in] data1 the argument of \a b_proc
* \param[in] r_proc a function which rescues an exception in \a b_proc.
* \param[in] data2 the first argument of \a r_proc
* \param[in] ... 1 or more exception classes. Must be terminated by \c (VALUE)0.
*
* First it calls the function \a b_proc, with \a data1 as the argument.
* When \a b_proc raises an exception, it calls \a r_proc with \a data2 and
* the exception object if the exception is a kind of one of the given
* exception classes.
*
* \return the return value of \a b_proc if no exception occurs,
* or the return value of \a r_proc if otherwise.
* \sa rb_rescue
* \sa rb_ensure
* \sa rb_protect
* \ingroup exception
/*!
* \copydoc rb_rescue2
* \param[in] args exception classes, terminated by 0.
*/
VALUE
rb_rescue2(VALUE (* b_proc) (ANYARGS), VALUE data1,
VALUE (* r_proc) (ANYARGS), VALUE data2, ...)
static VALUE
rb_vrescue2(VALUE (* b_proc) (VALUE), VALUE data1,
VALUE (* r_proc) (VALUE, VALUE), VALUE data2,
va_list args)
{
enum ruby_tag_type state;
rb_execution_context_t * volatile ec = GET_EC();
rb_control_frame_t *volatile cfp = ec->cfp;
volatile VALUE result = Qfalse;
volatile VALUE e_info = ec->errinfo;
va_list args;
EC_PUSH_TAG(ec);
if ((state = EC_EXEC_TAG()) == TAG_NONE) {
......
int handle = FALSE;
VALUE eclass;
va_init_list(args, data2);
while ((eclass = va_arg(args, VALUE)) != 0) {
if (rb_obj_is_kind_of(ec->errinfo, eclass)) {
handle = TRUE;
break;
}
}
va_end(args);
if (handle) {
result = Qnil;
......
return result;
}
/*! An equivalent of \c rescue clause.
*
* Equivalent to <code>begin .. rescue err_type .. end</code>
*
* \param[in] b_proc a function which potentially raises an exception.
* \param[in] data1 the argument of \a b_proc
* \param[in] r_proc a function which rescues an exception in \a b_proc.
* \param[in] data2 the first argument of \a r_proc
* \param[in] ... 1 or more exception classes. Must be terminated by \c (VALUE)0.
*
* First it calls the function \a b_proc, with \a data1 as the argument.
* When \a b_proc raises an exception, it calls \a r_proc with \a data2 and
* the exception object if the exception is a kind of one of the given
* exception classes.
*
* \return the return value of \a b_proc if no exception occurs,
* or the return value of \a r_proc if otherwise.
* \sa rb_rescue
* \sa rb_ensure
* \sa rb_protect
* \ingroup exception
*/
VALUE
rb_rescue2(VALUE (* b_proc) (ANYARGS), VALUE data1,
VALUE (* r_proc) (ANYARGS), VALUE data2, ...)
{
va_list ap;
va_start(ap, data2);
return rb_vrescue2(b_proc, data1, r_proc, data2, ap);
va_end(ap);
}
/*! An equivalent of \c rescue clause.
*
* Equivalent to <code>begin .. rescue .. end</code>.
    (1-1/1)