ruby-changes:62369
From: Nobuyoshi <ko1@a...>
Date: Thu, 23 Jul 2020 11:58:58 +0900 (JST)
Subject: [ruby-changes:62369] caf565f7bf (master): Ensure time object meets a given condition [Bug #17042]
https://git.ruby-lang.org/ruby.git/commit/?id=caf565f7bf From caf565f7bf9b279449c893b9e812c466a26e8f4b Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 23 Jul 2020 11:48:59 +0900 Subject: Ensure time object meets a given condition [Bug #17042] diff --git a/time.c b/time.c index e993d78..f00e0cd 100644 --- a/time.c +++ b/time.c @@ -1765,6 +1765,14 @@ static VALUE time_get_tm(VALUE, struct time_object *); https://github.com/ruby/ruby/blob/trunk/time.c#L1765 time_get_tm((time), (tobj)); \ } \ } while (0) +#define MAKE_TM_ENSURE(time, tobj, cond) \ + do { \ + MAKE_TM(time, tobj); \ + if (!(cond)) { \ + VALUE zone = (tobj)->vtm.zone; \ + if (!NIL_P(zone)) zone_localtime(zone, (time)); \ + } \ + } while (0) static void time_mark(void *ptr) @@ -4593,11 +4601,7 @@ time_wday(VALUE time) https://github.com/ruby/ruby/blob/trunk/time.c#L4601 struct time_object *tobj; GetTimeval(time, tobj); - MAKE_TM(time, tobj); - if (tobj->vtm.wday == VTM_WDAY_INITVAL) { - VALUE zone = tobj->vtm.zone; - if (!NIL_P(zone)) zone_localtime(zone, time); - } + MAKE_TM_ENSURE(time, tobj, tobj->vtm.wday != VTM_WDAY_INITVAL); return INT2FIX((int)tobj->vtm.wday); } @@ -4733,11 +4737,7 @@ time_yday(VALUE time) https://github.com/ruby/ruby/blob/trunk/time.c#L4737 struct time_object *tobj; GetTimeval(time, tobj); - MAKE_TM(time, tobj); - if (tobj->vtm.yday == 0) { - VALUE zone = tobj->vtm.zone; - if (!NIL_P(zone)) zone_localtime(zone, time); - } + MAKE_TM_ENSURE(time, tobj, tobj->vtm.yday != 0); return INT2FIX(tobj->vtm.yday); } @@ -5109,11 +5109,7 @@ time_strftime(VALUE time, VALUE format) https://github.com/ruby/ruby/blob/trunk/time.c#L5109 VALUE tmp; GetTimeval(time, tobj); - if (tobj->vtm.yday == 0) { - VALUE zone = tobj->vtm.zone; - if (!NIL_P(zone)) zone_localtime(zone, time); - } - MAKE_TM(time, tobj); + MAKE_TM_ENSURE(time, tobj, tobj->vtm.yday != 0); StringValue(format); if (!rb_enc_str_asciicompat_p(format)) { rb_raise(rb_eArgError, "format should have ASCII compatible encoding"); -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/