[前][次][番号順一覧][スレッド一覧]

ruby-changes:5697

From: shyouhei <ko1@a...>
Date: Sun, 15 Jun 2008 20:20:50 +0900 (JST)
Subject: [ruby-changes:5697] Ruby:r17204 (ruby_1_8_5): merge revision(s) 15749:

shyouhei	2008-06-15 20:20:41 +0900 (Sun, 15 Jun 2008)

  New Revision: 17204

  Modified files:
    branches/ruby_1_8_5/ChangeLog
    branches/ruby_1_8_5/numeric.c
    branches/ruby_1_8_5/version.h

  Log:
    merge revision(s) 15749:
    * numeric.c (fix_coerce): try conversion before type check.
      [ruby-core:15838]


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_5/numeric.c?r1=17204&r2=17203&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_5/version.h?r1=17204&r2=17203&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8_5/ChangeLog?r1=17204&r2=17203&diff_format=u

Index: ruby_1_8_5/numeric.c
===================================================================
--- ruby_1_8_5/numeric.c	(revision 17203)
+++ ruby_1_8_5/numeric.c	(revision 17204)
@@ -1537,6 +1537,7 @@
 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 @@
 
       default:
 	val = rb_to_int(val);
-	return NUM2LONG(val);
+	goto again;
     }
 }
 
@@ -2432,6 +2433,16 @@
     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 @@
 {
     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 @@
 {
     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 @@
 {
     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 @@
     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 @@
 	    return INT2FIX(1);
 	}
     }
-    i = NUM2LONG(idx);
+    i = FIX2LONG(idx);
 
     if (i < 0) return INT2FIX(0);
     if (sizeof(VALUE)*CHAR_BIT-1 < i) {
Index: ruby_1_8_5/ChangeLog
===================================================================
--- ruby_1_8_5/ChangeLog	(revision 17203)
+++ ruby_1_8_5/ChangeLog	(revision 17204)
@@ -1,3 +1,8 @@
+Sun Jun 15 20:07:30 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* numeric.c (fix_coerce): try conversion before type check.
+	  [ruby-core:15838]
+
 Sun Jun 15 19:55:46 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* bignum.c (BIGZEROP): fix for longer Bignum zeros.  [ruby-Bugs-17454]
Index: ruby_1_8_5/version.h
===================================================================
--- ruby_1_8_5/version.h	(revision 17203)
+++ ruby_1_8_5/version.h	(revision 17204)
@@ -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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]