ruby-changes:4822
From: ko1@a...
Date: Wed, 7 May 2008 22:25:14 +0900 (JST)
Subject: [ruby-changes:4822] matz - Ruby:r16316 (trunk): * numeric.c (bit_coerce): float should not be a valid operand of
matz 2008-05-07 22:24:55 +0900 (Wed, 07 May 2008)
New Revision: 16316
Modified files:
trunk/ChangeLog
trunk/numeric.c
trunk/test/ruby/test_numeric.rb
Log:
* numeric.c (bit_coerce): float should not be a valid operand of
bitwise operations. [ruby-dev:34583]
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/numeric.c?r1=16316&r2=16315&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16316&r2=16315&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_numeric.rb?r1=16316&r2=16315&diff_format=u
Index: ChangeLog
===================================================================
--- ChangeLog (revision 16315)
+++ ChangeLog (revision 16316)
@@ -4,6 +4,11 @@
after Init_prelude() because cannot load encoding extensions before
it.
+Wed May 7 20:00:21 2008 Yukihiro Matsumoto <matz@r...>
+
+ * numeric.c (bit_coerce): float should not be a valid operand of
+ bitwise operations. [ruby-dev:34583]
+
Wed May 7 19:35:29 2008 Yukihiro Matsumoto <matz@r...>
* thread.c (rb_thread_key_p): should always convert symbol to ID.
Index: numeric.c
===================================================================
--- numeric.c (revision 16315)
+++ numeric.c (revision 16316)
@@ -2636,9 +2636,12 @@
}
static VALUE
-fix_coerce(VALUE x)
+bit_coerce(VALUE x)
{
while (!FIXNUM_P(x) && TYPE(x) != T_BIGNUM) {
+ if (TYPE(x) == T_FLOAT) {
+ rb_raise(rb_eTypeError, "can't convert Float into Integer");
+ }
x = rb_to_int(x);
}
return x;
@@ -2656,7 +2659,7 @@
{
long val;
- if (!FIXNUM_P(y = fix_coerce(y))) {
+ if (!FIXNUM_P(y = bit_coerce(y))) {
return rb_big_and(y, x);
}
val = FIX2LONG(x) & FIX2LONG(y);
@@ -2675,7 +2678,7 @@
{
long val;
- if (!FIXNUM_P(y = fix_coerce(y))) {
+ if (!FIXNUM_P(y = bit_coerce(y))) {
return rb_big_or(y, x);
}
val = FIX2LONG(x) | FIX2LONG(y);
@@ -2694,7 +2697,7 @@
{
long val;
- if (!FIXNUM_P(y = fix_coerce(y))) {
+ if (!FIXNUM_P(y = bit_coerce(y))) {
return rb_big_xor(y, x);
}
val = FIX2LONG(x) ^ FIX2LONG(y);
@@ -2791,7 +2794,8 @@
long val = FIX2LONG(fix);
long i;
- if (!FIXNUM_P(idx = fix_coerce(idx))) {
+ idx = rb_to_int(idx);
+ if (!FIXNUM_P(idx)) {
idx = rb_big_norm(idx);
if (!FIXNUM_P(idx)) {
if (!RBIGNUM_SIGN(idx) || val >= 0)
Index: test/ruby/test_numeric.rb
===================================================================
--- test/ruby/test_numeric.rb (revision 16315)
+++ test/ruby/test_numeric.rb (revision 16316)
@@ -201,9 +201,9 @@
def test_num2long
assert_raise(TypeError) { 1 & nil }
- assert_equal(1, 1 & 1.0)
- assert_equal(0, 1 & 2147483648.0)
- assert_equal(0, 1 & 9223372036854777856.0)
+ assert_raise(TypeError) { 1 & 1.0 }
+ assert_raise(TypeError) { 1 & 2147483648.0 }
+ assert_raise(TypeError) { 1 & 9223372036854777856.0 }
o = Object.new
def o.to_int; 1; end
assert_equal(1, 1 & o)
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/