Skip to content

Commit 51cc71f

Browse files
authored
tree printer BUGFIX extension switching in loop (#2550)
1 parent 6a1f264 commit 51cc71f

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

src/printer_tree.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,7 +3111,7 @@ pt_ext_iter_next(ly_bool lysc_tree, void *exts, LY_ARRAY_COUNT_TYPE *i)
31113111
if (lysc_tree) {
31123112
ce = exts;
31133113
while (*i < LY_ARRAY_COUNT(ce)) {
3114-
if (ce->def->plugin_ref && pt_ext_parent_is_valid(1, &ce[*i])) {
3114+
if (ce[*i].def->plugin_ref && pt_ext_parent_is_valid(1, &ce[*i])) {
31153115
ext = &ce[*i];
31163116
break;
31173117
}
@@ -3137,19 +3137,27 @@ pt_ext_iter_next(ly_bool lysc_tree, void *exts, LY_ARRAY_COUNT_TYPE *i)
31373137
* @param[in] tc Contains current node.
31383138
* @param[in] ext_name Extension name to find.
31393139
* @param[in] from_module Set to 1 if extensions in the module
3140-
* sould be searched otherwise it will search in the node.
3140+
* should be searched otherwise it will search in the node.
3141+
* @param[in] origin_lysc_tree Optional parameter, if set then
3142+
* reset @p tc to the original lysc tree before iteration over
3143+
* next extension. If NULL then reset is not applied.
31413144
* @param[in,out] i State of iterator.
31423145
* @return First/next extension or NULL.
31433146
*/
31443147
static void *
3145-
pt_ext_iter(const struct pt_tree_ctx *tc, const char *ext_name,
3146-
ly_bool from_module, LY_ARRAY_COUNT_TYPE *i)
3148+
pt_ext_iter(struct pt_tree_ctx *tc, const char *ext_name,
3149+
ly_bool from_module, const ly_bool *origin_lysc_tree,
3150+
LY_ARRAY_COUNT_TYPE *i)
31473151
{
31483152
struct lysp_ext_instance *ext_pars;
31493153
struct lysc_ext_instance *ext_comp;
31503154
void *ext = NULL;
31513155
const char *name = "";
31523156

3157+
if (origin_lysc_tree) {
3158+
tc->lysc_tree = *origin_lysc_tree;
3159+
}
3160+
31533161
do {
31543162
if (tc->lysc_tree) {
31553163
ext_comp = from_module ? tc->cmod->exts : tc->cn->exts;
@@ -3182,7 +3190,7 @@ pt_ext_is_present(struct pt_tree_ctx *tc, const char *ext_name)
31823190
{
31833191
uint64_t i = 0;
31843192

3185-
if (pt_ext_iter(tc, ext_name, 0, &i)) {
3193+
if (pt_ext_iter(tc, ext_name, 0, NULL, &i)) {
31863194
return 1;
31873195
} else {
31883196
return 0;
@@ -3418,7 +3426,7 @@ pt_print_schema_mount(struct pt_wrapper wr, struct pt_parent_cache ca,
34183426

34193427
/* load children of mount-point */
34203428
i = 0;
3421-
while ((ext = pt_ext_iter(&tc, "mount-point", 0, &i))) {
3429+
while ((ext = pt_ext_iter(&tc, "mount-point", 0, NULL, &i))) {
34223430
rc = pt_create_mount_point(tc.lysc_tree, ext, &schema_mount);
34233431
LY_CHECK_ERR_GOTO(rc, tc.last_error = rc, end);
34243432

@@ -3881,6 +3889,7 @@ pt_ext_read(void *ext, ly_bool *compiled, struct pt_keyword_stmt *ks)
38813889
void *schema;
38823890

38833891
if (!*compiled) {
3892+
/* lysp tree */
38843893
ext_pars = ext;
38853894
ks->argument = ext_pars->argument;
38863895
name = strchr(ext_pars->name, ':') + 1;
@@ -3891,9 +3900,9 @@ pt_ext_read(void *ext, ly_bool *compiled, struct pt_keyword_stmt *ks)
38913900
} else {
38923901
schema = pt_ext_parsed_read_storage(ext_pars, LY_STMT_DATA_NODE_MASK);
38933902
}
3894-
*compiled = 0;
38953903
return schema;
38963904
}
3905+
/* else lysc tree */
38973906

38983907
/* for compiled extension instance */
38993908
ext_comp = ext;
@@ -3902,19 +3911,19 @@ pt_ext_read(void *ext, ly_bool *compiled, struct pt_keyword_stmt *ks)
39023911

39033912
/* search in lysc_ext_instance */
39043913
lyplg_ext_get_storage(ext, LY_STMT_DATA_NODE_MASK, sizeof schema, (const void **)&schema);
3905-
*compiled = 1;
39063914
if (schema) {
39073915
return schema;
39083916
}
39093917

39103918
/* no data nodes lysc_ext_instance, so search in lysp_ext_instance */
3911-
*compiled = 0;
39123919
if (!strcmp(ks->section_name, "augment-structure")) {
39133920
lyplg_ext_parsed_get_storage(ext_comp, LY_STMT_AUGMENT, sizeof schema, (const void **)&schema);
39143921
schema = ((struct lysp_node_augment *)schema)->child;
39153922
} else {
39163923
lyplg_ext_parsed_get_storage(ext_comp, LY_STMT_DATA_NODE_MASK, sizeof schema, (const void **)&schema);
39173924
}
3925+
/* switching from lysc tree to lysp tree */
3926+
*compiled = 0;
39183927

39193928
return schema;
39203929
}
@@ -3939,9 +3948,7 @@ pt_print_extensions(struct pt_tree_ctx tc)
39393948
tc.plugin_ctx.schema = &ext_schema;
39403949
tc.plugin_ctx.schema->ext = PT_EXT_GENERIC;
39413950

3942-
while ((ext = pt_ext_iter(&tc, NULL, 1, &i))) {
3943-
tc.lysc_tree = origin_lysc_tree;
3944-
3951+
while ((ext = pt_ext_iter(&tc, NULL, 1, &origin_lysc_tree, &i))) {
39453952
schema = pt_ext_read(ext, &tc.lysc_tree, &ks);
39463953
if (!strcmp(ks.section_name, "mount-point") ||
39473954
!strcmp(ks.section_name, "annotation")) {
@@ -3967,8 +3974,6 @@ pt_print_extensions(struct pt_tree_ctx tc)
39673974
/* print subtree */
39683975
node = pt_modi_first_sibling(PT_EMPTY_PARENT_CACHE, &tc);
39693976
pt_print_siblings(&node, PT_INIT_WRAPPER_BODY, PT_EMPTY_PARENT_CACHE, &tc);
3970-
3971-
tc.lysc_tree = origin_lysc_tree;
39723977
}
39733978
}
39743979

0 commit comments

Comments
 (0)