]> git.draconx.ca Git - cdecl99.git/commitdiff
Provide strtoumax fallback in the scanner.
authorNick Bowler <nbowler@draconx.ca>
Tue, 24 Jan 2023 04:47:18 +0000 (23:47 -0500)
committerNick Bowler <nbowler@draconx.ca>
Tue, 24 Jan 2023 04:47:18 +0000 (23:47 -0500)
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.

configure.ac
src/scan.l

index f1171ff8d0cb9e2b65c2f848d7311fc2612948da..7729fccfb546c6332fdbaaa2121ce716c717d6b6 100644 (file)
@@ -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 <conf_post.h>])
 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
index cc152b9984609a17182c513d7b97118fe7ff34a6..1688873eea7a98744f68041bd16a858cfd82b332 100644 (file)
@@ -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
 #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 <inttypes.h> */
+#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)