From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:45976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QlI9p-00059R-CA for qemu-devel@nongnu.org; Mon, 25 Jul 2011 06:13:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QlI9n-0001Gc-E3 for qemu-devel@nongnu.org; Mon, 25 Jul 2011 06:13:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14100) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QlI9n-0001D9-1m for qemu-devel@nongnu.org; Mon, 25 Jul 2011 06:13:03 -0400 Message-ID: <4E2D41A9.5020709@redhat.com> Date: Mon, 25 Jul 2011 13:12:57 +0300 From: Avi Kivity MIME-Version: 1.0 References: <1311583872-362-1-git-send-email-avi@redhat.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] Introduce QEMU_NEW() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org On 07/25/2011 01:06 PM, Stefan Hajnoczi wrote: > > char *qemu_strndup(const char *str, size_t size); > > > > +#define QEMU_NEW(type) ((type *)(qemu_malloc(sizeof(type)))) > > +#define QEMU_NEWZ(type) ((type *)(qemu_mallocz(sizeof(type)))) > > Does this mean we need to duplicate the type name for each allocation? > > struct foo *f; > > ... > f = qemu_malloc(sizeof(*f)); > > Becomes: > > struct foo *f; > > ... > f = QEMU_NEW(struct foo); > > If you ever change the name of the type you have to search-replace > these instances. The idomatic C way works well, I don't see a reason > to use QEMU_NEW(). It works as long as you don't make any mistakes: f = qemu_malloc(sizeof(*g)); f = qemu_malloc(sizeof(f)); qemu_malloc() returns a void pointer, these are poisonous. -- error compiling committee.c: too many arguments to function