Skip to content

Commit cd3eb56

Browse files
committed
tree data UPDATE different context node find support
1 parent 7c18d0b commit cd3eb56

3 files changed

Lines changed: 22 additions & 21 deletions

File tree

src/tree_data.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,14 +1505,7 @@ lyd_create_attr(struct lyd_node *parent, struct lyd_attr **attr, const struct ly
15051505
return LY_SUCCESS;
15061506
}
15071507

1508-
/**
1509-
* @brief Check the equality of the two schemas from different contexts.
1510-
*
1511-
* @param schema1 of first node.
1512-
* @param schema2 of second node.
1513-
* @return 1 if the schemas are equal otherwise 0.
1514-
*/
1515-
static ly_bool
1508+
ly_bool
15161509
lyd_compare_schema_equal(const struct lysc_node *schema1, const struct lysc_node *schema2)
15171510
{
15181511
if (!schema1 && !schema2) {
@@ -1521,7 +1514,9 @@ lyd_compare_schema_equal(const struct lysc_node *schema1, const struct lysc_node
15211514
return 0;
15221515
}
15231516

1524-
assert(schema1->module->ctx != schema2->module->ctx);
1517+
if (schema1->module->ctx == schema2->module->ctx) {
1518+
return (schema1 == schema2) ? 1 : 0;
1519+
}
15251520

15261521
if (schema1->nodetype != schema2->nodetype) {
15271522
return 0;
@@ -3177,10 +3172,11 @@ lyd_find_meta(const struct lyd_meta *first, const struct lys_module *module, con
31773172
LIBYANG_API_DEF LY_ERR
31783173
lyd_find_sibling_first(const struct lyd_node *siblings, const struct lyd_node *target, struct lyd_node **match)
31793174
{
3180-
struct lyd_node **match_p, *iter, *dup = NULL, *parent;
3175+
struct lyd_node **match_p, *iter, *parent;
31813176
ly_bool found;
31823177

31833178
LY_CHECK_ARG_RET(NULL, target, LY_EINVAL);
3179+
31843180
if (!siblings) {
31853181
/* no data */
31863182
if (match) {
@@ -3189,15 +3185,9 @@ lyd_find_sibling_first(const struct lyd_node *siblings, const struct lyd_node *t
31893185
return LY_ENOTFOUND;
31903186
}
31913187

3192-
if (LYD_CTX(siblings) != LYD_CTX(target)) {
3193-
/* create a duplicate in this context */
3194-
LY_CHECK_RET(lyd_dup_single_to_ctx(target, lyd_dup_get_top_ctx(siblings), NULL, 0, &dup));
3195-
target = dup;
3196-
}
3197-
3198-
if ((siblings->schema && target->schema && (lysc_data_parent(siblings->schema) != lysc_data_parent(target->schema)))) {
3188+
if ((siblings->schema && target->schema &&
3189+
!lyd_compare_schema_equal(lysc_data_parent(siblings->schema), lysc_data_parent(target->schema)))) {
31993190
/* schema mismatch */
3200-
lyd_free_tree(dup);
32013191
if (match) {
32023192
*match = NULL;
32033193
}
@@ -3214,7 +3204,9 @@ lyd_find_sibling_first(const struct lyd_node *siblings, const struct lyd_node *t
32143204
if (lysc_is_dup_inst_list(target->schema)) {
32153205
/* we must search the instances from beginning to find the first matching one */
32163206
found = 0;
3217-
LYD_LIST_FOR_INST(siblings, target->schema, iter) {
3207+
for (lyd_find_sibling_val(siblings, target->schema, NULL, 0, &iter);
3208+
iter && lyd_compare_schema_equal(iter->schema, target->schema);
3209+
iter = iter->next) {
32183210
if (!lyd_compare_single(target, iter, LYD_COMPARE_FULL_RECURSION)) {
32193211
found = 1;
32203212
break;
@@ -3249,7 +3241,6 @@ lyd_find_sibling_first(const struct lyd_node *siblings, const struct lyd_node *t
32493241
}
32503242
}
32513243

3252-
lyd_free_tree(dup);
32533244
if (!siblings) {
32543245
if (match) {
32553246
*match = NULL;

src/tree_data_hash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "plugins_types.h"
2626
#include "tree.h"
2727
#include "tree_data.h"
28+
#include "tree_data_internal.h"
2829
#include "tree_schema.h"
2930

3031
LY_ERR
@@ -108,7 +109,7 @@ lyd_hash_table_val_equal(void *val1_p, void *val2_p, ly_bool mod, void *UNUSED(c
108109
if (!lyd_compare_single(val1, val2, 0)) {
109110
return 1;
110111
}
111-
} else if (val1->schema == val2->schema) {
112+
} else if (lyd_compare_schema_equal(val1->schema, val2->schema)) {
112113
/* just schema match */
113114
return 1;
114115
}

src/tree_data_internal.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,15 @@ LY_ERR lyd_create_attr(struct lyd_node *parent, struct lyd_attr **attr, const st
581581
uint32_t name_len, const char *prefix, uint32_t prefix_len, const char *module_key, uint32_t module_key_len,
582582
const char *value, uint32_t value_len, ly_bool *dynamic, LY_VALUE_FORMAT format, void *val_prefix_data, uint32_t hints);
583583

584+
/**
585+
* @brief Check the equality of the two schemas.
586+
*
587+
* @param schema1 Schema of first node.
588+
* @param schema2 Schema of second node.
589+
* @return 1 if the schemas are equal otherwise 0.
590+
*/
591+
ly_bool lyd_compare_schema_equal(const struct lysc_node *schema1, const struct lysc_node *schema2);
592+
584593
/**
585594
* @brief Store and canonize the given @p value into @p val according to the schema node type rules.
586595
*

0 commit comments

Comments
 (0)