From 1b50e7d4d63fee04dbe06d4a58f3061c569fede8 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 8 Jan 2021 19:50:16 -0800 Subject: [PATCH] =?UTF-8?q?dynarray:=20work=20even=20if=20=E2=80=98free?= =?UTF-8?q?=E2=80=99=20is=20replaced?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem reported by Darshit Shah in: https://lists.gnu.org/r/bug-gnulib/2021-01/msg00140.html * lib/malloc/dynarray-skeleton.c (DYNARRAY_FREE): New macro. Use it everywhere instead of DYNARRAY_NAME (free). --- ChangeLog | 6 ++++++ lib/malloc/dynarray-skeleton.c | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index b76330e5b..1e589aac3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2021-01-08 Paul Eggert + dynarray: work even if ‘free’ is replaced + Problem reported by Darshit Shah in: + https://lists.gnu.org/r/bug-gnulib/2021-01/msg00140.html + * lib/malloc/dynarray-skeleton.c (DYNARRAY_FREE): New macro. + Use it everywhere instead of DYNARRAY_NAME (free). + tempname: don’t block for minutes Derived from a patch proposed by Adhemerval Zanella in: https://sourceware.org/pipermail/libc-alpha/2021-January/121302.html diff --git a/lib/malloc/dynarray-skeleton.c b/lib/malloc/dynarray-skeleton.c index fe886102c..5b9f37bdd 100644 --- a/lib/malloc/dynarray-skeleton.c +++ b/lib/malloc/dynarray-skeleton.c @@ -150,6 +150,10 @@ struct DYNARRAY_STRUCT #define DYNARRAY_CONCAT1(prefix, name) DYNARRAY_CONCAT0(prefix, name) #define DYNARRAY_NAME(name) DYNARRAY_CONCAT1(DYNARRAY_PREFIX, name) +/* Use DYNARRAY_FREE instead of DYNARRAY_NAME (free), + so that Gnulib does not change 'free' to 'rpl_free'. */ +#define DYNARRAY_FREE DYNARRAY_CONCAT1 (DYNARRAY_NAME (f), ree) + /* Address of the scratch buffer if any. */ #if DYNARRAY_HAVE_SCRATCH # define DYNARRAY_SCRATCH(list) (list)->scratch @@ -200,7 +204,7 @@ DYNARRAY_NAME (init) (struct DYNARRAY_STRUCT *list) /* Deallocate the dynamic array and its elements. */ __attribute_maybe_unused__ __nonnull ((1)) static void -DYNARRAY_NAME (free) (struct DYNARRAY_STRUCT *list) +DYNARRAY_FREE (struct DYNARRAY_STRUCT *list) { DYNARRAY_NAME (free__elements__) (list->u.dynarray_header.array, list->u.dynarray_header.used); @@ -466,7 +470,7 @@ DYNARRAY_NAME (finalize) (struct DYNARRAY_STRUCT *list, else { /* On error, we need to free all data. */ - DYNARRAY_NAME (free) (list); + DYNARRAY_FREE (list); errno = ENOMEM; return false; } @@ -497,7 +501,7 @@ DYNARRAY_NAME (finalize) (struct DYNARRAY_STRUCT *list, size_t *lengthp) else { /* On error, we need to free all data. */ - DYNARRAY_NAME (free) (list); + DYNARRAY_FREE (list); errno = ENOMEM; return NULL; } -- 2.27.0