From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7948 invoked by alias); 16 Oct 2007 15:31:53 -0000 Received: (qmail 7923 invoked by uid 22791); 16 Oct 2007 15:31:51 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 16 Oct 2007 15:31:47 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id l9GFZG23000449; Tue, 16 Oct 2007 17:35:16 +0200 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id l9GFZGEl000448; Tue, 16 Oct 2007 17:35:16 +0200 Date: Tue, 16 Oct 2007 15:31:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: Re: [PATCH] tzfile.c fixes Message-ID: <20071016153515.GL2896@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek References: <20071016113817.GK2896@sunsite.mff.cuni.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20071016113817.GK2896@sunsite.mff.cuni.cz> User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2007-10/txt/msg00017.txt.bz2 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 #include #include 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