diff options
Diffstat (limited to 'mpcommon.h')
-rw-r--r-- | mpcommon.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/mpcommon.h b/mpcommon.h index 2ff66fed40..87f074c6f2 100644 --- a/mpcommon.h +++ b/mpcommon.h @@ -19,6 +19,8 @@ #ifndef MPLAYER_MPCOMMON_H #define MPLAYER_MPCOMMON_H +#include <stdlib.h> + // both int64_t and double should be able to represent this exactly #define MP_NOPTS_VALUE (-1LL<<63) @@ -31,6 +33,28 @@ #define MP_RESIZE_ARRAY(ctx, p, count) do { \ p = talloc_realloc_size((ctx), p, (count) * sizeof(p[0])); } while (0) + +#define MP_TARRAY_GROW(ctx, p, nextidx) \ + do { \ + size_t nextidx_ = (nextidx); \ + size_t nelems_ = MP_TALLOC_ELEMS(p); \ + if (nextidx_ <= nelems_) \ + p = talloc_realloc_size((ctx), p, \ + (nextidx_ + 1) * sizeof((p)[0]) * 2);\ + } while (0) + +#define MP_TARRAY_APPEND(ctx, p, idxvar, val) \ + do { \ + MP_TARRAY_GROW(ctx, p, idxvar); \ + p[idxvar] = (val); \ + idxvar++; \ + } while (0) + +#define MP_EXPAND_ARGS(...) __VA_ARGS__ + +#define talloc_struct(ctx, type, ...) \ + talloc_memdup(ctx, &(type) MP_EXPAND_ARGS(__VA_ARGS__), sizeof(type)) + #ifdef __GNUC__ /** Use gcc attribute to check printf fns. a1 is the 1-based index of |