From: Hans Dedecker Date: Thu, 21 Dec 2017 10:56:31 +0000 (+0100) Subject: file: remove unnecessary uci_fixup_section calls X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=021fd65643a7932dc67ebeb2291264e308432428;p=oweals%2Fuci.git file: remove unnecessary uci_fixup_section calls This makes it clear uci_fixup_section only needs to be called in uci_add_section when an unnamed section is added. Before it was a bit misleading when walking through the code seeing uci_fixup_section being called in uci_parse_config and uci_import. When uci config is parsed via these functions uci_add_section is eventually called which in the end constructs a name for an unnamed section. Signed-off-by: Hans Dedecker --- diff --git a/file.c b/file.c index 494c649..9856369 100644 --- a/file.c +++ b/file.c @@ -408,7 +408,6 @@ static void uci_parse_config(struct uci_context *ctx) char *name; char *type; - uci_fixup_section(ctx, ctx->pctx->section); if (!ctx->pctx->package) { if (!ctx->pctx->name) uci_parse_error(ctx, "attempting to import a file without a package name"); @@ -689,7 +688,6 @@ error: UCI_THROW(ctx, ctx->err); } - uci_fixup_section(ctx, ctx->pctx->section); if (!pctx->package && name) uci_switch_config(ctx); if (package) diff --git a/list.c b/list.c index 321861c..e78012b 100644 --- a/list.c +++ b/list.c @@ -144,7 +144,7 @@ static unsigned int djbhash(unsigned int hash, char *str) } /* fix up an unnamed section, e.g. after adding options to it */ -__private void uci_fixup_section(struct uci_context *ctx, struct uci_section *s) +static void uci_fixup_section(struct uci_context *ctx, struct uci_section *s) { unsigned int hash = ~0; struct uci_element *e; @@ -535,7 +535,8 @@ int uci_add_section(struct uci_context *ctx, struct uci_package *p, const char * UCI_HANDLE_ERR(ctx); UCI_ASSERT(ctx, p != NULL); s = uci_alloc_section(p, type, NULL); - uci_fixup_section(ctx, s); + if (s && s->anonymous) + uci_fixup_section(ctx, s); *res = s; if (!internal && p->has_delta) uci_add_delta(ctx, &p->delta, UCI_CMD_ADD, s->e.name, NULL, type); diff --git a/uci_internal.h b/uci_internal.h index db8cc30..61f2da2 100644 --- a/uci_internal.h +++ b/uci_internal.h @@ -61,7 +61,6 @@ __private void uci_alloc_parse_context(struct uci_context *ctx); __private void uci_cleanup(struct uci_context *ctx); __private struct uci_element *uci_lookup_list(struct uci_list *list, const char *name); -__private void uci_fixup_section(struct uci_context *ctx, struct uci_section *s); __private void uci_free_package(struct uci_package **package); __private struct uci_element *uci_alloc_generic(struct uci_context *ctx, int type, const char *name, int size); __private void uci_free_element(struct uci_element *e);