]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/generic/array: add array_push_mm shorthand
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 13 Apr 2018 13:16:22 +0000 (15:16 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 13 Apr 2018 15:23:04 +0000 (17:23 +0200)
It just feels more consistent with the rest.

lib/generic/array.h

index 6c4f4b7428faa68233d9fd93b9b8f830a5532b2a..fb10c0cd13462aa36192223efb5115f629fbc480 100644 (file)
@@ -125,13 +125,22 @@ static inline void array_std_free(void *baton, void *p)
        (reserve)((baton), (char **) &(array).at, sizeof((array).at[0]), (n), &(array).cap)
 
 /**
- * Push value at the end of the array, resize it if necessary (malloc/free).
+ * Push value at the end of the array, resize it if necessary (plain malloc/free).
  * @note May fail if the capacity is not reserved.
  * @return element index on success, <0 on failure
  */
 #define array_push(array, val) \
+       array_push_mm(array, val, array_std_reserve, NULL)
+
+/**
+ * Push value at the end of the array, resize it if necessary.
+ * Mempool usage: pass kr_memreserve and a knot_mm_t* .
+ * @note May fail if the capacity is not reserved.
+ * @return element index on success, <0 on failure
+ */
+#define array_push_mm(array, val, reserve, baton) \
        (int)((array).len < (array).cap ? ((array).at[(array).len] = val, (array).len++) \
-               : (array_reserve(array, ((array).cap + 1)) < 0 ? -1 \
+               : (array_reserve_mm(array, ((array).cap + 1), reserve, baton) < 0 ? -1 \
                        : ((array).at[(array).len] = val, (array).len++)))
 
 /**