]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
safe-alloc: make obsolete and remove REALLOC_N
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 13 Jul 2025 07:43:36 +0000 (00:43 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 13 Jul 2025 07:49:59 +0000 (00:49 -0700)
Problem reported by Vivien Kraus in:
https://lists.gnu.org/r/bug-gnulib/2025-07/msg00073.html
This module never caught on.
* lib/safe-alloc.h (REALLOC_N): Remove.
* modules/safe-alloc: Now obsolete.
* tests/test-safe-alloc.c (main): Remove REALLOC_N test.

ChangeLog
NEWS
doc/safe-alloc.texi
lib/safe-alloc.h
modules/safe-alloc
tests/test-safe-alloc.c

index 20229b3fd52cafdbb69bd4a15bd773bfaa544f72..73b9cfd7a5858a5ef9acfcbdacc2e16c1bacbecb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2025-07-13  Paul Eggert  <eggert@cs.ucla.edu>
+
+       safe-alloc: make obsolete and remove REALLOC_N
+       Problem reported by Vivien Kraus in:
+       https://lists.gnu.org/r/bug-gnulib/2025-07/msg00073.html
+       This module never caught on.
+       * lib/safe-alloc.h (REALLOC_N): Remove.
+       * modules/safe-alloc: Now obsolete.
+       * tests/test-safe-alloc.c (main): Remove REALLOC_N test.
+
 2025-07-12  Bruno Haible  <bruno@clisp.org>
 
        next-prime: Revert to original behaviour in GNU gettext.
diff --git a/NEWS b/NEWS
index 5499535f2a368dc51533f0ae01b208fa0e1f7462..08981f26e96055675d8383b89a7a394e530b3725 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -74,6 +74,9 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2025-07-13  safe-alloc      This module is now obsolete.  Also, it no longer
+                            defines the REALLOC_N macro.
+
 2025-05-09  string-desc     These modules now distinguish between read-only
             xstring-desc    string descriptors (type string_desc_t) and
                             writable string descriptors (type rw_string_desc_t).
index 238209c920d984afe2218c1a1b162858c5c4180b..d4cd63ed26574503540a3fd0d2101b9598988c44 100644 (file)
@@ -7,6 +7,10 @@ number of common coding errors.  The @code{safe-alloc} module provides
 macros that make it easier to avoid many of them.  It still uses the
 standard C allocation functions behind the scenes.
 
+This module is obsolete, as it does not seem to have caught on in
+practice and some of its features could not be ported to unusual
+platforms.
+
 Some of the memory allocation mistakes that are commonly made are
 
 @itemize @bullet
@@ -71,18 +75,6 @@ bytes long, and store the address of allocated memory in
 Returns @minus{}1 on failure, 0 on success.
 @end defmac
 
-@defmac {int} REALLOC_N (ptr, count)
-@findex REALLOC_N
-Reallocate the memory pointed to by @code{ptr} to be big enough to hold
-at least @code{count} elements, each @code{sizeof *ptr} bytes long,
-and store the address of allocated memory in @code{ptr}.  If
-reallocation fails, the @code{ptr} variable is not modified.
-If the new array is smaller than the old one, discard excess contents;
-if larger, the newly added storage is not initialized.
-
-Returns @minus{}1 on failure, 0 on success.
-@end defmac
-
 @defmac {void} FREE (ptr)
 @findex FREE
 Free the memory stored in @code{ptr} and set @code{ptr} to
index 08daaa86ee03859378a52ce03bfdfb070b51286c..4341b43edfe0eab93f1f7629b03429615cc5082f 100644 (file)
@@ -86,20 +86,6 @@ safe_alloc_check (void *ptr)
 #define ALLOC_N_UNINITIALIZED(ptr, count) \
   safe_alloc_check ((ptr) = reallocarray (NULL, count, sizeof *(ptr)))
 
-/**
- * REALLOC_N:
- * @ptr: pointer to allocated memory
- * @count: number of elements to allocate
- *
- * Re-allocate an array of 'count' elements, each sizeof *ptr
- * bytes long and store the address of allocated memory in
- * 'ptr'.  Fill the newly allocated memory with zeros.
- *
- * Return -1 on failure to reallocate, zero on success.
- */
-#define REALLOC_N(ptr, count) \
-  safe_alloc_check ((ptr) = reallocarray (ptr, count, sizeof *(ptr)))
-
 /**
  * FREE:
  * @ptr: pointer holding address to be freed
index 370b30f625fcfe6b18d6664fd6086a2e0c589565..72e079b8bb88a3131e4bdf7c9a114e05780e1781 100644 (file)
@@ -1,6 +1,12 @@
 Description:
 A set of macros to make calls to alloc/calloc/realloc safer.
 
+Status:
+obsolete
+
+Notice:
+This module is obsolete.
+
 Files:
 lib/safe-alloc.h
 lib/safe-alloc.c
index 32cb4714fd518497919c9f85fb9c86990f6a8cc1..332d378a92088b39ba35d3e16a8f4ea45a0c2e5e 100644 (file)
@@ -42,11 +42,6 @@ main ()
 
   ASSERT (p->a == 0 && p->b == 0);
 
-  p->a = p->b = 42;
-  r = REALLOC_N (p, 5);
-
-  ASSERT (p[0].a == 42 && p[0].b == 42);
-
   FREE (p);
   ASSERT (p == NULL);