bug-gnulib
[Top][All Lists]
Advanced

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

[Bug-gnulib] new module 'free'


From: Paul Eggert
Subject: [Bug-gnulib] new module 'free'
Date: Sat, 27 Sep 2003 09:18:44 -0700

I'd like to start off the malloc-related improvements by adding a new
module 'free' that works around ancient hosts where free (NULL)
doesn't work.  So I installed the following.  I think it addresses all
the comments on this subject that have been received on bug-gnulib.

Unfortunately I can't test this well, as I lack access to ancient
hosts where free (NULL) doesn't work.

2003-09-27  Paul Eggert  <address@hidden>

        * modules/free, lib/free.c, m4/free.m4: New files.

--- /dev/null   Tue Mar 18 13:55:57 2003
+++ modules/free        Thu Sep 18 10:39:17 2003
@@ -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
+
--- /dev/null   Tue Mar 18 13:55:57 2003
+++ lib/free.c  Thu Sep 18 10:40:22 2003
@@ -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);
+}
--- /dev/null   Tue Mar 18 13:55:57 2003
+++ m4/free.m4  Thu Sep 18 10:37:45 2003
@@ -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(
+         address@hidden:@if HAVE_UNISTD_H
+             @%:@include <unistd.h>
+           @%:@endif]],
+         address@hidden:@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], [:])




reply via email to

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