summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-17 06:52:00 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-17 06:52:00 +0000
commitbc6c037f8499bd630da8f05e8e63e65f5eef76eb (patch)
tree1455a48335b31b47f2fd32ef666fba740db7b667 /ext
parent559b717567e61206294a310cdeedea9f28426e22 (diff)
Merge commit r32996 from trunk:
* ext/bigdecimal/bigdecimal.c (cannot_be_coerced_into_BigDecimal): add a new function for raising error when an object cannot coerce into BigDecimal. [Bug #5172] * ext/bigdecimal/bigdecimal.c (BigDecimalValueWithPrec): use cannot_be_coerced_into_BigDecimal function. * ext/bigdecimal/bigdecimal.c (BigMath_s_exp): ditto. * ext/bigdecimal/bigdecimal.c (BigMath_s_log): ditto. * test/bigdecimal/test_bigdecimal.rb: test for the avobe changes. * test/bigdecimal/testbase.rb (under_gc_stress): add a new utility method to run tests under the condition of GC.stress = true. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@32997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-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 bea5180b58..a02bcc98aa 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);