]> Savannah Git Hosting - gnulib.git/commitdiff
regex: port to non-GCC pre-IEC-60559
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 27 Jan 2020 21:00:57 +0000 (13:00 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 27 Jan 2020 21:03:38 +0000 (13:03 -0800)
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
lib/regex_internal.h

index a4ea8009b47beae7898ef0aa89a3abf585fdd85b..d3d1942a1eb737a62a86ddd2d1c55a7f2746abc9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-01-27  Paul Eggert  <eggert@cs.ucla.edu>
+
+       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  <bruno@clisp.org>
 
        c32isxdigit: Add tests.
index 6d436fde1e979e748189c8cc021dde34fa3524f5..8c42586c4212e34887faf6231a607a42397094ab 100644 (file)
 # 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,