From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id BED331F8C6 for ; Wed, 25 Aug 2021 03:14:01 +0000 (UTC) Received: from localhost ([::1]:35242 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIjMV-0006z2-U3 for normalperson@yhbt.net; Tue, 24 Aug 2021 23:14:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45568) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIjMS-0006yu-CQ for bug-gnulib@gnu.org; Tue, 24 Aug 2021 23:13:56 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:55034) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIjMP-0000Kr-Rk for bug-gnulib@gnu.org; Tue, 24 Aug 2021 23:13:55 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 0A5FE1600BE for ; Tue, 24 Aug 2021 20:13:51 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id U5m1xL2J-2Js; Tue, 24 Aug 2021 20:13:46 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 0F6BA1600BC; Tue, 24 Aug 2021 20:13:46 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id uOf7MNix6D5B; Tue, 24 Aug 2021 20:13:45 -0700 (PDT) Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id DF46D1600BB; Tue, 24 Aug 2021 20:13:45 -0700 (PDT) From: Paul Eggert To: bug-gnulib@gnu.org Subject: [PATCH] dfa: prefer idx_t to ptrdiff_t for nonnegative Date: Tue, 24 Aug 2021 20:13:42 -0700 Message-Id: <20210825031342.306944-1-eggert@cs.ucla.edu> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=131.179.128.68; envelope-from=eggert@cs.ucla.edu; helo=zimbra.cs.ucla.edu X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Eggert Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" * 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 =20 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 =20 /* dfaexec implementation. */ char *(*dfaexec) (struct dfa *, char const *, char *, - bool, ptrdiff_t *, bool *); + bool, idx_t *, bool *); =20 /* Other cached information derived from the locale. */ struct localeinfo localeinfo; @@ -3352,7 +3352,7 @@ skip_remains_mb (struct dfa *d, unsigned char const= *p, =20 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 <=3D d->sindex) { @@ -3535,14 +3535,14 @@ dfaexec_main (struct dfa *d, char const *begin, c= har *end, bool allow_nl, =20 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); } =20 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 =3D true; return (char *) begin; @@ -3563,7 +3563,7 @@ dfaexec_noop (struct dfa *d, char const *begin, cha= r *end, =20 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_ =20 +#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 *); =20 /* 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 *); =20 struct dfamust; =20 @@ -102,7 +103,7 @@ extern struct dfamust *dfamust (struct dfa const *) The last argument says whether to build a searching or an exact match= er. 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); =20 /* 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); =20 /* Return a superset for D. The superset matches everything that D matches, along with some other strings (though the latter should be --=20 2.31.1