bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* [PATCH] dfa: prefer idx_t to ptrdiff_t for nonnegative
@ 2021-08-25  3:13 Paul Eggert
  0 siblings, 0 replies; only message in thread
From: Paul Eggert @ 2021-08-25  3:13 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Paul Eggert

* lib/dfa.c (struct dfa, dfaexec_main, dfaexec_mb, dfaexec_sb)
(dfaexec_noop, dfaexec):
* lib/dfa.h (dfaparse, dfacomp, dfaexec):
Prefer idx_t to ptrdiff_t for counts, which should be nonnegative.
* lib/dfa.h: Include idx.h.
---
 ChangeLog |  9 +++++++++
 lib/dfa.c | 12 ++++++------
 lib/dfa.h |  7 ++++---
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index db94f5107d..e1f89f7ef4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2021-08-24  Paul Eggert  <eggert@cs.ucla.edu>
+
+	dfa: prefer idx_t to ptrdiff_t for nonnegative
+	* lib/dfa.c (struct dfa, dfaexec_main, dfaexec_mb, dfaexec_sb)
+	(dfaexec_noop, dfaexec):
+	* lib/dfa.h (dfaparse, dfacomp, dfaexec):
+	Prefer idx_t to ptrdiff_t for counts, which should be nonnegative.
+	* lib/dfa.h: Include idx.h.
+
 2021-08-22  Bruno Haible  <bruno@clisp.org>
 
 	snippet/unused-parameter: Mark unused module obsolete.
diff --git a/lib/dfa.c b/lib/dfa.c
index 8286ea10d1..459f10f7f3 100644
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -590,7 +590,7 @@ struct dfa
 
   /* dfaexec implementation.  */
   char *(*dfaexec) (struct dfa *, char const *, char *,
-                    bool, ptrdiff_t *, bool *);
+                    bool, idx_t *, bool *);
 
   /* Other cached information derived from the locale.  */
   struct localeinfo localeinfo;
@@ -3352,7 +3352,7 @@ skip_remains_mb (struct dfa *d, unsigned char const *p,
 
 static inline char *
 dfaexec_main (struct dfa *d, char const *begin, char *end, bool allow_nl,
-              ptrdiff_t *count, bool multibyte)
+              idx_t *count, bool multibyte)
 {
   if (MAX_TRCOUNT <= d->sindex)
     {
@@ -3535,14 +3535,14 @@ dfaexec_main (struct dfa *d, char const *begin, char *end, bool allow_nl,
 
 static char *
 dfaexec_mb (struct dfa *d, char const *begin, char *end,
-            bool allow_nl, ptrdiff_t *count, bool *backref)
+            bool allow_nl, idx_t *count, bool *backref)
 {
   return dfaexec_main (d, begin, end, allow_nl, count, true);
 }
 
 static char *
 dfaexec_sb (struct dfa *d, char const *begin, char *end,
-            bool allow_nl, ptrdiff_t *count, bool *backref)
+            bool allow_nl, idx_t *count, bool *backref)
 {
   return dfaexec_main (d, begin, end, allow_nl, count, false);
 }
@@ -3551,7 +3551,7 @@ dfaexec_sb (struct dfa *d, char const *begin, char *end,
    any regexp that uses a construct not supported by this code.  */
 static char *
 dfaexec_noop (struct dfa *d, char const *begin, char *end,
-              bool allow_nl, ptrdiff_t *count, bool *backref)
+              bool allow_nl, idx_t *count, bool *backref)
 {
   *backref = true;
   return (char *) begin;
@@ -3563,7 +3563,7 @@ dfaexec_noop (struct dfa *d, char const *begin, char *end,
 
 char *
 dfaexec (struct dfa *d, char const *begin, char *end,
-         bool allow_nl, ptrdiff_t *count, bool *backref)
+         bool allow_nl, idx_t *count, bool *backref)
 {
   return d->dfaexec (d, begin, end, allow_nl, count, backref);
 }
diff --git a/lib/dfa.h b/lib/dfa.h
index edc39dc49c..59a0211dfe 100644
--- a/lib/dfa.h
+++ b/lib/dfa.h
@@ -21,6 +21,7 @@
 #ifndef DFA_H_
 #define DFA_H_
 
+#include "idx.h"
 #include <regex.h>
 #include <stdbool.h>
 #include <stddef.h>
@@ -86,7 +87,7 @@ extern void dfasyntax (struct dfa *, struct localeinfo const *,
 extern void dfacopysyntax (struct dfa *, struct dfa const *);
 
 /* Parse the given string of given length into the given struct dfa.  */
-extern void dfaparse (char const *, ptrdiff_t, struct dfa *);
+extern void dfaparse (char const *, idx_t, struct dfa *);
 
 struct dfamust;
 
@@ -102,7 +103,7 @@ extern struct dfamust *dfamust (struct dfa const *)
    The last argument says whether to build a searching or an exact matcher.
    A null first argument means the struct dfa has already been
    initialized by dfaparse; the second argument is ignored.  */
-extern void dfacomp (char const *, ptrdiff_t, struct dfa *, bool);
+extern void dfacomp (char const *, idx_t, struct dfa *, bool);
 
 /* Search through a buffer looking for a match to the given struct dfa.
    Find the first occurrence of a string matching the regexp in the
@@ -117,7 +118,7 @@ extern void dfacomp (char const *, ptrdiff_t, struct dfa *, bool);
    encountered a back-reference.  The caller can use this to decide
    whether to fall back on a backtracking matcher.  */
 extern char *dfaexec (struct dfa *d, char const *begin, char *end,
-                      bool allow_nl, ptrdiff_t *count, bool *backref);
+                      bool allow_nl, idx_t *count, bool *backref);
 
 /* Return a superset for D.  The superset matches everything that D
    matches, along with some other strings (though the latter should be
-- 
2.31.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-25  3:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-25  3:13 [PATCH] dfa: prefer idx_t to ptrdiff_t for nonnegative Paul Eggert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).