Skip to content

Commit

Permalink
Support Ruby < 2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkn committed Oct 9, 2019
1 parent 97e794a commit 61ec452
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ext/bigdecimal/bigdecimal.c
Expand Up @@ -127,6 +127,30 @@ rb_rational_den(VALUE rat)
}
#endif

#ifndef HAVE_RB_COMPLEX_REAL
static inline VALUE
rb_complex_real(VALUE cmp)
{
#ifdef HAVE_TYPE_STRUCT_RCOMPLEX
return RCOMPLEX(cmp)->real;
#else
return rb_funcall(cmp, rb_intern("real"), 0);
#endif
}
#endif

#ifndef HAVE_RB_COMPLEX_IMAG
static inline VALUE
rb_complex_imag(VALUE cmp)
{
#ifdef HAVE_TYPE_STRUCT_RCOMPLEX
return RCOMPLEX(cmp)->imag;
#else
return rb_funcall(cmp, rb_intern("imag"), 0);
#endif
}
#endif

#define BIGDECIMAL_POSITIVE_P(bd) ((bd)->sign > 0)
#define BIGDECIMAL_NEGATIVE_P(bd) ((bd)->sign < 0)

Expand Down
3 changes: 3 additions & 0 deletions ext/bigdecimal/extconf.rb
Expand Up @@ -36,6 +36,9 @@ def check_bigdecimal_version(gemspec_path)
have_type("struct RRational", "ruby.h")
have_func("rb_rational_num", "ruby.h")
have_func("rb_rational_den", "ruby.h")
have_type("struct RComplex", "ruby.h")
have_func("rb_complex_real", "ruby.h")
have_func("rb_complex_imag", "ruby.h")
have_func("rb_array_const_ptr", "ruby.h")
have_func("rb_sym2str", "ruby.h")
have_func("rb_opts_exception_p", "ruby.h")
Expand Down

0 comments on commit 61ec452

Please sign in to comment.