Bug 1172609 - Part 8: Fix the tz detection code. r=waldo
authorTed Clancy <tclancy@mozilla.com>
Wed, 05 Aug 2015 19:05:04 -0700
changeset 259007 37d99d80d58b100b8d141c2e6bfe0d41fb4d2086
parent 259006 811e0e236714935d17e7cfc493e499c83a0a8fef
child 259008 b1255b21a94a2d09304c6d8cc55672281e5863c7
push idunknown
push userunknown
push dateunknown
reviewerswaldo
bugs1172609
milestone43.0a1
Bug 1172609 - Part 8: Fix the tz detection code. r=waldo
intl/icu-patches/bug-1172609-icu-fix.diff
intl/icu/source/common/putil.cpp
intl/icu/source/common/putilimp.h
intl/icu/source/i18n/timezone.cpp
intl/update-icu.sh
new file mode 100644
--- /dev/null
+++ b/intl/icu-patches/bug-1172609-icu-fix.diff
@@ -0,0 +1,81 @@
+This patch is taken from the version of ICU in Google's Chromium.
+
+See: https://chromium.googlesource.com/chromium/deps/icu/+/10834e84d250eb31a73496bfdb7923eaa43ead51
+
+diff --git a/intl/icu/source/common/putil.cpp b/intl/icu/source/common/putil.cpp
+--- a/intl/icu/source/common/putil.cpp
++++ b/intl/icu/source/common/putil.cpp
+@@ -965,16 +965,25 @@ static char* searchForTZFile(const char*
+                 }
+             }
+         }
+     }
+     closedir(dirp);
+     return result;
+ }
+ #endif
++
++U_CAPI void U_EXPORT2
++uprv_tzname_clear_cache()
++{
++#if defined(CHECK_LOCALTIME_LINK) && !defined(DEBUG_SKIP_LOCALTIME_LINK)
++    gTimeZoneBufferPtr = NULL;
++#endif
++}
++
+ U_CAPI const char* U_EXPORT2
+ uprv_tzname(int n)
+ {
+     const char *tzid = NULL;
+ #if U_PLATFORM_USES_ONLY_WIN32_API
+     tzid = uprv_detectWindowsTimeZone();
+ 
+     if (tzid != NULL) {
+diff --git a/intl/icu/source/common/putilimp.h b/intl/icu/source/common/putilimp.h
+--- a/intl/icu/source/common/putilimp.h
++++ b/intl/icu/source/common/putilimp.h
+@@ -478,16 +478,22 @@ U_INTERNAL int32_t  U_EXPORT2 uprv_timez
+  *   tzname(1)  Three-letter DST zone name derived from TZ environment
+  *              variable.  E.g., "PDT". If DST zone is omitted from TZ,
+  *              tzname(1) is an empty string.
+  * @internal
+  */
+ U_INTERNAL const char* U_EXPORT2 uprv_tzname(int n);
+ 
+ /**
++ * Reset the global tzname cache.
++ * @internal
++ */
++U_INTERNAL void uprv_tzname_clear_cache();
++
++/**
+  * Get UTC (GMT) time measured in milliseconds since 0:00 on 1/1/1970.
+  * This function is affected by 'faketime' and should be the bottleneck for all user-visible ICU time functions.
+  * @return the UTC time measured in milliseconds
+  * @internal
+  */
+ U_INTERNAL UDate U_EXPORT2 uprv_getUTCtime(void);
+ 
+ /**
+diff --git a/intl/icu/source/i18n/timezone.cpp b/intl/icu/source/i18n/timezone.cpp
+--- a/intl/icu/source/i18n/timezone.cpp
++++ b/intl/icu/source/i18n/timezone.cpp
+@@ -453,16 +453,18 @@ TimeZone::detectHostTimeZone()
+     int32_t rawOffset = 0;
+     const char *hostID;
+ 
+     // First, try to create a system timezone, based
+     // on the string ID in tzname[0].
+ 
+     uprv_tzset(); // Initialize tz... system data
+ 
++    uprv_tzname_clear_cache();
++
+     // Get the timezone ID from the host.  This function should do
+     // any required host-specific remapping; e.g., on Windows this
+     // function maps the Date and Time control panel setting to an
+     // ICU timezone ID.
+     hostID = uprv_tzname(0);
+ 
+     // Invert sign because UNIX semantics are backwards
+     rawOffset = uprv_timezone() * -U_MILLIS_PER_SECOND;
--- a/intl/icu/source/common/putil.cpp
+++ b/intl/icu/source/common/putil.cpp
@@ -965,16 +965,25 @@ static char* searchForTZFile(const char*
                 }
             }
         }
     }
     closedir(dirp);
     return result;
 }
 #endif
+
+U_CAPI void U_EXPORT2
+uprv_tzname_clear_cache()
+{
+#if defined(CHECK_LOCALTIME_LINK) && !defined(DEBUG_SKIP_LOCALTIME_LINK)
+    gTimeZoneBufferPtr = NULL;
+#endif
+}
+
 U_CAPI const char* U_EXPORT2
 uprv_tzname(int n)
 {
     const char *tzid = NULL;
 #if U_PLATFORM_USES_ONLY_WIN32_API
     tzid = uprv_detectWindowsTimeZone();
 
     if (tzid != NULL) {
--- a/intl/icu/source/common/putilimp.h
+++ b/intl/icu/source/common/putilimp.h
@@ -478,16 +478,22 @@ U_INTERNAL int32_t  U_EXPORT2 uprv_timez
  *   tzname(1)  Three-letter DST zone name derived from TZ environment
  *              variable.  E.g., "PDT". If DST zone is omitted from TZ,
  *              tzname(1) is an empty string.
  * @internal
  */
 U_INTERNAL const char* U_EXPORT2 uprv_tzname(int n);
 
 /**
+ * Reset the global tzname cache.
+ * @internal
+ */
+U_INTERNAL void uprv_tzname_clear_cache();
+
+/**
  * Get UTC (GMT) time measured in milliseconds since 0:00 on 1/1/1970.
  * This function is affected by 'faketime' and should be the bottleneck for all user-visible ICU time functions.
  * @return the UTC time measured in milliseconds
  * @internal
  */
 U_INTERNAL UDate U_EXPORT2 uprv_getUTCtime(void);
 
 /**
--- a/intl/icu/source/i18n/timezone.cpp
+++ b/intl/icu/source/i18n/timezone.cpp
@@ -453,16 +453,18 @@ TimeZone::detectHostTimeZone()
     int32_t rawOffset = 0;
     const char *hostID;
 
     // First, try to create a system timezone, based
     // on the string ID in tzname[0].
 
     uprv_tzset(); // Initialize tz... system data
 
+    uprv_tzname_clear_cache();
+
     // Get the timezone ID from the host.  This function should do
     // any required host-specific remapping; e.g., on Windows this
     // function maps the Date and Time control panel setting to an
     // ICU timezone ID.
     hostID = uprv_tzname(0);
 
     // Invert sign because UNIX semantics are backwards
     rawOffset = uprv_timezone() * -U_MILLIS_PER_SECOND;
--- a/intl/update-icu.sh
+++ b/intl/update-icu.sh
@@ -50,14 +50,15 @@ rm ${icu_dir}/source/data/unit/*.txt
 # (This ensures that if ICU modifications are performed properly, it's always
 # possible to run the command at the top of this script and make no changes to
 # the tree.)
 svn info $1 | grep -v '^Revision: [[:digit:]]\+$' > ${icu_dir}/SVN-INFO
 
 patch -d ${icu_dir}/../../ -p1 < ${icu_dir}/../icu-patches/bug-915735
 patch -d ${icu_dir}/../../ -p1 < ${icu_dir}/../icu-patches/suppress-warnings.diff
 patch -d ${icu_dir}/../../ -p1 < ${icu_dir}/../icu-patches/pkgdata-large-buffer.diff
+patch -d ${icu_dir}/../../ -p1 < ${icu_dir}/../icu-patches/bug-1172609-icu-fix.diff
 
 # NOTE: If you're updating this script for a new ICU version, you have to rerun
 # js/src/tests/ecma_6/String/make-normalize-generateddata-input.py for any
 # normalization changes the new ICU implements.
 
 hg addremove ${icu_dir}