From 3a65727b33b0a6acb4d713a16005f5628f74b6c3 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 27 Jan 2020 13:00:57 -0800 Subject: [PATCH] regex: port to non-GCC pre-IEC-60559 Problem reported by Arnold Robbins in: https://lists.gnu.org/r/bug-gnulib/2020-01/msg00154.html * lib/regex_internal.h (ULONG_WIDTH): Make this usable in #if. --- ChangeLog | 7 +++++++ lib/regex_internal.h | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a4ea8009b4..d3d1942a1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2020-01-27 Paul Eggert + + regex: port to non-GCC pre-IEC-60559 + Problem reported by Arnold Robbins in: + https://lists.gnu.org/r/bug-gnulib/2020-01/msg00154.html + * lib/regex_internal.h (ULONG_WIDTH): Make this usable in #if. + 2020-01-25 Bruno Haible c32isxdigit: Add tests. diff --git a/lib/regex_internal.h b/lib/regex_internal.h index 6d436fde1e..8c42586c42 100644 --- a/lib/regex_internal.h +++ b/lib/regex_internal.h @@ -142,7 +142,22 @@ # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2)) #endif #ifndef ULONG_WIDTH -# define ULONG_WIDTH (CHAR_BIT * sizeof (unsigned long int)) +# define ULONG_WIDTH REGEX_UINTEGER_WIDTH (ULONG_MAX) +/* The number of usable bits in an unsigned integer type with maximum + value MAX, as an int expression suitable in #if. Cover all known + practical hosts. This implementation exploits the fact that MAX is + 1 less than a power of 2, and merely counts the number of 1 bits in + MAX; "COBn" means "count the number of 1 bits in the low-order n bits". */ +# define REGEX_UINTEGER_WIDTH(max) REGEX_COB128 (max) +# define REGEX_COB128(n) (REGEX_COB64 ((n) >> 31 >> 31 >> 2) + REGEX_COB64 (n)) +# define REGEX_COB64(n) (REGEX_COB32 ((n) >> 31 >> 1) + REGEX_COB32 (n)) +# define REGEX_COB32(n) (REGEX_COB16 ((n) >> 16) + REGEX_COB16 (n)) +# define REGEX_COB16(n) (REGEX_COB8 ((n) >> 8) + REGEX_COB8 (n)) +# define REGEX_COB8(n) (REGEX_COB4 ((n) >> 4) + REGEX_COB4 (n)) +# define REGEX_COB4(n) (!!((n) & 8) + !!((n) & 4) + !!((n) & 2) + ((n) & 1)) +# if ULONG_MAX / 2 + 1 != 1ul << (ULONG_WIDTH - 1) +# error "ULONG_MAX out of range" +# endif #endif /* The type of indexes into strings. This is signed, not size_t, -- 2.39.5