]> Savannah Git Hosting - gnulib.git/commitdiff
free: Fix warning.
authorBruno Haible <bruno@clisp.org>
Thu, 17 Dec 2020 23:41:07 +0000 (00:41 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 17 Dec 2020 23:41:07 +0000 (00:41 +0100)
Reported by Pádraig Brady <P@draigBrady.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00148.html>.

* lib/stdlib.in.h (free): New declaration.
* m4/stdlib_h.m4 (gl_STDLIB_H): Test whether 'free' is declared.
(gl_STDLIB_H_DEFAULTS): Initialize GNULIB_FREE, REPLACE_FREE.
* modules/stdlib (Makefile.am): Substitute GNULIB_FREE, REPLACE_FREE.
* m4/free.m4 (gl_FUNC_FREE): Set REPLACE_FREE, instead of defining
'free' as a macro here.
* modules/free (Depends-on): Add stdlib.
(configure.ac): Test REPLACE_FREE. Invoke gl_STDLIB_MODULE_INDICATOR.

ChangeLog
lib/stdlib.in.h
m4/free.m4
m4/stdlib_h.m4
modules/free
modules/stdlib

index 74f2ceb34cd77f253dfccd8588a0f2e265dcaa47..2c6fae91032f4e15b95b61b3e1e02461fd47edaa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2020-12-17  Bruno Haible  <bruno@clisp.org>
+
+       free: Fix warning.
+       Reported by Pádraig Brady <P@draigBrady.com> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00148.html>.
+       * lib/stdlib.in.h (free): New declaration.
+       * m4/stdlib_h.m4 (gl_STDLIB_H): Test whether 'free' is declared.
+       (gl_STDLIB_H_DEFAULTS): Initialize GNULIB_FREE, REPLACE_FREE.
+       * modules/stdlib (Makefile.am): Substitute GNULIB_FREE, REPLACE_FREE.
+       * m4/free.m4 (gl_FUNC_FREE): Set REPLACE_FREE, instead of defining
+       'free' as a macro here.
+       * modules/free (Depends-on): Add stdlib.
+       (configure.ac): Test REPLACE_FREE. Invoke gl_STDLIB_MODULE_INDICATOR.
+
 2020-12-17  Paul Eggert  <eggert@cs.ucla.edu>
 
        canonicalize-lgpl: fix AIX test failures
index a76fbdc3d43998ef2aed1564806bd18f888f9816..a512459e2d0cd3d7f8827511be208e4a07371612 100644 (file)
@@ -284,6 +284,27 @@ _GL_CXXALIAS_SYS (fcvt, char *,
 _GL_CXXALIASWARN (fcvt);
 #endif
 
+#if @GNULIB_FREE@
+# if @REPLACE_FREE@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef free
+#   define free rpl_free
+#  endif
+_GL_FUNCDECL_RPL (free, void, (void *ptr));
+_GL_CXXALIAS_RPL (free, void, (void *ptr));
+# else
+_GL_CXXALIAS_SYS (free, void, (void *ptr));
+# endif
+# if __GLIBC__ >= 2
+_GL_CXXALIASWARN (free);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef free
+/* Assume free is always declared.  */
+_GL_WARN_ON_USE (free, "free is not future POSIX compliant everywhere - "
+                 "use gnulib module free for portability");
+#endif
+
 /* On native Windows, map 'gcvt' to '_gcvt', so that -loldnames is not
    required.  In C++ with GNULIB_NAMESPACE, avoid differences between
    platforms by defining GNULIB_NAMESPACE::gcvt on all platforms that have
index 62daa8ecc3a3e583715d077dddb8389f4997e78e..9f108c184de9d1100d860efac7d04c166ae31510 100644 (file)
@@ -1,5 +1,4 @@
-# Check whether free (NULL) is supposed to work.
-
+# free.m4 serial 1
 # 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,
@@ -16,6 +15,7 @@
 
 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],
@@ -67,10 +67,7 @@ AC_DEFUN([gl_FUNC_FREE],
 
   case $gl_cv_func_free,$gl_cv_func_free_preserves_errno in
    *yes,*yes) ;;
-   *)
-    AC_DEFINE([free], [rpl_free],
-      [Define to rpl_free if the replacement function should be used.])
-    ;;
+   *) REPLACE_FREE=1 ;;
   esac
 ])
 
index 8b3cfe3183d78b42a4dfbd4e9aeeadca3f523ac7..6b519c4e37d82edbe54debf2a348e82544a54226 100644 (file)
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 52
+# stdlib_h.m4 serial 53
 dnl Copyright (C) 2007-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -22,7 +22,7 @@ AC_DEFUN([gl_STDLIB_H],
 #if HAVE_RANDOM_H
 # include <random.h>
 #endif
-    ]], [_Exit aligned_alloc atoll canonicalize_file_name
+    ]], [_Exit aligned_alloc atoll canonicalize_file_name free
     getloadavg getsubopt grantpt
     initstate initstate_r mbtowc mkdtemp mkostemp mkostemps mkstemp mkstemps
     posix_memalign posix_openpt ptsname ptsname_r qsort_r
@@ -62,6 +62,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   GNULIB_ATOLL=0;         AC_SUBST([GNULIB_ATOLL])
   GNULIB_CALLOC_POSIX=0;  AC_SUBST([GNULIB_CALLOC_POSIX])
   GNULIB_CANONICALIZE_FILE_NAME=0;  AC_SUBST([GNULIB_CANONICALIZE_FILE_NAME])
+  GNULIB_FREE=0;          AC_SUBST([GNULIB_FREE])
   GNULIB_GETLOADAVG=0;    AC_SUBST([GNULIB_GETLOADAVG])
   GNULIB_GETSUBOPT=0;     AC_SUBST([GNULIB_GETSUBOPT])
   GNULIB_GRANTPT=0;       AC_SUBST([GNULIB_GRANTPT])
@@ -140,6 +141,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   REPLACE_ALIGNED_ALLOC=0;   AC_SUBST([REPLACE_ALIGNED_ALLOC])
   REPLACE_CALLOC=0;          AC_SUBST([REPLACE_CALLOC])
   REPLACE_CANONICALIZE_FILE_NAME=0;  AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME])
+  REPLACE_FREE=0;            AC_SUBST([REPLACE_FREE])
   REPLACE_INITSTATE=0;       AC_SUBST([REPLACE_INITSTATE])
   REPLACE_MALLOC=0;          AC_SUBST([REPLACE_MALLOC])
   REPLACE_MBTOWC=0;          AC_SUBST([REPLACE_MBTOWC])
index 3c06b4756e55698bc88c0a46a3ae8306afb91e37..dc5cb56c47c12683ceca8c2c31c1670dd94fa2ed 100644 (file)
@@ -6,16 +6,15 @@ lib/free.c
 m4/free.m4
 
 Depends-on:
+stdlib
 
 configure.ac:
 gl_FUNC_FREE
-case $gl_cv_func_free,$gl_cv_func_free_errno in
- *yes,*yes) ;;
- *)
+if test $REPLACE_FREE = 1; then
   AC_LIBOBJ([free])
   gl_PREREQ_FREE
-  ;;
-esac
+fi
+gl_STDLIB_MODULE_INDICATOR([free])
 
 Makefile.am:
 
index 930c5db5a269247409bfd4347e981035877e83a1..1daa0f9619feac2469a4399ec4e44ce23b9d53e8 100644 (file)
@@ -36,6 +36,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
              -e 's/@''GNULIB_ATOLL''@/$(GNULIB_ATOLL)/g' \
              -e 's/@''GNULIB_CALLOC_POSIX''@/$(GNULIB_CALLOC_POSIX)/g' \
              -e 's/@''GNULIB_CANONICALIZE_FILE_NAME''@/$(GNULIB_CANONICALIZE_FILE_NAME)/g' \
+             -e 's/@''GNULIB_FREE''@/$(GNULIB_FREE)/g' \
              -e 's/@''GNULIB_GETLOADAVG''@/$(GNULIB_GETLOADAVG)/g' \
              -e 's/@''GNULIB_GETSUBOPT''@/$(GNULIB_GETSUBOPT)/g' \
              -e 's/@''GNULIB_GRANTPT''@/$(GNULIB_GRANTPT)/g' \
@@ -113,6 +114,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
              -e 's|@''REPLACE_ALIGNED_ALLOC''@|$(REPLACE_ALIGNED_ALLOC)|g' \
              -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \
              -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
+             -e 's|@''REPLACE_FREE''@|$(REPLACE_FREE)|g' \
              -e 's|@''REPLACE_INITSTATE''@|$(REPLACE_INITSTATE)|g' \
              -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
              -e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \