bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CVS coreutils doesn't build due to xalloc.h reversion?


From: Jim Meyering
Subject: Re: CVS coreutils doesn't build due to xalloc.h reversion?
Date: Tue, 13 Sep 2005 23:22:31 +0200

Paul Eggert <address@hidden> wrote:
> CVS coreutils currently doesn't build out of the box since some of the
> code uses X2REALLOC and X2NREALLOC but these macros were removed from
> xalloc.h.  Was the removal intentional?  If so, uses of X2REALLOC need
> to be replaced by x2realloc elsewhere.
>
> Personally I'm becoming more inclined to not use those macros, as in
> practice I'm finding the readability confusion to be more than any
> potential reliability improvement.  But it's not a big deal either
> way.
>
> Or perhaps you meant to move the macro defns to system.h?  That would
> be fine as well, and a bit more modular.

That was inadvertent.  Thanks for pointing it out.
I've just restored those definitions, for now.

I used gnulib-tool to import the latest into another
project (cppi) that still had symlinked ,v files pointing
into coreutils repository.  When I committed things for cppi,
that clobbered the file in coreutils.

If no one else likes these macros, I'll move them to system.h,
but I do think they're worth the added safety (at least for X2REALLOC)
and improved readability (eliminating the often-redundant `sizeof VAR').

For examples, look in coreutils/src/*.c:

  rho$ grep -E 'X2N?REALLOC' *.c
  chmod.c:              mode = X2REALLOC (mode, &mode_alloc);
  csplit.c:    controls = X2NREALLOC (controls, &control_allocated);
  cut.c:          (rp) = X2NREALLOC (rp, &n_rp_allocated);      \
  expand.c:    tab_list = X2NREALLOC (tab_list, &n_tabs_allocated);
  fold.c:       line_out = X2REALLOC (line_out, &allocated_out);
  join.c:      line->fields = X2NREALLOC (line->fields, 
&line->nfields_allocated);
  join.c:    seq->lines = X2NREALLOC (seq->lines, &seq->alloc);
  od.c: spec = X2NREALLOC (spec, &n_specs_allocated);
  od.c:       buf = X2REALLOC (buf, &bufsize);
  pr.c:       = X2REALLOC (column_count_string, &n_alloc);
  pr.c:      buff = X2REALLOC (buff, &buff_allocated);
  sort.c:    temp_dirs = X2NREALLOC (temp_dirs, &temp_dir_alloc);
  sort.c:      buf->buf = X2REALLOC (buf->buf, &buf->alloc);
  unexpand.c:    tab_list = X2NREALLOC (tab_list, &n_tabs_allocated);

Most of those now fit on one line, but before the conversion,
many did not, and hence were a little less readable.  Using
the macro to eliminate the `sizeof VAR' parameter makes the
code more maintainable, too, imho.

For the lurkers, here's a change that was representative of
the conversion:

diff -u -p -u -r1.142 -r1.143
--- join.c      9 Jul 2005 22:10:39 -0000       1.142
+++ join.c      12 Aug 2005 07:16:25 -0000      1.143
@@ -188,8 +188,7 @@ extract_field (struct line *line, char *
 {
   if (line->nfields >= line->nfields_allocated)
     {
-      line->fields = x2nrealloc (line->fields, &line->nfields_allocated,
-                                sizeof (struct field));
+      line->fields = X2NREALLOC (line->fields, &line->nfields_allocated);
     }
   line->fields[line->nfields].beg = field;
   line->fields[line->nfields].len = len;
@@ -283,7 +282,7 @@ static bool
 getseq (FILE *fp, struct seq *seq)
 {
   if (seq->count == seq->alloc)
-    seq->lines = x2nrealloc (seq->lines, &seq->alloc, sizeof *seq->lines);
+    seq->lines = X2NREALLOC (seq->lines, &seq->alloc);
 
   if (get_line (fp, &seq->lines[seq->count]))
     {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]