[FFmpeg-devel] [PATCH 1/4] lavu: add simple array implementation
Lukasz Marek
lukasz.m.luki at gmail.com
Wed Mar 5 23:04:49 CET 2014
On 05.03.2014 21:15, Nicolas George wrote:
> Le quintidi 15 ventôse, an CCXXII, Nicolas George a écrit :
>> For that issue, I would conclude: let us not discuss without actually seeing
>> the code.
>
> And since it is always better to have something concrete to discuss about,
> here is a first draft:
>
> #define AV_DYNARRAY_ADD(av_size_max, av_array, av_size, av_success, av_failure) \
> do { \
> size_t av_size_new = av_size; \
> if (!(av_size & (av_size - 1))) { \
> av_size_new = av_size ? av_size << 1 : 1; \
> if (av_size_new > av_size_max) { \
> av_size_new = 0; \
> } else { \
> void *av_array_new = \
> av_realloc(tab, av_size_new * sizeof(*av_array)); \
> if (!av_array_new) \
> av_size_new = 0; \
> else \
> av_array = av_array_new; \
> } \
> } \
> if (av_size_new) { \
> av_success; \
> av_size++; \
> } else { \
> av_failure; \
> } \
> } while (0)
>
> I realize that the types (of the size and of the elements) were actually not
> needed, even with type-safe code.
>
> This is not tested, I have no time to do it right now, but it can still
> serve as a base for discussion.
I agree with wm4 that removing success part would be nicer. It can be
done outside the macro.
--
Best Regards,
Lukasz Marek
Insanity: doing the same thing over and over again and expecting
different results. - Albert Einstein
More information about the ffmpeg-devel
mailing list