summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-15 11:20:41 (GMT)
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-15 11:20:41 (GMT)
commit19ce20916a7d3922d9526310aea055bd2c77dfbb (patch)
tree593eca862429e2ff7ffe83958e6f5ebb42fa0585
parente6b158dea9743fac7807d9ae0bb634066d2b2643 (diff)
merge revision(s) 15749:
* numeric.c (fix_coerce): try conversion before type check. [ruby-core:15838] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_5@17204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--numeric.c29
-rw-r--r--version.h2
3 files changed, 26 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 49ae48b..9a1519a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Jun 15 20:07:30 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * numeric.c (fix_coerce): try conversion before type check.
+ [ruby-core:15838]
+
Sun Jun 15 19:55:46 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* bignum.c (BIGZEROP): fix for longer Bignum zeros. [ruby-Bugs-17454]
diff --git a/numeric.c b/numeric.c
index 04379a4..52775a7 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1537,6 +1537,7 @@ long
rb_num2long(val)
VALUE val;
{
+ again:
if (NIL_P(val)) {
rb_raise(rb_eTypeError, "no implicit conversion from nil to integer");
}
@@ -1563,7 +1564,7 @@ rb_num2long(val)
default:
val = rb_to_int(val);
- return NUM2LONG(val);
+ goto again;
}
}
@@ -2432,6 +2433,16 @@ fix_rev(num)
return LONG2NUM(val);
}
+static VALUE
+fix_coerce(x)
+ VALUE x;
+{
+ while (!FIXNUM_P(x) && TYPE(x) != T_BIGNUM) {
+ x = rb_to_int(x);
+ }
+ return x;
+}
+
/*
* call-seq:
* fix & other => integer
@@ -2445,10 +2456,10 @@ fix_and(x, y)
{
long val;
- if (TYPE(y) == T_BIGNUM) {
+ if (!FIXNUM_P(y = fix_coerce(y))) {
return rb_big_and(y, x);
}
- val = FIX2LONG(x) & NUM2LONG(y);
+ val = FIX2LONG(x) & FIX2LONG(y);
return LONG2NUM(val);
}
@@ -2465,10 +2476,10 @@ fix_or(x, y)
{
long val;
- if (TYPE(y) == T_BIGNUM) {
+ if (!FIXNUM_P(y = fix_coerce(y))) {
return rb_big_or(y, x);
}
- val = FIX2LONG(x) | NUM2LONG(y);
+ val = FIX2LONG(x) | FIX2LONG(y);
return LONG2NUM(val);
}
@@ -2485,10 +2496,10 @@ fix_xor(x, y)
{
long val;
- if (TYPE(y) == T_BIGNUM) {
+ if (!FIXNUM_P(y = fix_coerce(y))) {
return rb_big_xor(y, x);
}
- val = FIX2LONG(x) ^ NUM2LONG(y);
+ val = FIX2LONG(x) ^ FIX2LONG(y);
return LONG2NUM(val);
}
@@ -2587,7 +2598,7 @@ fix_aref(fix, idx)
long val = FIX2LONG(fix);
long i;
- if (TYPE(idx) == T_BIGNUM) {
+ if (!FIXNUM_P(idx = fix_coerce(idx))) {
idx = rb_big_norm(idx);
if (!FIXNUM_P(idx)) {
if (!RBIGNUM(idx)->sign || val >= 0)
@@ -2595,7 +2606,7 @@ fix_aref(fix, idx)
return INT2FIX(1);
}
}
- i = NUM2LONG(idx);
+ i = FIX2LONG(idx);
if (i < 0) return INT2FIX(0);
if (sizeof(VALUE)*CHAR_BIT-1 < i) {
diff --git a/version.h b/version.h
index c3c348f..459c6ce 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2008-06-15"
#define RUBY_VERSION_CODE 185
#define RUBY_RELEASE_CODE 20080615
-#define RUBY_PATCHLEVEL 184
+#define RUBY_PATCHLEVEL 185
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8