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

ruby-changes:34968

From: nagachika <ko1@a...>
Date: Mon, 4 Aug 2014 00:50:47 +0900 (JST)
Subject: [ruby-changes:34968] nagachika:r47050 (ruby_2_1): merge revision(s) r44610, r44617:

nagachika	2014-08-04 00:50:33 +0900 (Mon, 04 Aug 2014)

  New Revision: 47050

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47050

  Log:
    merge revision(s) r44610,r44617:
    
    numeric.c: preserve encoding
    
    * numeric.c (coerce_failed): preserve encoding of error message.

  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/numeric.c
    branches/ruby_2_1/test/ruby/test_numeric.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/numeric.c
===================================================================
--- ruby_2_1/numeric.c	(revision 47049)
+++ ruby_2_1/numeric.c	(revision 47050)
@@ -232,17 +232,19 @@ coerce_body(VALUE *x) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/numeric.c#L232
     return rb_funcall(x[1], id_coerce, 1, x[0]);
 }
 
+NORETURN(static void coerce_failed(VALUE x, VALUE y));
+static void
+coerce_failed(VALUE x, VALUE y)
+{
+    rb_raise(rb_eTypeError, "%"PRIsVALUE" can't be coerced into %"PRIsVALUE,
+	     (rb_special_const_p(y)? rb_inspect(y) : rb_obj_class(y)),
+	     rb_obj_class(x));
+}
+
 static VALUE
 coerce_rescue(VALUE *x)
 {
-    volatile VALUE v = rb_inspect(x[1]);
-
-    rb_raise(rb_eTypeError, "%s can't be coerced into %s",
-	     rb_special_const_p(x[1])?
-	     RSTRING_PTR(v):
-	     rb_obj_classname(x[1]),
-	     rb_obj_classname(x[0]));
-
+    coerce_failed(x[0], x[1]);
     return Qnil;		/* dummy */
 }
 
@@ -3297,11 +3299,7 @@ bit_coerce(VALUE *x, VALUE *y, int err) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/numeric.c#L3299
 	if (!FIXNUM_P(*x) && !RB_TYPE_P(*x, T_BIGNUM)
 	    && !FIXNUM_P(*y) && !RB_TYPE_P(*y, T_BIGNUM)) {
 	    if (!err) return FALSE;
-	    rb_raise(rb_eTypeError,
-		     "%s can't be coerced into %s for bitwise arithmetic",
-		     rb_special_const_p(*y) ?
-			RSTRING_PTR(rb_inspect(*y)) : rb_obj_classname(*y),
-		     rb_obj_classname(*x));
+	    coerce_failed(*x, *y);
 	}
     }
     return TRUE;
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 47049)
+++ ruby_2_1/version.h	(revision 47050)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.2"
-#define RUBY_RELEASE_DATE "2014-08-03"
-#define RUBY_PATCHLEVEL 188
+#define RUBY_RELEASE_DATE "2014-08-04"
+#define RUBY_PATCHLEVEL 189
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 8
-#define RUBY_RELEASE_DAY 3
+#define RUBY_RELEASE_DAY 4
 
 #include "ruby/version.h"
 
Index: ruby_2_1/test/ruby/test_numeric.rb
===================================================================
--- ruby_2_1/test/ruby/test_numeric.rb	(revision 47049)
+++ ruby_2_1/test/ruby/test_numeric.rb	(revision 47050)
@@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_numeric.rb#L1
 require 'test/unit'
+require_relative 'envutil'
 
 class TestNumeric < Test::Unit::TestCase
   class DummyNumeric < Numeric
@@ -14,6 +15,19 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_numeric.rb#L15
     assert_equal(Float, b.class)
 
     assert_raise(TypeError) { -Numeric.new }
+
+    EnvUtil.with_default_external(Encoding::UTF_8) do
+      assert_raise_with_message(TypeError, /:\u{3042}/) {1+:"\u{3042}"}
+      assert_raise_with_message(TypeError, /:\u{3042}/) {1&:"\u{3042}"}
+      assert_raise_with_message(TypeError, /:\u{3042}/) {1|:"\u{3042}"}
+      assert_raise_with_message(TypeError, /:\u{3042}/) {1^:"\u{3042}"}
+    end
+    EnvUtil.with_default_external(Encoding::US_ASCII) do
+      assert_raise_with_message(TypeError, /:"\\u3042"/) {1+:"\u{3042}"}
+      assert_raise_with_message(TypeError, /:"\\u3042"/) {1&:"\u{3042}"}
+      assert_raise_with_message(TypeError, /:"\\u3042"/) {1|:"\u{3042}"}
+      assert_raise_with_message(TypeError, /:"\\u3042"/) {1^:"\u{3042}"}
+    end
   end
 
   def test_dummynumeric

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r44610,44617


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

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