summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog20
-rw-r--r--NEWS3
-rw-r--r--ext/bigdecimal/bigdecimal.c20
-rw-r--r--ext/date/date_core.c14
-rw-r--r--include/ruby/intern.h2
-rw-r--r--include/ruby/ruby.h10
-rw-r--r--internal.h8
-rw-r--r--rational.c15
8 files changed, 65 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index 7b668e0067..91d14526a1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+Sun May 18 01:21:23 2014 Tanaka Akira <akr@fsij.org>
+
+ * include/ruby/ruby.h: Hide Rational internal.
+ (RRational): Moved to internal.h
+ (RRATIONAL): Ditto.
+ (RRATIONAL_SET_NUM): Moved to rational.c.
+ (RRATIONAL_SET_DEN): Ditto.
+
+ * rational.c (rb_rational_num): New function.
+ (rb_rational_den): Ditto.
+
+ * include/ruby/intern.h (rb_rational_num): Declared.
+ (rb_rational_den): Ditto.
+
+ * ext/bigdecimal/bigdecimal.c: Follow the above change.
+
+ * ext/date/date_core.c: Ditto.
+
+ [ruby-core:60665] [Feature #9513]
+
Sat May 17 17:04:32 2014 Shota Fukumori <her@sorah.jp>
* NEWS: Add news about removal of lib/test/**/*.rb.
diff --git a/NEWS b/NEWS
index 1187740ae6..4cc997faf3 100644
--- a/NEWS
+++ b/NEWS
@@ -133,6 +133,9 @@ with all sufficient information, see the ChangeLog file.
* struct RBignum is hidden. [Feature #6083]
Use rb_integer_pack and rb_integer_unpack instead.
+* struct RRational is hidden. [Feature #9513]
+ Use rb_rational_num and rb_rational_den instead.
+
* rb_big_new and rb_big_resize takes a size_t instead of long.
* rb_num2long returns a long instead of SIGNED_VALUE.
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 31479d4edb..44e13a49d7 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -87,8 +87,8 @@ static ID id_eq;
#endif
#ifndef RRATIONAL_ZERO_P
-# define RRATIONAL_ZERO_P(x) (FIXNUM_P(RRATIONAL(x)->num) && \
- FIX2LONG(RRATIONAL(x)->num) == 0)
+# define RRATIONAL_ZERO_P(x) (FIXNUM_P(rb_rational_num(x)) && \
+ FIX2LONG(rb_rational_num(x)) == 0)
#endif
#ifndef RRATIONAL_NEGATIVE_P
@@ -235,11 +235,11 @@ again:
if (prec < 0) goto unable_to_coerce_without_prec;
if (orig == Qundef ? (orig = v, 1) : orig != v) {
- num = RRATIONAL(v)->num;
+ num = rb_rational_num(v);
pv = GetVpValueWithPrec(num, -1, must);
if (pv == NULL) goto SomeOneMayDoIt;
- v = BigDecimal_div2(ToValue(pv), RRATIONAL(v)->den, LONG2NUM(prec));
+ v = BigDecimal_div2(ToValue(pv), rb_rational_den(v), LONG2NUM(prec));
goto again;
}
@@ -2114,7 +2114,7 @@ is_zero(VALUE x)
return Qfalse;
case T_RATIONAL:
- num = RRATIONAL(x)->num;
+ num = rb_rational_num(x);
return FIXNUM_P(num) && FIX2LONG(num) == 0;
default:
@@ -2137,8 +2137,8 @@ is_one(VALUE x)
return Qfalse;
case T_RATIONAL:
- num = RRATIONAL(x)->num;
- den = RRATIONAL(x)->den;
+ num = rb_rational_num(x);
+ den = rb_rational_den(x);
return FIXNUM_P(den) && FIX2LONG(den) == 1 &&
FIXNUM_P(num) && FIX2LONG(num) == 1;
@@ -2244,14 +2244,14 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self)
break;
case T_RATIONAL:
- if (is_zero(RRATIONAL(vexp)->num)) {
+ if (is_zero(rb_rational_num(vexp))) {
if (is_positive(vexp)) {
vexp = INT2FIX(0);
goto retry;
}
}
- else if (is_one(RRATIONAL(vexp)->den)) {
- vexp = RRATIONAL(vexp)->num;
+ else if (is_one(rb_rational_den(vexp))) {
+ vexp = rb_rational_num(vexp);
goto retry;
}
exp = GetVpValueWithPrec(vexp, n, 1);
diff --git a/ext/date/date_core.c b/ext/date/date_core.c
index ee360b4afb..0775fecbf2 100644
--- a/ext/date/date_core.c
+++ b/ext/date/date_core.c
@@ -114,7 +114,7 @@ f_zero_p(VALUE x)
return Qfalse;
case T_RATIONAL:
{
- VALUE num = RRATIONAL(x)->num;
+ VALUE num = rb_rational_num(x);
return f_boolcast(FIXNUM_P(num) && FIX2LONG(num) == 0);
}
}
@@ -305,9 +305,9 @@ inline static VALUE
canon(VALUE x)
{
if (TYPE(x) == T_RATIONAL) {
- VALUE den = RRATIONAL(x)->den;
+ VALUE den = rb_rational_den(x);
if (FIXNUM_P(den) && FIX2LONG(den) == 1)
- return RRATIONAL(x)->num;
+ return rb_rational_num(x);
}
return x;
}
@@ -2373,8 +2373,8 @@ offset_to_sec(VALUE vof, int *rof)
return 1;
}
#endif
- vn = RRATIONAL(vs)->num;
- vd = RRATIONAL(vs)->den;
+ vn = rb_rational_num(vs);
+ vd = rb_rational_den(vs);
if (FIXNUM_P(vn) && FIXNUM_P(vd) && (FIX2LONG(vd) == 1))
n = FIX2LONG(vn);
@@ -3097,7 +3097,7 @@ wholenum_p(VALUE x)
break;
case T_RATIONAL:
{
- VALUE den = RRATIONAL(x)->den;
+ VALUE den = rb_rational_den(x);
return FIXNUM_P(den) && FIX2LONG(den) == 1;
}
break;
@@ -5707,7 +5707,7 @@ d_lite_plus(VALUE self, VALUE other)
int jd, df, s;
if (wholenum_p(other))
- return d_lite_plus(self, RRATIONAL(other)->num);
+ return d_lite_plus(self, rb_rational_num(other));
if (f_positive_p(other))
s = +1;
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index f36f19214d..387f000c66 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -168,6 +168,8 @@ VALUE rb_rational_new(VALUE, VALUE);
VALUE rb_Rational(VALUE, VALUE);
#define rb_Rational1(x) rb_Rational((x), INT2FIX(1))
#define rb_Rational2(x,y) rb_Rational((x), (y))
+VALUE rb_rational_num(VALUE rat);
+VALUE rb_rational_den(VALUE rat);
VALUE rb_flt_rationalize_with_prec(VALUE, VALUE);
VALUE rb_flt_rationalize(VALUE);
/* complex.c */
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 54fa9f121d..a39b958617 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -943,15 +943,6 @@ struct RFile {
struct rb_io_t *fptr;
};
-struct RRational {
- struct RBasic basic;
- const VALUE num;
- const VALUE den;
-};
-
-#define RRATIONAL_SET_NUM(rat, n) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->num,(n))
-#define RRATIONAL_SET_DEN(rat, d) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->den,(d))
-
struct RComplex {
struct RBasic basic;
const VALUE real;
@@ -1101,7 +1092,6 @@ struct RStruct {
#define RTYPEDDATA(obj) (R_CAST(RTypedData)(obj))
#define RSTRUCT(obj) (R_CAST(RStruct)(obj))
#define RFILE(obj) (R_CAST(RFile)(obj))
-#define RRATIONAL(obj) (R_CAST(RRational)(obj))
#define RCOMPLEX(obj) (R_CAST(RComplex)(obj))
#define RSYMBOL(obj) (R_CAST(RSymbol)(obj))
diff --git a/internal.h b/internal.h
index 9b5fb0d0bb..7cd04756cc 100644
--- a/internal.h
+++ b/internal.h
@@ -404,6 +404,14 @@ struct RBignum {
#define RBIGNUM(obj) (R_CAST(RBignum)(obj))
+struct RRational {
+ struct RBasic basic;
+ const VALUE num;
+ const VALUE den;
+};
+
+#define RRATIONAL(obj) (R_CAST(RRational)(obj))
+
/* class.c */
void rb_class_subclass_add(VALUE super, VALUE klass);
void rb_class_remove_from_super_subclasses(VALUE);
diff --git a/rational.c b/rational.c
index 517a79769e..e50497944f 100644
--- a/rational.c
+++ b/rational.c
@@ -404,6 +404,9 @@ f_lcm(VALUE x, VALUE y)
adat = ((struct RRational *)(x));\
bdat = ((struct RRational *)(y))
+#define RRATIONAL_SET_NUM(rat, n) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->num,(n))
+#define RRATIONAL_SET_DEN(rat, d) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->den,(d))
+
inline static VALUE
nurat_s_new_internal(VALUE klass, VALUE num, VALUE den)
{
@@ -1775,6 +1778,18 @@ rb_Rational(VALUE x, VALUE y)
return nurat_s_convert(2, a, rb_cRational);
}
+VALUE
+rb_rational_num(VALUE rat)
+{
+ return nurat_numerator(rat);
+}
+
+VALUE
+rb_rational_den(VALUE rat)
+{
+ return nurat_denominator(rat);
+}
+
#define id_numerator rb_intern("numerator")
#define f_numerator(x) rb_funcall((x), id_numerator, 0)