Skip to content

Commit 380ceec

Browse files
committed
tree schema BUGFIX separate submod unres
Store submodule unres separated from the main module unres to allow for its freeing in case of an error or submodule duplicate.
1 parent 16f0297 commit 380ceec

4 files changed

Lines changed: 30 additions & 17 deletions

File tree

src/parser_yang.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct lys_glob_unres;
100100
goto ERR_LABEL; \
101101
} \
102102
if (KW == LY_STMT_SYNTAX_RIGHT_BRACE) { \
103-
if (EXTS && (RET = ly_set_add(&(CTX)->main_ctx->ext_inst, (EXTS), 1, NULL))) { \
103+
if (EXTS && (RET = ly_set_add(&(CTX)->ext_inst, (EXTS), 1, NULL))) { \
104104
goto ERR_LABEL; \
105105
} \
106106
__loop_end = 1; \
@@ -2842,8 +2842,7 @@ parse_typedef(struct lysp_yang_ctx *ctx, struct lysp_node *parent, struct lysp_t
28422842

28432843
/* store data for collision check */
28442844
if (parent) {
2845-
assert(ctx->main_ctx);
2846-
LY_CHECK_RET(ly_set_add(&ctx->main_ctx->tpdfs_nodes, parent, 0, NULL));
2845+
LY_CHECK_RET(ly_set_add(&ctx->tpdfs_nodes, parent, 0, NULL));
28472846
}
28482847

28492848
cleanup:
@@ -3184,8 +3183,7 @@ parse_grouping(struct lysp_yang_ctx *ctx, struct lysp_node *parent, struct lysp_
31843183

31853184
/* store data for collision check */
31863185
if (parent) {
3187-
assert(ctx->main_ctx);
3188-
LY_CHECK_RET(ly_set_add(&ctx->main_ctx->grps_nodes, parent, 0, NULL));
3186+
LY_CHECK_RET(ly_set_add(&ctx->grps_nodes, parent, 0, NULL));
31893187
}
31903188

31913189
cleanup:

src/parser_yin.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ yin_unres_exts_add(struct lysp_yin_ctx *ctx, struct lysp_ext_instance *exts)
646646
return LY_SUCCESS;
647647
}
648648

649-
return ly_set_add(&ctx->main_ctx->ext_inst, exts, 1, NULL);
649+
return ly_set_add(&ctx->ext_inst, exts, 1, NULL);
650650
}
651651

652652
/**
@@ -1713,8 +1713,7 @@ yin_parse_typedef(struct lysp_yin_ctx *ctx, struct tree_node_meta *typedef_meta)
17131713

17141714
/* store data for collision check */
17151715
if (typedef_meta->parent) {
1716-
assert(ctx->main_ctx);
1717-
LY_CHECK_RET(ly_set_add(&ctx->main_ctx->tpdfs_nodes, typedef_meta->parent, 0, NULL));
1716+
LY_CHECK_RET(ly_set_add(&ctx->tpdfs_nodes, typedef_meta->parent, 0, NULL));
17181717
}
17191718

17201719
return LY_SUCCESS;
@@ -2472,8 +2471,7 @@ yin_parse_grouping(struct lysp_yin_ctx *ctx, struct tree_node_meta *gr_meta)
24722471

24732472
/* store data for collision check */
24742473
if (!ret && grp->parent) {
2475-
assert(ctx->main_ctx);
2476-
LY_CHECK_RET(ly_set_add(&ctx->main_ctx->grps_nodes, grp->parent, 0, NULL));
2474+
LY_CHECK_RET(ly_set_add(&ctx->grps_nodes, grp->parent, 0, NULL));
24772475
}
24782476

24792477
return ret;

src/tree_schema.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ lys_parse_submodule(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, s
15421542
struct lysp_submodule *submod = NULL, *latest_sp;
15431543
struct lysp_yang_ctx *yangctx = NULL;
15441544
struct lysp_yin_ctx *yinctx = NULL;
1545-
struct lysp_ctx *pctx;
1545+
struct lysp_ctx *pctx = NULL;
15461546
struct lysf_ctx fctx = {.ctx = ctx};
15471547
const char *submod_name;
15481548

@@ -1594,6 +1594,9 @@ lys_parse_submodule(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, s
15941594
r = lysp_load_module_data_check(ctx, NULL, submod, mod_data);
15951595
if (r == LY_EEXIST) {
15961596
/* not an error, the submodule already exists so free this one */
1597+
ly_set_erase(&pctx->tpdfs_nodes, NULL);
1598+
ly_set_erase(&pctx->grps_nodes, NULL);
1599+
ly_set_erase(&pctx->ext_inst, NULL);
15971600
lysp_module_free(&fctx, (struct lysp_module *)submod);
15981601
submod = NULL;
15991602
goto cleanup;
@@ -1627,9 +1630,22 @@ lys_parse_submodule(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, s
16271630
LOGERR(ctx, rc, "Parsing submodule failed.");
16281631
}
16291632

1633+
if (pctx) {
1634+
ly_set_erase(&pctx->tpdfs_nodes, NULL);
1635+
ly_set_erase(&pctx->grps_nodes, NULL);
1636+
ly_set_erase(&pctx->ext_inst, NULL);
1637+
}
16301638
lysp_module_free(&fctx, (struct lysp_module *)submod);
1631-
} else {
1639+
} else if (submod) {
16321640
*submodule = submod;
1641+
1642+
/* merge submod unres into main_ctx unres */
1643+
ly_set_merge(&pctx->main_ctx->tpdfs_nodes, &pctx->tpdfs_nodes, 1, NULL);
1644+
ly_set_erase(&pctx->tpdfs_nodes, NULL);
1645+
ly_set_merge(&pctx->main_ctx->grps_nodes, &pctx->grps_nodes, 1, NULL);
1646+
ly_set_erase(&pctx->grps_nodes, NULL);
1647+
ly_set_merge(&pctx->main_ctx->ext_inst, &pctx->ext_inst, 1, NULL);
1648+
ly_set_erase(&pctx->ext_inst, NULL);
16331649
}
16341650

16351651
if (format == LYS_IN_YANG) {

src/tree_schema_internal.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,12 @@ enum yang_arg {
130130

131131
struct lysp_ctx {
132132
LYS_INFORMAT format; /**< parser format */
133-
struct ly_set tpdfs_nodes; /**< Set of nodes that contain typedef(s). Invalid in case of
134-
submodule, use ::lysp_ctx.main_ctx instead. */
135-
struct ly_set grps_nodes; /**< Set of nodes that contain grouping(s). Invalid in case of
136-
submodule, use ::lysp_ctx.main_ctx instead. */
137-
struct ly_set ext_inst; /**< parsed extension instances to finish parsing */
133+
struct ly_set tpdfs_nodes; /**< Set of nodes that contain typedef(s). Used only temporarily in case of
134+
submodule, ::lysp_ctx.main_ctx used instead. */
135+
struct ly_set grps_nodes; /**< Set of nodes that contain grouping(s). Used only temporarily in case of
136+
submodule, ::lysp_ctx.main_ctx used instead. */
137+
struct ly_set ext_inst; /**< Set of parsed extension instances to finish parsing. Used only temporarily
138+
in case of submodule, ::lysp_ctx.main_ctx used instead. */
138139

139140
struct ly_set *parsed_mods; /**< (sub)modules being parsed, the last one is the current */
140141
struct lysp_ctx *main_ctx; /**< This pointer must not be NULL. If this context deals with the submodule,

0 commit comments

Comments
 (0)