[LEDE-DEV] [PATCH uci 1/2] file: remove unnecessary uci_fixup_section calls

Hans Dedecker dedeckeh at gmail.com
Thu Dec 21 02:56:31 PST 2017


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 <dedeckeh at gmail.com>
---
 file.c         | 2 --
 list.c         | 5 +++--
 uci_internal.h | 1 -
 3 files changed, 3 insertions(+), 5 deletions(-)

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);
-- 
1.9.1




More information about the Lede-dev mailing list