summaryrefslogtreecommitdiffstats
path: root/core/mp_talloc.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/mp_talloc.h')
-rw-r--r--core/mp_talloc.h22
1 files changed, 16 insertions, 6 deletions
diff --git a/core/mp_talloc.h b/core/mp_talloc.h
index ff2b808125..1dcb0bce07 100644
--- a/core/mp_talloc.h
+++ b/core/mp_talloc.h
@@ -25,24 +25,34 @@
#define MP_TALLOC_ELEMS(p) (talloc_get_size(p) / sizeof((p)[0]))
#define MP_GROW_ARRAY(p, nextidx) do { \
if ((nextidx) == MP_TALLOC_ELEMS(p)) \
- p = talloc_realloc_size(NULL, p, talloc_get_size(p) * 2); } while (0)
+ (p) = talloc_realloc_size(NULL, p, talloc_get_size(p) * 2); } while (0)
#define MP_RESIZE_ARRAY(ctx, p, count) do { \
- p = talloc_realloc_size((ctx), p, (count) * sizeof(p[0])); } while (0)
+ (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);\
+ (p) = talloc_realloc_size(ctx, p, \
+ (nextidx_ + 1) * sizeof((p)[0]) * 2);\
} while (0)
#define MP_TARRAY_APPEND(ctx, p, idxvar, ...) \
do { \
MP_TARRAY_GROW(ctx, p, idxvar); \
- p[idxvar] = (MP_EXPAND_ARGS(__VA_ARGS__)); \
- idxvar++; \
+ (p)[(idxvar)] = (MP_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, ...) \