[FFmpeg-devel] [PATCH] avutil/internal: add FF_ALLOC_ARRAY_OR_GOTO & FF_ALLOCZ_ARRAY_OR_GOTO

Nicolas George george at nsup.org
Sat Apr 19 00:01:00 CEST 2014

Le nonidi 29 germinal, an CCXXII, Michael Niedermayer a écrit :
> These are similar to the existing FF_ALLOCZ_OR_GOTO & FF_ALLOC_OR_GOTO
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
>  libavutil/internal.h |   18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> diff --git a/libavutil/internal.h b/libavutil/internal.h
> index 9c5546f..05a017f 100644
> --- a/libavutil/internal.h
> +++ b/libavutil/internal.h
> @@ -133,6 +133,24 @@
>      }\
>  }
> +#define FF_ALLOC_ARRAY_OR_GOTO(ctx, p, size0, size1, label)\
> +{\
> +    p = av_malloc(size0, size1);\
> +    if (p == NULL) {\
> +        av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
> +        goto label;\
> +    }\
> +}

A short doxy would be nice. Or at least, naming the arguments more
explicitly than size0 and size1. Maybe nelem and elsize, like in SUS.

A lot of places would require some kind of "ret = AVERROR(ENOMEM);" before
jumping to the failure label.

I am not sure about the unconditional log. Especially for OOM: the error
message is completely redundant with AVERROR(ENOMEM), and someone higher in
the call graph will probably translate the returned error code and print it.
That will print the error message twice.

(I still hope someone will come up with something brilliant to make error
handling simpler and more practical. Or at least more consistent. Maybe
thread-local storage can help. Or longjmp(). Or storing things in AVClass
objects. I do not know. I like the way Gtk+ works, with a GError** extra
argument to return the information. Also, a way of knowing the point in the
code that generated the error would be nice, at least for debug builds.)


  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140419/d57c8ae3/attachment.asc>

More information about the ffmpeg-devel mailing list