Skip to content

Commit 0b044b4

Browse files
committed
tree data BUGFIX schema comparison in different ctxs
1 parent 4ddebd1 commit 0b044b4

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

src/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ lyd_diff_dup(const struct lyd_node *node, enum lyd_diff_op op, struct lyd_node *
353353
node_parent = node;
354354
sparent = parent ? parent->schema : NULL;
355355
while (lysc_data_parent(dup_parent->schema) &&
356-
!lyd_compare_schema_equal(lysc_data_parent(dup_parent->schema), sparent)) {
356+
!lyd_compare_schema_equal(lysc_data_parent(dup_parent->schema), sparent, 0)) {
357357
node_parent = node_parent->parent;
358358

359359
/* duplicate the next parent */

src/tree_data.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,7 @@ lyd_create_attr(struct lyd_node *parent, struct lyd_attr **attr, const struct ly
15061506
}
15071507

15081508
ly_bool
1509-
lyd_compare_schema_equal(const struct lysc_node *schema1, const struct lysc_node *schema2)
1509+
lyd_compare_schema_equal(const struct lysc_node *schema1, const struct lysc_node *schema2, ly_bool cmp_parents)
15101510
{
15111511
if (!schema1 && !schema2) {
15121512
return 1;
@@ -1518,15 +1518,24 @@ lyd_compare_schema_equal(const struct lysc_node *schema1, const struct lysc_node
15181518
return (schema1 == schema2) ? 1 : 0;
15191519
}
15201520

1521-
if (schema1->nodetype != schema2->nodetype) {
1522-
return 0;
1523-
}
1521+
do {
1522+
if (schema1->nodetype != schema2->nodetype) {
1523+
return 0;
1524+
}
15241525

1525-
if (strcmp(schema1->name, schema2->name)) {
1526-
return 0;
1527-
}
1526+
if (strcmp(schema1->name, schema2->name)) {
1527+
return 0;
1528+
}
1529+
1530+
if (strcmp(schema1->module->name, schema2->module->name)) {
1531+
return 0;
1532+
}
1533+
1534+
schema1 = schema1->parent;
1535+
schema2 = schema2->parent;
1536+
} while (cmp_parents && schema1 && schema2);
15281537

1529-
if (strcmp(schema1->module->name, schema2->module->name)) {
1538+
if ((schema1 && !schema2) || (!schema1 && schema2)) {
15301539
return 0;
15311540
}
15321541

@@ -1552,7 +1561,7 @@ lyd_compare_schema_parents_equal(const struct lyd_node *node1, const struct lyd_
15521561
for (parent1 = node1->schema->parent, parent2 = node2->schema->parent;
15531562
parent1 && parent2;
15541563
parent1 = parent1->parent, parent2 = parent2->parent) {
1555-
if (!lyd_compare_schema_equal(parent1, parent2)) {
1564+
if (!lyd_compare_schema_equal(parent1, parent2, 0)) {
15561565
return 0;
15571566
}
15581567
}
@@ -1669,7 +1678,7 @@ lyd_compare_single_schema(const struct lyd_node *node1, const struct lyd_node *n
16691678
}
16701679
} else {
16711680
/* different contexts */
1672-
if (!lyd_compare_schema_equal(node1->schema, node2->schema)) {
1681+
if (!lyd_compare_schema_equal(node1->schema, node2->schema, 0)) {
16731682
return LY_ENOT;
16741683
}
16751684
if (!parental_schemas_checked) {
@@ -2369,7 +2378,7 @@ lyd_dup_get_local_parent(const struct lyd_node *node, const struct ly_ctx **trg_
23692378
iter = parent;
23702379
repeat = 0;
23712380
} else if (parent && (LYD_CTX(parent) != LYD_CTX(orig_parent)) &&
2372-
lyd_compare_schema_equal(parent->schema, orig_parent->schema) &&
2381+
lyd_compare_schema_equal(parent->schema, orig_parent->schema, 0) &&
23732382
lyd_compare_schema_parents_equal(parent, orig_parent)) {
23742383
iter = parent;
23752384
repeat = 0;
@@ -3186,7 +3195,7 @@ lyd_find_sibling_first(const struct lyd_node *siblings, const struct lyd_node *t
31863195
}
31873196

31883197
if ((siblings->schema && target->schema &&
3189-
!lyd_compare_schema_equal(lysc_data_parent(siblings->schema), lysc_data_parent(target->schema)))) {
3198+
!lyd_compare_schema_equal(lysc_data_parent(siblings->schema), lysc_data_parent(target->schema), 1))) {
31903199
/* schema mismatch */
31913200
if (match) {
31923201
*match = NULL;
@@ -3205,7 +3214,7 @@ lyd_find_sibling_first(const struct lyd_node *siblings, const struct lyd_node *t
32053214
/* we must search the instances from beginning to find the first matching one */
32063215
found = 0;
32073216
for (lyd_find_sibling_val(siblings, target->schema, NULL, 0, &iter);
3208-
iter && lyd_compare_schema_equal(iter->schema, target->schema);
3217+
iter && lyd_compare_schema_equal(iter->schema, target->schema, 0);
32093218
iter = iter->next) {
32103219
if (!lyd_compare_single(target, iter, LYD_COMPARE_FULL_RECURSION)) {
32113220
found = 1;

src/tree_data_common.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,12 +1080,7 @@ lyd_hash_table_schema_val_equal(void *val1_p, void *val2_p, ly_bool UNUSED(mod),
10801080
val1 = *((struct lysc_node **)val1_p);
10811081
val2 = *((struct lyd_node **)val2_p);
10821082

1083-
if (val1 == val2->schema) {
1084-
/* schema match is enough */
1085-
return 1;
1086-
} else {
1087-
return 0;
1088-
}
1083+
return lyd_compare_schema_equal(val1, val2->schema, 1);
10891084
}
10901085

10911086
LY_ERR

src/tree_data_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ lyd_hash_table_val_equal(void *val1_p, void *val2_p, ly_bool mod, void *UNUSED(c
109109
if (!lyd_compare_single(val1, val2, 0)) {
110110
return 1;
111111
}
112-
} else if (lyd_compare_schema_equal(val1->schema, val2->schema)) {
112+
} else if (lyd_compare_schema_equal(val1->schema, val2->schema, 1)) {
113113
/* just schema match */
114114
return 1;
115115
}

src/tree_data_internal.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,11 +584,12 @@ LY_ERR lyd_create_attr(struct lyd_node *parent, struct lyd_attr **attr, const st
584584
/**
585585
* @brief Check the equality of the two schemas.
586586
*
587-
* @param schema1 Schema of first node.
588-
* @param schema2 Schema of second node.
587+
* @param[in] schema1 Schema of first node.
588+
* @param[in] schema2 Schema of second node.
589+
* @param[in] cmp_parents Whether to also compare all the parents.
589590
* @return 1 if the schemas are equal otherwise 0.
590591
*/
591-
ly_bool lyd_compare_schema_equal(const struct lysc_node *schema1, const struct lysc_node *schema2);
592+
ly_bool lyd_compare_schema_equal(const struct lysc_node *schema1, const struct lysc_node *schema2, ly_bool cmp_parents);
592593

593594
/**
594595
* @brief Store and canonize the given @p value into @p val according to the schema node type rules.

0 commit comments

Comments
 (0)