]> Savannah Git Hosting - gnulib.git/commitdiff
free-posix: Assume future POSIX compliance only on OpenBSD and Solaris.
authorBruno Haible <bruno@clisp.org>
Sat, 19 Dec 2020 19:19:45 +0000 (20:19 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 19 Dec 2020 19:19:45 +0000 (20:19 +0100)
* m4/free.m4 (gl_FUNC_FREE): Guess yes only on OpenBSD and Solaris.
Don't trust _POSIX_VERSION for this test.

ChangeLog
m4/free.m4

index ef9ec28a488c95614a2f00c52884243b239ff219..0d8c2ee6d7be6e77451e419d69869029a740cac6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-12-19  Bruno Haible  <bruno@clisp.org>
+
+       free-posix: Assume future POSIX compliance only on OpenBSD and Solaris.
+       * m4/free.m4 (gl_FUNC_FREE): Guess yes only on OpenBSD and Solaris.
+       Don't trust _POSIX_VERSION for this test.
+
 2020-12-19  Paul Eggert  <eggert@cs.ucla.edu>
 
        free-posix: port to GNU/Linux
index e7a72039e8656b180229e26c9d10f92827dbe881..53df7439b53224186a57b7b3cd06a0ac6b9a6fd3 100644 (file)
@@ -1,33 +1,43 @@
-# free.m4 serial 3
+# free.m4 serial 4
 # 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,
 # with or without modifications, as long as this notice is preserved.
 
-# Written by Paul Eggert.
+# Written by Paul Eggert and Bruno Haible.
 
 AC_DEFUN([gl_FUNC_FREE],
 [
   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
 
   dnl In the next release of POSIX, free must preserve errno.
   dnl https://www.austingroupbugs.net/view.php?id=385
   dnl https://sourceware.org/bugzilla/show_bug.cgi?id=17924
-  dnl For now, assume implementations other than glibc do not preserve errno
-  dnl unless they set _POSIX_VERSION to the next release number,
-  dnl whatever that happens to be.
+  dnl So far, we know of two platforms that do this:
+  dnl * OpenBSD >= 4.5, thanks to this commit:
+  dnl   <https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdlib/malloc.c.diff?r1=1.100&r2=1.101&f=h>
+  dnl * Solaris, because its malloc() implementation is based on brk(),
+  dnl   not mmap(); hence its free() implementation makes no system calls.
+  dnl For other platforms, you can only be sure if they state it in their
+  dnl documentation, or by code inspection of the free() implementation in libc.
   AC_CACHE_CHECK([whether free is known to preserve errno],
     [gl_cv_func_free_preserves_errno],
-    [AC_COMPILE_IFELSE(
-       [AC_LANG_PROGRAM(
-          [[#include <unistd.h>
-          ]],
-          [[#if _POSIX_VERSION <= 200809
-              #error "'free' is not known to preserve errno"
-            #endif
-          ]])],
-       [gl_cv_func_free_preserves_errno=yes],
-       [gl_cv_func_free_preserves_errno=no])
+    [case "$host_os" in
+       # Say yes only if we know it.
+       openbsd* | solaris*)
+         gl_cv_func_free_preserves_errno=yes
+         ;;
+       # It's no on Linux, for implementations that call munmap(), due to
+       # /proc/sys/vm/max_map_count.
+       linux*)
+         gl_cv_func_free_preserves_errno=no
+         ;;
+       # If we don't know, obey --enable-cross-guesses.
+       *)
+         gl_cv_func_free_preserves_errno="$gl_cross_guess_normal"
+         ;;
+     esac
     ])
 
   case $gl_cv_func_free_preserves_errno in