* [PATCH] tzfile.c fixes
@ 2007-10-16 11:34 Jakub Jelinek
2007-10-16 15:31 ` Jakub Jelinek
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2007-10-16 11:34 UTC (permalink / raw)
To: Ulrich Drepper; +Cc: Glibc hackers
Hi!
TZ=Asia/Tokyo date
since last tzfile.c changes shows 1hr more than actually is and JDT
for 32-bit date (and correct time and timezone for 64-bit date).
The difference is that for 32-bit libc we don't read the TZif2 part
of the zoneinfo file nor the POSIX string in it, and after the use_last
label the new code sets i to num_transitions - 1 and at found it
looks at i - 1 (i.e. num_transitions - 2).
The following patch fixes that, as well as assertion failure
on tst-mktime2 on 32-bit - e.g. for America/Sao_Paulo if time is in between
last transition and 0x7fffffff and last transition is dst, then
__tzname[0] == NULL, __tzname[1] = "something" and num_types > 1.
Generally, the forward search doesn't have to find the other __tzname
if i is sufficiently close to num_transitions, so I think it is best to
search backwards if the forward search doesn't help.
2007-10-16 Jakub Jelinek <jakub@redhat.com>
* time/tzfile.c (__tzfile_compute): For use_last case set
i to num_transition rather than num_transitions - 1. If forward
search for other __tzname didn't find it, search backwards.
--- libc/time/tzfile.c.jj 2007-10-16 09:50:03.000000000 +0200
+++ libc/time/tzfile.c 2007-10-16 13:10:25.000000000 +0200
@@ -596,7 +596,7 @@ __tzfile_compute (time_t timer, int use_
if (tzspec == NULL)
{
use_last:
- i = num_transitions - 1;
+ i = num_transitions;
goto found;
}
@@ -666,7 +666,8 @@ __tzfile_compute (time_t timer, int use_
i = hi;
found:
- /* assert (timer >= transitions[i - 1] && timer < transitions[i]); */
+ /* assert (timer >= transitions[i - 1]
+ && (i == num_transitions || timer < transitions[i])); */
__tzname[types[type_idxs[i - 1]].isdst]
= __tzstring (&zone_names[types[type_idxs[i - 1]].idx]);
size_t j = i;
@@ -681,12 +682,30 @@ __tzfile_compute (time_t timer, int use_
__tzname[dst] = __tzstring (&zone_names[idx]);
if (__tzname[1 - dst] != NULL)
- break;
+ goto got_tznames;
}
++j;
}
+ j = i - 1;
+ while (j > 0)
+ {
+ int type = type_idxs[--j];
+ int dst = types[type].isdst;
+ int idx = types[type].idx;
+
+ if (__tzname[dst] == NULL)
+ {
+ __tzname[dst] = __tzstring (&zone_names[idx]);
+
+ if (__tzname[1 - dst] != NULL)
+ goto got_tznames;
+ }
+ }
+ __tzname[1 - types[type_idxs[i - 1]].isdst]
+ = __tzname[types[type_idxs[i - 1]].isdst];
+ got_tznames:
i = type_idxs[i - 1];
}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] tzfile.c fixes
2007-10-16 11:34 [PATCH] tzfile.c fixes Jakub Jelinek
@ 2007-10-16 15:31 ` Jakub Jelinek
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2007-10-16 15:31 UTC (permalink / raw)
To: Ulrich Drepper; +Cc: Glibc hackers
Hi!
The second part isn't desirable e.g. in case of Asia/Tokyo and gave
different results between 32-bit and 64-bit libc say on:
#define _GNU_SOURCE
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
int
main (void)
{
setenv ("TZ", "Europe/Paris", 1);
tzset ();
time_t t = 2144000000; /* Dec 9th, 2037 */
struct tm *tmp = localtime (&t);
printf ("Paris: is_dst %d %s %s\n", tmp->tm_isdst, tzname[0], tzname[1]);
setenv ("TZ", "America/Sao_Paulo", 1);
tzset ();
tmp = localtime (&t);
printf ("Sao Paulo: is_dst %d %s %s\n", tmp->tm_isdst, tzname[0], tzname[1]);
setenv ("TZ", "Asia/Tokyo", 1);
tzset ();
tmp = localtime (&t);
printf ("Tokyo: is_dst %d %s %s\n", tmp->tm_isdst, tzname[0], tzname[1]);
return 0;
}
which IMHO should print:
Paris: is_dst 0 CET CEST
Sao Paulo: is_dst 1 BRT BRST
Tokyo: is_dst 0 JST JST
(and does in 64-bit libc). The following patch only does backward
search if timer was past last transition and only considers transitions
at most a year before the last transition, which is IMHO good enough.
Other alternative is to grab POSIX time string even in 32-bit libc
(but even then we'd need to do at least something in __tzfile_compute
for this, like the
__tzname[1 - types[type_idxs[i - 1]].isdst]
= __tzname[types[type_idxs[i - 1]].isdst];
assignment if we haven't found the second __tzname.
--- libc/time/tzfile.c.jj 2007-10-16 17:01:56.000000000 +0200
+++ libc/time/tzfile.c 2007-10-16 17:12:31.000000000 +0200
@@ -671,9 +671,21 @@ __tzfile_compute (time_t timer, int use_
__tzname[types[type_idxs[i - 1]].isdst]
= __tzstring (&zone_names[types[type_idxs[i - 1]].idx]);
size_t j = i;
- while (j < num_transitions)
+ do
{
- int type = type_idxs[j];
+ int type;
+ if (__builtin_expect (i == num_transitions, 0))
+ {
+ if (j-- == 0)
+ break;
+ /* When doing backward search, only look at recent
+ transitions (within last year). */
+ if (transitions[j] < timer - 31556952)
+ break;
+ type = type_idxs[j];
+ }
+ else
+ type = type_idxs[j++];
int dst = types[type].isdst;
int idx = types[type].idx;
@@ -682,12 +694,15 @@ __tzfile_compute (time_t timer, int use_
__tzname[dst] = __tzstring (&zone_names[idx]);
if (__tzname[1 - dst] != NULL)
- break;
+ goto got_tznames;
}
-
- ++j;
}
+ while (j < num_transitions);
+
+ __tzname[1 - types[type_idxs[i - 1]].isdst]
+ = __tzname[types[type_idxs[i - 1]].isdst];
+ got_tznames:
i = type_idxs[i - 1];
}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-10-16 15:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-16 11:34 [PATCH] tzfile.c fixes Jakub Jelinek
2007-10-16 15:31 ` Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).