+2024-10-30 Paul Eggert <eggert@cs.ucla.edu>
+
+ aligned_alloc: check for GNU behavior with size 0
+ If someone ever needs to distinguish between GNU and merely POSIX
+ behavior we can split this into two modules, but for now just
+ make this module act like GNU.
+ * lib/aligned_alloc.c (aligned_alloc): Treat zero size like GNU.
+ * m4/aligned_alloc.m4 (gl_FUNC_ALIGNED_ALLOC):
+ * tests/test-aligned_alloc.c (main):
+ Test zero size too.
+
2024-10-30 Bruno Haible <bruno@clisp.org>
assert-h, stdbool: Fix compilation error with MSVC 14 (regr. yesterday).
This function fails if the alignment argument is smaller than
@code{sizeof (void *)} on some platforms:
macOS 14, AIX 7.3.1.
+
+@item
+This function returns a null pointer if the size argument is zero:
+AIX 7.3.
@end itemize
Portability problems not fixed by Gnulib:
aligned_alloc (size_t alignment, size_t size)
#undef aligned_alloc
{
+ if (size == 0)
+ size = 1;
if (alignment >= sizeof (void *))
return aligned_alloc (alignment, size);
else
# aligned_alloc.m4
-# serial 6
+# serial 7
dnl Copyright (C) 2020-2024 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 test $ac_cv_func_aligned_alloc = yes; then
dnl On macOS 11.1 and AIX 7.3.1, aligned_alloc returns NULL when the
dnl alignment argument is smaller than sizeof (void *).
- AC_CACHE_CHECK([whether aligned_alloc works for small alignments],
+ dnl On AIX 7.3, aligned_alloc with a zero size returns NULL.
+ AC_CACHE_CHECK([whether aligned_alloc works for small alignments and sizes],
[gl_cv_func_aligned_alloc_works],
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
[[#include <stdlib.h>
- ]],
- [[void *volatile p = aligned_alloc (2, 18);
- return p == NULL;
+ /* Use paligned_alloc to test; 'volatile' prevents the compiler
+ from optimizing the malloc call away. */
+ void *(*volatile paligned_alloc) (size_t, size_t)
+ = aligned_alloc;]],
+ [[void *p = paligned_alloc (2, 18);
+ void *q = paligned_alloc (sizeof (void *), 0);
+ return p == NULL || q == NULL;
]])
],
[gl_cv_func_aligned_alloc_works=yes],
{
#if HAVE_ALIGNED_ALLOC
static size_t sizes[] =
- { 13, 8, 17, 450, 320, 1, 99, 4, 15, 16, 2, 76, 37, 127, 2406, 641, 5781 };
+ {
+ 13, 8, 17, 450, 320, 1, 99, 4, 15, 16,
+ 2, 76, 37, 127, 2406, 641, 5781, 0
+ };
void *volatile aligned2_blocks[SIZEOF (sizes)];
void *volatile aligned4_blocks[SIZEOF (sizes)];
void *volatile aligned8_blocks[SIZEOF (sizes)];