Skip to content

Commit

Permalink
add include/ruby/backward/cxxanyargs.hpp
Browse files Browse the repository at this point in the history
Compilation of extension libraries written in C++ are reportedly
broken due to #2404

The root cause of this issue was that the definition of ANYARGS
differ between C and C++, and that of C++ is incompatible with the
updated ones.

We are using the incompatibility against itself.  In C++ two distinct
function prototypes can be overloaded.  We provide the old, ANYARGSed
prototypes in addition to the current granular ones; and let the
older ones warn about types.
  • Loading branch information
shyouhei committed Sep 6, 2019
1 parent d6a94cf commit a569bc0
Show file tree
Hide file tree
Showing 5 changed files with 399 additions and 6 deletions.
18 changes: 15 additions & 3 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,13 +947,27 @@ rb_need_block(void)
VALUE
rb_rescue2(VALUE (* b_proc) (VALUE), VALUE data1,
VALUE (* r_proc) (VALUE, VALUE), VALUE data2, ...)
{
va_list ap;
va_start(ap, data2);
return rb_vrescue2(b_proc, data1, r_proc, data2, ap);
va_end(ap);
}

/*!
* \copydoc rb_rescue2
* \param[in] args exception classes, terminated by 0.
*/
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) {
Expand All @@ -976,14 +990,12 @@ rb_rescue2(VALUE (* b_proc) (VALUE), VALUE data1,
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;
Expand Down
Loading

0 comments on commit a569bc0

Please sign in to comment.