bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] regex: glibc does not use intprops.h


From: Paul Eggert
Subject: [PATCH] regex: glibc does not use intprops.h
Date: Fri, 29 Jun 2018 15:57:19 -0700

Maybe we can talk glibc into using intprops.h someday, but
now doesn’t seem to be a good time.
* lib/regcomp.c (TYPE_SIGNED): Remove; regex_internal.h now defines.
* lib/regex_internal.h [_LIBC]: Do not include intprops.h.
(TYPE_SIGNED, INT_ADD_WRAPV): New macros.
---
 ChangeLog            |  9 +++++++++
 lib/regcomp.c        |  4 ----
 lib/regex_internal.h | 18 +++++++++++++++++-
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1b2505a1a..e5c1e02c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2018-06-29  Paul Eggert  <address@hidden>
+
+       regex: glibc does not use intprops.h
+       Maybe we can talk glibc into using intprops.h someday, but
+       now doesn’t seem to be a good time.
+       * lib/regcomp.c (TYPE_SIGNED): Remove; regex_internal.h now defines.
+       * lib/regex_internal.h [_LIBC]: Do not include intprops.h.
+       (TYPE_SIGNED, INT_ADD_WRAPV): New macros.
+
 2018-06-28  Paul Eggert  <address@hidden>
 
        regex: port to recently proposed glibc regex merge
diff --git a/lib/regcomp.c b/lib/regcomp.c
index 6aaa54f66..7b5ddaad0 100644
--- a/lib/regcomp.c
+++ b/lib/regcomp.c
@@ -2650,10 +2650,6 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, 
re_dfa_t *dfa,
   if (BE (tree == NULL, 0))
     goto parse_dup_op_espace;
 
-/* From gnulib's "intprops.h":
-   True if the arithmetic type T is signed.  */
-#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
-
   /* This loop is actually executed only when end != -1,
      to rewrite <re>{0,n} as (<re>(<re>...<re>?)?)?...  We have
      already created the start+1-th copy.  */
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index b27afbda2..3b836ed20 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -33,7 +33,23 @@
 #include <stdbool.h>
 #include <stdint.h>
 
-#include "intprops.h"
+/* Properties of integers.  Although Gnulib has intprops.h, glibc does
+   without for now.  */
+#ifndef _LIBC
+# include "intprops.h"
+#else
+/* True if the real type T is signed.  */
+# define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+
+/* True if adding the nonnegative Idx values A and B would overflow.
+   If false, set *R to A + B.  A, B, and R may be evaluated more than
+   once, or zero times.  Although this is not a full implementation of
+   Gnulib INT_ADD_WRAPV, it is good enough for glibc regex code.
+   FIXME: This implementation is a fragile stopgap, and this file would
+   be simpler and more robust if intprops.h were migrated into glibc.  */
+# define INT_ADD_WRAPV(a, b, r) \
+   (IDX_MAX - (a) < (b) ? true : (*(r) = (a) + (b), false))
+#endif
 
 #ifdef _LIBC
 # include <libc-lock.h>
-- 
2.17.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]