tree data BUGFIX added return value for unlink
Added return value for functions lyd_unlink_siblings() and
lyd_unlink_tree(), which causes ABI breaks.
diff --git a/src/plugins_exts/schema_mount.c b/src/plugins_exts/schema_mount.c
index b349921..e812053 100644
--- a/src/plugins_exts/schema_mount.c
+++ b/src/plugins_exts/schema_mount.c
@@ -940,7 +940,7 @@
}
/* create accessible tree, remove LYD_EXT to not call this callback recursively */
- lyd_unlink_siblings(sibling);
+ LY_CHECK_GOTO(lyd_unlink_siblings(sibling), cleanup);
LY_LIST_FOR(sibling, iter) {
iter->flags &= ~LYD_EXT;
}
diff --git a/src/tree_data.c b/src/tree_data.c
index faeae00..2e7ee00 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -1010,10 +1010,10 @@
LY_CHECK_RET(lyd_insert_check_schema(parent->schema, NULL, node->schema));
if (node->parent || node->prev->next || !node->next) {
- lyd_unlink_tree(node);
+ LY_CHECK_RET(lyd_unlink_tree(node));
lyd_insert_node(parent, NULL, node, 0);
} else {
- lyd_move_nodes(parent, NULL, node);
+ LY_CHECK_RET(lyd_move_nodes(parent, NULL, node));
}
return LY_SUCCESS;
@@ -1054,10 +1054,10 @@
first_sibling = lyd_first_sibling(sibling);
if (node->parent || node->prev->next || !node->next) {
- lyd_unlink_tree(node);
+ LY_CHECK_RET(lyd_unlink_tree(node));
lyd_insert_node(NULL, &first_sibling, node, 0);
} else {
- lyd_move_nodes(NULL, first_sibling, node);
+ LY_CHECK_RET(lyd_move_nodes(NULL, first_sibling, node));
}
if (first) {
@@ -1189,7 +1189,7 @@
lyd_unlink_ignore_lyds(node);
}
-LIBYANG_API_DEF void
+LIBYANG_API_DEF LY_ERR
lyd_unlink_siblings(struct lyd_node *node)
{
struct lyd_node *next, *iter, *leader, *start;
@@ -1200,25 +1200,29 @@
lyds_split(leader, node, &start);
} else {
/* unlink @p node */
- LY_CHECK_RET(lyd_unlink_check(node), );
+ LY_CHECK_RET(lyd_unlink_check(node));
start = node->next;
lyd_unlink_ignore_lyds(node);
}
/* continue unlinking the rest */
LY_LIST_FOR_SAFE(start, next, iter) {
- LY_CHECK_RET(lyd_unlink_check(iter), );
+ LY_CHECK_RET(lyd_unlink_check(iter));
lyd_unlink_ignore_lyds(iter);
lyd_insert_after_node(node->prev, iter);
lyd_insert_hash(iter);
}
+
+ return LY_SUCCESS;
}
-LIBYANG_API_DEF void
+LIBYANG_API_DEF LY_ERR
lyd_unlink_tree(struct lyd_node *node)
{
- LY_CHECK_RET(lyd_unlink_check(node), );
+ LY_CHECK_RET(lyd_unlink_check(node));
lyd_unlink(node);
+
+ return LY_SUCCESS;
}
void
diff --git a/src/tree_data.h b/src/tree_data.h
index a929d8b..2319655 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -1860,15 +1860,19 @@
* @brief Unlink the specified node with all the following siblings.
*
* @param[in] node Data tree node to be unlinked (together with all the children and following siblings).
+ * @return LYS_SUCCESS on success.
+ * @return LY_ERR error on error.
*/
-LIBYANG_API_DECL void lyd_unlink_siblings(struct lyd_node *node);
+LIBYANG_API_DECL LY_ERR lyd_unlink_siblings(struct lyd_node *node);
/**
* @brief Unlink the specified data subtree.
*
* @param[in] node Data tree node to be unlinked (together with all the children).
+ * @return LYS_SUCCESS on success.
+ * @return LY_ERR error on error.
*/
-LIBYANG_API_DECL void lyd_unlink_tree(struct lyd_node *node);
+LIBYANG_API_DECL LY_ERR lyd_unlink_tree(struct lyd_node *node);
/**
* @brief Free all the nodes (even parents of the node) in the data tree.
diff --git a/tests/utests/data/test_tree_data_sorted.c b/tests/utests/data/test_tree_data_sorted.c
index de2f121..ad0e6cf 100644
--- a/tests/utests/data/test_tree_data_sorted.c
+++ b/tests/utests/data/test_tree_data_sorted.c
@@ -1203,7 +1203,7 @@
assert_int_equal(lyd_new_term(src, mod, "ll", "1", 0, &node), LY_SUCCESS);
assert_int_equal(lyd_new_term(src, mod, "ll", "2", 0, &node), LY_SUCCESS);
first = lyd_child(src);
- lyd_unlink_siblings(first);
+ assert_int_equal(lyd_unlink_siblings(first), LY_SUCCESS);
assert_int_equal(lyd_new_inner(NULL, mod, "cn", 0, &dst), LY_SUCCESS);
assert_int_equal(lyd_insert_child(dst, first), LY_SUCCESS);
first = lyd_child(dst);
@@ -1218,7 +1218,7 @@
assert_int_equal(lyd_new_term(src, mod, "ll", "1", 0, &node), LY_SUCCESS);
assert_int_equal(lyd_new_term(src, mod, "ll", "2", 0, &node), LY_SUCCESS);
first = lyd_child(src);
- lyd_unlink_siblings(lyd_child(src));
+ assert_int_equal(lyd_unlink_siblings(lyd_child(src)), LY_SUCCESS);
assert_int_equal(lyd_new_inner(NULL, mod, "cn", 0, &dst), LY_SUCCESS);
assert_int_equal(lyd_new_term(dst, mod, "tail", "a", 0, &node), LY_SUCCESS);
assert_int_equal(lyd_insert_sibling(lyd_child(dst), first, NULL), LY_SUCCESS);
@@ -1234,7 +1234,7 @@
assert_int_equal(lyd_new_term(src, mod, "ll", "1", 0, &node), LY_SUCCESS);
assert_int_equal(lyd_new_term(src, mod, "ll", "2", 0, &node), LY_SUCCESS);
first = lyd_child(src);
- lyd_unlink_siblings(lyd_child(src));
+ assert_int_equal(lyd_unlink_siblings(lyd_child(src)), LY_SUCCESS);
assert_int_equal(lyd_new_inner(NULL, mod, "cn", 0, &dst), LY_SUCCESS);
assert_int_equal(lyd_new_term(dst, mod, "head", "a", 0, &node), LY_SUCCESS);
assert_int_equal(lyd_insert_sibling(lyd_child(dst), first, NULL), LY_SUCCESS);
@@ -1451,7 +1451,7 @@
assert_int_equal(lyd_new_term(cont, mod, "tail", "b", 0, NULL), LY_SUCCESS);
node = lyd_child(cont)->next;
- lyd_unlink_siblings(node);
+ assert_int_equal(lyd_unlink_siblings(node), LY_SUCCESS);
first = lyd_child(cont);
assert_true(first && first->meta && !first->next);
assert_string_equal(first->meta->name, META_NAME);