bug-gnulib
[Top][All Lists]
Advanced

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

free: Remove support for obsolete platforms


From: Bruno Haible
Subject: free: Remove support for obsolete platforms
Date: Sat, 19 Dec 2020 00:02:23 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-197-generic; KDE/5.18.0; x86_64; ; )

Paul Eggert wrote:
> Also, define CANNOT_FREE_NULL if free cannot free NULL.

We can simplify this. SunOS 4 stopped being one of our portability targets
around 2005. The module 'free' was accordingly marked obsolete in 2008.
This old cruft makes the module 'free' now more complex than needed.


2020-12-18  Bruno Haible  <bruno@clisp.org>

        free: Remove support for obsolete platforms.
        * m4/free.m4 (gl_FUNC_FREE): Assume free(NULL) works. Don't define
        CANNOT_FREE_NULL.
        * lib/free.c (rpl_free): Don't test CANNOT_FREE_NULL.
        * modules/free (Description): Update.
        * doc/posix-functions/free.texi: Don't mention SunOS 4 any more.

diff --git a/doc/posix-functions/free.texi b/doc/posix-functions/free.texi
index ba3484c..1c397d1 100644
--- a/doc/posix-functions/free.texi
+++ b/doc/posix-functions/free.texi
@@ -8,11 +8,6 @@ Gnulib module: free
 
 Portability problems fixed by Gnulib:
 @itemize
-@item
-On old platforms such as SunOS4, @code{free (NULL)} fails.
-However, since all such systems are so old as to no longer
-be considered ``reasonable portability targets,''
-this module is no longer useful.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/free.c b/lib/free.c
index 843ce48..2f689a7 100644
--- a/lib/free.c
+++ b/lib/free.c
@@ -1,4 +1,4 @@
-/* Work around incompatibility on older systems where free (NULL) fails.
+/* Make free() preserve errno.
 
    Copyright (C) 2003, 2006, 2009-2020 Free Software Foundation, Inc.
 
@@ -18,7 +18,6 @@
 /* written by Paul Eggert */
 
 #include <config.h>
-#undef free
 
 #include <stdlib.h>
 
@@ -26,12 +25,8 @@
 
 void
 rpl_free (void *p)
+#undef free
 {
-#ifdef CANNOT_FREE_NULL
-  if (!p)
-    return;
-#endif
-
   int err = errno;
   free (p);
   errno = err;
diff --git a/m4/free.m4 b/m4/free.m4
index 9f108c1..fb191df 100644
--- a/m4/free.m4
+++ b/m4/free.m4
@@ -1,4 +1,4 @@
-# free.m4 serial 1
+# free.m4 serial 2
 # Copyright (C) 2003-2005, 2009-2020 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -6,34 +6,10 @@
 
 # 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_REQUIRE([gl_STDLIB_H_DEFAULTS])
   AC_REQUIRE([AC_CANONICAL_HOST])
-  AC_CACHE_CHECK([whether free (NULL) is known to work],
-    [gl_cv_func_free],
-    [case "$host_os" in
-       mingw*) gl_cv_func_free=yes ;;
-       *)
-         AC_COMPILE_IFELSE(
-           [AC_LANG_PROGRAM(
-              [[#include <unistd.h>]],
-              [[#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])
-     esac
-    ])
 
   dnl In the next release of POSIX, free must preserve errno.
   dnl https://www.austingroupbugs.net/view.php?id=385
@@ -60,13 +36,8 @@ AC_DEFUN([gl_FUNC_FREE],
      esac
     ])
 
-  if test $gl_cv_func_free = no; then
-    AC_DEFINE([CANNOT_FREE_NULL], [1],
-      [Define to 1 if free (NULL) does not work.])
-  fi
-
-  case $gl_cv_func_free,$gl_cv_func_free_preserves_errno in
-   *yes,*yes) ;;
+  case $gl_cv_func_free_preserves_errno in
+   *yes) ;;
    *) REPLACE_FREE=1 ;;
   esac
 ])
diff --git a/modules/free b/modules/free
index dc5cb56..29ec637 100644
--- a/modules/free
+++ b/modules/free
@@ -1,5 +1,5 @@
 Description:
-Work around systems where free sets errno or free (NULL) fails.
+Work around systems where free clobbers errno.
 
 Files:
 lib/free.c




reply via email to

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