yin parser BUGFIX check that a submodule was not yet included by another submodule
diff --git a/src/parser_yin.c b/src/parser_yin.c
index a082dfe..4d114cd 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -2319,7 +2319,7 @@
char *module_data;
void (*module_data_free)(char *module_data) = NULL;
LYS_INFORMAT format = LYS_IN_UNKNOWN;
- int count;
+ int count, i;
LY_TREE_FOR(yin->child, child) {
if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) {
@@ -2344,6 +2344,21 @@
GETVAL(value, yin, "module");
+ /* check that the submodule was not included yet (previous submodule could have included it) */
+ for (i = 0; i < module->inc_size; ++i) {
+ if (module->inc[i].submodule && (module->inc[i].submodule->name == value)) {
+ /* let's fake we included it now */
+ memcpy(inc, &module->inc[i], sizeof *inc);
+ inc->external = 0;
+
+ /* remove the include we are going to add again in a moment */
+ --module->inc_size;
+ memmove(&module->inc[i], &module->inc[i + 1], (module->inc_size - i) * sizeof *module->inc);
+
+ return EXIT_SUCCESS;
+ }
+ }
+
/* check for circular include, store it if passed */
if (!module->ctx->models.parsing) {
count = 0;
@@ -4949,11 +4964,11 @@
* 2) we cannot pass directly the structure in the array since
* submodule parser can realloc our array of includes */
r = fill_yin_include(module, child, &inc, unres);
+ memcpy(&trg->inc[inc_size_aux], &inc, sizeof inc);
+ inc_size_aux++;
if (r) {
goto error;
}
- memcpy(&trg->inc[inc_size_aux], &inc, sizeof inc);
- inc_size_aux++;
/* check duplications in include submodules */
for (i = 0; i < inc_size_aux - 1; i++) {