Project

General

Profile

Bug #5172 ยป 0001-ext-bigdecimal-bigdecimal.c-RB_GC_GUARD-rb_inspect-o.patch

normalperson (Eric Wong), 08/09/2011 08:46 AM

View differences:

ext/bigdecimal/bigdecimal.c
return p->obj;
}
static void raise_inspect(VALUE exc_class, VALUE v)
{
VALUE str;
const char *cstr;
if (rb_special_const_p(v)) {
str = rb_inspect(v);
RB_GC_GUARD(str);
cstr = RSTRING_PTR(str);
} else {
cstr = rb_obj_classname(v);
}
rb_raise(exc_class, "%s can't be coerced into BigDecimal", cstr);
}
static VALUE BigDecimal_div2(int, VALUE*, VALUE);
static Real*
......
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));
raise_inspect(rb_eTypeError, v);
}
return NULL; /* NULL means to coerce */
......
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));
raise_inspect(rb_eArgError, x);
}
RB_GC_GUARD(vx->obj);
......
"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));
raise_inspect(rb_eArgError, x);
}
x = ToValue(vx);
test/bigdecimal/test_bigdecimal.rb
b = BigDecimal.new("1"+"0"*i)
assert_equal([1, "1", 10, i+1], b.split, bug3258)
end
expect = ":too_long_to_embed_as_string can't be coerced into BigDecimal"
b = BigDecimal.new("1")
10.times do
begin
b.coerce(:too_long_to_embed_as_string)
rescue => e
assert_instance_of TypeError, e
assert_equal expect, e.message
end
end
ensure
GC.stress = stress
end
test/bigdecimal/test_bigmath.rb
assert_equal(BigDecimal("0.823840753418636291769355073102514088959345624027952954058347023122539489"),
atan(BigDecimal("1.08"), 72).round(72), '[ruby-dev:41257]')
end
def test_gc
stress, GC.stress = GC.stress, true
expect = ":too_long_to_embed_as_string can't be coerced into BigDecimal"
10.times do
begin
BigMath.log(:too_long_to_embed_as_string, 6)
rescue => e
assert_instance_of ArgumentError, e
assert_equal expect, e.message
end
end
10.times do
begin
BigMath.exp(:too_long_to_embed_as_string, 6)
rescue => e
assert_instance_of ArgumentError, e
assert_equal expect, e.message
end
end
ensure
GC.stress = stress
end
end
    (1-1/1)