From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MBaEK-0002Gh-1r for qemu-devel@nongnu.org; Tue, 02 Jun 2009 16:05:04 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MBaEF-00027y-5t for qemu-devel@nongnu.org; Tue, 02 Jun 2009 16:05:03 -0400 Received: from [199.232.76.173] (port=58213 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MBaEE-00027b-Vx for qemu-devel@nongnu.org; Tue, 02 Jun 2009 16:04:59 -0400 Received: from mx20.gnu.org ([199.232.41.8]:63834) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MBaEE-0006re-Ez for qemu-devel@nongnu.org; Tue, 02 Jun 2009 16:04:58 -0400 Received: from mail.codesourcery.com ([65.74.133.4]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MBaED-0003cG-Eo for qemu-devel@nongnu.org; Tue, 02 Jun 2009 16:04:57 -0400 From: Paul Brook Subject: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently Date: Tue, 2 Jun 2009 21:04:54 +0100 References: <200905290758.11551.jcd@tribudubois.net> <200906021913.09517.paul@codesourcery.com> <60cad3f0906021249t435fc1a8w4f89027e0863ff52@mail.gmail.com> In-Reply-To: <60cad3f0906021249t435fc1a8w4f89027e0863ff52@mail.gmail.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200906022104.55121.paul@codesourcery.com> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Turner Cc: Kevin Wolf , Jean-Christophe Dubois , qemu-devel@nongnu.org, Gerd Hoffmann On Tuesday 02 June 2009, David Turner wrote: > On Tue, Jun 2, 2009 at 8:13 PM, Paul Brook wrote: > > > > QEMU_NEW_ARRAY(ptr, ...); > > > > > > > > instead of > > > > > > > > ptr = QEMU_NEW_ARRAY(...); > > > > > > > > then. I don't see another easy way to get the automagic sizeof(*ptr) > > > > stuff done though. > > > > > > The first version will extract the item size automatically for you, > > > > making > > > > > it less likely that you screw things in the second version's parameter > > > list. > > > > Not if you do it properly it won't. > > Very frankly I don't see your point. My point is that #define QEMU_NEW(type) ((type *)qemu_malloc(sizeof(type))) foo *ptr = QEMU_NEW(foo); is just as safe as #define QEMU_NEW(ptr) (ptr) = qemu_malloc(sizeof(*(ptr))) foo *ptr; QEMU_NEW(ptr); Because the compiler will catch the type mismatch. Paul