* m4/free.m4 (gl_FUNC_FREE): Define HAVE_FREE_POSIX.
* lib/free.c: Don't define rpl_free if not needed.
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.
#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
errno = 0;
free (p);
errno = err[errno == 0];
-#else
+# else
int err = errno;
free (p);
errno = err;
-#endif
+# endif
}
+
+#endif
-# 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,
])
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
])