Browse Source

schema: Don't iterate elements within link objects

Serj Kalichev 1 year ago
parent
commit
91afefb6e4
2 changed files with 10 additions and 3 deletions
  1. 6 3
      klish/kscheme/kentry.c
  2. 4 0
      klish/kscheme/kscheme.c

+ 6 - 3
klish/kscheme/kentry.c

@@ -27,8 +27,8 @@ struct kentry_s {
 	bool_t filter; // Is entry filter. Filter can't have inline actions.
 	faux_list_t *entrys; // Nested ENTRYs
 	faux_list_t *actions; // Nested ACTIONs
-	// Fast links to nested entries with special purposes:
-	kentry_t* nested_by_purpose[KENTRY_PURPOSE_MAX];
+	// Fast links to nested entries with special purposes.
+	kentry_t** nested_by_purpose;
 };
 
 
@@ -142,7 +142,8 @@ kentry_t *kentry_new(const char *name)
 		NULL, NULL, (void (*)(void *))kaction_free);
 	assert(entry->actions);
 
-	faux_bzero(entry->nested_by_purpose, sizeof(entry->nested_by_purpose));
+	entry->nested_by_purpose = faux_zmalloc(
+		KENTRY_PURPOSE_MAX * sizeof(*(entry->nested_by_purpose)));
 
 	return entry;
 }
@@ -155,6 +156,7 @@ static void kentry_free_non_link(kentry_t *entry)
 
 	faux_list_free(entry->entrys);
 	faux_list_free(entry->actions);
+	faux_free(entry->nested_by_purpose);
 }
 
 
@@ -216,6 +218,7 @@ bool_t kentry_link(kentry_t *dst, const kentry_t *src)
 	dst->filter = src->filter;
 	dst->entrys = src->entrys;
 	dst->actions = src->actions;
+	dst->nested_by_purpose = src->nested_by_purpose;
 
 	return BOOL_TRUE;
 }

+ 4 - 0
klish/kscheme/kscheme.c

@@ -252,6 +252,7 @@ bool_t kscheme_prepare_action_list(kscheme_t *scheme, kentry_t *entry,
 		ksym_t *sym = NULL;
 		kplugin_t *plugin = NULL;
 		const char *sym_ref = kaction_sym_ref(action);
+
 		sym = kscheme_find_sym(scheme, sym_ref, &plugin);
 		if (!sym) {
 			faux_error_sprintf(error, "Can't find symbol \"%s\"",
@@ -335,6 +336,8 @@ bool_t kscheme_prepare_entry(kscheme_t *scheme, kentry_t *entry,
 	// Firstly if ENTRY is link to another ENTRY then make a copy
 	if (kentry_ref_str(entry)) {
 		ref_entry = entry;
+		// Find the most deep real (non-link) object to reference to it
+		// i.e. the link can't reference a link.
 		while ((ref = kentry_ref_str(ref_entry))) {
 			ref_entry = kscheme_find_entry_by_path(scheme, ref);
 			if (!ref_entry) {
@@ -346,6 +349,7 @@ bool_t kscheme_prepare_entry(kscheme_t *scheme, kentry_t *entry,
 			faux_error_sprintf(error, "Can't create link to ENTRY \"%s\"", ref);
 			return BOOL_FALSE;
 		}
+		return BOOL_TRUE;
 	}
 
 	// ACTIONs