Skip to content

Commit e436fee

Browse files
committed
merge revision(s) r44610,r44617:
numeric.c: preserve encoding * numeric.c (coerce_failed): preserve encoding of error message. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@47050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 5816247 commit e436fee

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

numeric.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,19 @@ coerce_body(VALUE *x)
232232
return rb_funcall(x[1], id_coerce, 1, x[0]);
233233
}
234234

235+
NORETURN(static void coerce_failed(VALUE x, VALUE y));
236+
static void
237+
coerce_failed(VALUE x, VALUE y)
238+
{
239+
rb_raise(rb_eTypeError, "%"PRIsVALUE" can't be coerced into %"PRIsVALUE,
240+
(rb_special_const_p(y)? rb_inspect(y) : rb_obj_class(y)),
241+
rb_obj_class(x));
242+
}
243+
235244
static VALUE
236245
coerce_rescue(VALUE *x)
237246
{
238-
volatile VALUE v = rb_inspect(x[1]);
239-
240-
rb_raise(rb_eTypeError, "%s can't be coerced into %s",
241-
rb_special_const_p(x[1])?
242-
RSTRING_PTR(v):
243-
rb_obj_classname(x[1]),
244-
rb_obj_classname(x[0]));
245-
247+
coerce_failed(x[0], x[1]);
246248
return Qnil; /* dummy */
247249
}
248250

@@ -3297,11 +3299,7 @@ bit_coerce(VALUE *x, VALUE *y, int err)
32973299
if (!FIXNUM_P(*x) && !RB_TYPE_P(*x, T_BIGNUM)
32983300
&& !FIXNUM_P(*y) && !RB_TYPE_P(*y, T_BIGNUM)) {
32993301
if (!err) return FALSE;
3300-
rb_raise(rb_eTypeError,
3301-
"%s can't be coerced into %s for bitwise arithmetic",
3302-
rb_special_const_p(*y) ?
3303-
RSTRING_PTR(rb_inspect(*y)) : rb_obj_classname(*y),
3304-
rb_obj_classname(*x));
3302+
coerce_failed(*x, *y);
33053303
}
33063304
}
33073305
return TRUE;

test/ruby/test_numeric.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'test/unit'
2+
require_relative 'envutil'
23

34
class TestNumeric < Test::Unit::TestCase
45
class DummyNumeric < Numeric
@@ -14,6 +15,19 @@ def test_coerce
1415
assert_equal(Float, b.class)
1516

1617
assert_raise(TypeError) { -Numeric.new }
18+
19+
EnvUtil.with_default_external(Encoding::UTF_8) do
20+
assert_raise_with_message(TypeError, /:\u{3042}/) {1+:"\u{3042}"}
21+
assert_raise_with_message(TypeError, /:\u{3042}/) {1&:"\u{3042}"}
22+
assert_raise_with_message(TypeError, /:\u{3042}/) {1|:"\u{3042}"}
23+
assert_raise_with_message(TypeError, /:\u{3042}/) {1^:"\u{3042}"}
24+
end
25+
EnvUtil.with_default_external(Encoding::US_ASCII) do
26+
assert_raise_with_message(TypeError, /:"\\u3042"/) {1+:"\u{3042}"}
27+
assert_raise_with_message(TypeError, /:"\\u3042"/) {1&:"\u{3042}"}
28+
assert_raise_with_message(TypeError, /:"\\u3042"/) {1|:"\u{3042}"}
29+
assert_raise_with_message(TypeError, /:"\\u3042"/) {1^:"\u{3042}"}
30+
end
1731
end
1832

1933
def test_dummynumeric

version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#define RUBY_VERSION "2.1.2"
2-
#define RUBY_RELEASE_DATE "2014-08-03"
3-
#define RUBY_PATCHLEVEL 188
2+
#define RUBY_RELEASE_DATE "2014-08-04"
3+
#define RUBY_PATCHLEVEL 189
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 8
7-
#define RUBY_RELEASE_DAY 3
7+
#define RUBY_RELEASE_DAY 4
88

99
#include "ruby/version.h"
1010

0 commit comments

Comments
 (0)