Project

General

Profile

Bug #5171 ยป 0001-ext-date-date_core.c-d_lite_inspect-RB_GC_GUARD-temp.patch

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

View differences:

ext/date/date_core.c
6655 6655
static VALUE
6656 6656
mk_inspect(union DateData *x, const char *klass, const char *to_s)
6657 6657
{
6658
    VALUE real_jd = f_inspect(m_real_jd(x));
6659
    VALUE sf = f_inspect(m_sf(x));
6660

  
6661
    RB_GC_GUARD(real_jd);
6662
    RB_GC_GUARD(sf);
6663

  
6658 6664
    return rb_enc_sprintf(rb_usascii_encoding(),
6659 6665
			  "#<%s: %s ((%sj,%ds,%sn),%+ds,%.0fj)>",
6660 6666
			  klass ? klass : "?",
6661 6667
			  to_s ? to_s : "?",
6662
			  RSTRING_PTR(f_inspect(m_real_jd(x))), m_df(x),
6663
			  RSTRING_PTR(f_inspect(m_sf(x))),
6668
			  RSTRING_PTR(real_jd), m_df(x),
6669
			  RSTRING_PTR(sf),
6664 6670
			  m_of(x), m_sg(x));
6665 6671
}
6666 6672

  
......
6681 6687
static VALUE
6682 6688
d_lite_inspect(VALUE self)
6683 6689
{
6690
    VALUE to_s;
6691

  
6684 6692
    get_d1(self);
6685
    return mk_inspect(dat, rb_obj_classname(self),
6686
		      RSTRING_PTR(f_to_s(self)));
6693

  
6694
    to_s = f_to_s(self);
6695
    RB_GC_GUARD(to_s);
6696
    return mk_inspect(dat, rb_obj_classname(self), RSTRING_PTR(to_s));
6687 6697
}
6688 6698

  
6689 6699
#include <errno.h>
test/date/test_date.rb
141 141
    assert_instance_of(String, d.to_s)
142 142
  end
143 143

  
144
  def test_gc
145
    stress, GC.stress = GC.stress, true
146
    5.times do
147
      Date.new(1965, 5, 23).inspect.gsub!(/./, '')
148
      DateTime.new(1965, 5, 23, 22, 31, 59).inspect.gsub!(/./, '')
149
    end
150
  ensure
151
    GC.stress = stress
152
  end
144 153
end