summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/bigdecimal.c
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-17 06:35:21 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-17 06:35:21 +0000
commit4e8d6c105c22c40f1abf1aab357419e8f4ef2f5b (patch)
tree8663c427f448abbc89539c56d9f9e185e0e44d70 /ext/bigdecimal/bigdecimal.c
parentb30d203fed8c29fd05d010631ca8e4750ce34849 (diff)
Merge branch '5172_bigdecimal_gc_issue' into trunk
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal/bigdecimal.c')
-rw-r--r--ext/bigdecimal/bigdecimal.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 67c093e..151a68c 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -174,6 +174,25 @@ ToValue(Real *p)
return p->obj;
}
+NORETURN(static void cannot_be_coerced_into_BigDecimal(VALUE, VALUE));
+
+static void
+cannot_be_coerced_into_BigDecimal(VALUE exc_class, VALUE v)
+{
+ VALUE str;
+
+ if (rb_special_const_p(v)) {
+ str = rb_str_cat2(rb_str_dup(rb_inspect(v)),
+ " can't be coerced into BigDecimal");
+ }
+ else {
+ str = rb_str_cat2(rb_str_dup(rb_class_name(rb_obj_class(v))),
+ " can't be coerced into BigDecimal");
+ }
+
+ rb_exc_raise(rb_exc_new3(exc_class, str));
+}
+
static VALUE BigDecimal_div2(int, VALUE*, VALUE);
static Real*
@@ -240,8 +259,7 @@ again:
SomeOneMayDoIt:
if (must) {
- rb_raise(rb_eTypeError, "%s can't be coerced into BigDecimal",
- rb_special_const_p(v) ? RSTRING_PTR(rb_inspect(v)) : rb_obj_classname(v));
+ cannot_be_coerced_into_BigDecimal(rb_eTypeError, v);
}
return NULL; /* NULL means to coerce */
@@ -2463,8 +2481,7 @@ BigMath_s_exp(VALUE klass, VALUE x, VALUE vprec)
return ToValue(vy);
}
else if (vx == NULL) {
- rb_raise(rb_eArgError, "%s can't be coerced into BigDecimal",
- rb_special_const_p(x) ? RSTRING_PTR(rb_inspect(x)) : rb_obj_classname(x));
+ cannot_be_coerced_into_BigDecimal(rb_eArgError, x);
}
RB_GC_GUARD(vx->obj);
@@ -2619,8 +2636,7 @@ get_vp_value:
"Zero or negative argument for log");
}
else if (vx == NULL) {
- rb_raise(rb_eArgError, "%s can't be coerced into BigDecimal",
- rb_special_const_p(x) ? RSTRING_PTR(rb_inspect(x)) : rb_obj_classname(x));
+ cannot_be_coerced_into_BigDecimal(rb_eArgError, x);
}
x = ToValue(vx);