From 65e69185fa2061e9e668e39a8684f69c31e7152d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 24 Aug 2021 20:12:19 -0700 Subject: [PATCH] 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. --- 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 + + 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 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 #include #include @@ -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.39.5