]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/conf-intr.c
Mempool: Do not count the struct mempool to its stats.used_size.
[libucw.git] / ucw / conf-intr.c
index 0b5d5407397ac95d2e37cddeb5bdd533f940e780..509dc8b63fa7449e729826e54ccf1c3604e394bf 100644 (file)
@@ -2,7 +2,7 @@
  *     UCW Library -- Configuration files: interpreter
  *
  *     (c) 2001--2006 Robert Spalek <robert@ucw.cz>
- *     (c) 2003--2012 Martin Mares <mj@ucw.cz>
+ *     (c) 2003--2014 Martin Mares <mj@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
@@ -13,6 +13,8 @@
 #include <ucw/getopt.h>
 #include <ucw/conf-internal.h>
 #include <ucw/clists.h>
+#include <ucw/gary.h>
+#include <ucw/mempool.h>
 
 #include <string.h>
 #include <stdio.h>
@@ -102,17 +104,14 @@ char *cf_op_names[] = { CF_OPERATIONS };
 #undef T
 char *cf_type_names[] = { "int", "u64", "double", "ip", "string", "lookup", "user" };
 
-#define DARY_HDR_SIZE ALIGN_TO(sizeof(uns), CPU_STRUCT_ALIGN)
-
 static char *
 interpret_set_dynamic(struct cf_item *item, int number, char **pars, void **ptr)
 {
   enum cf_type type = item->type;
+  uns size = cf_type_size(type, item->u.utype);
   cf_journal_block(ptr, sizeof(void*));
   // boundary checks done by the caller
-  uns size = cf_type_size(item->type, item->u.utype);
-  *ptr = cf_malloc(DARY_HDR_SIZE + number * size) + DARY_HDR_SIZE;
-  DARY_LEN(*ptr) = number;
+  *ptr = gary_init(size, number, mp_get_allocator(cf_get_pool()));
   return cf_parse_ary(number, pars, *ptr, type, &item->u);
 }
 
@@ -123,12 +122,11 @@ interpret_add_dynamic(struct cf_item *item, int number, char **pars, int *proces
   void *old_p = *ptr;
   uns size = cf_type_size(item->type, item->u.utype);
   ASSERT(size >= sizeof(uns));
-  int old_nr = old_p ? DARY_LEN(old_p) : 0;
+  int old_nr = old_p ? GARY_SIZE(old_p) : 0;
   int taken = MIN(number, ABS(item->number)-old_nr);
   *processed = taken;
   // stretch the dynamic array
-  void *new_p = cf_malloc(DARY_HDR_SIZE + (old_nr + taken) * size) + DARY_HDR_SIZE;
-  DARY_LEN(new_p) = old_nr + taken;
+  void *new_p = gary_init(size, old_nr + taken, mp_get_allocator(cf_get_pool()));
   cf_journal_block(ptr, sizeof(void*));
   *ptr = new_p;
   if (op == OP_APPEND) {
@@ -321,8 +319,7 @@ interpret_set_all(struct cf_item *item, void *ptr, enum cf_operation op)
     clist_init(ptr);
   } else if (item->cls == CC_DYNAMIC) {
     cf_journal_block(ptr, sizeof(void *));
-    static uns zero = 0;
-    * (void**) ptr = (&zero) + 1;
+    * (void**) ptr = GARY_FOREVER_EMPTY;
   } else if (item->cls == CC_STATIC && item->type == CT_STRING) {
     cf_journal_block(ptr, item->number * sizeof(char*));
     bzero(ptr, item->number * sizeof(char*));
@@ -654,13 +651,5 @@ cf_init_stack(struct cf_context *cc)
 int
 cf_done_stack(struct cf_context *cc)
 {
-  if (cc->stack_level > 0) {
-    msg(L_ERROR, "Unterminated block");
-    return 1;
-  }
-  if (cf_commit_all(cc->postpone_commit ? CF_NO_COMMIT : cc->everything_committed ? CF_COMMIT : CF_COMMIT_ALL))
-    return 1;
-  if (!cc->postpone_commit)
-    cc->everything_committed = 1;
-  return 0;
+  return (cc->stack_level > 0);
 }