bug-gnulib
[Top][All Lists]
Advanced

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

[Bug-gnulib] Re: gnulib/lib exclude.c,1.18,1.19


From: Jim Meyering
Subject: [Bug-gnulib] Re: gnulib/lib exclude.c,1.18,1.19
Date: Thu, 16 Oct 2003 08:54:20 +0200

"Paul Eggert <address@hidden>" <address@hidden> wrote:
...
> (add_exclude, add_exclude_file): Use xnrealloc instead of rolling
> our own address arithmetic overflow checking.
...

> !       ex->exclude = xnrealloc (ex->exclude, ex->exclude_alloc,
> !                            2 * sizeof *ex->exclude);
> !       ex->exclude_alloc *= 2;

Hi Paul,
Thanks for doing that!

The above is becoming a common idiom.
For an idiom, I'm uncomfortable with the amount of duplication in
those two statements (three uses of V, and two each of N_ALLOC and
MULTIPLIER -- see below).
What do you think of writing something like this instead:

  XNREALLOC (ex->exclude_alloc, ex->exclude, 2);

where XNREALLOC is defined like this:

  /* Caution: N_ALLOC and V must be L-values.  */
  #define XNREALLOC (N_ALLOC, V, MULTIPLIER)                    \
    do                                                          \
      {                                                         \
        V = xnrealloc (V, N_ALLOC, (MULTIPLIER) * sizeof *(V)); \
        N_ALLOC *= MULTIPLIER;                                  \
      }                                                         \
    while (0)

Of course, that doesn't help if you prefer to increase by some
non-integer multiplier, but it should cover the majority of cases.

How about it?




reply via email to

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