From: Nick Bowler Date: Tue, 24 Jan 2023 04:47:18 +0000 (-0500) Subject: Provide strtoumax fallback in the scanner. X-Git-Tag: v1.3~180 X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/commitdiff_plain/802e3b1cc242d149fc23cc65f1714c99c1f8520a Provide strtoumax fallback in the scanner. We already do something similar in the test suite. We don't really care about the full range of uintmax_t, we just prefer the widest type that is available to us. It is no real problem to fall back to a narrower conversion function. --- diff --git a/configure.ac b/configure.ac index f1171ff..7729fcc 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -dnl Copyright © 2011-2013, 2020-2022 Nick Bowler +dnl Copyright © 2011-2013, 2020-2023 Nick Bowler dnl dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2. dnl This is free software: you are free to do what the fuck you want to. @@ -91,7 +91,7 @@ AH_BOTTOM([#include ]) AC_CONFIG_TESTDIR([.], [test:.]) DX_PROG_AUTOTEST AM_CONDITIONAL([HAVE_AUTOTEST], [test x"$dx_cv_autotest_works" = x"yes"]) -AC_CHECK_FUNCS_ONCE([strtoull __strtoull]) +AC_CHECK_FUNCS_ONCE([strtoumax strtoull __strtoull]) AC_CONFIG_FILES([ Makefile diff --git a/src/scan.l b/src/scan.l index cc152b9..1688873 100644 --- a/src/scan.l +++ b/src/scan.l @@ -1,7 +1,7 @@ %top{ /* * Scanner for C declarations. - * Copyright © 2011 Nick Bowler + * Copyright © 2011, 2021, 2023 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,6 +30,20 @@ #include "cdecl-internal.h" #include "cdecl.h" +#if HAVE_STRTOUMAX +/* Best case, implementation provides strtoumax. */ +# define STRTOUMAX strtoumax +#elif HAVE_STRTOULL +/* Fall back to strtoull, with possibly reduced range. */ +#define STRTOUMAX strtoull +#elif HAVE___STRTOULL +/* HP-UX 11 has __strtoull in */ +#define STRTOUMAX __strtoull +#else +/* Fall back to strtoul, with possibly reduced range. */ +#define STRTOUMAX strtoul +#endif + #define lex_error(...) do { \ cdecl__err(CDECL_ENOPARSE, __VA_ARGS__); \ return T_LEX_ERROR; \ @@ -102,7 +116,7 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+ char *end; errno = 0; - yylval->uintval = strtoumax(yytext, &end, 0); + yylval->uintval = STRTOUMAX(yytext, &end, 0); if (errno == ERANGE) lex_error(_("integer constant out of range")); if (*end)