Skip to content

Commit

Permalink
merge revision(s) 63994: [Backport #14920]
Browse files Browse the repository at this point in the history
	reduce tzset

	* time.c (rb_localtime_r): call tzset() only after TZ environment
	  variable is changed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@64602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nagachika committed Sep 1, 2018
1 parent 3993fbb commit f636974
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
9 changes: 9 additions & 0 deletions hash.c
Expand Up @@ -3294,6 +3294,9 @@ env_str_new2(const char *ptr)

static int env_path_tainted(const char *);

static const char TZ_ENV[] = "TZ";
extern int ruby_tz_update;

static rb_encoding *
env_encoding_for(const char *name, const char *ptr)
{
Expand Down Expand Up @@ -3375,6 +3378,9 @@ env_delete(VALUE obj, VALUE name)
RB_GC_GUARD(name);
path_tainted = 0;
}
else if (ENVMATCH(nam, TZ_ENV)) {
ruby_tz_update = 0;
}
return value;
}
return Qnil;
Expand Down Expand Up @@ -3734,6 +3740,9 @@ env_aset(VALUE obj, VALUE nm, VALUE val)
path_tainted_p(value);
}
}
else if (ENVMATCH(name, TZ_ENV)) {
ruby_tz_update = 0;
}
return val;
}

Expand Down
8 changes: 7 additions & 1 deletion time.c
Expand Up @@ -646,12 +646,18 @@ static struct vtm *localtimew(wideval_t timew, struct vtm *result);
static int leap_year_p(long y);
#define leap_year_v_p(y) leap_year_p(NUM2LONG(modv((y), INT2FIX(400))))

int ruby_tz_update;

static struct tm *
rb_localtime_r(const time_t *t, struct tm *result)
{
#if defined __APPLE__ && defined __LP64__
if (*t != (time_t)(int)*t) return NULL;
#endif
if (!ruby_tz_update) {
ruby_tz_update = 1;
tzset();
}
#ifdef HAVE_GMTIME_R
result = localtime_r(t, result);
#else
Expand All @@ -677,7 +683,7 @@ rb_localtime_r(const time_t *t, struct tm *result)
#endif
return result;
}
#define LOCALTIME(tm, result) (tzset(),rb_localtime_r((tm), &(result)))
#define LOCALTIME(tm, result) rb_localtime_r((tm), &(result))

#ifndef HAVE_STRUCT_TM_TM_GMTOFF
static struct tm *
Expand Down
8 changes: 4 additions & 4 deletions version.h
@@ -1,10 +1,10 @@
#define RUBY_VERSION "2.5.2"
#define RUBY_RELEASE_DATE "2018-08-18"
#define RUBY_PATCHLEVEL 82
#define RUBY_RELEASE_DATE "2018-09-01"
#define RUBY_PATCHLEVEL 83

#define RUBY_RELEASE_YEAR 2018
#define RUBY_RELEASE_MONTH 8
#define RUBY_RELEASE_DAY 18
#define RUBY_RELEASE_MONTH 9
#define RUBY_RELEASE_DAY 1

#include "ruby/version.h"

Expand Down

0 comments on commit f636974

Please sign in to comment.