]> Savannah Git Hosting - gnulib.git/commitdiff
eealloc: update commentary
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 26 Oct 2024 00:02:02 +0000 (17:02 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 26 Oct 2024 21:46:38 +0000 (14:46 -0700)
Even if we remove eealloc we might as well add commentary
explaining some of its confusion, before we remove it.
* lib/eealloc.h: Update comment.
* modules/eealloc (Description):
Update, since eealloc is not glibc compatible.

ChangeLog
lib/eealloc.h
modules/eealloc

index 8b9e8c14f70c2a7bfe7d370e3374ca1177e637ee..ca83d5e14e1691f178e5e4519c627cd442cf4fc9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-10-26  Paul Eggert  <eggert@cs.ucla.edu>
+
+       eealloc: update commentary
+       Even if we remove eealloc we might as well add commentary
+       explaining some of its confusion, before we remove it.
+       * lib/eealloc.h: Update comment.
+       * modules/eealloc (Description):
+       Update, since eealloc is not glibc compatible.
+
 2024-10-26  Bruno Haible  <bruno@clisp.org>
 
        regex: Avoid dialog while running configure test on Haiku/x86_64.
index 522da0f86bb47824ce2fe3c606dc8a93b0d32684..0b42df1b7ba17195f9d5967611a6e7f84c2f2c82 100644 (file)
 #ifndef _EEALLOC_H
 #define _EEALLOC_H
 
-/* malloc() and realloc() are allowed to return NULL when asked to allocate
-   a memory block of 0 bytes; this is not an out-of-memory condition.
-   (See ISO C 99 section 7.20.3.)  In some places, this is not welcome,
-   because it requires extra checking (so as not to confuse a zero-sized
-   allocation with an out-of-memory condition).  This file provides
-   malloc()/realloc() workalikes which return non-NULL pointers for
-   succeeding zero-sized allocations.  GNU libc already defines malloc()
-   and realloc() this way; on such platforms the workalikes are aliased
-   to the original malloc()/realloc() functions.  */
+/* malloc (0) and realloc (NULL, 0) can return NULL even when memory
+   is available; see ISO C 23 sections 7.24.3.
+
+   When P is non-null realloc (P, 0) is worse, in that C23 says the
+   behavior is undefined whereas POSIX.1-2024 (which extends C17) says
+   that realloc (P, 0) when successful behaves like either (free (P),
+   errno = EINVAL, NULL), or like (free (P), malloc (1)) returning non-null
+   so long as you do not dereference the non-null pointer;
+   and glibc does not conform to POSIX as it behaves like (free (P), NULL).
+   There are similar issues with reallocarray.
+
+   This behavior is sometimes unwelcome, as it entails extra checking
+   to avoid confusing a zero-sized allocation with memory exhaustion,
+   and to avoid undefined behavior in C23.
+
+   This file provides malloc and realloc workalikes that consistently
+   treat zero sizes as requests for zero-sized allocations instead of
+   for null pointers.  However, it does not provide workalikes for
+   related functions like aligned_alloc, calloc, and reallocarray.  */
 
 /* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _GL_ATTRIBUTE_ALLOC_SIZE,
    _GL_ATTRIBUTE_MALLOC.  */
index 8f4c279a388c25fb61a9d06a8d27d1608c7932eb..d63e9947375a06c6f489464905e74f8b7ab35b06 100644 (file)
@@ -1,5 +1,5 @@
 Description:
-Memory allocation with expensive empty allocations (glibc compatible).
+Memory allocation with expensive empty allocations
 
 Files:
 lib/eealloc.h