* lib/stdlib.in.h (aligned_alloc): New declaration.
* lib/aligned_alloc.c: New file.
* m4/aligned_alloc.m4: New file.
* m4/stdlib_h.m4 (gl_STDLIB_H): Test whether aligned_alloc is declared.
(gl_STDLIB_H_DEFAULTS): Initialize GNULIB_ALIGNED_ALLOC,
HAVE_ALIGNED_ALLOC, REPLACE_ALIGNED_ALLOC.
* modules/stdlib (Makefile.am): Substitute GNULIB_ALIGNED_ALLOC,
HAVE_ALIGNED_ALLOC, REPLACE_ALIGNED_ALLOC.
* modules/aligned_alloc: New file.
* tests/test-stdlib-c++.cc (aligned_alloc): Check signature.
* doc/posix-functions/aligned_alloc.texi: Mention the new module and the
AIX bug.
+2020-11-03 Bruno Haible <bruno@clisp.org>
+
+ aligned_alloc: New module.
+ * lib/stdlib.in.h (aligned_alloc): New declaration.
+ * lib/aligned_alloc.c: New file.
+ * m4/aligned_alloc.m4: New file.
+ * m4/stdlib_h.m4 (gl_STDLIB_H): Test whether aligned_alloc is declared.
+ (gl_STDLIB_H_DEFAULTS): Initialize GNULIB_ALIGNED_ALLOC,
+ HAVE_ALIGNED_ALLOC, REPLACE_ALIGNED_ALLOC.
+ * modules/stdlib (Makefile.am): Substitute GNULIB_ALIGNED_ALLOC,
+ HAVE_ALIGNED_ALLOC, REPLACE_ALIGNED_ALLOC.
+ * modules/aligned_alloc: New file.
+ * tests/test-stdlib-c++.cc (aligned_alloc): Check signature.
+ * doc/posix-functions/aligned_alloc.texi: Mention the new module and the
+ AIX bug.
+
2020-11-03 Bruno Haible <bruno@clisp.org>
posix_memalign: Add tests.
Documentation:@* @uref{https://www.kernel.org/doc/man-pages/online/pages/man3/aligned_alloc.3.html,,man aligned_alloc}
-Gnulib module: ---
+Gnulib module: aligned_alloc
Portability problems fixed by Gnulib:
@itemize
+This function fails if the alignment argument is smaller than
+@code{sizeof (void *)} on some platforms:
+AIX 7.2.
@end itemize
Portability problems not fixed by Gnulib:
--- /dev/null
+/* An aligned_alloc() function that works around platform bugs.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdlib.h>
+
+void *
+aligned_alloc (size_t alignment, size_t size)
+#undef aligned_alloc
+{
+ if (alignment >= sizeof (void *))
+ return aligned_alloc (alignment, size);
+ else
+ return malloc (size);
+}
#endif
+/* Allocate memory with indefinite extent and specified alignment. */
+#if @GNULIB_ALIGNED_ALLOC@
+# if @REPLACE_ALIGNED_ALLOC@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef aligned_alloc
+# define aligned_alloc rpl_aligned_alloc
+# endif
+_GL_FUNCDECL_RPL (aligned_alloc, void *, (size_t alignment, size_t size));
+_GL_CXXALIAS_RPL (aligned_alloc, void *, (size_t alignment, size_t size));
+# else
+# if @HAVE_ALIGNED_ALLOC@
+_GL_CXXALIAS_SYS (aligned_alloc, void *, (size_t alignment, size_t size));
+# endif
+# endif
+# if @HAVE_ALIGNED_ALLOC@
+_GL_CXXALIASWARN (aligned_alloc);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef aligned_alloc
+# if HAVE_RAW_DECL_ALIGNED_ALLOC
+_GL_WARN_ON_USE (aligned_alloc, "aligned_alloc is not portable - "
+ "use gnulib module aligned_alloc for portability");
+# endif
+#endif
+
#if @GNULIB_ATOLL@
/* Parse a signed decimal integer.
Returns the value of the integer. Errors are not detected. */
--- /dev/null
+# aligned_alloc.m4 serial 1
+dnl Copyright (C) 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,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_ALIGNED_ALLOC],
+[
+ AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+
+ dnl Persuade glibc <stdlib.h> to declare aligned_alloc().
+ AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+ AC_CHECK_FUNCS_ONCE([aligned_alloc])
+ if test $ac_cv_func_aligned_alloc = yes; then
+ dnl On AIX 7.2, aligned_alloc returns NULL when the alignment argument is
+ dnl smaller than sizeof (void *).
+ AC_CACHE_CHECK([whether aligned_alloc works for small alignments],
+ [gl_cv_func_aligned_alloc_works],
+ [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <stdlib.h>
+ ]],
+ [[return aligned_alloc (2, 18) == NULL;
+ ]])
+ ],
+ [gl_cv_func_aligned_alloc_works=yes],
+ [gl_cv_func_aligned_alloc_works=no],
+ [case "$host_os" in
+ # Guess no on AIX.
+ aix*) gl_cv_func_aligned_alloc_works="guessing no" ;;
+ # If we don't know, obey --enable-cross-guesses.
+ *) gl_cv_func_aligned_alloc_works="$gl_cross_guess_normal" ;;
+ esac
+ ])
+ ])
+ case "$gl_cv_func_aligned_alloc_works" in
+ *yes) ;;
+ *) REPLACE_ALIGNED_ALLOC=1 ;;
+ esac
+ else
+ dnl The system does not have aligned_alloc.
+ HAVE_ALIGNED_ALLOC=0
+ fi
+])
-# stdlib_h.m4 serial 50
+# stdlib_h.m4 serial 51
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,
#if HAVE_RANDOM_H
# include <random.h>
#endif
- ]], [_Exit atoll canonicalize_file_name getloadavg getsubopt grantpt
+ ]], [_Exit aligned_alloc atoll canonicalize_file_name
+ getloadavg getsubopt grantpt
initstate initstate_r mbtowc mkdtemp mkostemp mkostemps mkstemp mkstemps
posix_memalign posix_openpt ptsname ptsname_r qsort_r
random random_r reallocarray realpath rpmatch secure_getenv setenv
AC_DEFUN([gl_STDLIB_H_DEFAULTS],
[
GNULIB__EXIT=0; AC_SUBST([GNULIB__EXIT])
+ GNULIB_ALIGNED_ALLOC=0; AC_SUBST([GNULIB_ALIGNED_ALLOC])
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_WCTOMB=0; AC_SUBST([GNULIB_WCTOMB])
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE__EXIT=1; AC_SUBST([HAVE__EXIT])
+ HAVE_ALIGNED_ALLOC=1; AC_SUBST([HAVE_ALIGNED_ALLOC])
HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL])
HAVE_CANONICALIZE_FILE_NAME=1; AC_SUBST([HAVE_CANONICALIZE_FILE_NAME])
HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG])
HAVE_SYS_LOADAVG_H=0; AC_SUBST([HAVE_SYS_LOADAVG_H])
HAVE_UNLOCKPT=1; AC_SUBST([HAVE_UNLOCKPT])
HAVE_DECL_UNSETENV=1; AC_SUBST([HAVE_DECL_UNSETENV])
+ 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_INITSTATE=0; AC_SUBST([REPLACE_INITSTATE])
--- /dev/null
+Description:
+Allocate memory with indefinite extent and specified alignment.
+
+Files:
+lib/aligned_alloc.c
+m4/aligned_alloc.m4
+
+Depends-on:
+extensions
+stdlib
+
+configure.ac:
+gl_FUNC_ALIGNED_ALLOC
+if test $REPLACE_ALIGNED_ALLOC = 1; then
+ AC_LIBOBJ([aligned_alloc])
+fi
+gl_STDLIB_MODULE_INDICATOR([aligned_alloc])
+
+Makefile.am:
+
+Include:
+<stdlib.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
-e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \
-e 's/@''GNULIB__EXIT''@/$(GNULIB__EXIT)/g' \
+ -e 's/@''GNULIB_ALIGNED_ALLOC''@/$(GNULIB_ALIGNED_ALLOC)/g' \
-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_WCTOMB''@/$(GNULIB_WCTOMB)/g' \
< $(srcdir)/stdlib.in.h | \
sed -e 's|@''HAVE__EXIT''@|$(HAVE__EXIT)|g' \
+ -e 's|@''HAVE_ALIGNED_ALLOC''@|$(HAVE_ALIGNED_ALLOC)|g' \
-e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \
-e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \
-e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \
-e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \
-e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \
-e 's|@''HAVE_DECL_UNSETENV''@|$(HAVE_DECL_UNSETENV)|g' \
+ -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_INITSTATE''@|$(REPLACE_INITSTATE)|g' \
SIGNATURE_CHECK (GNULIB_NAMESPACE::_Exit, void, (int));
#endif
+#if GNULIB_TEST_ALIGNED_ALLOC && HAVE_ALIGNED_ALLOC
+SIGNATURE_CHECK (GNULIB_NAMESPACE::aligned_alloc, void *, (size_t, size_t));
+#endif
+
//SIGNATURE_CHECK (GNULIB_NAMESPACE::atexit, int, (void (*) (void)));
#if GNULIB_TEST_ATOLL