Browse Source

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 <dedeckeh@gmail.com>
Hans Dedecker 6 years ago
parent
commit
021fd65643
3 changed files with 3 additions and 5 deletions
  1. 0 2
      file.c
  2. 3 2
      list.c
  3. 0 1
      uci_internal.h

+ 0 - 2
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)

+ 3 - 2
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);

+ 0 - 1
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);