From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8926 invoked by alias); 26 Jun 2004 17:22:19 -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 8868 invoked from network); 26 Jun 2004 17:22:18 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org with SMTP; 26 Jun 2004 17:22:18 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.10/8.12.10) with ESMTP id i5QHMIe3028986; Sat, 26 Jun 2004 13:22:18 -0400 Received: from localhost.redhat.com (porkchop.devel.redhat.com [172.16.58.2]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id i5QHM5025843; Sat, 26 Jun 2004 13:22:05 -0400 Received: from gnu.org (localhost [127.0.0.1]) by localhost.redhat.com (Postfix) with ESMTP id 4DD732B9D; Sat, 26 Jun 2004 13:22:00 -0400 (EDT) Message-ID: <40DDB0B7.1040902@gnu.org> Date: Sat, 26 Jun 2004 17:22:00 -0000 From: Andrew Cagney User-Agent: Mozilla/5.0 (X11; U; NetBSD macppc; en-GB; rv:1.4.1) Gecko/20040217 MIME-Version: 1.0 To: Bernardo Innocenti Cc: Daniel Jacobowitz , Ian Lance Taylor , GCC Patches , gdb-patches@sources.redhat.com, binutils@sources.redhat.com, DJ Delorie Subject: Re: [top-level] C++-friendly allocators for libiberty References: <40DCC86A.4010306@develer.com> <40DCD0EE.9010208@develer.com> <40DCE1C8.4020202@develer.com> <20040626024617.GA31620@nevyn.them.org> In-Reply-To: <20040626024617.GA31620@nevyn.them.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2004-06/txt/msg00569.txt.bz2 >>>> > No, people use realloc with variable size arrays at the end of >>>> > structs. xrenewvec (or xresizevec) is a good idea, but you still need >>>> > xrenew (or xresize). > > > Bernando, you've now got an interface which allows reallocating to a > variable size, but not allocating to one... There's no need for a > rush, let's give people some time to comment before putting this into > libiberty. As DJ says, it's hard to take things out of libiberty. I guess daniel had this in mind: > /* Utility macros to allocate typed memory. Avoids errors like: > struct foo *foo = xmalloc (sizeof struct bar); and memset (foo, > sizeof (struct foo), 0). */ > #define XZALLOC(TYPE) ((TYPE*) memset (xmalloc (sizeof (TYPE)), 0, sizeof (TYPE) > )) > #define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE))) > #define XCALLOC(NMEMB, TYPE) ((TYPE*) xcalloc ((NMEMB), sizeof (TYPE))) They first appeared in GDB in '99 and were added to GDB's global header file in '02 (and I'm sure the idea was stolen from elsewhere). Unlike the macros being proposed, these: - use uppercase to make it very very clear that they are macros - are named in a way that directly reflects their C herritage While I agree with the type casing idea underlying "xnew" et.al. (I was in part responsible for the above :-), I don't see any benefit in adopting C++ names and pretending that we're writing C++. Andrew