libstdc++: Test for tzdata.zi before fallback version files.

Message ID 20221224114009.20261-1-iain@sandoe.co.uk
State Committed
Headers
Series libstdc++: Test for tzdata.zi before fallback version files. |

Commit Message

Iain Sandoe Dec. 24, 2022, 11:40 a.m. UTC
  I tested this (along with the other posted patches for zoneinfo) using
an installation built from the 2022g release on x86_64-darwin21.  Wider
testing will follow.  If we are in an installation without the tzdata.zi
then although we'll report the version OK, the available functionality
will be basic.

OK for trunk?
Iain

--- 8< ---

Several systems/distributions do not provide the raw tzdata.zi file in
their zoneinfo installation.  However, we might provide an alternate
installation path at configure time, so that we should check for the
tzdata.zi file first and then fall back to system-specific files like
+VERSION etc. on those systems.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

libstdc++-v3/ChangeLog:

	* src/c++20/tzdb.cc (remote_version): Look for the tzdata.zi
	file before falling back to system-specific ones on Darwin and
	BSD.
---
 libstdc++-v3/src/c++20/tzdb.cc | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
  

Comments

Jonathan Wakely Dec. 24, 2022, 12:03 p.m. UTC | #1
On Sat, 24 Dec 2022, 11:40 Iain Sandoe via Libstdc++, <libstdc++@gcc.gnu.org>
wrote:

> I tested this (along with the other posted patches for zoneinfo) using
> an installation built from the 2022g release on x86_64-darwin21.  Wider
> testing will follow.  If we are in an installation without the tzdata.zi
> then although we'll report the version OK, the available functionality
> will be basic.
>

Yeah, my thinking was that you could still query the "remote version" i.e.
the one on disk, even if it can't be loaded (in which case, the basic
fallback one has version "ersatz", so you can tell it doesn't match the one
on disk).


> OK for trunk?
> Iain
>
> --- 8< ---
>
> Several systems/distributions do not provide the raw tzdata.zi file in
> their zoneinfo installation.  However, we might provide an alternate
> installation path at configure time, so that we should check for the
> tzdata.zi file first and then fall back to system-specific files like
> +VERSION etc. on those systems.
>


Oh yes, good point. If we have an override for tzdata then than is the
on-disk one and we should check its version.


OK for trunk, thanks.



> Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
>
> libstdc++-v3/ChangeLog:
>
>         * src/c++20/tzdb.cc (remote_version): Look for the tzdata.zi
>         file before falling back to system-specific ones on Darwin and
>         BSD.
> ---
>  libstdc++-v3/src/c++20/tzdb.cc | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/libstdc++-v3/src/c++20/tzdb.cc
> b/libstdc++-v3/src/c++20/tzdb.cc
> index c4311d0902a..39e4466f932 100644
> --- a/libstdc++-v3/src/c++20/tzdb.cc
> +++ b/libstdc++-v3/src/c++20/tzdb.cc
> @@ -1061,16 +1061,11 @@ namespace std::chrono
>    namespace
>    {
>      // Read the version number from a tzdata.zi file.
> +    // Note that some systems do not have this file available by default
> +    // but we can configure the library to point to an alternate
> installation.
>      string
>      remote_version(istream* zif)
>      {
> -#if defined __NetBSD__
> -    if (string ver; ifstream(zoneinfo_dir() + "/TZDATA_VERSION") >> ver)
> -      return ver;
> -#elif defined __APPLE__
> -    if (string ver; ifstream(zoneinfo_dir() + "/+VERSION") >> ver)
> -      return ver;
> -#else
>        ifstream f;
>        if (!zif)
>         {
> @@ -1083,6 +1078,14 @@ namespace std::chrono
>        if (*zif >> hash >> label >> version)
>         if (hash == '#' && label == "version")
>           return version;
> +#if defined __NetBSD__
> +    if (string ver; ifstream(zoneinfo_dir() + "/TZDATA_VERSION") >> ver)
> +      return ver;
> +#elif defined __APPLE__
> +    // The standard install on macOS has no tzdata.zi, but we can find the
> +    // version from +VERSION.
> +    if (string ver; ifstream(zoneinfo_dir() + "/+VERSION") >> ver)
> +      return ver;
>  #endif
>        __throw_runtime_error("tzdb: no version found in tzdata.zi");
>      }
> --
> 2.37.1 (Apple Git-137.1)
>
>
  
Andreas Schwab Dec. 24, 2022, 12:25 p.m. UTC | #2
On Dez 24 2022, Iain Sandoe via Gcc-patches wrote:

> @@ -1083,6 +1078,14 @@ namespace std::chrono
>        if (*zif >> hash >> label >> version)
>  	if (hash == '#' && label == "version")
>  	  return version;
> +#if defined __NetBSD__
> +    if (string ver; ifstream(zoneinfo_dir() + "/TZDATA_VERSION") >> ver)
> +      return ver;
> +#elif defined __APPLE__
> +    // The standard install on macOS has no tzdata.zi, but we can find the
> +    // version from +VERSION.
> +    if (string ver; ifstream(zoneinfo_dir() + "/+VERSION") >> ver)
> +      return ver;
>  #endif
>        __throw_runtime_error("tzdb: no version found in tzdata.zi");
>      }

Looks like indentation is off here.
  
Iain Sandoe Dec. 24, 2022, 5:52 p.m. UTC | #3
> On 24 Dec 2022, at 12:25, Andreas Schwab <schwab@linux-m68k.org> wrote:
> 
> On Dez 24 2022, Iain Sandoe via Gcc-patches wrote:
> 
>> @@ -1083,6 +1078,14 @@ namespace std::chrono
>>       if (*zif >> hash >> label >> version)
>> 	if (hash == '#' && label == "version")
>> 	  return version;
>> +#if defined __NetBSD__
>> +    if (string ver; ifstream(zoneinfo_dir() + "/TZDATA_VERSION") >> ver)
>> +      return ver;
>> +#elif defined __APPLE__
>> +    // The standard install on macOS has no tzdata.zi, but we can find the
>> +    // version from +VERSION.
>> +    if (string ver; ifstream(zoneinfo_dir() + "/+VERSION") >> ver)
>> +      return ver;
>> #endif
>>       __throw_runtime_error("tzdb: no version found in tzdata.zi");
>>     }
> 
> Looks like indentation is off here.

thanks, I corrected that before pushing the patch.
Iain

> 
> -- 
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."
  

Patch

diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc
index c4311d0902a..39e4466f932 100644
--- a/libstdc++-v3/src/c++20/tzdb.cc
+++ b/libstdc++-v3/src/c++20/tzdb.cc
@@ -1061,16 +1061,11 @@  namespace std::chrono
   namespace
   {
     // Read the version number from a tzdata.zi file.
+    // Note that some systems do not have this file available by default
+    // but we can configure the library to point to an alternate installation.
     string
     remote_version(istream* zif)
     {
-#if defined __NetBSD__
-    if (string ver; ifstream(zoneinfo_dir() + "/TZDATA_VERSION") >> ver)
-      return ver;
-#elif defined __APPLE__
-    if (string ver; ifstream(zoneinfo_dir() + "/+VERSION") >> ver)
-      return ver;
-#else
       ifstream f;
       if (!zif)
 	{
@@ -1083,6 +1078,14 @@  namespace std::chrono
       if (*zif >> hash >> label >> version)
 	if (hash == '#' && label == "version")
 	  return version;
+#if defined __NetBSD__
+    if (string ver; ifstream(zoneinfo_dir() + "/TZDATA_VERSION") >> ver)
+      return ver;
+#elif defined __APPLE__
+    // The standard install on macOS has no tzdata.zi, but we can find the
+    // version from +VERSION.
+    if (string ver; ifstream(zoneinfo_dir() + "/+VERSION") >> ver)
+      return ver;
 #endif
       __throw_runtime_error("tzdb: no version found in tzdata.zi");
     }