From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MBOS3-0003tn-Nk for qemu-devel@nongnu.org; Tue, 02 Jun 2009 03:30:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MBORz-0003qs-Tx for qemu-devel@nongnu.org; Tue, 02 Jun 2009 03:30:27 -0400 Received: from [199.232.76.173] (port=40916 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MBORz-0003qp-PK for qemu-devel@nongnu.org; Tue, 02 Jun 2009 03:30:23 -0400 Received: from mx20.gnu.org ([199.232.41.8]:9211) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MBORz-00014L-2y for qemu-devel@nongnu.org; Tue, 02 Jun 2009 03:30:23 -0400 Received: from mx2.redhat.com ([66.187.237.31]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MBORy-0005Zo-4h for qemu-devel@nongnu.org; Tue, 02 Jun 2009 03:30:22 -0400 Message-ID: <4A24D40E.2060704@redhat.com> Date: Tue, 02 Jun 2009 09:26:06 +0200 From: Gerd Hoffmann MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently References: <200905290758.11551.jcd@tribudubois.net> <4A1FD6E2.9020006@redhat.com> <200905291407.26757.paul@codesourcery.com> <200905291917.10535.jseward@acm.org> <60cad3f0905291412m670c7a6cw45f9b51f3122ddfb@mail.gmail.com> In-Reply-To: <60cad3f0905291412m670c7a6cw45f9b51f3122ddfb@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Turner Cc: Kevin Wolf , Paul Brook , qemu-devel@nongnu.org, Jean-Christophe Dubois On 05/29/09 23:12, David Turner wrote: > I would even suggest providing helper macros to make the programmer's intent > even more clear > and less error-prone, as in: > > #define QEMU_NEW(ptr) (ptr) = qemu_alloc(sizeof(*(ptr))) > #define QEMU_NEW_ARRAY(ptr,cnt) (ptr) = qemu_calloc((cnt),sizeof(*(ptr))) > #define QEMU_RENEW_ARRAY(ptr,cnt) (ptr) = > qemu_realloc((ptr),(cnt),sizeof(*(ptr))) > #define QEMU_FREE_ARRAY(ptr) qemu_free(ptr) The idea to have allocators for arrays (and have them allow zero-length arrays) is fine. I wouldn't create two macros for new and renew array, you can just use usual realloc semantics (ptr == NULL -> alloc). Also I don't like the syntax that much as you'll have the IMHO non-intuitive code like this: 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. cheers, Gerd