[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch
From: |
Paul Eggert |
Subject: |
Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch |
Date: |
12 Sep 2003 15:06:04 -0700 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
"Gary V. Vaughan" <address@hidden> writes:
> I propose applying your patch without autoconfigury...
I thought about it a bit more, and decided that it'd be better to use
a solution that simply causes 'free' to work as expected in C89 or
letter. We shouldn't introduce yet another symbol like 'xfree'; we
should just make 'free' work. So I propose the following patch instead.
I'm also proposing changing the maintainer for the xalloc module to 'all'.
(The actual maintainers have mostly been Bruno, Jim, and myself.)
I'd still like to get rid of XMALLOC, XCALLOC, XREALLOC, XFREE, CCLONE,
and CLONE, but that's a different matter, which I'll look into later.
2003-09-12 Paul Eggert <address@hidden>
* modules/xalloc: Add m4/free-null.m4. Change maintainer to "all".
* lib/xalloc.h (free) [!HAVE_FREE_NULL]: New macro.
(rpl_free) [!HAVE_FREE_NULL]: New function.
(XFREE): Use 'free'. Add a comment that XFREE is obsolescent.
* m4/xalloc.m4 (gl_XALLOC): Require AC_C_INLINE, gl_FUNC_FREE_NULL.
* m4/free-null.m4: New file.
Index: modules/xalloc
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/xalloc,v
retrieving revision 1.5
diff -p -u -r1.5 xalloc
--- modules/xalloc 12 Sep 2003 20:14:11 -0000 1.5
+++ modules/xalloc 12 Sep 2003 21:55:28 -0000
@@ -5,6 +5,7 @@ Files:
lib/xalloc.h
lib/xmalloc.c
lib/xstrdup.c
+m4/free-null.m4
m4/xalloc.m4
Depends-on:
@@ -25,5 +26,5 @@ Include:
"xalloc.h"
Maintainer:
-Bruno Haible
+all
Index: lib/xalloc.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/xalloc.h,v
retrieving revision 1.16
diff -p -u -r1.16 xalloc.h
--- lib/xalloc.h 22 Jul 2003 22:10:56 -0000 1.16
+++ lib/xalloc.h 12 Sep 2003 21:55:28 -0000
@@ -61,11 +61,19 @@ char *xstrdup (const char *str);
# define NEW(Type, Var) Type *(Var) = XMALLOC (Type, 1)
/* Free VAR only if non NULL. */
-# define XFREE(Var) \
- do { \
- if (Var) \
- free (Var); \
- } while (0)
+# if !HAVE_FREE_NULL
+# include <stdlib.h>
+static inline void
+rpl_free (void *p)
+{
+ if (p)
+ free (p);
+}
+# define free rpl_free
+# endif
+/* XFREE is for backwards compatibility only; you should use plain
+ 'free' instead. */
+# define XFREE(Var) free (Var)
/* Return a pointer to a malloc'ed copy of the array SRC of NUM elements. */
# define CCLONE(Src, Num) \
Index: m4/xalloc.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/xalloc.m4,v
retrieving revision 1.3
diff -p -u -r1.3 xalloc.m4
--- m4/xalloc.m4 12 Sep 2003 18:24:51 -0000 1.3
+++ m4/xalloc.m4 12 Sep 2003 21:55:28 -0000
@@ -1,4 +1,4 @@
-# xalloc.m4 serial 3
+# xalloc.m4 serial 4
dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
@@ -8,6 +8,8 @@ dnl the same distribution terms as the r
AC_DEFUN([gl_XALLOC],
[
+ AC_REQUIRE([AC_C_INLINE])
+ AC_REQUIRE([gl_FUNC_FREE_NULL])
gl_PREREQ_XMALLOC
gl_PREREQ_XSTRDUP
])
--- /dev/null Tue Mar 18 13:55:57 2003
+++ m4/free-null.m4 Fri Sep 12 14:57:04 2003
@@ -0,0 +1,36 @@
+dnl Check whether free (NULL) is supposed to work.
+
+dnl Copyright (C) 2003 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+dnl From Paul Eggert
+
+dnl We can't test for free (NULL) even at runtime, since it might
+dnl happen to "work" for our test program, but not in general. So, be
+dnl conservative and use feature tests for relatively modern hosts,
+dnl where free (NULL) is known to work. This costs a bit of
+dnl performance on some older hosts, but we can fix that later if
+dnl needed.
+
+AC_DEFUN([gl_FUNC_FREE_NULL],
+[
+ AC_CACHE_CHECK([whether free (NULL) is known to work],
+ [gl_cv_func_free_null],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ address@hidden:@include <unistd.h>]],
+ address@hidden:@if _POSIX_VERSION < 200112 && !defined __GLIBC__
+ @%:@error "'free (NULL)' is not known to work"
+ @%:@endif]])],
+ [gl_cv_func_free_null=yes],
+ [gl_cv_func_free_null=no])])
+
+ if test $gl_cv_func_free_null = yes; then
+ AC_DEFINE([HAVE_FREE_NULL], 1,
+ [Define to 1 if free (NULL) is known to work.])
+ fi
+])
- [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch, Gary V. Vaughan, 2003/09/10
- Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch, Bruno Haible, 2003/09/10
- Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch, Paul Eggert, 2003/09/11
- Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch, Paul Eggert, 2003/09/11
- Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch, Gary V. Vaughan, 2003/09/11
- Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch,
Paul Eggert <=
- Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch, Jim Meyering, 2003/09/13
- Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch, Gary V. Vaughan, 2003/09/15
- Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch, Paul Eggert, 2003/09/15
- Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch, Gary V . Vaughan, 2003/09/16
- [Bug-gnulib] Re: Patch proposal: 1-gary-safe-xfree.patch, Simon Josefsson, 2003/09/16
- Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch, Bruno Haible, 2003/09/15
- Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch, Paul Eggert, 2003/09/15
- Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch, Bruno Haible, 2003/09/15
- Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch, Gary V. Vaughan, 2003/09/19
- Re: [Bug-gnulib] Patch proposal: 1-gary-safe-xfree.patch, Paul Eggert, 2003/09/22