diff options
| author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2024-06-03 10:45:16 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-06-03 05:23:44 +0000 |
| commit | 77e5e06846ffac01459fe18e9e293b6e5ebb3d4e (patch) | |
| tree | d63a70aa2dcf263a9c582b280ef1819bb5443c7d /ext | |
| parent | d50404d6fe9dcd991dbad4f8757d23d38d1b5b80 (diff) | |
[ruby/date] Prevent converted gregorian date from GC
`m_sf_in_sec` calls `rb_rational_new` that can cause GC.
https://github.com/ruby/date/commit/6de449ab6a
Diffstat (limited to 'ext')
| -rw-r--r-- | ext/date/date_core.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/ext/date/date_core.c b/ext/date/date_core.c index 0fcefd671b..b2b11e7d63 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -8955,18 +8955,22 @@ time_to_datetime(VALUE self) static VALUE date_to_time(VALUE self) { + VALUE t; + get_d1a(self); if (m_julian_p(adat)) { - VALUE tmp = d_lite_gregorian(self); - get_d1b(tmp); + self = d_lite_gregorian(self); + get_d1b(self); adat = bdat; } - return f_local3(rb_cTime, + t = f_local3(rb_cTime, m_real_year(adat), INT2FIX(m_mon(adat)), INT2FIX(m_mday(adat))); + RB_GC_GUARD(self); /* may be the converted gregorian */ + return t; } /* @@ -9055,6 +9059,7 @@ datetime_to_time(VALUE self) f_add(INT2FIX(m_sec(dat)), m_sf_in_sec(dat)), INT2FIX(m_of(dat))); + RB_GC_GUARD(self); /* may be the converted gregorian */ return t; } } |
