X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fconf-section.c;h=30f5898c6347197f17772bc0a9e244894ebd5ae8;hb=db2e817025638b9738e5ff8f8f5ccc1fbf68a2f3;hp=c7bd32473be5c3bb8d686f5578ff8ab86d023045;hpb=b541de765129b6bf28c5601bb355779652001150;p=libucw.git diff --git a/ucw/conf-section.c b/ucw/conf-section.c index c7bd3247..30f5898c 100644 --- a/ucw/conf-section.c +++ b/ucw/conf-section.c @@ -2,7 +2,7 @@ * UCW Library -- Configuration files: sections * * (c) 2001--2006 Robert Spalek - * (c) 2003--2012 Martin Mares + * (c) 2003--2014 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -13,6 +13,7 @@ #include #include #include +#include #include @@ -92,7 +93,7 @@ inspect_section(struct cf_section *sec) } void -cf_declare_section(const char *name, struct cf_section *sec, uns allow_unknown) +cf_declare_rel_section(const char *name, struct cf_section *sec, void *ptr, uint allow_unknown) { struct cf_context *cc = cf_obtain_context(); if (!cc->sections.cfg) @@ -106,7 +107,7 @@ cf_declare_section(const char *name, struct cf_section *sec, uns allow_unknown) ci->cls = CC_SECTION; ci->name = name; ci->number = 1; - ci->ptr = NULL; + ci->ptr = ptr; ci->u.sec = sec; inspect_section(sec); if (allow_unknown) @@ -121,7 +122,13 @@ cf_declare_section(const char *name, struct cf_section *sec, uns allow_unknown) } void -cf_init_section(const char *name, struct cf_section *sec, void *ptr, uns do_bzero) +cf_declare_section(const char *name, struct cf_section *sec, uint allow_unknown) +{ + cf_declare_rel_section(name, sec, NULL, allow_unknown); +} + +void +cf_init_section(const char *name, struct cf_section *sec, void *ptr, uint do_bzero) { if (do_bzero) { ASSERT(sec->size); @@ -134,10 +141,8 @@ cf_init_section(const char *name, struct cf_section *sec, void *ptr, uns do_bzer clist_init(ptr + (uintptr_t) ci->ptr); else if (ci->cls == CC_DYNAMIC) { void **dyn = ptr + (uintptr_t) ci->ptr; - if (!*dyn) { // replace NULL by an empty array - static uns zero = 0; - *dyn = (&zero) + 1; - } + if (!*dyn) // replace NULL by an empty array + *dyn = GARY_FOREVER_EMPTY; } if (sec->init) { char *msg = sec->init(ptr); @@ -147,7 +152,7 @@ cf_init_section(const char *name, struct cf_section *sec, void *ptr, uns do_bzer } static char * -commit_section(struct cf_section *sec, void *ptr, uns commit_all) +commit_section(struct cf_section *sec, void *ptr, uint commit_all) { struct cf_context *cc = cf_get_context(); char *err; @@ -159,7 +164,7 @@ commit_section(struct cf_section *sec, void *ptr, uns commit_all) return "commit of a subsection failed"; } } else if (ci->cls == CC_LIST) { - uns idx = 0; + uint idx = 0; CLIST_FOR_EACH(cnode *, n, * (clist*) (ptr + (uintptr_t) ci->ptr)) if (idx++, err = commit_section(ci->u.sec, n, commit_all)) { msg(L_ERROR, "Cannot commit node #%d of list %s: %s", idx, ci->name, err); @@ -172,7 +177,7 @@ commit_section(struct cf_section *sec, void *ptr, uns commit_all) * hence we need to call them in a fixed order. */ #define ARY_LT_X(ary,i,x) ary[i].sec < x.sec || ary[i].sec == x.sec && ary[i].ptr < x.ptr struct dirty_section comp = { sec, ptr }; - uns pos = BIN_SEARCH_FIRST_GE_CMP(cc->dirty.ptr, cc->dirties, comp, ARY_LT_X); + uint pos = BIN_SEARCH_FIRST_GE_CMP(cc->dirty.ptr, cc->dirties, comp, ARY_LT_X); if (commit_all || (pos < cc->dirties && cc->dirty.ptr[pos].sec == sec && cc->dirty.ptr[pos].ptr == ptr))