From e044ca12570b74b60109bcf19818a5889f806be8 Mon Sep 17 00:00:00 2001 From: Olivier Matz Date: Sun, 11 Mar 2018 22:24:40 +0100 Subject: [PATCH] sort init list --- lib/ecoli_init.c | 18 ++++++++++++++++-- lib/ecoli_malloc.c | 2 +- lib/ecoli_parsed.c | 6 +++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/ecoli_init.c b/lib/ecoli_init.c index b5bd755..fd5c0c3 100644 --- a/lib/ecoli_init.c +++ b/lib/ecoli_init.c @@ -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; diff --git a/lib/ecoli_malloc.c b/lib/ecoli_malloc.c index eb3c73d..505f49f 100644 --- a/lib/ecoli_malloc.c +++ b/lib/ecoli_malloc.c @@ -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); diff --git a/lib/ecoli_parsed.c b/lib/ecoli_parsed.c index 2886f5b..035ec13 100644 --- a/lib/ecoli_parsed.c +++ b/lib/ecoli_parsed.c @@ -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); -- 2.39.5