bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] free: preserve errno


From: Bruno Haible
Subject: Re: [PATCH] free: preserve errno
Date: Fri, 18 Dec 2020 00:44:46 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-197-generic; KDE/5.18.0; x86_64; ; )

Pádraig Brady wrote:
> coreutils is now failing to build with:
> 
>    lib/free.c:28:1: error: no previous declaration
>      for 'rpl_free' [-Werror=missing-declarations]
>     28 | rpl_free (void *p)
>        | ^~~~~~~~
> 
> In early 2008 coreutils removed use of the then deprecated "free" module,
> but I now see 'canonicalize' explicitly depends on this now undeprecated 
> module.

What I see is a warning:

free.c:28:1: warning: no previous declaration for ‘rpl_free’ 
[-Wmissing-declarations]
 rpl_free (void *p)
 ^

Recall that Gnulib does not guarantee warning-free compilation on any
platform.

This patch should fix the warning, by using the modern idioms (that also support
C++ compilation). But there are more issues in this area; more patches to come.


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.

diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index a76fbdc..a512459 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -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
diff --git a/m4/free.m4 b/m4/free.m4
index 62daa8e..9f108c1 100644
--- a/m4/free.m4
+++ b/m4/free.m4
@@ -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
 ])
 
diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4
index 8b3cfe3..6b519c4 100644
--- a/m4/stdlib_h.m4
+++ b/m4/stdlib_h.m4
@@ -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])
diff --git a/modules/free b/modules/free
index 3c06b47..dc5cb56 100644
--- a/modules/free
+++ b/modules/free
@@ -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:
 
diff --git a/modules/stdlib b/modules/stdlib
index 930c5db..1daa0f9 100644
--- a/modules/stdlib
+++ b/modules/stdlib
@@ -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' \




reply via email to

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