bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: bug-gnulib@gnu.org
Cc: Paul Eggert <eggert@cs.ucla.edu>
Subject: [PATCH 07/13] linebuffer: prefer idx_t for indexes
Date: Fri, 11 Jun 2021 17:25:47 -0700	[thread overview]
Message-ID: <20210612002553.1105537-7-eggert@cs.ucla.edu> (raw)
In-Reply-To: <20210612002553.1105537-1-eggert@cs.ucla.edu>

* 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.
 
 	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, FILE *stream,
         }
       if (p == end)
         {
-          size_t oldsize = linebuffer->size;
-          buffer = x2realloc (buffer, &linebuffer->size);
+          idx_t oldsize = linebuffer->size;
+          buffer = xpalloc (buffer, &linebuffer->size, 1, -1, 1);
           p = buffer + oldsize;
           linebuffer->buffer = buffer;
           end = 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
 
+# include "idx.h"
 # include <stdio.h>
 
 /* A 'struct linebuffer' holds a line of text. */
 
 struct linebuffer
 {
-  size_t size;                  /* Allocated. */
-  size_t length;                /* Used. */
+  idx_t size;                  /* Allocated. */
+  idx_t length;                /* Used. */
   char *buffer;
 };
 
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
 
 Depends-on:
+idx
 xalloc
 
 configure.ac:
@@ -21,4 +22,3 @@ GPL
 
 Maintainer:
 Jim Meyering
-
-- 
2.30.2



  parent reply	other threads:[~2021-06-12  0:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-12  0:25 [PATCH 01/13] ialloc: new module Paul Eggert
2021-06-12  0:25 ` [PATCH 02/13] xalloc: new idx_t-based allocators Paul Eggert
2021-06-12  0:25 ` [PATCH 03/13] dirname: prefer idx_t for some indexes Paul Eggert
2021-06-12  0:25 ` [PATCH 04/13] dfa: prefer idx_t for indexes Paul Eggert
2021-06-12  0:25 ` [PATCH 05/13] exclude: prefer idx_t for most indexes Paul Eggert
2021-06-12  0:25 ` [PATCH 06/13] getusershell: prefer idx_t for indexes Paul Eggert
2021-06-12  0:25 ` Paul Eggert [this message]
2021-06-12  0:25 ` [PATCH 08/13] readtokens: " Paul Eggert
2021-06-12  0:25 ` [PATCH 09/13] readutmp: " Paul Eggert
2021-06-12  0:25 ` [PATCH 10/13] savedir: " Paul Eggert
2021-06-12  0:25 ` [PATCH 11/13] stack: " Paul Eggert
2021-06-13 10:19   ` Bruno Haible
2021-06-13 17:47     ` Paul Eggert
2021-06-12  0:25 ` [PATCH 12/13] userspec: " Paul Eggert
2021-06-12  0:25 ` [PATCH 13/13] xgethostname: " Paul Eggert
2021-06-13 10:05 ` [PATCH 01/13] ialloc: new module Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210612002553.1105537-7-eggert@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).