From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jes Sorensen Subject: Re: [Qemu-devel] [PATCH] Introduce QEMU_NEW() Date: Mon, 25 Jul 2011 17:17:24 +0200 Message-ID: <4E2D8904.5080200@redhat.com> References: <1311583872-362-1-git-send-email-avi@redhat.com> <4E2D876C.3010300@redhat.com> <4E2D8896.7070100@codemonkey.ws> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Stefan Hajnoczi , Avi Kivity , kvm@vger.kernel.org, qemu-devel@nongnu.org To: Anthony Liguori Return-path: Received: from mx1.redhat.com ([209.132.183.28]:51114 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751189Ab1GYPT1 (ORCPT ); Mon, 25 Jul 2011 11:19:27 -0400 In-Reply-To: <4E2D8896.7070100@codemonkey.ws> Sender: kvm-owner@vger.kernel.org List-ID: On 07/25/11 17:15, Anthony Liguori wrote: > On 07/25/2011 10:10 AM, Jes Sorensen wrote: >> On 07/25/11 12:06, Stefan Hajnoczi wrote: >>>> +#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(). >> >> You're right, and it will promote even more abuse of the ugly typedefs. >> This really makes the code less readable, especially for outsiders :( > > I don't think it really matters either way. If some people prefer to > use g_new(struct foo, 1) vs. g_malloc(sizeof(*f)), I don't think it > significantly impacts overall code readability. > > But having nice, documentation for key internal APIs does which is why > using the glib interfaces makes sense IMHO. Using the commands consistently does have an impact, and at least with qemu_malloc() it is obvious what they are and how they behave. The proposed macros on the other hand requires everybody to go look up the macro to find out what it is trying to do. Jes