summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2023-05-17 12:38:28 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2023-05-17 12:49:42 -0700
commit29bf76b33dbffb77d028e0663f09bc065b362655 (patch)
tree63cf62c8aed5828df4e9cff70ab58c424a2ab7fe
parentd959e39cbd54b4755525bcbd907a3402843dabba (diff)
downloadgnulib-master.tar.gz
stdckdint: use in parse-datetimeHEADmaster
* lib/parse-datetime.y (apply_relative_time, zone, date) (iso_8601_date, relunit, relunit_snumber, time_zone_hhmm) (to_tm_year, yylex, parse_datetime_body): Prefer ckd_add to INT_ADD_WRAPV etc., and include stdckdint.h. * modules/parse-datetime (Depends-on): Add stdckdint.
-rw-r--r--ChangeLog7
-rw-r--r--lib/parse-datetime.y107
-rw-r--r--modules/parse-datetime1
3 files changed, 60 insertions, 55 deletions
diff --git a/ChangeLog b/ChangeLog
index fc4e43a881..323d41c0b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,12 +2,15 @@
stdckdint: use in more modules
* lib/nstrftime.c (__strftime_internal):
+ * lib/parse-datetime.y (apply_relative_time, zone, date)
+ (iso_8601_date, relunit, relunit_snumber, time_zone_hhmm)
+ (to_tm_year, yylex, parse_datetime_body):
* lib/timespec-add.c (timespec_add):
* lib/timespec-sub.c (timespec_sub):
* lib/xstrtol.c (bkm_scale):
Prefer ckd_add to INT_ADD_WRAPV etc., and include stdckdint.h.
- * modules/nstrftime, modules/timespec-add, modules/timespec-sub:
- * modules/xstrtol:
+ * modules/nstrftime, modules/parse-datetime:
+ * modules/timespec-add, modules/timespec-sub, modules/xstrtol:
(Depends-on): Add stdckdint.
nstrftime: suggest to glibc how to avoid alloca
diff --git a/lib/parse-datetime.y b/lib/parse-datetime.y
index a0487a3713..18c9ebef3c 100644
--- a/lib/parse-datetime.y
+++ b/lib/parse-datetime.y
@@ -54,6 +54,7 @@
#include <inttypes.h>
#include <c-ctype.h>
#include <stdarg.h>
+#include <stdckdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -293,20 +294,20 @@ static bool
apply_relative_time (parser_control *pc, relative_time rel, int factor)
{
if (factor < 0
- ? (INT_SUBTRACT_WRAPV (pc->rel.ns, rel.ns, &pc->rel.ns)
- | INT_SUBTRACT_WRAPV (pc->rel.seconds, rel.seconds, &pc->rel.seconds)
- | INT_SUBTRACT_WRAPV (pc->rel.minutes, rel.minutes, &pc->rel.minutes)
- | INT_SUBTRACT_WRAPV (pc->rel.hour, rel.hour, &pc->rel.hour)
- | INT_SUBTRACT_WRAPV (pc->rel.day, rel.day, &pc->rel.day)
- | INT_SUBTRACT_WRAPV (pc->rel.month, rel.month, &pc->rel.month)
- | INT_SUBTRACT_WRAPV (pc->rel.year, rel.year, &pc->rel.year))
- : (INT_ADD_WRAPV (pc->rel.ns, rel.ns, &pc->rel.ns)
- | INT_ADD_WRAPV (pc->rel.seconds, rel.seconds, &pc->rel.seconds)
- | INT_ADD_WRAPV (pc->rel.minutes, rel.minutes, &pc->rel.minutes)
- | INT_ADD_WRAPV (pc->rel.hour, rel.hour, &pc->rel.hour)
- | INT_ADD_WRAPV (pc->rel.day, rel.day, &pc->rel.day)
- | INT_ADD_WRAPV (pc->rel.month, rel.month, &pc->rel.month)
- | INT_ADD_WRAPV (pc->rel.year, rel.year, &pc->rel.year)))
+ ? (ckd_sub (&pc->rel.ns, pc->rel.ns, rel.ns)
+ | ckd_sub (&pc->rel.seconds, pc->rel.seconds, rel.seconds)
+ | ckd_sub (&pc->rel.minutes, pc->rel.minutes, rel.minutes)
+ | ckd_sub (&pc->rel.hour, pc->rel.hour, rel.hour)
+ | ckd_sub (&pc->rel.day, pc->rel.day, rel.day)
+ | ckd_sub (&pc->rel.month, pc->rel.month, rel.month)
+ | ckd_sub (&pc->rel.year, pc->rel.year, rel.year))
+ : (ckd_add (&pc->rel.ns, pc->rel.ns, rel.ns)
+ | ckd_add (&pc->rel.seconds, pc->rel.seconds, rel.seconds)
+ | ckd_add (&pc->rel.minutes, pc->rel.minutes, rel.minutes)
+ | ckd_add (&pc->rel.hour, pc->rel.hour, rel.hour)
+ | ckd_add (&pc->rel.day, pc->rel.day, rel.day)
+ | ckd_add (&pc->rel.month, pc->rel.month, rel.month)
+ | ckd_add (&pc->rel.year, pc->rel.year, rel.year)))
return false;
pc->rels_seen = true;
return true;
@@ -760,7 +761,7 @@ zone:
}
| tZONE tSNUMBER o_colon_minutes
{ if (! time_zone_hhmm (pc, $2, $3)) YYABORT;
- if (INT_ADD_WRAPV (pc->time_zone, $1, &pc->time_zone)) YYABORT; }
+ if (ckd_add (&pc->time_zone, pc->time_zone, $1)) YYABORT; }
| tDAYZONE
{ pc->time_zone = $1 + 60 * 60; }
| tZONE tDST
@@ -836,15 +837,15 @@ date:
/* E.g., 17-JUN-1992. */
pc->day = $1.value;
pc->month = $2;
- if (INT_SUBTRACT_WRAPV (0, $3.value, &pc->year.value)) YYABORT;
+ if (ckd_sub (&pc->year.value, 0, $3.value)) YYABORT;
pc->year.digits = $3.digits;
}
| tMONTH tSNUMBER tSNUMBER
{
/* E.g., JUN-17-1992. */
pc->month = $1;
- if (INT_SUBTRACT_WRAPV (0, $2.value, &pc->day)) YYABORT;
- if (INT_SUBTRACT_WRAPV (0, $3.value, &pc->year.value)) YYABORT;
+ if (ckd_sub (&pc->day, 0, $2.value)) YYABORT;
+ if (ckd_sub (&pc->year.value, 0, $3.value)) YYABORT;
pc->year.digits = $3.digits;
}
| tMONTH tUNUMBER
@@ -877,8 +878,8 @@ iso_8601_date:
{
/* ISO 8601 format. YYYY-MM-DD. */
pc->year = $1;
- if (INT_SUBTRACT_WRAPV (0, $2.value, &pc->month)) YYABORT;
- if (INT_SUBTRACT_WRAPV (0, $3.value, &pc->day)) YYABORT;
+ if (ckd_sub (&pc->month, 0, $2.value)) YYABORT;
+ if (ckd_sub (&pc->day, 0, $3.value)) YYABORT;
}
;
@@ -906,10 +907,10 @@ relunit:
{ $$ = RELATIVE_TIME_0; $$.month = 1; }
| tORDINAL tDAY_UNIT
{ $$ = RELATIVE_TIME_0;
- if (INT_MULTIPLY_WRAPV ($1, $2, &$$.day)) YYABORT; }
+ if (ckd_mul (&$$.day, $1, $2)) YYABORT; }
| tUNUMBER tDAY_UNIT
{ $$ = RELATIVE_TIME_0;
- if (INT_MULTIPLY_WRAPV ($1.value, $2, &$$.day)) YYABORT; }
+ if (ckd_mul (&$$.day, $1.value, $2)) YYABORT; }
| tDAY_UNIT
{ $$ = RELATIVE_TIME_0; $$.day = $1; }
| tORDINAL tHOUR_UNIT
@@ -944,7 +945,7 @@ relunit_snumber:
{ $$ = RELATIVE_TIME_0; $$.month = $1.value; }
| tSNUMBER tDAY_UNIT
{ $$ = RELATIVE_TIME_0;
- if (INT_MULTIPLY_WRAPV ($1.value, $2, &$$.day)) YYABORT; }
+ if (ckd_mul (&$$.day, $1.value, $2)) YYABORT; }
| tSNUMBER tHOUR_UNIT
{ $$ = RELATIVE_TIME_0; $$.hour = $1.value; }
| tSNUMBER tMINUTE_UNIT
@@ -1214,10 +1215,10 @@ time_zone_hhmm (parser_control *pc, textint s, intmax_t mm)
n_minutes = (s.value / 100) * 60 + s.value % 100;
else
{
- overflow |= INT_MULTIPLY_WRAPV (s.value, 60, &n_minutes);
+ overflow |= ckd_mul (&n_minutes, s.value, 60);
overflow |= (s.negative
- ? INT_SUBTRACT_WRAPV (n_minutes, mm, &n_minutes)
- : INT_ADD_WRAPV (n_minutes, mm, &n_minutes));
+ ? ckd_sub (&n_minutes, n_minutes, mm)
+ : ckd_add (&n_minutes, n_minutes, mm));
}
if (overflow || ! (-24 * 60 <= n_minutes && n_minutes <= 24 * 60))
@@ -1277,8 +1278,8 @@ to_tm_year (textint textyear, bool debug, int *tm_year)
}
if (year < 0
- ? INT_SUBTRACT_WRAPV (-TM_YEAR_BASE, year, tm_year)
- : INT_SUBTRACT_WRAPV (year, TM_YEAR_BASE, tm_year))
+ ? ckd_sub (tm_year, -TM_YEAR_BASE, year)
+ : ckd_sub (tm_year, year, TM_YEAR_BASE))
{
if (debug)
dbg_printf (_("error: out-of-range year %"PRIdMAX"\n"), year);
@@ -1434,9 +1435,9 @@ yylex (union YYSTYPE *lvalp, parser_control *pc)
time_t value = 0;
do
{
- if (INT_MULTIPLY_WRAPV (value, 10, &value))
+ if (ckd_mul (&value, value, 10))
return '?';
- if (INT_ADD_WRAPV (value, sign < 0 ? '0' - c : c - '0', &value))
+ if (ckd_add (&value, value, sign < 0 ? '0' - c : c - '0'))
return '?';
c = *++p;
}
@@ -1473,7 +1474,7 @@ yylex (union YYSTYPE *lvalp, parser_control *pc)
negative. */
if (sign < 0 && ns)
{
- if (INT_SUBTRACT_WRAPV (s, 1, &s))
+ if (ckd_sub (&s, s, 1))
return '?';
ns = BILLION - ns;
}
@@ -1799,7 +1800,7 @@ parse_datetime_body (struct timespec *result, char const *p,
#ifdef GNULIB_PARSE_DATETIME2
pc.parse_datetime_debug = (flags & PARSE_DATETIME_DEBUG) != 0;
#endif
- if (INT_ADD_WRAPV (tmp.tm_year, TM_YEAR_BASE, &pc.year.value))
+ if (ckd_add (&pc.year.value, tmp.tm_year, TM_YEAR_BASE))
{
if (debugging (&pc))
dbg_printf (_("error: initial year out of range\n"));
@@ -1846,7 +1847,7 @@ parse_datetime_body (struct timespec *result, char const *p,
for (quarter = 1; quarter <= 3; quarter++)
{
time_t probe;
- if (INT_ADD_WRAPV (Start, quarter * (90 * 24 * 60 * 60), &probe))
+ if (ckd_add (&probe, Start, quarter * (90 * 24 * 60 * 60)))
break;
struct tm probe_tm;
if (localtime_rz (tz, &probe, &probe_tm) && probe_tm.tm_zone
@@ -1965,8 +1966,8 @@ parse_datetime_body (struct timespec *result, char const *p,
}
if (! to_tm_year (pc.year, debugging (&pc), &tm.tm_year)
- || INT_ADD_WRAPV (pc.month, -1, &tm.tm_mon)
- || INT_ADD_WRAPV (pc.day, 0, &tm.tm_mday))
+ || ckd_add (&tm.tm_mon, pc.month, -1)
+ || ckd_add (&tm.tm_mday, pc.day, 0))
{
if (debugging (&pc))
dbg_printf (_("error: year, month, or day overflow\n"));
@@ -2072,13 +2073,13 @@ parse_datetime_body (struct timespec *result, char const *p,
{
intmax_t dayincr;
tm.tm_yday = -1;
- if (! (INT_MULTIPLY_WRAPV ((pc.day_ordinal
- - (0 < pc.day_ordinal
- && tm.tm_wday != pc.day_number)),
- 7, &dayincr)
- || INT_ADD_WRAPV ((pc.day_number - tm.tm_wday + 7) % 7,
- dayincr, &dayincr)
- || INT_ADD_WRAPV (dayincr, tm.tm_mday, &tm.tm_mday)))
+ intmax_t day_ordinal = (pc.day_ordinal
+ - (0 < pc.day_ordinal
+ && tm.tm_wday != pc.day_number));
+ if (! (ckd_mul (&dayincr, day_ordinal, 7)
+ || ckd_add (&dayincr, (pc.day_number - tm.tm_wday + 7) % 7,
+ dayincr)
+ || ckd_add (&tm.tm_mday, dayincr, tm.tm_mday)))
{
tm.tm_isdst = -1;
Start = mktime_z (tz, &tm);
@@ -2135,9 +2136,9 @@ parse_datetime_body (struct timespec *result, char const *p,
}
int year, month, day;
- if (INT_ADD_WRAPV (tm.tm_year, pc.rel.year, &year)
- || INT_ADD_WRAPV (tm.tm_mon, pc.rel.month, &month)
- || INT_ADD_WRAPV (tm.tm_mday, pc.rel.day, &day))
+ if (ckd_add (&year, tm.tm_year, pc.rel.year)
+ || ckd_add (&month, tm.tm_mon, pc.rel.month)
+ || ckd_add (&day, tm.tm_mday, pc.rel.day))
{
if (debugging (&pc))
dbg_printf (_("error: %s:%d\n"), __FILE__, __LINE__);
@@ -2234,9 +2235,9 @@ parse_datetime_body (struct timespec *result, char const *p,
: (overflow = true, 0));
#endif
intmax_t delta;
- overflow |= INT_SUBTRACT_WRAPV (pc.time_zone, utcoff, &delta);
+ overflow |= ckd_sub (&delta, pc.time_zone, utcoff);
time_t t1;
- overflow |= INT_SUBTRACT_WRAPV (Start, delta, &t1);
+ overflow |= ckd_sub (&t1, Start, delta);
if (overflow)
{
if (debugging (&pc))
@@ -2270,12 +2271,12 @@ parse_datetime_body (struct timespec *result, char const *p,
int d4 = (sum_ns - normalized_ns) / BILLION;
intmax_t d1, t1, d2, t2, t3;
time_t t4;
- if (INT_MULTIPLY_WRAPV (pc.rel.hour, 60 * 60, &d1)
- || INT_ADD_WRAPV (Start, d1, &t1)
- || INT_MULTIPLY_WRAPV (pc.rel.minutes, 60, &d2)
- || INT_ADD_WRAPV (t1, d2, &t2)
- || INT_ADD_WRAPV (t2, pc.rel.seconds, &t3)
- || INT_ADD_WRAPV (t3, d4, &t4))
+ if (ckd_mul (&d1, pc.rel.hour, 60 * 60)
+ || ckd_add (&t1, Start, d1)
+ || ckd_mul (&d2, pc.rel.minutes, 60)
+ || ckd_add (&t2, t1, d2)
+ || ckd_add (&t3, t2, pc.rel.seconds)
+ || ckd_add (&t4, t3, d4))
{
if (debugging (&pc))
dbg_printf (_("error: adding relative time caused an "
diff --git a/modules/parse-datetime b/modules/parse-datetime
index ef281dcf30..60ac0b0824 100644
--- a/modules/parse-datetime
+++ b/modules/parse-datetime
@@ -22,6 +22,7 @@ inttypes
mktime
nstrftime
setenv
+stdckdint
unsetenv
time-h
time_r