bug-gnulib
[Top][All Lists]
Advanced

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

Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch


From: Gary V . Vaughan
Subject: Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch
Date: Thu, 11 Sep 2003 10:04:56 +0100


On Thursday, September 11, 2003, at 08:59  am, Paul Eggert wrote:

"Gary V. Vaughan" <address@hidden> writes:

This patch does change the semantics of XFREE slightly, but in a
beneficial way.

The part about evaluating the argument once is nice, but why do you
want XFREE to return NULL?  I find this:

   XFREE (p);
   p = NULL;

to be much clearer than this:

   p = XFREE (p);

Fair enough. In which case getting rid of the multiple expansions would be good enough for me. M4 has container data types that return their contents when released, and I think this:

    XFREE (m4_hash_remove (symtab->table, name));

is cleaner than this:

    {
      void *stale = m4_hash_remove (symtab->table, name);
      XFREE (stale);
    }

Traditionally 'free' returns 'void', and it's confusing to have
XFREE return something else.

How about the following implementation instead?  It evaluates
Var only once.

# define XFREE(Var)                \
   do                              \
     {                             \
       void *to_be_freed = (Var);  \
       if (to_be_freed)            \
         free (to_be_freed);       \
     }                             \
   while (0)

Okay.  I'd also like an equivalent xfree (in xfree.c) so I can:

    lt_dlmalloc  = xmalloc;
    lt_dlrealloc = xrealloc;
    lt_dlfree    = xfree;

Or even:

    #define obstack_chunk_alloc xmalloc
    #define obstack_chunk_free  xfree

I think an additional module for xfree is too much, but how else to prototype the function without polluting xalloc.h? Anyway, how's this?

Cheers,
        Gary.

Attachment: 2-gary-xfree-module-and-DELETE-macro.patch
Description: Binary data


--
  ())_. Gary V. Vaughan     gary@(oranda.demon.co.uk|gnu.org)
( '/ Research Scientist http://www.oranda.demon.co.uk ,_())____ / )= GNU Hacker http://www.gnu.org/software/libtool \' `& `(_~)_ Tech' Author http://sources.redhat.com/autobook =`---d__/


reply via email to

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