From 315d3362b22a8ecd0216505ee29f2cad0d9f3182 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sun, 15 Mar 2020 10:19:18 -0600 Subject: time64.[ch]: Inline only use of another macro This macro is now only used once. It is accessible outside perl because it is in time64.h, but isn't used in cpan. Remove it and place its expansion in time64.c. Part of the expansion called another function. That function can be removed and the expansion simplified, since gmtime() is now automatically converted into gmtime_r() if available and needed. --- time64.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) (limited to 'time64.c') diff --git a/time64.c b/time64.c index 6c75c482cf..dfd5776e3a 100644 --- a/time64.c +++ b/time64.c @@ -289,28 +289,6 @@ static void S_copy_little_tm_to_big_TM(const struct tm *src, struct TM *dest) { #endif } - -#ifndef HAS_GMTIME_R -/* Simulate gmtime_r() to the best of our ability */ -static struct tm * S_gmtime_r(const time_t *clock, struct tm *result) { -#ifdef __VMS - dTHX; /* the following is defined as Perl_my_localtime(aTHX_ ...) */ -#endif - const struct tm * const static_result = gmtime(clock); - - assert(result != NULL); - - if( static_result == NULL ) { - memset(result, 0, sizeof(*result)); - return NULL; - } - else { - memcpy(result, static_result, sizeof(*result)); - return result; - } -} -#endif - struct TM *Perl_gmtime64_r (const Time64_T *in_time, struct TM *p) { int v_tm_sec, v_tm_min, v_tm_hour, v_tm_mon, v_tm_wday; @@ -319,6 +297,7 @@ struct TM *Perl_gmtime64_r (const Time64_T *in_time, struct TM *p) Time64_T m; Time64_T time = *in_time; Year year = 70; + dTHX; assert(p != NULL); @@ -326,9 +305,27 @@ struct TM *Perl_gmtime64_r (const Time64_T *in_time, struct TM *p) if( SHOULD_USE_SYSTEM_GMTIME(*in_time) ) { time_t safe_time = (time_t)*in_time; struct tm safe_date; - GMTIME_R(&safe_time, &safe_date); + struct tm * result; + + /* reentr.h will automatically replace this with a call to gmtime_r() + * when appropriate */ + result = gmtime(&safe_time); + + assert(result != NULL); + +#if defined(HAS_GMTIME_R) && defined(USE_REENTRANT_API) + + PERL_UNUSED_VAR(safe_date); +#else + /* Here, no gmtime_r() and is a threaded perl where the result can be + * overwritten by a call in another thread. Copy to a safe place, + * hopefully before another gmtime can jump in and trash this + * result. */ + memcpy(&safe_date, result, sizeof(safe_date)); + result = &safe_date; +#endif - S_copy_little_tm_to_big_TM(&safe_date, p); + S_copy_little_tm_to_big_TM(result, p); assert(S_check_tm(p)); return p; -- cgit v1.2.1