From 265465e1145409720be48d30b6277a59151d293a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 27 Sep 2003 16:13:48 +0000 Subject: [PATCH] Add 'free' module. --- ChangeLog | 4 ++++ lib/ChangeLog | 4 ++++ lib/free.c | 33 +++++++++++++++++++++++++++++++++ m4/ChangeLog | 4 ++++ m4/free.m4 | 46 ++++++++++++++++++++++++++++++++++++++++++++++ modules/free | 20 ++++++++++++++++++++ 6 files changed, 111 insertions(+) create mode 100644 lib/free.c create mode 100644 m4/free.m4 create mode 100644 modules/free diff --git a/ChangeLog b/ChangeLog index 0240e083d..c9e480aeb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2003-09-27 Paul Eggert + + * modules/free: New file. + 2003-09-25 Bruno Haible * modules/version-etc-2: New file, from modules/version-etc with diff --git a/lib/ChangeLog b/lib/ChangeLog index dea641cd0..7be4fbe56 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,7 @@ +2003-09-27 Paul Eggert + + * free.c: New file. + 2003-09-26 Jim Meyering * error.c (error_tail): Move some declarations diff --git a/lib/free.c b/lib/free.c new file mode 100644 index 000000000..0fc9d8ba5 --- /dev/null +++ b/lib/free.c @@ -0,0 +1,33 @@ +/* Work around incompatibility on older systems where free (NULL) fails. + + Copyright (C) 2003 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* written by Paul Eggert */ + +#if HAVE_CONFIG_H +# include +#endif +#undef free + +#include + +void +rpl_free (void *p) +{ + if (p) + free (p); +} diff --git a/m4/ChangeLog b/m4/ChangeLog index 3dea04556..f0893aa2c 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,7 @@ +2003-09-27 Paul Eggert + + * free.m4: New file. + 2003-09-26 Bruno Haible * stpncpy.m4 (gl_FUNC_STPNCPY): Add comments about the AIX stpncpy(). diff --git a/m4/free.m4 b/m4/free.m4 new file mode 100644 index 000000000..537fb893e --- /dev/null +++ b/m4/free.m4 @@ -0,0 +1,46 @@ +# Check whether free (NULL) is supposed to work. + +# Copyright (C) 2003 Free Software Foundation, Inc. + +# This file is free software, distributed under the terms of the GNU +# General Public License. As a special exception to the GNU General +# Public License, this file may be distributed as part of a program +# that contains a configuration script generated by Autoconf, under +# the same distribution terms as the rest of that program. + +# Written by Paul Eggert. + +# We can't test for free (NULL) even at runtime, since it might +# happen to "work" for our test program, but not in general. So, be +# conservative and use feature tests for relatively modern hosts, +# where free (NULL) is known to work. This costs a bit of +# performance on some older hosts, but we can fix that later if +# needed. + +AC_DEFUN([gl_FUNC_FREE], +[ + AC_CHECK_HEADERS_ONCE(unistd.h) + AC_CACHE_CHECK([whether free (NULL) is known to work], + [gl_cv_func_free], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[@%:@if HAVE_UNISTD_H + @%:@include + @%:@endif]], + [[@%:@if _POSIX_VERSION < 199009L && \ + (defined unix || defined _unix || defined _unix_ \ + || defined __unix || defined __unix__) + @%:@error "'free (NULL)' is not known to work" + @%:@endif]])], + [gl_cv_func_free=yes], + [gl_cv_func_free=no])]) + + if test $gl_cv_func_free = yes; then + AC_LIBOBJ(free) + AC_DEFINE(free, rpl_free, + [Define to rpl_free if the replacement function should be used.]) + fi +]) + +# Prerequisites of lib/free.c. +AC_DEFUN([gl_PREREQ_FREE], [:]) diff --git a/modules/free b/modules/free new file mode 100644 index 000000000..9ccaba310 --- /dev/null +++ b/modules/free @@ -0,0 +1,20 @@ +Description: +Work around incompatibility on older systems where free (NULL) fails. + +Files: +lib/free.c +m4/free.m4 + +Depends-on: + +configure.ac: +gl_FUNC_FREE + +Makefile.am: + +Include: + + +Maintainer: +Paul Eggert + -- 2.11.0