summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-15 08:16:37 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-15 08:16:37 +0000
commit2c65cdd31901e4e183f869913711176765f7cf42 (patch)
treef7f99b2212365fd5f56b9bb24391945aa092e198 /numeric.c
parent5f3e675bdffee823f863ed94aa71e225178a37c3 (diff)
numeric.c: preserve encoding
* numeric.c (coerce_failed): preserve encoding of error message. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/numeric.c b/numeric.c
index 039869f367..662e7f1c54 100644
--- a/numeric.c
+++ b/numeric.c
@@ -232,17 +232,19 @@ coerce_body(VALUE *x)
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 */
}
@@ -3261,11 +3263,7 @@ bit_coerce(VALUE *x, VALUE *y, int err)
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;