[FFmpeg-devel] [PATCH 1/4] lavu: add simple array implementation
wm4
nfxjfg at googlemail.com
Wed Mar 5 18:32:34 CET 2014
On Wed, 5 Mar 2014 14:04:01 +0100
Nicolas George <george at nsup.org> wrote:
> AV_DYNARRAY_ADD(size_t, SIZE_MAX, AVCodecContext *,
> array, size,
> array[size - 1] = new_element, /* if success */
> goto fail /* if failure */
> );
Unfortunately, this is pretty horrible. GET_UTF8 style.
It could be simplified a bit. First off, you don't need to put the code
for "success" as macro parameter. You could call the macro something
like AV_DYNARRAY_GROW, and put the "success" code after it.
Second, you could drop the type for the size. You'll only ever use
size_t or int as index, so it's better to duplicate the macro for those
two types, instead of wasting 2 macro parameters on them.
Third: are you sure you need the element type? In most situations, you
can probably just use sizeof(array[0]) inside the macro to get the size
of the element.
That leaves error handling. I'm not sure how to do that. Passing a
statement as macro parameter is really ugly. Maybe pass only the label
and hard code the goto? IMHO slightly better, but not really great
either. A shame that you most likely can't write the macro so that it
returns success, other than using GNU extensions, or violating strict
aliasing rules.
More information about the ffmpeg-devel
mailing list