From 4564a22d13b693efed847ba77361ea4e2448a7bf Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 28 Dec 2019 21:04:55 +0100 Subject: ta: add another funny macro --- ta/ta_talloc.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ta/ta_talloc.h b/ta/ta_talloc.h index 8975dbbdfc..c2c8ac953d 100644 --- a/ta/ta_talloc.h +++ b/ta/ta_talloc.h @@ -124,6 +124,21 @@ char *ta_talloc_asprintf_append_buffer(char *s, const char *fmt, ...) TA_PRF(2, (p)[at_] = (TA_EXPAND_ARGS(__VA_ARGS__)); \ } while (0) +// Given an array p with count idxvar, insert c elements at p[at], so that +// p[at] to p[at+c-1] can be accessed. The elements at p[at] and following +// are shifted up by c before insertion. The new entries are uninitialized. +// ctx as ta parent. Required: at >= 0 && at <= idxvar. +#define MP_TARRAY_INSERT_N_AT(ctx, p, idxvar, at, c)\ + do { \ + size_t at_ = (at); \ + assert(at_ <= (idxvar)); \ + size_t c_ = (c); \ + MP_TARRAY_GROW(ctx, p, (idxvar) + c_); \ + memmove((p) + at_ + c_, (p) + at_, \ + ((idxvar) - at_) * sizeof((p)[0])); \ + (idxvar) += c_; \ + } while (0) + // Remove p[at] from array p with count idxvar (inverse of MP_TARRAY_INSERT_AT()). // Doesn't actually free any memory, or do any other talloc calls. #define MP_TARRAY_REMOVE_AT(p, idxvar, at) \ -- cgit v1.2.3