qemu-block
[Top][All Lists]
Advanced

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

Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense


From: Christian Schoenebeck
Subject: Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense
Date: Mon, 14 Mar 2022 21:37:00 +0100

On Montag, 14. März 2022 20:48:47 CET Alex Bennée wrote:
> Markus Armbruster <armbru@redhat.com> writes:
> > g_new(T, n) is neater than g_malloc(sizeof(T) * n).  It's also safer,
> > for two reasons.  One, it catches multiplication overflowing size_t.
> > Two, it returns T * rather than void *, which lets the compiler catch
> > more type errors.
> > 
> > This commit only touches allocations with size arguments of the form
> > sizeof(T).
> > 
> > Patch created mechanically with:
> >     $ spatch --in-place --sp-file scripts/coccinelle/use-g_new-etc.cocci \
> >     
> >          --macro-file scripts/cocci-macro-file.h FILES...
> > 
> > Signed-off-by: Markus Armbruster <armbru@redhat.com>
> 
> <snip>
> 
> > --- a/audio/jackaudio.c
> > +++ b/audio/jackaudio.c
> > @@ -97,9 +97,9 @@ static void qjack_buffer_create(QJackBuffer *buffer, int
> > channels, int frames)> 
> >      buffer->used     = 0;
> >      buffer->rptr     = 0;
> >      buffer->wptr     = 0;
> > 
> > -    buffer->data     = g_malloc(channels * sizeof(float *));
> > +    buffer->data     = g_new(float *, channels);
> > 
> >      for (int i = 0; i < channels; ++i) {
> > 
> > -        buffer->data[i] = g_malloc(frames * sizeof(float));
> > +        buffer->data[i] = g_new(float, frames);
> 
> Are these actually buffers of pointers to floats? I guess I leave that
> to the JACK experts...

That's correct. JACK does not use interleaved audio format, it uses separate 
buffers for each audio channel. For the audio stuff of this patch:

Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>

Best regards,
Christian Schoenebeck





reply via email to

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