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
174 174
    return p->obj;
175 175
}
176 176

  
177
static void raise_inspect(VALUE exc_class, VALUE v)
178
{
179
    VALUE str;
180
    const char *cstr;
181

  
182
    if (rb_special_const_p(v)) {
183
	str = rb_inspect(v);
184
	RB_GC_GUARD(str);
185
	cstr = RSTRING_PTR(str);
186
    } else {
187
	cstr = rb_obj_classname(v);
188
    }
189

  
190
    rb_raise(exc_class, "%s can't be coerced into BigDecimal", cstr);
191
}
192

  
177 193
static VALUE BigDecimal_div2(int, VALUE*, VALUE);
178 194

  
179 195
static Real*
......
240 256

  
241 257
SomeOneMayDoIt:
242 258
    if (must) {
243
	rb_raise(rb_eTypeError, "%s can't be coerced into BigDecimal",
244
		 rb_special_const_p(v) ? RSTRING_PTR(rb_inspect(v)) : rb_obj_classname(v));
259
	raise_inspect(rb_eTypeError, v);
245 260
    }
246 261
    return NULL; /* NULL means to coerce */
247 262

  
......
2463 2478
	return ToValue(vy);
2464 2479
    }
2465 2480
    else if (vx == NULL) {
2466
	rb_raise(rb_eArgError, "%s can't be coerced into BigDecimal",
2467
		 rb_special_const_p(x) ? RSTRING_PTR(rb_inspect(x)) : rb_obj_classname(x));
2481
	raise_inspect(rb_eArgError, x);
2468 2482
    }
2469 2483
    RB_GC_GUARD(vx->obj);
2470 2484

  
......
2619 2633
		 "Zero or negative argument for log");
2620 2634
    }
2621 2635
    else if (vx == NULL) {
2622
	rb_raise(rb_eArgError, "%s can't be coerced into BigDecimal",
2623
		 rb_special_const_p(x) ? RSTRING_PTR(rb_inspect(x)) : rb_obj_classname(x));
2636
	raise_inspect(rb_eArgError, x);
2624 2637
    }
2625 2638
    x = ToValue(vx);
2626 2639

  
test/bigdecimal/test_bigdecimal.rb
1093 1093
      b = BigDecimal.new("1"+"0"*i)
1094 1094
      assert_equal([1, "1", 10, i+1], b.split, bug3258)
1095 1095
    end
1096

  
1097
    expect = ":too_long_to_embed_as_string can't be coerced into BigDecimal"
1098
    b = BigDecimal.new("1")
1099
    10.times do
1100
      begin
1101
        b.coerce(:too_long_to_embed_as_string)
1102
      rescue => e
1103
        assert_instance_of TypeError, e
1104
        assert_equal expect, e.message
1105
      end
1106
    end
1096 1107
  ensure
1097 1108
    GC.stress = stress
1098 1109
  end
test/bigdecimal/test_bigmath.rb
60 60
    assert_equal(BigDecimal("0.823840753418636291769355073102514088959345624027952954058347023122539489"),
61 61
                 atan(BigDecimal("1.08"), 72).round(72), '[ruby-dev:41257]')
62 62
  end
63

  
64
  def test_gc
65
    stress, GC.stress = GC.stress, true
66
    expect = ":too_long_to_embed_as_string can't be coerced into BigDecimal"
67
    10.times do
68
      begin
69
        BigMath.log(:too_long_to_embed_as_string, 6)
70
      rescue => e
71
        assert_instance_of ArgumentError, e
72
        assert_equal expect, e.message
73
      end
74
    end
75

  
76
    10.times do
77
      begin
78
        BigMath.exp(:too_long_to_embed_as_string, 6)
79
      rescue => e
80
        assert_instance_of ArgumentError, e
81
        assert_equal expect, e.message
82
      end
83
    end
84
  ensure
85
    GC.stress = stress
86
  end
63 87
end