From: Jes Sorensen <Jes.Sorensen@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: Stefan Hajnoczi <stefanha@gmail.com>, Avi Kivity <avi@redhat.com>,
kvm@vger.kernel.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] Introduce QEMU_NEW()
Date: Mon, 25 Jul 2011 17:17:24 +0200 [thread overview]
Message-ID: <4E2D8904.5080200@redhat.com> (raw)
In-Reply-To: <4E2D8896.7070100@codemonkey.ws>
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
next prev parent reply other threads:[~2011-07-25 15:19 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-25 8:51 [Qemu-devel] [PATCH] Introduce QEMU_NEW() Avi Kivity
2011-07-25 9:32 ` Alexander Graf
2011-07-25 9:37 ` Sasha Levin
2011-07-25 9:43 ` Alexander Graf
2011-07-25 9:49 ` Avi Kivity
2011-07-25 9:48 ` Peter Maydell
2011-07-25 9:52 ` Avi Kivity
2011-07-25 9:56 ` Alexander Graf
2011-07-25 10:02 ` Avi Kivity
2011-07-25 10:04 ` Alexander Graf
2011-07-25 10:09 ` Avi Kivity
2011-07-25 10:19 ` Alexander Graf
2011-07-25 10:46 ` malc
2011-07-25 10:59 ` Markus Armbruster
2011-07-25 11:11 ` Alexander Graf
2011-07-25 12:19 ` Anthony Liguori
2011-07-25 14:16 ` Blue Swirl
2011-07-25 14:20 ` Avi Kivity
2011-07-25 12:30 ` Anthony Liguori
2011-07-25 11:35 ` Avi Kivity
2011-07-25 10:06 ` Stefan Hajnoczi
2011-07-25 10:12 ` Avi Kivity
2011-07-25 10:25 ` Kevin Wolf
2011-07-25 10:28 ` Stefan Hajnoczi
2011-07-25 11:02 ` Markus Armbruster
2011-07-25 11:45 ` Avi Kivity
2011-07-25 15:10 ` Jes Sorensen
2011-07-25 15:15 ` Anthony Liguori
2011-07-25 15:17 ` Jes Sorensen [this message]
2011-07-25 15:20 ` Avi Kivity
2011-07-25 15:21 ` Jes Sorensen
2011-07-25 15:24 ` Avi Kivity
2011-07-25 15:28 ` Jes Sorensen
2011-07-25 15:35 ` Avi Kivity
2011-07-25 12:11 ` Anthony Liguori
2011-07-25 12:18 ` Avi Kivity
2011-07-25 12:21 ` Anthony Liguori
2011-07-25 12:41 ` Avi Kivity
2011-07-25 14:23 ` Blue Swirl
2011-07-25 14:25 ` Anthony Liguori
2011-07-25 14:30 ` Max Filippov
2011-07-25 14:43 ` Anthony Liguori
2011-07-25 14:47 ` malc
2011-07-25 14:50 ` Avi Kivity
2011-07-25 14:58 ` malc
2011-07-25 14:59 ` Avi Kivity
2011-07-25 14:51 ` Paolo Bonzini
2011-07-25 14:56 ` Blue Swirl
2011-07-25 15:21 ` Paolo Bonzini
2011-08-01 10:49 ` Richard W.M. Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E2D8904.5080200@redhat.com \
--to=jes.sorensen@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).