summaryrefslogtreecommitdiffstats
path: root/ta
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-17 02:18:16 +0100
committerwm4 <wm4@nowhere>2013-12-17 02:18:16 +0100
commit73a5417950a2d21a397597c05521725f3d125993 (patch)
tree46fc5856d7774a39d449bbbd80405d0d2ba92fd9 /ta
parenteb15151705d47d23da844449126cc6b4879f110e (diff)
downloadmpv-73a5417950a2d21a397597c05521725f3d125993.tar.bz2
mpv-73a5417950a2d21a397597c05521725f3d125993.tar.xz
Merge mp_talloc.h into ta/ta_talloc.h
Diffstat (limited to 'ta')
-rw-r--r--ta/ta_talloc.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/ta/ta_talloc.h b/ta/ta_talloc.h
index cd41e63818..ff131a610e 100644
--- a/ta/ta_talloc.h
+++ b/ta/ta_talloc.h
@@ -71,4 +71,42 @@ char *ta_talloc_vasprintf_append_buffer(char *s, const char *fmt, va_list ap) TA
char *ta_talloc_asprintf_append(char *s, const char *fmt, ...) TA_PRF(2, 3);
char *ta_talloc_asprintf_append_buffer(char *s, const char *fmt, ...) TA_PRF(2, 3);
+// mpv specific stuff - should be made part of proper TA API
+
+#define TA_EXPAND_ARGS(...) __VA_ARGS__
+
+#define MP_TALLOC_ELEMS(p) (talloc_get_size(p) / sizeof((p)[0]))
+
+#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); \
+ if (nextidx_ >= MP_TALLOC_ELEMS(p)) \
+ MP_RESIZE_ARRAY(ctx, p, (nextidx_ + 1) * 2);\
+ } while (0)
+
+#define MP_GROW_ARRAY(p, nextidx) MP_TARRAY_GROW(NULL, p, nextidx)
+
+#define MP_TARRAY_APPEND(ctx, p, idxvar, ...) \
+ do { \
+ MP_TARRAY_GROW(ctx, p, idxvar); \
+ (p)[(idxvar)] = (TA_EXPAND_ARGS(__VA_ARGS__));\
+ (idxvar)++; \
+ } while (0)
+
+// Doesn't actually free any memory, or do any other talloc calls.
+#define MP_TARRAY_REMOVE_AT(p, idxvar, at) \
+ do { \
+ size_t at_ = (at); \
+ assert(at_ <= (idxvar)); \
+ memmove((p) + at_, (p) + at_ + 1, \
+ ((idxvar) - at_ - 1) * sizeof((p)[0])); \
+ (idxvar)--; \
+ } while (0)
+
+#define talloc_struct(ctx, type, ...) \
+ talloc_memdup(ctx, &(type) TA_EXPAND_ARGS(__VA_ARGS__), sizeof(type))
+
#endif