free.m4 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # free.m4 serial 6
  2. # Copyright (C) 2003-2005, 2009-2023 Free Software Foundation, Inc.
  3. # This file is free software; the Free Software Foundation
  4. # gives unlimited permission to copy and/or distribute it,
  5. # with or without modifications, as long as this notice is preserved.
  6. # Written by Paul Eggert and Bruno Haible.
  7. AC_DEFUN([gl_FUNC_FREE],
  8. [
  9. AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
  10. dnl In the next release of POSIX, free must preserve errno.
  11. dnl https://www.austingroupbugs.net/view.php?id=385
  12. dnl https://sourceware.org/bugzilla/show_bug.cgi?id=17924
  13. dnl So far, we know of three platforms that do this:
  14. dnl * glibc >= 2.33, thanks to the fix for this bug:
  15. dnl <https://sourceware.org/bugzilla/show_bug.cgi?id=17924>
  16. dnl * OpenBSD >= 4.5, thanks to this commit:
  17. dnl <https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdlib/malloc.c.diff?r1=1.100&r2=1.101&f=h>
  18. dnl * Solaris, because its malloc() implementation is based on brk(),
  19. dnl not mmap(); hence its free() implementation makes no system calls.
  20. dnl For other platforms, you can only be sure if they state it in their
  21. dnl documentation, or by code inspection of the free() implementation in libc.
  22. AC_CACHE_CHECK([whether free is known to preserve errno],
  23. [gl_cv_func_free_preserves_errno],
  24. [AC_COMPILE_IFELSE(
  25. [AC_LANG_PROGRAM(
  26. [[#include <stdlib.h>
  27. ]],
  28. [[#if 2 < __GLIBC__ + (33 <= __GLIBC_MINOR__)
  29. #elif defined __OpenBSD__
  30. #elif defined __sun
  31. #else
  32. #error "'free' is not known to preserve errno"
  33. #endif
  34. ]])],
  35. [gl_cv_func_free_preserves_errno=yes],
  36. [gl_cv_func_free_preserves_errno=no])
  37. ])
  38. case $gl_cv_func_free_preserves_errno in
  39. *yes)
  40. AC_DEFINE([HAVE_FREE_POSIX], [1],
  41. [Define if the 'free' function is guaranteed to preserve errno.])
  42. ;;
  43. *) REPLACE_FREE=1 ;;
  44. esac
  45. ])
  46. # Prerequisites of lib/free.c.
  47. AC_DEFUN([gl_PREREQ_FREE], [:])