bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* [PATCH] malloc, realloc: fix recently-introduced #undef typos
@ 2021-04-17  0:07 Paul Eggert
  2021-04-17  2:53 ` Bruno Haible
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Eggert @ 2021-04-17  0:07 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Paul Eggert

* lib/malloc.c (malloc):
* lib/realloc.c (malloc, realloc): #undef before using.
---
 ChangeLog     | 6 ++++++
 lib/malloc.c  | 3 +++
 lib/realloc.c | 4 ++++
 3 files changed, 13 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 7c519ee44..3207c22cf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2021-04-16  Paul Eggert  <eggert@cs.ucla.edu>
+
+	malloc, realloc: fix recently-introduced #undef typos
+	* lib/malloc.c (malloc):
+	* lib/realloc.c (malloc, realloc): #undef before using.
+
 2021-04-14  Bruno Haible  <bruno@clisp.org>
 
 	hamt tests: Fix link error.
diff --git a/lib/malloc.c b/lib/malloc.c
index 7b5ae9589..272b8b9f4 100644
--- a/lib/malloc.c
+++ b/lib/malloc.c
@@ -33,6 +33,9 @@
 
 # include <errno.h>
 
+/* Call the system's malloc below.  */
+# undef malloc
+
 /* Allocate an N-byte block of memory from the heap.
    If N is zero, allocate a 1-byte block.  */
 
diff --git a/lib/realloc.c b/lib/realloc.c
index 3bf1bea2d..c3e3cdfc5 100644
--- a/lib/realloc.c
+++ b/lib/realloc.c
@@ -40,6 +40,10 @@
 
 # include <errno.h>
 
+/* Call the system's malloc and realloc below.  */
+# undef malloc
+# undef realloc
+
 /* Change the size of an allocated block of memory P to N bytes,
    with error checking.  If N is zero, change it to 1.  If P is NULL,
    use malloc.  */
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] malloc, realloc: fix recently-introduced #undef typos
  2021-04-17  0:07 [PATCH] malloc, realloc: fix recently-introduced #undef typos Paul Eggert
@ 2021-04-17  2:53 ` Bruno Haible
  2021-04-18 23:24   ` Paul Eggert
  0 siblings, 1 reply; 4+ messages in thread
From: Bruno Haible @ 2021-04-17  2:53 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Paul Eggert

> +2021-04-16  Paul Eggert  <eggert@cs.ucla.edu>
> +
> +	malloc, realloc: fix recently-introduced #undef typos

That must have been more than a typo? It must have been an endless recursion?

Thanks for the fix!

Bruno



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] malloc, realloc: fix recently-introduced #undef typos
  2021-04-17  2:53 ` Bruno Haible
@ 2021-04-18 23:24   ` Paul Eggert
  2021-04-21 18:54     ` Paul Eggert
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Eggert @ 2021-04-18 23:24 UTC (permalink / raw)
  To: Bruno Haible, bug-gnulib

On 4/16/21 7:53 PM, Bruno Haible wrote:
>> +	malloc, realloc: fix recently-introduced #undef typos
> That must have been more than a typo? It must have been an endless recursion?

Yes, they were typos that caused infloops. But little harm done; I don't 
think they escaped into any distributions.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] malloc, realloc: fix recently-introduced #undef typos
  2021-04-18 23:24   ` Paul Eggert
@ 2021-04-21 18:54     ` Paul Eggert
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Eggert @ 2021-04-21 18:54 UTC (permalink / raw)
  To: Bruno Haible; +Cc: Gnulib bugs

