diff --git a/cpan/Time-Piece/Piece.pm b/cpan/Time-Piece/Piece.pm index f5d87cd0316e..69c209656d7d 100644 --- a/cpan/Time-Piece/Piece.pm +++ b/cpan/Time-Piece/Piece.pm @@ -19,7 +19,7 @@ our %EXPORT_TAGS = ( ':override' => 'internal', ); -our $VERSION = '1.3401'; +our $VERSION = '1.3402'; XSLoader::load( 'Time::Piece', $VERSION ); diff --git a/cpan/Time-Piece/Piece.xs b/cpan/Time-Piece/Piece.xs index 8164cdd73a9e..ca86ecf9070d 100644 --- a/cpan/Time-Piece/Piece.xs +++ b/cpan/Time-Piece/Piece.xs @@ -26,6 +26,27 @@ extern "C" { #define WEEKDAY_BIAS 6 /* (1+6)%7 makes Sunday 0 again */ #define TP_BUF_SIZE 160 +#ifndef ENV_LOCK +# define ENV_LOCK +# define ENV_UNLOCK +#endif +#ifndef GMTIME_LOCK +# define GMTIME_LOCK ENV_LOCK +# define GMTIME_UNLOCK ENV_UNLOCK +#endif +#ifndef LOCALTIME_LOCK +# define LOCALTIME_LOCK ENV_LOCK +# define LOCALTIME_UNLOCK ENV_UNLOCK +#endif +#ifndef STRFTIME_LOCK +# define STRFTIME_LOCK ENV_LOCK +# define STRFTIME_UNLOCK ENV_UNLOCK +#endif +#ifndef TZSET_LOCK +# define TZSET_LOCK ENV_LOCK +# define TZSET_UNLOCK ENV_UNLOCK +#endif + #ifdef WIN32 /* @@ -151,7 +172,9 @@ my_tzset(pTHX) #endif fix_win32_tzenv(); #endif + TZSET_LOCK; tzset(); + TZSET_UNLOCK; } /* @@ -758,10 +781,14 @@ label: buf = cp; memset(&mytm, 0, sizeof(mytm)); - if(*got_GMT == 1) + if(*got_GMT == 1) { + LOCALTIME_LOCK; mytm = *localtime(&t); - else + } + else { + GMTIME_LOCK; mytm = *gmtime(&t); + } tm->tm_sec = mytm.tm_sec; tm->tm_min = mytm.tm_min; @@ -772,6 +799,13 @@ label: tm->tm_wday = mytm.tm_wday; tm->tm_yday = mytm.tm_yday; tm->tm_isdst = mytm.tm_isdst; + + if(*got_GMT == 1) { + LOCALTIME_UNLOCK; + } + else { + GMTIME_UNLOCK; + } } break; @@ -963,12 +997,17 @@ _strftime(fmt, epoch, islocal = 1) struct tm mytm; size_t len; - if(islocal == 1) + /* This should achieve locking localtime and gmtime as well */ + STRFTIME_LOCK; + if(islocal == 1) { mytm = *localtime(&epoch); - else + } + else { mytm = *gmtime(&epoch); + } len = strftime(tmpbuf, TP_BUF_SIZE, fmt, &mytm); + STRFTIME_UNLOCK; /* ** The following is needed to handle to the situation where ** tmpbuf overflows. Basically we want to allocate a buffer @@ -994,7 +1033,9 @@ _strftime(fmt, epoch, islocal = 1) New(0, buf, bufsize, char); while (buf) { + STRFTIME_LOCK; buflen = strftime(buf, bufsize, fmt, &mytm); + STRFTIME_UNLOCK; if (buflen > 0 && buflen < bufsize) break; /* heuristic to prevent out-of-memory errors */ @@ -1069,7 +1110,9 @@ _mini_mktime(int sec, int min, int hour, int mday, int mon, int year) time_t t; PPCODE: t = 0; + GMTIME_LOCK; mytm = *gmtime(&t); + GMTIME_UNLOCK; mytm.tm_sec = sec; mytm.tm_min = min; @@ -1088,8 +1131,16 @@ _crt_localtime(time_t sec) PREINIT: struct tm mytm; PPCODE: - if(ix) mytm = *gmtime(&sec); - else mytm = *localtime(&sec); + if(ix) { + GMTIME_LOCK; + mytm = *gmtime(&sec); + GMTIME_UNLOCK; + } + else { + LOCALTIME_LOCK; + mytm = *localtime(&sec); + LOCALTIME_UNLOCK; + } /* Need to get: $s,$n,$h,$d,$m,$y */ EXTEND(SP, 10); @@ -1120,15 +1171,22 @@ _get_localization() char buf[TP_BUF_SIZE]; size_t i; time_t t = 1325386800; /*1325386800 = Sun, 01 Jan 2012 03:00:00 GMT*/ - struct tm mytm = *gmtime(&t); + struct tm mytm; CODE: + GMTIME_LOCK; + mytm = *gmtime(&t); + GMTIME_UNLOCK; for(i = 0; i < 7; ++i){ + STRFTIME_LOCK; len = strftime(buf, TP_BUF_SIZE, "%a", &mytm); + STRFTIME_UNLOCK; av_push(wdays, (SV *) newSVpvn(buf, len)); + STRFTIME_LOCK; len = strftime(buf, TP_BUF_SIZE, "%A", &mytm); + STRFTIME_UNLOCK; av_push(weekdays, (SV *) newSVpvn(buf, len)); ++mytm.tm_wday; @@ -1136,10 +1194,14 @@ _get_localization() for(i = 0; i < 12; ++i){ + STRFTIME_LOCK; len = strftime(buf, TP_BUF_SIZE, "%b", &mytm); + STRFTIME_UNLOCK; av_push(mons, (SV *) newSVpvn(buf, len)); + STRFTIME_LOCK; len = strftime(buf, TP_BUF_SIZE, "%B", &mytm); + STRFTIME_UNLOCK; av_push(months, (SV *) newSVpvn(buf, len)); ++mytm.tm_mon; @@ -1151,10 +1213,14 @@ _get_localization() tmp = hv_store(locales, "month", 5, newRV_noinc((SV *) months), 0); tmp = hv_store(locales, "alt_month", 9, newRV((SV *) months), 0); + STRFTIME_LOCK; len = strftime(buf, TP_BUF_SIZE, "%p", &mytm); + STRFTIME_UNLOCK; tmp = hv_store(locales, "AM", 2, newSVpvn(buf,len), 0); mytm.tm_hour = 18; + STRFTIME_LOCK; len = strftime(buf, TP_BUF_SIZE, "%p", &mytm); + STRFTIME_UNLOCK; tmp = hv_store(locales, "PM", 2, newSVpvn(buf,len), 0); if(tmp == NULL || !SvOK( (SV *) *tmp)){