]> git.droids-corp.org - protos/libecoli.git/commitdiff
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 b5bd7553679a8243f90f9ce1272853fee8aba479..fd5c0c37704225789cccc38e3d8a01da724c3dd1 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 eb3c73d4587eb24a1319ba58bdfaf8a08050cfdf..505f49f753254d1827af5635ed821b27cb960369 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 2886f5bebe120a274e3eda65ba1aed927d5d5f1c..035ec13fdaa50241eca85e06d70347f0bdca0797 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);