[-- Attachment #1: Type: text/plain, Size: 536 bytes --]

On 4/18/21 4:24 PM, Paul Eggert wrote:

> Yes, they were typos that caused infloops. But little harm done; I don't 
> think they escaped into any distributions.

Whoops, I take it back. Because those modules defined 
_GL_USE_STDLIB_ALLOC, stdlib.h did not define malloc and realloc and so 
the undefs were not needed. And as it was, realloc-gnu did not work on 
AIX 7.1 because the realloc replacement assumed the malloc replacement. 
I fixed this by installing the attached two patches. It's still a bit 
messy but at least it works.


[-- Attachment #2: 0001-malloc-simplify.patch --]
[-- Type: text/x-patch, Size: 1444 bytes --]

From 147828bccdcbb7af648d24ef9eaa68e9cb6b89d2 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 21 Apr 2021 11:09:01 -0700
Subject: [PATCH 1/2] malloc: simplify
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lib/malloc.c: Omit unnecessary "#undef malloc".
I recently introduced it by mistake.  This module defines
_GL_USE_STDLIB_ALLOC and so malloc isn’t redefined to rpl_malloc.
---
 ChangeLog    | 5 +++++
 lib/malloc.c | 3 ---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e72362077..b013d915f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2021-04-21  Paul Eggert  <eggert@cs.ucla.edu>
 
+	malloc: simplify
+	* lib/malloc.c: Omit unnecessary "#undef malloc".
+	I recently introduced it by mistake.  This module defines
+	_GL_USE_STDLIB_ALLOC and so malloc isn’t redefined to rpl_malloc.
+
 	malloca: avoid ptrdiff_t overflow
 	* lib/malloca.c: Include idx.h, intprops.h.
 	(mmalloca): Check for ptrdiff_t overflow.  Since this module uses
diff --git a/lib/malloc.c b/lib/malloc.c
index a900046ec..30f791fb9 100644
--- a/lib/malloc.c
+++ b/lib/malloc.c
@@ -26,9 +26,6 @@
 
 #include "xalloc-oversized.h"
 
-/* Call the system's malloc below.  */
-# undef malloc
-
 /* Allocate an N-byte block of memory from the heap, even if N is 0.  */
 
 void *
-- 
2.27.0



[-- Attachment #3: 0002-realloc-port-to-AIX-7.1.patch --]
[-- Type: text/x-patch, Size: 1478 bytes --]

From 882243dcfe41bd703db61af56e954d8dff3369ce Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 21 Apr 2021 11:10:06 -0700
Subject: [PATCH 2/2] realloc: port to AIX 7.1

* lib/realloc.c (_GL_USE_STDLIB_ALLOC): Do not define.  This
module relies on GNU malloc.  This fixes a test failure on AIX 7.1.
---
 ChangeLog     | 4 ++++
 lib/realloc.c | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b013d915f..579284336 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2021-04-21  Paul Eggert  <eggert@cs.ucla.edu>
 
+	realloc: port to AIX 7.1
+	* lib/realloc.c (_GL_USE_STDLIB_ALLOC): Do not define.  This
+	module relies on GNU malloc.  This fixes a test failure on AIX 7.1.
+
 	malloc: simplify
 	* lib/malloc.c: Omit unnecessary "#undef malloc".
 	I recently introduced it by mistake.  This module defines
diff --git a/lib/realloc.c b/lib/realloc.c
index c0d94b439..0c87d0d92 100644
--- a/lib/realloc.c
+++ b/lib/realloc.c
@@ -18,7 +18,6 @@
 
 /* written by Jim Meyering and Bruno Haible */
 
-#define _GL_USE_STDLIB_ALLOC 1
 #include <config.h>
 
 #include <stdlib.h>
@@ -27,7 +26,8 @@
 
 #include "xalloc-oversized.h"
 
-/* Call the system's realloc below.  */
+/* Call the system's realloc below.  This file does not define
+   _GL_USE_STDLIB_ALLOC because it needs Gnulib's malloc if present.  */
 #undef realloc
 
 /* Change the size of an allocated block of memory P to N bytes,
-- 
2.27.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-21 18:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-17  0:07 [PATCH] malloc, realloc: fix recently-introduced #undef typos Paul Eggert
2021-04-17  2:53 ` Bruno Haible
2021-04-18 23:24   ` Paul Eggert
2021-04-21 18:54     ` Paul Eggert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).