Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python configure fails to detect tzname on platforms that have it. #72295

Open
abalkin opened this issue Sep 12, 2016 · 9 comments
Open

Python configure fails to detect tzname on platforms that have it. #72295

abalkin opened this issue Sep 12, 2016 · 9 comments
Labels
3.7 (EOL) end of life build The build process and cross-build type-bug An unexpected behavior, bug, or error

Comments

@abalkin
Copy link
Member

abalkin commented Sep 12, 2016

BPO 28108
Nosy @malemburg, @abalkin, @vstinner, @izbyshev

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2016-09-12.19:33:55.115>
labels = ['type-bug', '3.7']
title = 'Python configure fails to detect tzname on platforms that have it.'
updated_at = <Date 2019-01-04.23:50:18.162>
user = 'https://github.com/abalkin'

bugs.python.org fields:

activity = <Date 2019-01-04.23:50:18.162>
actor = 'vstinner'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = []
creation = <Date 2016-09-12.19:33:55.115>
creator = 'belopolsky'
dependencies = []
files = []
hgrepos = []
issue_num = 28108
keywords = []
message_count = 9.0
messages = ['276098', '276111', '276112', '276117', '276121', '276122', '276123', '332394', '333025']
nosy_count = 4.0
nosy_names = ['lemburg', 'belopolsky', 'vstinner', 'izbyshev']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue28108'
versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

@abalkin
Copy link
Member Author

abalkin commented Sep 12, 2016

After running ./configure on Linux or MacOS X, check the generated pyconfig.h header:

$ grep TZNAME pyconfig.h
/* #undef HAVE_DECL_TZNAME */
/* #undef HAVE_TZNAME */

However, tzname exists and is declared in time.h on Linux and MacOS X as can be seen by compiling and running the following simple program:

$ cat tzname.c
#include <time.h>
#include <stdio.h>

int main() {
    tzset();
    printf("%s/%s\n", tzname[0], tzname[1]);
}
$ clang tzname.c -o tzname
$ ./tzname
EST/EDT

Note that tzname is mandated by the recent editions of POSIX <http://pubs.opengroup.org/onlinepubs/009695399/functions/tzset.html\>, so I am not sure whether we need to check for it in configure.

@abalkin abalkin added 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error labels Sep 12, 2016
@malemburg
Copy link
Member

Looking at the autoconf documentation, HAVE_TZNAME is only set iff struct tm does not have a tm_zone member *and* the external array tzname is found:

https://www.gnu.org/software/autoconf/manual/autoconf-2.64/html_node/Particular-Structures.html

If the struct tm does have a tm_zone member (which it does on Linux), the check for tzname is not even run.

@abalkin
Copy link
Member Author

abalkin commented Sep 12, 2016

HAVE_TZNAME is only set iff struct tm does not have a tm_zone member ...

I've figured that much from reading the generated configure script, but thanks for the pointer to the documentation.

@malemburg
Copy link
Member

If you want to separately check for the definition of tzname,
I guess you have to add a AC_DEFINE() section specifically
for tzname.

@abalkin
Copy link
Member Author

abalkin commented Sep 12, 2016

The real issue is that when setting the tzname tuple in the time module, we use a guess based on the value of tm_zone probed in June and January. I am not sure whether this is wise. Shouldn't we just use C tzname is it is available?

@malemburg
Copy link
Member

The real issue is that when setting the tzname tuple in the time module, we use a guess based on the value of tm_zone probed in June and January. I am not sure whether this is wise. Shouldn't we just use C tzname is it is available?

I don't think tzname is really all that useful. In mxDateTime,
I use strftime() with "%Z" to obtain the timezone string for
a given local time.

tzname tries to identify non-DST vs. DST of the local time zone,
but this may fail for cases where a country switches DST settings
in a particular year as it happened in Russia:

https://www.timeanddate.com/time/zone/russia/moscow

@abalkin
Copy link
Member Author

abalkin commented Sep 12, 2016

I don't think tzname is really all that useful.

I agree. More so after bpo-25283 (Make tm_gmtoff and tm_zone available on all platforms). That's why I don't see why the time module need to set tzname to anything other than what the C library does.

Interestingly, glibc may even change tzname[0] as a side-effect of calling localtime:

(on Linux)
$ cat lt.c
#include <time.h>
#include <stdio.h>


int main() {
  struct tm tm = {0, 0, 0, 1, 1, -100};
  time_t t;
  t = mktime(&tm);
  localtime(&t);
  printf("%s/%s  %d %d\n", tzname[0], tzname[1], timezone, daylight);
  t = 0;
  localtime(&t);
  printf("%s/%s  %d %d\n", tzname[0], tzname[1], timezone, daylight);
}
$ gcc lt.c -o lt
$ ./lt
LMT/EDT  18000 1
EST/EDT  18000 1

I think that's a bug in glibc because it makes no sense to change tzname[0] while not updating timezone.

@izbyshev
Copy link
Mannequin

izbyshev mannequin commented Dec 23, 2018

The resolution of this [1] glibc bug report effectively says that the use of global variables tzname, timezone and daylight is not supported by glibc unless a POSIX-style TZ setting is used (which is probably never in real world).

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=23859

@vstinner
Copy link
Member

vstinner commented Jan 4, 2019

See also bpo-35385.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@iritkatriel iritkatriel added the build The build process and cross-build label Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life build The build process and cross-build type-bug An unexpected behavior, bug, or error
Projects
Development

No branches or pull requests

4 participants