Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 10bfda0

Browse files
committed
Sync our copy of the timezone library with IANA release tzcode2018g.
This patch absorbs an upstream fix to "zic" for a recently-introduced bug that made it output data that some 32-bit clients couldn't read. Given the current source data, the bug only manifests in zones with leap seconds, which we don't generate, so that there's no actual change in our installed timezone data files from this. Still, in case somebody uses our copy of "zic" to do something else, it seems best to apply the fix promptly. Also, update the README's notes about converting upstream code to our conventions.
1 parent 5c2e0ca commit 10bfda0

File tree

2 files changed

+49
-37
lines changed

2 files changed

+49
-37
lines changed

src/timezone/README

+10-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ match properly on the old version.
5555
Time Zone code
5656
==============
5757

58-
The code in this directory is currently synced with tzcode release 2018f.
58+
The code in this directory is currently synced with tzcode release 2018g.
5959
There are many cosmetic (and not so cosmetic) differences from the
6060
original tzcode library, but diffs in the upstream version should usually
6161
be propagated to our version. Here are some notes about that.
@@ -73,13 +73,18 @@ fixed that.)
7373
includes relying on configure's results rather than hand-hacked #defines,
7474
and not relying on <stdint.h> features that may not exist on old systems.
7575
(In particular this means using Postgres' definitions of the int32 and
76-
int64 typedefs, not int_fast32_t/int_fast64_t.)
76+
int64 typedefs, not int_fast32_t/int_fast64_t. Likewise we use
77+
PG_INT32_MIN/MAX not INT32_MIN/MAX.)
7778

7879
* Since Postgres is typically built on a system that has its own copy
7980
of the <time.h> functions, we must avoid conflicting with those. This
8081
mandates renaming typedef time_t to pg_time_t, and similarly for most
8182
other exposed names.
8283

84+
* zic.c's typedef "lineno" is renamed to "lineno_t", because having
85+
"lineno" in our typedefs list would cause unfortunate pgindent behavior
86+
in some other files where we have variables named that.
87+
8388
* We have exposed the tzload() and tzparse() internal functions, and
8489
slightly modified the API of the former, in part because it now relies
8590
on our own pg_open_tzfile() rather than opening files for itself.
@@ -108,8 +113,11 @@ to first run the tzcode source files through a sed filter like this:
108113
-e 's/\bregister[ \t]//g' \
109114
-e 's/int_fast32_t/int32/g' \
110115
-e 's/int_fast64_t/int64/g' \
116+
-e 's/INT32_MIN/PG_INT32_MIN/g' \
117+
-e 's/INT32_MAX/PG_INT32_MAX/g' \
111118
-e 's/struct[ \t]+tm\b/struct pg_tm/g' \
112119
-e 's/\btime_t\b/pg_time_t/g' \
120+
-e 's/lineno/lineno_t/g' \
113121

114122
and then run them through pgindent. (The first three sed patterns deal
115123
with conversion of their block comment style to something pgindent

src/timezone/zic.c

+39-35
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,11 @@ PERCENT_Z_LEN_BOUND = sizeof "+995959" - 1};
167167
QTBUG-53071 <https://bugreports.qt.io/browse/QTBUG-53071>. This
168168
workaround will no longer be needed when Qt 5.6.1 and earlier are
169169
obsolete, say in the year 2021. */
170+
#ifndef WORK_AROUND_QTBUG_53071
170171
enum
171172
{
172173
WORK_AROUND_QTBUG_53071 = true};
174+
#endif
173175

174176
static int charcnt;
175177
static bool errors;
@@ -1912,12 +1914,6 @@ atcomp(const void *avp, const void *bvp)
19121914
return (a < b) ? -1 : (a > b);
19131915
}
19141916

