From 62e3e64ce8c24ebc560a72e204ce1b61eaf56e26 Mon Sep 17 00:00:00 2001 From: Jerry D'Antonio Date: Wed, 30 Jul 2014 10:36:59 -0400 Subject: [PATCH] Fixed problems preventing C extensions from building on some platforms. --- ext/concurrent_ruby_ext/atomic_boolean.c | 2 +- ext/concurrent_ruby_ext/atomic_fixnum.c | 2 +- ext/concurrent_ruby_ext/common.h | 13 --------- ext/concurrent_ruby_ext/ruby_193_compatible.h | 28 +++++++++++++++++++ 4 files changed, 30 insertions(+), 15 deletions(-) delete mode 100644 ext/concurrent_ruby_ext/common.h create mode 100644 ext/concurrent_ruby_ext/ruby_193_compatible.h diff --git a/ext/concurrent_ruby_ext/atomic_boolean.c b/ext/concurrent_ruby_ext/atomic_boolean.c index 139250114..d86fe2057 100644 --- a/ext/concurrent_ruby_ext/atomic_boolean.c +++ b/ext/concurrent_ruby_ext/atomic_boolean.c @@ -2,7 +2,7 @@ #include "atomic_boolean.h" #include "atomic_reference.h" -#include "common.h" +#include "ruby_193_compatible.h" void atomic_boolean_mark(void *value) { rb_gc_mark_maybe((VALUE) value); diff --git a/ext/concurrent_ruby_ext/atomic_fixnum.c b/ext/concurrent_ruby_ext/atomic_fixnum.c index d747bd963..20404ba95 100644 --- a/ext/concurrent_ruby_ext/atomic_fixnum.c +++ b/ext/concurrent_ruby_ext/atomic_fixnum.c @@ -2,7 +2,7 @@ #include "atomic_fixnum.h" #include "atomic_reference.h" -#include "common.h" +#include "ruby_193_compatible.h" void atomic_fixnum_mark(void *value) { rb_gc_mark_maybe((VALUE) value); diff --git a/ext/concurrent_ruby_ext/common.h b/ext/concurrent_ruby_ext/common.h deleted file mode 100644 index ed77fdb17..000000000 --- a/ext/concurrent_ruby_ext/common.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef rb_check_arity - -// https://github.com/ruby/ruby/blob/ruby_2_0_0/include/ruby/intern.h -// rb_check_arity was added in Ruby 2.0 - -#define UNLIMITED_ARGUMENTS (-1) - -#define rb_check_arity(argc, min, max) do { \ - if (((argc) < (min)) || ((argc) > (max) && (max) != UNLIMITED_ARGUMENTS)) \ - rb_error_arity(argc, min, max); \ -} while(0) - -#endif diff --git a/ext/concurrent_ruby_ext/ruby_193_compatible.h b/ext/concurrent_ruby_ext/ruby_193_compatible.h new file mode 100644 index 000000000..d636068fe --- /dev/null +++ b/ext/concurrent_ruby_ext/ruby_193_compatible.h @@ -0,0 +1,28 @@ +#ifndef rb_check_arity + +// https://github.com/ruby/ruby/blob/ruby_2_0_0/include/ruby/intern.h +// rb_check_arity was added in Ruby 2.0 + +#define UNLIMITED_ARGUMENTS (-1) + +static inline void rb_error_arity(int argc, int min, int max) +{ + VALUE err_mess = 0; + if (min == max) { + err_mess = rb_sprintf("wrong number of arguments (%d for %d)", argc, min); + } + else if (max == UNLIMITED_ARGUMENTS) { + err_mess = rb_sprintf("wrong number of arguments (%d for %d+)", argc, min); + } + else { + err_mess = rb_sprintf("wrong number of arguments (%d for %d..%d)", argc, min, max); + } + rb_raise(rb_eTypeError, err_mess); +} + +#define rb_check_arity(argc, min, max) do { \ + if (((argc) < (min)) || ((argc) > (max) && (max) != UNLIMITED_ARGUMENTS)) \ + rb_error_arity(argc, min, max); \ +} while(0) + +#endif