summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-29 14:34:43 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-29 14:34:43 +0000
commit78400919bad04fcba0b9dee75b6217933c958fbc (patch)
tree3209c640f27c4eca4dfb08519fe89064c3414a0c /ext/bigdecimal
parent21f6bb283f3eac8e723a23f0a7f78ffcfe574540 (diff)
* ext/bigdecimal/bigdecimal.c (rb_rational_num): add fallback function
for rubies lower than 2.2.0. * ext/bigdecimal/bigdecimal.c (rb_rational_den): ditto. * ext/bigdecimal/extconf.rb: check the existences of struct RRational, rb_rational_num, and rb_rational_den. * ext/bigdecimal/bigdecimal.bundle: bump version. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c24
-rw-r--r--ext/bigdecimal/bigdecimal.gemspec2
-rw-r--r--ext/bigdecimal/extconf.rb4
3 files changed, 29 insertions, 1 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index f9a25a5..6d3ef77 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -109,6 +109,30 @@ static ID id_eq;
# define RB_OBJ_STRING(obj) StringValueCStr(obj)
#endif
+#ifndef HAVE_RB_RATIONAL_NUM
+static inline VALUE
+rb_rational_num(VALUE rat)
+{
+#ifdef HAVE_TYPE_STRUCT_RRATIONAL
+ return RRATIONAL(rat)->num;
+#else
+ return rb_funcall(rat, rb_intern("numerator"));
+#endif
+}
+#endif
+
+#ifndef HAVE_RB_RATIONAL_DEN
+static inline VALUE
+rb_rational_den(VALUE rat)
+{
+#ifdef HAVE_TYPE_STRUCT_RRATIONAL
+ return RRATIONAL(rat)->den;
+#else
+ return rb_funcall(rat, rb_intern("denominator"));
+#endif
+}
+#endif
+
/*
* ================== Ruby Interface part ==========================
*/
diff --git a/ext/bigdecimal/bigdecimal.gemspec b/ext/bigdecimal/bigdecimal.gemspec
index 197bdea..95e3bbd 100644
--- a/ext/bigdecimal/bigdecimal.gemspec
+++ b/ext/bigdecimal/bigdecimal.gemspec
@@ -1,5 +1,5 @@
# -*- ruby -*-
-_VERSION = "1.2.6"
+_VERSION = "1.2.7"
date = %w$Date:: $[1]
Gem::Specification.new do |s|
diff --git a/ext/bigdecimal/extconf.rb b/ext/bigdecimal/extconf.rb
index d6be3e5..a3ec7b4 100644
--- a/ext/bigdecimal/extconf.rb
+++ b/ext/bigdecimal/extconf.rb
@@ -3,4 +3,8 @@ require 'mkmf'
have_func("labs", "stdlib.h")
have_func("llabs", "stdlib.h")
+have_type("struct RRational", "ruby.h")
+have_func("rb_rational_num", "ruby.h")
+have_func("rb_rational_den", "ruby.h")
+
create_makefile('bigdecimal')