1915-
static bool
1916-
is32(const zic_t x)
1917-
{
1918-
return x == ((zic_t) ((int32) x));
1919-
}
1920-
19211917
static void
19221918
swaptypes(int i, int j)
19231919
{
@@ -1971,7 +1967,12 @@ writezone(const char *const name, const char *const string, char version,
19711967
zic_t one = 1;
19721968
zic_t y2038_boundary = one << 31;
19731969
ptrdiff_t nats = timecnt + WORK_AROUND_QTBUG_53071;
1974-
zic_t *ats = emalloc(size_product(nats, sizeof *ats + 1));
1970+
1971+
/*
1972+
* Allocate the ATS and TYPES arrays via a single malloc, as this is a bit
1973+
* faster.
1974+
*/
1975+
zic_t *ats = emalloc(MAXALIGN(size_product(nats, sizeof *ats + 1)));
19751976
void *typesptr = ats + nats;
19761977
unsigned char *types = typesptr;
19771978

@@ -2029,20 +2030,6 @@ writezone(const char *const name, const char *const string, char version,
20292030
types[i] = attypes[i].type;
20302031
}
20312032

2032-
/*
2033-
* Work around QTBUG-53071 for timestamps less than y2038_boundary - 1, by
2034-
* inserting a no-op transition at time y2038_boundary - 1. This works
2035-
* only for timestamps before the boundary, which should be good enough in
2036-
* practice as QTBUG-53071 should be long-dead by 2038.
2037-
*/
2038-
if (WORK_AROUND_QTBUG_53071 && timecnt != 0
2039-
&& ats[timecnt - 1] < y2038_boundary - 1 && strchr(string, '<'))
2040-
{
2041-
ats[timecnt] = y2038_boundary - 1;
2042-
types[timecnt] = types[timecnt - 1];
2043-
timecnt++;
2044-
}
2045-
20462033
/*
20472034
* Correct for leap seconds.
20482035
*/
@@ -2057,32 +2044,48 @@ writezone(const char *const name, const char *const string, char version,
20572044
}
20582045
}
20592046

2047+
/*
2048+
* Work around QTBUG-53071 for timestamps less than y2038_boundary - 1, by
2049+
* inserting a no-op transition at time y2038_boundary - 1. This works
2050+
* only for timestamps before the boundary, which should be good enough in
2051+
* practice as QTBUG-53071 should be long-dead by 2038. Do this after
2052+
* correcting for leap seconds, as the idea is to insert a transition just
2053+
* before 32-bit pg_time_t rolls around, and this occurs at a slightly
2054+
* different moment if transitions are leap-second corrected.
2055+
*/
2056+
if (WORK_AROUND_QTBUG_53071 && timecnt != 0
2057+
&& ats[timecnt - 1] < y2038_boundary - 1 && strchr(string, '<'))
2058+
{
2059+
ats[timecnt] = y2038_boundary - 1;
2060+
types[timecnt] = types[timecnt - 1];
2061+
timecnt++;
2062+
}
2063+
20602064
/*
20612065
* Figure out 32-bit-limited starts and counts.
20622066
*/
20632067
timecnt32 = timecnt;
20642068
timei32 = 0;
20652069
leapcnt32 = leapcnt;
20662070
leapi32 = 0;
2067-
while (timecnt32 > 0 && !is32(ats[timecnt32 - 1]))
2071+
while (0 < timecnt32 && PG_INT32_MAX < ats[timecnt32 - 1])
20682072
--timecnt32;
2069-
while (timecnt32 > 0 && !is32(ats[timei32]))
2073+
while (1 < timecnt32 && ats[timei32] < PG_INT32_MIN
2074+
&& ats[timei32 + 1] <= PG_INT32_MIN)
20702075
{
2076+
/*
2077+
* Discard too-low transitions, except keep any last too-low
2078+
* transition if no transition is exactly at PG_INT32_MIN. The kept
2079+
* transition will be output as an PG_INT32_MIN "transition"
2080+
* appropriate for buggy 32-bit clients that do not use time type 0
2081+
* for timestamps before the first transition; see below.
2082+
*/
20712083
--timecnt32;
20722084
++timei32;
20732085
}
2074-
2075-
/*
2076-
* Output an INT32_MIN "transition" if appropriate; see below.
2077-
*/
2078-
if (timei32 > 0 && ats[timei32] > PG_INT32_MIN)
2079-
{
2080-
--timei32;
2081-
++timecnt32;
2082-
}
2083-
while (leapcnt32 > 0 && !is32(trans[leapcnt32 - 1]))
2086+
while (0 < leapcnt32 && PG_INT32_MAX < trans[leapcnt32 - 1])
20842087
--leapcnt32;
2085-
while (leapcnt32 > 0 && !is32(trans[leapi32]))
2088+
while (0 < leapcnt32 && trans[leapi32] < PG_INT32_MIN)
20862089
{
20872090
--leapcnt32;
20882091
++leapi32;
@@ -2315,7 +2318,8 @@ writezone(const char *const name, const char *const string, char version,
23152318
if (pass == 1)
23162319

23172320
/*
2318-
* Output an INT32_MIN "transition" if appropriate; see above.
2321+
* Output an PG_INT32_MIN "transition" if appropriate; see
2322+
* above.
23192323
*/
23202324
puttzcode(((ats[i] < PG_INT32_MIN) ?
23212325
PG_INT32_MIN : ats[i]), fp);

0 commit comments

Comments
 (0)