aboutsummaryrefslogtreecommitdiffstats
path: root/support/regex_internal.h
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2020-01-28 07:39:24 +0200
committerArnold D. Robbins <arnold@skeeve.com>2020-01-28 07:39:24 +0200
commit391b5daeb5371374d7ac3d88cadf1f46db935005 (patch)
tree7445452b8901e30caaf4eecddbf260cbc1bfd746 /support/regex_internal.h
parent455542e5a75843bb16c9e747fb63a8731021bf85 (diff)
downloadegawk-391b5daeb5371374d7ac3d88cadf1f46db935005.tar.gz
egawk-391b5daeb5371374d7ac3d88cadf1f46db935005.tar.bz2
egawk-391b5daeb5371374d7ac3d88cadf1f46db935005.zip
Update (and we hope fix) regex_internal.h.
Diffstat (limited to 'support/regex_internal.h')
-rw-r--r--support/regex_internal.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/support/regex_internal.h b/support/regex_internal.h
index 6d436fde..8c42586c 100644
--- a/support/regex_internal.h
+++ b/support/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,