qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently


From: Paul Brook
Subject: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently
Date: Tue, 2 Jun 2009 21:04:54 +0100
User-agent: KMail/1.11.2 (Linux/2.6.29-2-amd64; KDE/4.2.2; x86_64; ; )

On Tuesday 02 June 2009, David Turner wrote:
> On Tue, Jun 2, 2009 at 8:13 PM, Paul Brook <address@hidden> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]