]> mj.ucw.cz Git - libucw.git/commitdiff
Gary: Type-agnostic push
authorMartin Mares <mj@ucw.cz>
Tue, 28 Jan 2014 17:28:20 +0000 (18:28 +0100)
committerMartin Mares <mj@ucw.cz>
Tue, 28 Jan 2014 17:28:20 +0000 (18:28 +0100)
ucw/gary.h

index 1c5a647a0bf1bea36eff92bbf3047d7c637d01de..e2e295201e85038409e17bcecf1854befef1eb7c 100644 (file)
@@ -77,6 +77,15 @@ static inline void gary_free(void *ptr)
     }
 }
 
+/* Type-agnostic interface. Currently it's recommended for internal use only. */
+
+#define GARY_PUSH_GENERIC(ptr) ({                                      \
+  struct gary_hdr *_h = GARY_HDR(ptr);                                 \
+  void *_c = (byte *)(ptr) + _h->num_elts++ * _h->elt_size;            \
+  if (_h->num_elts > _h->have_space)                                   \
+    (ptr) = gary_push_helper((ptr), 1, (byte **) &_c);                 \
+  _c; })
+
 /* gary-mp.c */
 
 struct mempool;