sort init list
authorOlivier Matz <zer0@droids-corp.org>
Sun, 11 Mar 2018 21:24:40 +0000 (22:24 +0100)
committerOlivier Matz <zer0@droids-corp.org>
Sun, 11 Mar 2018 21:24:40 +0000 (22:24 +0100)
lib/ecoli_init.c
lib/ecoli_malloc.c
lib/ecoli_parsed.c

index b5bd755..fd5c0c3 100644 (file)
@@ -14,6 +14,22 @@ static struct ec_init_list init_list = TAILQ_HEAD_INITIALIZER(init_list);
 /* register an init function */
 void ec_init_register(struct ec_init *init)
 {
+       struct ec_init *cur;
+
+       if (TAILQ_EMPTY(&init_list)) {
+               TAILQ_INSERT_HEAD(&init_list, init, next);
+               return;
+       }
+
+
+       TAILQ_FOREACH(cur, &init_list, next) {
+               if (init->priority > cur->priority)
+                       continue;
+
+               TAILQ_INSERT_BEFORE(cur, init, next);
+               return;
+       }
+
        TAILQ_INSERT_TAIL(&init_list, init, next);
 }
 
@@ -21,8 +37,6 @@ int ec_init(void)
 {
        struct ec_init *init;
 
-       /* XXX sort list by priority */
-
        TAILQ_FOREACH(init, &init_list, next) {
                if (init->init() < 0)
                        return -1;
index eb3c73d..505f49f 100644 (file)
@@ -119,7 +119,7 @@ static int ec_malloc_init_func(void)
 
 static struct ec_init ec_malloc_init = {
        .init = ec_malloc_init_func,
-       .priority = 50,
+       .priority = 40,
 };
 
 EC_INIT_REGISTER(ec_malloc_init);
index 2886f5b..035ec13 100644 (file)
@@ -213,6 +213,7 @@ void ec_parsed_free_children(struct ec_parsed *parsed)
        while (!TAILQ_EMPTY(&parsed->children)) {
                child = TAILQ_FIRST(&parsed->children);
                TAILQ_REMOVE(&parsed->children, child, next);
+               child->parent = NULL;
                ec_parsed_free(child);
        }
 }
@@ -222,9 +223,8 @@ void ec_parsed_free(struct ec_parsed *parsed)
        if (parsed == NULL)
                return;
 
-       // assert(parsed->parent == NULL); XXX
-       // or
-       // parsed = ec_parsed_get_root(parsed);
+       ec_assert_print(parsed->parent == NULL,
+                       "parent not NULL in ec_parsed_free()");
 
        ec_parsed_free_children(parsed);
        ec_strvec_free(parsed->strvec);