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.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,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 E69DC1F5AE for ; Sat, 12 Jun 2021 00:26:28 +0000 (UTC) Received: from localhost ([::1]:58184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrrTo-00007h-2H for normalperson@yhbt.net; Fri, 11 Jun 2021 20:26:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrrTd-0008Oe-Do for bug-gnulib@gnu.org; Fri, 11 Jun 2021 20:26:17 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:39190) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrrTb-0003q6-FB for bug-gnulib@gnu.org; Fri, 11 Jun 2021 20:26:17 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 6E94F160132 for ; Fri, 11 Jun 2021 17:26:12 -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 nixp0gX8gwfQ; Fri, 11 Jun 2021 17:26:10 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 5503016011B; Fri, 11 Jun 2021 17:26:10 -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 EIHaoJ-jbgWf; Fri, 11 Jun 2021 17:26:10 -0700 (PDT) Received: from day.example.com (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 297EF160095; Fri, 11 Jun 2021 17:26:10 -0700 (PDT) From: Paul Eggert To: bug-gnulib@gnu.org Subject: [PATCH 07/13] linebuffer: prefer idx_t for indexes Date: Fri, 11 Jun 2021 17:25:47 -0700 Message-Id: <20210612002553.1105537-7-eggert@cs.ucla.edu> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210612002553.1105537-1-eggert@cs.ucla.edu> References: <20210612002553.1105537-1-eggert@cs.ucla.edu> 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/linebuffer.c (readlinebuffer_delim): * lib/linebuffer.h (struct linebuffer): Prefer idx_t to size_t for indexes, using idx_t-related allocators. * lib/linebuffer.h: Include idx.h. * modules/linebuffer (Depends-on): Add idx. --- ChangeLog | 3 +++ lib/linebuffer.c | 4 ++-- lib/linebuffer.h | 5 +++-- modules/linebuffer | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 84ccb3645..5dd638456 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,8 @@ * lib/exclude.c (struct exclude_pattern, free_exclude_segment) (file_pattern_matches, add_exclude, add_exclude_fp): * lib/getusershell.c (line_size, readname): + * lib/linebuffer.c (readlinebuffer_delim): + * lib/linebuffer.h (struct linebuffer): Prefer idx_t to size_t for indexes, and use idx_t-related allocators. * lib/basename.c: Do not include xstrndup.h. (basename): Simplify by always using memcpy. @@ -24,6 +26,7 @@ (x2nrealloc): Moved here from xalloc.h. * modules/xalloc (Depends-on): Add ialloc. * modules/dirname (Depends-on): Removbe xstrndup. + * modules/linebuffer (Depends-on): Add idx. =20 ialloc: new module * lib/ialloc.c, lib/ialloc.h, modules/ialloc: New files. diff --git a/lib/linebuffer.c b/lib/linebuffer.c index 10b0428d0..5b579019f 100644 --- a/lib/linebuffer.c +++ b/lib/linebuffer.c @@ -80,8 +80,8 @@ readlinebuffer_delim (struct linebuffer *linebuffer, FI= LE *stream, } if (p =3D=3D end) { - size_t oldsize =3D linebuffer->size; - buffer =3D x2realloc (buffer, &linebuffer->size); + idx_t oldsize =3D linebuffer->size; + buffer =3D xpalloc (buffer, &linebuffer->size, 1, -1, 1); p =3D buffer + oldsize; linebuffer->buffer =3D buffer; end =3D buffer + linebuffer->size; diff --git a/lib/linebuffer.h b/lib/linebuffer.h index 691a4c2f8..5fa5ad2fe 100644 --- a/lib/linebuffer.h +++ b/lib/linebuffer.h @@ -19,14 +19,15 @@ #if !defined LINEBUFFER_H # define LINEBUFFER_H =20 +# include "idx.h" # include =20 /* A 'struct linebuffer' holds a line of text. */ =20 struct linebuffer { - size_t size; /* Allocated. */ - size_t length; /* Used. */ + idx_t size; /* Allocated. */ + idx_t length; /* Used. */ char *buffer; }; =20 diff --git a/modules/linebuffer b/modules/linebuffer index 1444ff074..4ddd3c38e 100644 --- a/modules/linebuffer +++ b/modules/linebuffer @@ -6,6 +6,7 @@ lib/linebuffer.h lib/linebuffer.c =20 Depends-on: +idx xalloc =20 configure.ac: @@ -21,4 +22,3 @@ GPL =20 Maintainer: Jim Meyering - --=20 2.30.2