schema compile UPDATE keep deviation not-supported nodes as disabled
For the same reason disabled if-feature nodes are kept,
so that any references to these nodes can be resolved.
Fixes #1664
diff --git a/src/schema_compile.c b/src/schema_compile.c
index 2efc2e1..8ba8ad8 100644
--- a/src/schema_compile.c
+++ b/src/schema_compile.c
@@ -1375,7 +1375,7 @@
node = ds_unres->disabled.snodes[i];
if (node->flags & LYS_KEY) {
LOG_LOCSET(node, NULL, NULL, NULL);
- LOGVAL(ctx, LYVE_REFERENCE, "Key \"%s\" is disabled by its if-features.", node->name);
+ LOGVAL(ctx, LYVE_REFERENCE, "Key \"%s\" is disabled.", node->name);
LOG_LOCBACK(1, 0, 0, 0);
return LY_EVALID;
}
@@ -1399,8 +1399,8 @@
assert(ret != LY_ERECOMPILE);
if (ret) {
LOG_LOCSET(node, NULL, NULL, NULL);
- LOGVAL(ctx, LYVE_REFERENCE, "Target of leafref \"%s\" cannot be "
- "referenced because it is disabled by its if-features.", node->name);
+ LOGVAL(ctx, LYVE_REFERENCE, "Target of leafref \"%s\" cannot be referenced because it is disabled.",
+ node->name);
LOG_LOCBACK(1, 0, 0, 0);
return LY_EVALID;
}
diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c
index 59b2769..932ee9b 100644
--- a/src/schema_compile_node.c
+++ b/src/schema_compile_node.c
@@ -2399,6 +2399,7 @@
ly_bool not_supported, enabled;
struct lysp_node *dev_pnode = NULL;
struct lysp_when *pwhen = NULL;
+ uint32_t prev_opts = ctx->compile_opts;
node->nodetype = pnode->nodetype;
node->module = ctx->cur_mod;
@@ -2408,9 +2409,12 @@
/* compile any deviations for this node */
LY_CHECK_GOTO(ret = lys_compile_node_deviations_refines(ctx, pnode, parent, &dev_pnode, ¬_supported), error);
- if (not_supported) {
- goto error;
- } else if (dev_pnode) {
+ if (not_supported && !(ctx->compile_opts & (LYS_COMPILE_NO_DISABLED | LYS_COMPILE_DISABLED | LYS_COMPILE_GROUPING))) {
+ /* if not supported, keep it just like disabled nodes by if-feature */
+ ly_set_add(&ctx->unres->disabled, node, 1, NULL);
+ ctx->compile_opts |= LYS_COMPILE_DISABLED;
+ }
+ if (dev_pnode) {
pnode = dev_pnode;
}
@@ -2479,6 +2483,7 @@
if (ret && dev_pnode) {
LOGVAL(ctx->ctx, LYVE_OTHER, "Compilation of a deviated and/or refined node failed.");
}
+ ctx->compile_opts = prev_opts;
lysp_dev_node_free(ctx->ctx, dev_pnode);
return ret;
}
diff --git a/src/tree_schema_free.c b/src/tree_schema_free.c
index 234daf8..be848ce 100644
--- a/src/tree_schema_free.c
+++ b/src/tree_schema_free.c
@@ -921,10 +921,15 @@
void
lysc_node_free(struct ly_ctx *ctx, struct lysc_node *node, ly_bool unlink)
{
- struct lysc_node *iter, **child_p;
+ struct lysc_node *next, *iter, **child_p;
if (node->nodetype & (LYS_INPUT | LYS_OUTPUT)) {
- /* nothing to do - inouts are part of actions and cannot be unlinked/freed separately */
+ /* inouts are part of actions and cannot be unlinked/freed separately, we can only free all the children */
+ struct lysc_node_action_inout *inout = (struct lysc_node_action_inout *)node;
+ LY_LIST_FOR_SAFE(inout->child, next, iter) {
+ lysc_node_free_(ctx, iter);
+ }
+ inout->child = NULL;
return;
}
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index 098a84c..8c96af9 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -419,7 +419,7 @@
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;feature f;"
"list l {key x; leaf x {type string; if-feature f;}}}", LYS_IN_YANG, NULL));
- CHECK_LOG_CTX("Key \"x\" is disabled by its if-features.", "Schema location /cc:l/x.");
+ CHECK_LOG_CTX("Key \"x\" is disabled.", "Schema location /cc:l/x.");
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;"
"list l {key x; leaf x {type string; config false;}}}", LYS_IN_YANG, NULL));
@@ -1606,7 +1606,7 @@
"leaf ref1 {type leafref {path /target;}}"
"leaf target {if-feature 'f1'; type boolean;}}";
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, &mod));
- CHECK_LOG_CTX("Target of leafref \"ref1\" cannot be referenced because it is disabled by its if-features.", "Schema location /e:ref1.");
+ CHECK_LOG_CTX("Target of leafref \"ref1\" cannot be referenced because it is disabled.", "Schema location /e:ref1.");
str = "module en {yang-version 1.1;namespace urn:en;prefix en;feature f1;"
"leaf ref1 {if-feature 'f1'; type leafref {path /target;}}"
@@ -1626,7 +1626,7 @@
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module im {namespace urn:im;prefix im;import cl {prefix cl;}"
"leaf ref {must \"/cl:h > 0\"; type uint16;}}", LYS_IN_YANG, &mod));
ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_REF_IMPLEMENTED);
- CHECK_LOG_CTX("Target of leafref \"g\" cannot be referenced because it is disabled by its if-features.", "Schema location /cl:g.");
+ CHECK_LOG_CTX("Target of leafref \"g\" cannot be referenced because it is disabled.", "Schema location /cl:g.");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;"
"list interface{key name;leaf name{type string;}list address {key ip;leaf ip {type string;}}}"
@@ -3199,7 +3199,7 @@
"container c {leaf x {type string;} leaf y {type string;}}}", LYS_IN_YANG, &mod));
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module pp1 {namespace urn:pp1;prefix pp1; import pp {prefix pp;}"
"deviation /pp:c/pp:x {deviate not-supported;}}", LYS_IN_YANG, &mod));
- CHECK_LOG_CTX("Not found node \"x\" in path.", "Schema location /pp:l.");
+ CHECK_LOG_CTX("Target of leafref \"l\" cannot be referenced because it is disabled.", "Schema location /pp:l.");
}
static void