Skip to content

Commit

Permalink
Fix clang build for Ruby 2.6
Browse files Browse the repository at this point in the history
While RUBY_METHOD_FUNC causes problems with newer Rubies, it's still
needed under Ruby 2.6 with clang.  We'll define our own macro to
make it a no-op under Ruby 2.7+.

Tested with clang 10.0.0-4ubuntu1, 11.0.0-2~ubuntu20.04.1, and
12.0.0-3ubuntu1~20.04.4 on Ubuntu 20.04.3 LTS (x86-64).

Fixes: 7a16ef8 ("remove RUBY_METHOD_FUNC use")
Fixes: #223
  • Loading branch information
SamSaffron committed Jan 16, 2022
1 parent 55f6b27 commit 289587a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ext/mini_racer_extension/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,9 @@
$LDFLAGS.insert(0, " -fsanitize=address ")
end

# there doesn't seem to be a CPP macro for this in Ruby 2.6:
if RUBY_ENGINE == 'ruby'
$CPPFLAGS += ' -DENGINE_IS_CRUBY '
end

create_makefile 'mini_racer_extension'
13 changes: 11 additions & 2 deletions ext/mini_racer_extension/mini_racer_extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <ruby.h>
#include <ruby/thread.h>
#include <ruby/io.h>
#include <ruby/version.h>
#include <v8.h>
#include <v8-profiler.h>
#include <libplatform/libplatform.h>
Expand All @@ -13,6 +14,14 @@
#include <math.h>
#include <errno.h>

/* workaround C Ruby <= 2.x problems w/ clang in C++ mode */
#if defined(ENGINE_IS_CRUBY) && \
RUBY_API_VERSION_MAJOR == 2 && RUBY_API_VERSION_MINOR <= 6
# define MR_METHOD_FUNC(fn) RUBY_METHOD_FUNC(fn)
#else
# define MR_METHOD_FUNC(fn) fn
#endif

using namespace v8;

typedef struct {
Expand Down Expand Up @@ -1285,8 +1294,8 @@ gvl_ruby_callback(void* data) {
VALUE callback_data_value = (VALUE)&callback_data;

// TODO: use rb_vrescue2 in Ruby 2.7 and above
result = rb_rescue2(protected_callback, callback_data_value,
rescue_callback, callback_data_value, rb_eException, (VALUE)0);
result = rb_rescue2(MR_METHOD_FUNC(protected_callback), callback_data_value,
MR_METHOD_FUNC(rescue_callback), callback_data_value, rb_eException, (VALUE)0);

if(callback_data.failed) {
rb_iv_set(parent, "@current_exception", result);
Expand Down

0 comments on commit 289587a

Please sign in to comment.