Add 'free' module.
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 27 Sep 2003 16:13:48 +0000 (16:13 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 27 Sep 2003 16:13:48 +0000 (16:13 +0000)
ChangeLog
lib/ChangeLog
lib/free.c [new file with mode: 0644]
m4/ChangeLog
m4/free.m4 [new file with mode: 0644]
modules/free [new file with mode: 0644]

index 0240e08..c9e480a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2003-09-27  Paul Eggert  <eggert@twinsun.com>
+
+       * modules/free: New file.
+
 2003-09-25  Bruno Haible  <bruno@clisp.org>
 
        * modules/version-etc-2: New file, from modules/version-etc with
index dea641c..7be4fbe 100644 (file)
@@ -1,3 +1,7 @@
+2003-09-27  Paul Eggert  <eggert@twinsun.com>
+
+       * free.c: New file.
+
 2003-09-26  Jim Meyering  <jim@meyering.net>
 
        * error.c (error_tail): Move some declarations
diff --git a/lib/free.c b/lib/free.c
new file mode 100644 (file)
index 0000000..0fc9d8b
--- /dev/null
@@ -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 <config.h>
+#endif
+#undef free
+
+#include <stdlib.h>
+
+void
+rpl_free (void *p)
+{
+  if (p)
+    free (p);
+}
index 3dea045..f0893aa 100644 (file)
@@ -1,3 +1,7 @@
+2003-09-27  Paul Eggert  <eggert@twinsun.com>
+
+       * free.m4: New file.
+
 2003-09-26  Bruno Haible  <bruno@clisp.org>
 
        * 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 (file)
index 0000000..537fb89
--- /dev/null
@@ -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 <unistd.h>
+           @%:@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 (file)
index 0000000..9ccaba3
--- /dev/null
@@ -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:
+<stdlib.h>
+
+Maintainer:
+Paul Eggert
+