Time Zone code
==============
-The code in this directory is currently synced with tzcode release 2018f.
+The code in this directory is currently synced with tzcode release 2018g.
There are many cosmetic (and not so cosmetic) differences from the
original tzcode library, but diffs in the upstream version should usually
be propagated to our version. Here are some notes about that.
includes relying on configure's results rather than hand-hacked #defines,
and not relying on <stdint.h> features that may not exist on old systems.
(In particular this means using Postgres' definitions of the int32 and
-int64 typedefs, not int_fast32_t/int_fast64_t.)
+int64 typedefs, not int_fast32_t/int_fast64_t. Likewise we use
+PG_INT32_MIN/MAX not INT32_MIN/MAX.)
* Since Postgres is typically built on a system that has its own copy
of the <time.h> functions, we must avoid conflicting with those. This
mandates renaming typedef time_t to pg_time_t, and similarly for most
other exposed names.
+* zic.c's typedef "lineno" is renamed to "lineno_t", because having
+"lineno" in our typedefs list would cause unfortunate pgindent behavior
+in some other files where we have variables named that.
+
* We have exposed the tzload() and tzparse() internal functions, and
slightly modified the API of the former, in part because it now relies
on our own pg_open_tzfile() rather than opening files for itself.
-e 's/\bregister[ \t]//g' \
-e 's/int_fast32_t/int32/g' \
-e 's/int_fast64_t/int64/g' \
+ -e 's/INT32_MIN/PG_INT32_MIN/g' \
+ -e 's/INT32_MAX/PG_INT32_MAX/g' \
-e 's/struct[ \t]+tm\b/struct pg_tm/g' \
-e 's/\btime_t\b/pg_time_t/g' \
+ -e 's/lineno/lineno_t/g' \
and then run them through pgindent. (The first three sed patterns deal
with conversion of their block comment style to something pgindent
QTBUG-53071 <https://bugreports.qt.io/browse/QTBUG-53071>. This
workaround will no longer be needed when Qt 5.6.1 and earlier are
obsolete, say in the year 2021. */
+#ifndef WORK_AROUND_QTBUG_53071
enum
{
WORK_AROUND_QTBUG_53071 = true};
+#endif
static int charcnt;
static bool errors;
return (a < b) ? -1 : (a > b);
}
-static bool
-is32(const zic_t x)
-{
- return x == ((zic_t) ((int32) x));
-}
-
static void
swaptypes(int i, int j)
{
zic_t one = 1;
zic_t y2038_boundary = one << 31;
ptrdiff_t nats = timecnt + WORK_AROUND_QTBUG_53071;
- zic_t *ats = emalloc(size_product(nats, sizeof *ats + 1));
+
+ /*
+ * Allocate the ATS and TYPES arrays via a single malloc, as this is a bit
+ * faster.
+ */
+ zic_t *ats = emalloc(MAXALIGN(size_product(nats, sizeof *ats + 1)));
void *typesptr = ats + nats;
unsigned char *types = typesptr;
types[i] = attypes[i].type;
}
- /*
- * Work around QTBUG-53071 for timestamps less than y2038_boundary - 1, by
- * inserting a no-op transition at time y2038_boundary - 1. This works
- * only for timestamps before the boundary, which should be good enough in
- * practice as QTBUG-53071 should be long-dead by 2038.
- */
- if (WORK_AROUND_QTBUG_53071 && timecnt != 0
- && ats[timecnt - 1] < y2038_boundary - 1 && strchr(string, '<'))
- {
- ats[timecnt] = y2038_boundary - 1;
- types[timecnt] = types[timecnt - 1];
- timecnt++;
- }
-
/*
* Correct for leap seconds.
*/
}
}
+ /*
+ * Work around QTBUG-53071 for timestamps less than y2038_boundary - 1, by
+ * inserting a no-op transition at time y2038_boundary - 1. This works
+ * only for timestamps before the boundary, which should be good enough in
+ * practice as QTBUG-53071 should be long-dead by 2038. Do this after
+ * correcting for leap seconds, as the idea is to insert a transition just
+ * before 32-bit pg_time_t rolls around, and this occurs at a slightly
+ * different moment if transitions are leap-second corrected.
+ */
+ if (WORK_AROUND_QTBUG_53071 && timecnt != 0
+ && ats[timecnt - 1] < y2038_boundary - 1 && strchr(string, '<'))
+ {
+ ats[timecnt] = y2038_boundary - 1;
+ types[timecnt] = types[timecnt - 1];
+ timecnt++;
+ }
+
/*
* Figure out 32-bit-limited starts and counts.
*/
timei32 = 0;
leapcnt32 = leapcnt;
leapi32 = 0;
- while (timecnt32 > 0 && !is32(ats[timecnt32 - 1]))
+ while (0 < timecnt32 && PG_INT32_MAX < ats[timecnt32 - 1])
--timecnt32;
- while (timecnt32 > 0 && !is32(ats[timei32]))
+ while (1 < timecnt32 && ats[timei32] < PG_INT32_MIN
+ && ats[timei32 + 1] <= PG_INT32_MIN)
{
+ /*
+ * Discard too-low transitions, except keep any last too-low
+ * transition if no transition is exactly at PG_INT32_MIN. The kept
+ * transition will be output as an PG_INT32_MIN "transition"
+ * appropriate for buggy 32-bit clients that do not use time type 0
+ * for timestamps before the first transition; see below.
+ */
--timecnt32;
++timei32;
}
-
- /*
- * Output an INT32_MIN "transition" if appropriate; see below.
- */
- if (timei32 > 0 && ats[timei32] > PG_INT32_MIN)
- {
- --timei32;
- ++timecnt32;
- }
- while (leapcnt32 > 0 && !is32(trans[leapcnt32 - 1]))
+ while (0 < leapcnt32 && PG_INT32_MAX < trans[leapcnt32 - 1])
--leapcnt32;
- while (leapcnt32 > 0 && !is32(trans[leapi32]))
+ while (0 < leapcnt32 && trans[leapi32] < PG_INT32_MIN)
{
--leapcnt32;
++leapi32;
if (pass == 1)
/*
- * Output an INT32_MIN "transition" if appropriate; see above.
+ * Output an PG_INT32_MIN "transition" if appropriate; see
+ * above.
*/
puttzcode(((ats[i] < PG_INT32_MIN) ?
PG_INT32_MIN : ats[i]), fp);