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;
}