From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26232 invoked by alias); 12 Apr 2003 00:42:31 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 26222 invoked from network); 12 Apr 2003 00:42:30 -0000 Received: from unknown (HELO localhost.redhat.com) (207.219.125.105) by sources.redhat.com with SMTP; 12 Apr 2003 00:42:30 -0000 Received: from redhat.com (localhost [127.0.0.1]) by localhost.redhat.com (Postfix) with ESMTP id 4747D2B2F for ; Fri, 11 Apr 2003 20:42:30 -0400 (EDT) Message-ID: <3E9760F6.1040704@redhat.com> Date: Sat, 12 Apr 2003 00:42:00 -0000 From: Andrew Cagney User-Agent: Mozilla/5.0 (X11; U; NetBSD macppc; en-US; rv:1.0.2) Gecko/20030223 X-Accept-Language: en-us, en MIME-Version: 1.0 To: gdb-patches@sources.redhat.com Subject: [patch rfc] Make GDB's xmalloc match liberties Content-Type: multipart/mixed; boundary="------------070603060902050005000900" X-SW-Source: 2003-04/txt/msg00247.txt.bz2 This is a multi-part message in MIME format. --------------070603060902050005000900 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 122 Per recent discussion, this modifies GDB's xmalloc (actually xmmalloc) so that the behavior matches libiberty's. Andrew --------------070603060902050005000900 Content-Type: text/plain; name="diffs" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="diffs" Content-length: 1958 2003-04-11 Andrew Cagney * utils.c (xmmalloc): Always allocate something, matches libiberty/xmalloc's semantics. (xmrealloc, xmcalloc): Ditto. Index: utils.c =================================================================== RCS file: /cvs/src/src/gdb/utils.c,v retrieving revision 1.100 diff -u -r1.100 utils.c --- utils.c 10 Apr 2003 02:18:40 -0000 1.100 +++ utils.c 12 Apr 2003 00:40:30 -0000 @@ -1073,16 +1073,15 @@ { void *val; + /* See libiberty/xmalloc.c. This function need's to match that's + semantics. It never returns NULL. */ if (size == 0) - { - val = NULL; - } - else - { - val = mmalloc (md, size); - if (val == NULL) - nomem (size); - } + size = 1; + + val = mmalloc (md, size); + if (val == NULL) + nomem (size); + return (val); } @@ -1091,27 +1090,18 @@ { void *val; + /* See libiberty/xmalloc.c. This function need's to match that's + semantics. It never returns NULL. */ if (size == 0) - { - if (ptr != NULL) - mfree (md, ptr); - val = NULL; - } + size = 1; + + if (ptr != NULL) + val = mrealloc (md, ptr, size); else - { - if (ptr != NULL) - { - val = mrealloc (md, ptr, size); - } - else - { - val = mmalloc (md, size); - } - if (val == NULL) - { - nomem (size); - } - } + val = mmalloc (md, size); + if (val == NULL) + nomem (size); + return (val); } @@ -1119,14 +1109,19 @@ xmcalloc (void *md, size_t number, size_t size) { void *mem; + + /* See libiberty/xmalloc.c. This function need's to match that's + semantics. It never returns NULL. */ if (number == 0 || size == 0) - mem = NULL; - else { - mem = mcalloc (md, number, size); - if (mem == NULL) - nomem (number * size); + number = 1; + size = 1; } + + mem = mcalloc (md, number, size); + if (mem == NULL) + nomem (number * size); + return mem; } --------------070603060902050005000900--