]> Savannah Git Hosting - gnulib.git/commitdiff
Make it possible to compile free.c separately, unconditionally.
authorBruno Haible <bruno@clisp.org>
Sun, 31 Jan 2021 11:41:33 +0000 (12:41 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 31 Jan 2021 11:42:01 +0000 (12:42 +0100)
* m4/free.m4 (gl_FUNC_FREE): Define HAVE_FREE_POSIX.
* lib/free.c: Don't define rpl_free if not needed.

ChangeLog
lib/free.c
m4/free.m4

index e9e2b36929ada53bd8854dd6a15432a1288ba359..b8d5cd743c8401f4155e6411efaafada01bacb5f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2021-01-31  Bruno Haible  <bruno@clisp.org>
 
+       Make it possible to compile free.c separately, unconditionally.
+       * m4/free.m4 (gl_FUNC_FREE): Define HAVE_FREE_POSIX.
+       * lib/free.c: Don't define rpl_free if not needed.
+
        Make it possible to compile realloc.c separately, unconditionally.
        * modules/realloc-posix (configure.ac): Invoke gl_MODULE_INDICATOR.
        * lib/realloc.c: Don't define rpl_realloc if not needed.
index 5c89787aba1380c6d6b55ceffb838a9cca796d43..3f5968ca99fea461e0f934ce9253321b06a87e5f 100644 (file)
 
 #include <config.h>
 
+/* Specification.  */
 #include <stdlib.h>
 
-#include <errno.h>
+/* A function definition is only needed if HAVE_FREE_POSIX is not defined.  */
+#if !HAVE_FREE_POSIX
+
+# include <errno.h>
 
 void
 rpl_free (void *p)
-#undef free
+# undef free
 {
-#if defined __GNUC__ && !defined __clang__
+# if defined __GNUC__ && !defined __clang__
   /* An invalid GCC optimization
      <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98396>
      would optimize away the assignments in the code below, when link-time
@@ -39,9 +43,11 @@ rpl_free (void *p)
   errno = 0;
   free (p);
   errno = err[errno == 0];
-#else
+# else
   int err = errno;
   free (p);
   errno = err;
-#endif
+# endif
 }
+
+#endif
index d671376b0bb2768e0a809a366fdba80c35764992..a7923b905909f1b4b7031d6c143ed0e015a012d6 100644 (file)
@@ -1,4 +1,4 @@
-# free.m4 serial 5
+# free.m4 serial 6
 # Copyright (C) 2003-2005, 2009-2021 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -40,7 +40,10 @@ AC_DEFUN([gl_FUNC_FREE],
     ])
 
   case $gl_cv_func_free_preserves_errno in
-   *yes) ;;
+   *yes)
+    AC_DEFINE([HAVE_FREE_POSIX], [1],
+      [Define if the 'free' function is guaranteed to preserve errno.])
+    ;;
    *) REPLACE_FREE=1 ;;
   esac
 ])