Skip to content

Commit b45dba1

Browse files
committed
schema diff BUGFIX compiled ext-inst support
1 parent 1cb5d88 commit b45dba1

File tree

8 files changed

+271
-40
lines changed

8 files changed

+271
-40
lines changed

src/schema_diff.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ struct lys_diff_ext_changes_s {
118118
struct lys_diff_ext_change_s {
119119
const struct lysc_ext_instance *ext_old; /**< old compiled extension-instance */
120120
const struct lysc_ext_instance *ext_new; /**< new compiled extension-instance */
121-
struct lys_diff_changes_s *changes; /**< pointer to changes in the old and new extension-instance, may be empty */
121+
struct lys_diff_changes_s changes; /**< changes in the old and new extension-instance, may be empty */
122122
};
123123

124124
/**
@@ -222,6 +222,7 @@ struct lys_diff_node_change_s {
222222
*/
223223
struct lys_diff_s {
224224
struct lys_diff_changes_s module_changes; /**< module changes */
225+
struct lys_diff_ext_changes_s mod_ext_changes; /**< module extension-instance changes */
225226
struct lys_diff_import_change_s *import_changes; /**< array of all the changed imports */
226227
uint32_t import_change_count; /**< count of import changes */
227228
struct lys_diff_include_change_s *include_changes; /**< array of all the changed includes */
@@ -234,7 +235,6 @@ struct lys_diff_s {
234235
uint32_t feat_change_count; /**< count of feat changes */
235236
struct lys_diff_dev_change_s *dev_changes; /**< array of all the changed deviations */
236237
uint32_t dev_change_count; /**< count of dev changes */
237-
struct lys_diff_ext_changes_s mod_ext_changes; /**< module extension-instance changes */
238238
struct lys_diff_pnode_change_s *pnode_changes; /**< array of all the parsed-only nodes and their changes */
239239
uint32_t pnode_change_count; /**< count of pnode changes */
240240
struct lys_diff_refine_change_s *refine_changes; /**< array of all the changed refines */

src/schema_diff_change.c

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static LY_ERR schema_diff_node_type_change(const struct lysc_type *type1, const
2828
enum lys_diff_changed_e parent_changed, struct lys_diff_changes_s *changes,
2929
struct lys_diff_ext_changes_s *ext_changes, struct lys_diff_s *diff);
3030
static LY_ERR schema_diff_ext_insts_change(const struct lysc_ext_instance *exts1, const struct lysc_ext_instance *exts2,
31-
enum lys_diff_changed_e parent_changed, struct lys_diff_ext_changes_s *ext_changes, struct lys_diff_s *diff);
31+
struct lys_diff_ext_changes_s *ext_changes, struct lys_diff_s *diff);
3232
static LY_ERR schema_diff_nodes_change_r(const struct lysc_node *node1, const struct lysc_node *node2, struct lys_diff_s *diff);
3333

3434
/**
@@ -381,8 +381,8 @@ schema_diff_add_ext_change(const struct lysc_ext_instance *ext_old, const struct
381381
/* fill new ext_change */
382382
ec->ext_old = ext_old;
383383
ec->ext_new = ext_new;
384-
ec->changes = calloc(1, sizeof *ec->changes);
385-
LY_CHECK_ERR_RET(!ec->changes, LOGMEM(NULL), LY_EMEM);
384+
ec->changes.changes = NULL;
385+
ec->changes.count = 0;
386386

387387
*ext_change = ec;
388388
return LY_SUCCESS;
@@ -2910,8 +2910,8 @@ schema_diff_module_identities_change(const struct lysc_ident *idents1, const str
29102910
}
29112911

29122912
/* ext-instance */
2913-
LY_CHECK_GOTO(rc = schema_diff_ext_insts_change(idents1[u].exts, idents2[v].exts, LYS_CHANGED_IDENT,
2914-
&ident_change->ext_changes, diff), cleanup);
2913+
LY_CHECK_GOTO(rc = schema_diff_ext_insts_change(idents1[u].exts, idents2[v].exts, &ident_change->ext_changes,
2914+
diff), cleanup);
29152915

29162916
/* check whether any of the changes were NBC */
29172917
schema_diff_check_node_change_nbc(&ident_change->changes, diff);
@@ -2969,8 +2969,7 @@ schema_diff_module_change(const struct lys_module *mod1, const struct lys_module
29692969
LY_CHECK_RET(schema_diff_module_identities_change(mod1->identities, mod2->identities, LYS_CHANGED_NONE, diff));
29702970

29712971
/* ext-instance */
2972-
LY_CHECK_RET(schema_diff_ext_insts_change(mod1->compiled->exts, mod2->compiled->exts, LYS_CHANGED_NONE,
2973-
&diff->mod_ext_changes, diff));
2972+
LY_CHECK_RET(schema_diff_ext_insts_change(mod1->compiled->exts, mod2->compiled->exts, &diff->mod_ext_changes, diff));
29742973

29752974
return LY_SUCCESS;
29762975
}
@@ -3032,8 +3031,7 @@ schema_diff_node_musts_change(const struct lysc_must *musts1, const struct lysc_
30323031
LYS_CHANGED_ERR_APP_TAG, changes), cleanup);
30333032

30343033
/* ext-instance */
3035-
LY_CHECK_GOTO(rc = schema_diff_ext_insts_change(musts1[u].exts, musts2[v].exts, LYS_CHANGED_MUST,
3036-
ext_changes, diff), cleanup);
3034+
LY_CHECK_GOTO(rc = schema_diff_ext_insts_change(musts1[u].exts, musts2[v].exts, ext_changes, diff), cleanup);
30373035
}
30383036

30393037
LY_ARRAY_FOR(musts2, v) {
@@ -3234,8 +3232,7 @@ schema_diff_node_whens_change(struct lysc_when **whens1, struct lysc_when **when
32343232
cleanup);
32353233

32363234
/* ext-instance */
3237-
LY_CHECK_GOTO(rc = schema_diff_ext_insts_change(whens1[u]->exts, whens2[v]->exts, LYS_CHANGED_WHEN,
3238-
ext_changes, diff), cleanup);
3235+
LY_CHECK_GOTO(rc = schema_diff_ext_insts_change(whens1[u]->exts, whens2[v]->exts, ext_changes, diff), cleanup);
32393236
}
32403237

32413238
LY_ARRAY_FOR(whens2, v) {
@@ -3456,7 +3453,7 @@ schema_diff_node_type_range_change(const struct lysc_range *range1, const struct
34563453
changes));
34573454

34583455
/* ext-instance */
3459-
LY_CHECK_RET(schema_diff_ext_insts_change(range1->exts, range2->exts, LYS_CHANGED_TYPE, ext_changes, diff));
3456+
LY_CHECK_RET(schema_diff_ext_insts_change(range1->exts, range2->exts, ext_changes, diff));
34603457

34613458
return LY_SUCCESS;
34623459
}
@@ -3518,8 +3515,7 @@ schema_diff_node_type_patterns_change(struct lysc_pattern **patterns1, struct ly
35183515
LYS_CHANGED_ERR_APP_TAG, changes), cleanup);
35193516

35203517
/* ext-instance */
3521-
LY_CHECK_GOTO(rc = schema_diff_ext_insts_change(patterns1[u]->exts, patterns2[v]->exts, LYS_CHANGED_PATTERN,
3522-
ext_changes, diff), cleanup);
3518+
LY_CHECK_GOTO(rc = schema_diff_ext_insts_change(patterns1[u]->exts, patterns2[v]->exts, ext_changes, diff), cleanup);
35233519

35243520
/* inverted */
35253521
if (patterns1[u]->inverted != patterns2[v]->inverted) {
@@ -3614,8 +3610,7 @@ schema_diff_node_type_bitenum_change(const struct lysc_type_bitenum_item *bitenu
36143610
/* if-features not supported */
36153611

36163612
/* ext-instance */
3617-
LY_CHECK_GOTO(rc = schema_diff_ext_insts_change(bitenums1[u].exts, bitenums2[v].exts,
3618-
parent_changed ? parent_changed : changed, ext_changes, diff), cleanup);
3613+
LY_CHECK_GOTO(rc = schema_diff_ext_insts_change(bitenums1[u].exts, bitenums2[v].exts, ext_changes, diff), cleanup);
36193614

36203615
/* value/position, does not matter */
36213616
if (bitenums1[u].value != bitenums2[v].value) {
@@ -3886,7 +3881,7 @@ schema_diff_node_type_change(const struct lysc_type *type1, const struct lysc_ty
38863881
}
38873882

38883883
/* ext-instance */
3889-
LY_CHECK_RET(schema_diff_ext_insts_change(type1->exts, type2->exts, LYS_CHANGED_TYPE, ext_changes, diff));
3884+
LY_CHECK_RET(schema_diff_ext_insts_change(type1->exts, type2->exts, ext_changes, diff));
38903885

38913886
return LY_SUCCESS;
38923887
}
@@ -4027,7 +4022,7 @@ schema_diff_node_change(const struct lysc_node *node1, const struct lysc_node *n
40274022
}
40284023

40294024
/* ext-instance */
4030-
LY_CHECK_RET(schema_diff_ext_insts_change(node1->exts, node2->exts, LYS_CHANGED_NONE, ext_changes, diff));
4025+
LY_CHECK_RET(schema_diff_ext_insts_change(node1->exts, node2->exts, ext_changes, diff));
40314026

40324027
return LY_SUCCESS;
40334028
}
@@ -4150,7 +4145,7 @@ schema_diff_ext_inst_substmts_change(const struct lysc_ext_substmt *substmts1, c
41504145
case LY_STMT_EXTENSION_INSTANCE:
41514146
/* ext-instance */
41524147
LY_CHECK_GOTO(rc = schema_diff_ext_insts_change(*(substmts1[u].storage_p), *(substmts2[v].storage_p),
4153-
LYS_CHANGED_EXT_INST, ext_changes, diff), cleanup);
4148+
ext_changes, diff), cleanup);
41544149
break;
41554150
case LY_STMT_FRACTION_DIGITS:
41564151
case LY_STMT_REQUIRE_INSTANCE:
@@ -4287,11 +4282,11 @@ schema_diff_ext_inst_substmts_change(const struct lysc_ext_substmt *substmts1, c
42874282
*/
42884283
static LY_ERR
42894284
schema_diff_ext_insts_change(const struct lysc_ext_instance *exts1, const struct lysc_ext_instance *exts2,
4290-
enum lys_diff_changed_e parent_changed, struct lys_diff_ext_changes_s *ext_changes, struct lys_diff_s *diff)
4285+
struct lys_diff_ext_changes_s *ext_changes, struct lys_diff_s *diff)
42914286
{
42924287
LY_ERR rc = LY_SUCCESS;
42934288
ly_bool *exts2_found, found;
4294-
enum lys_diff_changed_e ext_parent_changed;
4289+
enum lys_diff_changed_e parent_changed;
42954290
struct lys_diff_ext_change_s *ext_change;
42964291
LY_ARRAY_COUNT_TYPE u, v;
42974292

@@ -4311,15 +4306,16 @@ schema_diff_ext_insts_change(const struct lysc_ext_instance *exts1, const struct
43114306

43124307
/* add new ext-instance to changes */
43134308
LY_CHECK_RET(schema_diff_add_ext_change(&exts1[u], found ? &exts2[v] : NULL, ext_changes, &ext_change));
4309+
parent_changed = schema_diff_stmt2changed(exts1[u].parent_stmt);
43144310

43154311
if (!found) {
43164312
/* removed */
43174313
if (schema_diff_has_bc_ext(exts1[u].exts)) {
43184314
LY_CHECK_GOTO(rc = schema_diff_add_change(LYS_CHANGE_REMOVED, parent_changed, LYS_CHANGED_EXT_INST, 0,
4319-
ext_change->changes), cleanup);
4315+
&ext_change->changes), cleanup);
43204316
} else {
43214317
LY_CHECK_GOTO(rc = schema_diff_add_change(LYS_CHANGE_REMOVED, parent_changed, LYS_CHANGED_EXT_INST, 1,
4322-
ext_change->changes), cleanup);
4318+
&ext_change->changes), cleanup);
43234319

43244320
/* NBC */
43254321
diff->is_nbc = 1;
@@ -4328,12 +4324,11 @@ schema_diff_ext_insts_change(const struct lysc_ext_instance *exts1, const struct
43284324
}
43294325

43304326
/* substatements */
4331-
ext_parent_changed = (parent_changed == LYS_CHANGED_NONE) ? LYS_CHANGED_EXT_INST : parent_changed;
4332-
LY_CHECK_GOTO(rc = schema_diff_ext_inst_substmts_change(exts1[u].substmts, exts2[v].substmts, ext_parent_changed,
4333-
ext_change->changes, ext_changes, diff), cleanup);
4327+
LY_CHECK_GOTO(rc = schema_diff_ext_inst_substmts_change(exts1[u].substmts, exts2[v].substmts, parent_changed,
4328+
&ext_change->changes, ext_changes, diff), cleanup);
43344329

43354330
/* check whether any of the changes were NBC */
4336-
schema_diff_check_node_change_nbc(ext_change->changes, diff);
4331+
schema_diff_check_node_change_nbc(&ext_change->changes, diff);
43374332
}
43384333

43394334
LY_ARRAY_FOR(exts2, v) {
@@ -4343,10 +4338,11 @@ schema_diff_ext_insts_change(const struct lysc_ext_instance *exts1, const struct
43434338

43444339
/* add new ext-instance to changes */
43454340
LY_CHECK_RET(schema_diff_add_ext_change(NULL, &exts2[v], ext_changes, &ext_change));
4341+
parent_changed = schema_diff_stmt2changed(exts2[v].parent_stmt);
43464342

43474343
/* added */
43484344
LY_CHECK_GOTO(rc = schema_diff_add_change(LYS_CHANGE_ADDED, parent_changed, LYS_CHANGED_EXT_INST, 0,
4349-
ext_change->changes), cleanup);
4345+
&ext_change->changes), cleanup);
43504346
}
43514347

43524348
cleanup:
@@ -4482,8 +4478,7 @@ lysc_diff_erase_ext_changes(struct lys_diff_ext_changes_s *ext_changes)
44824478
uint32_t i;
44834479

44844480
for (i = 0; i < ext_changes->count; ++i) {
4485-
free(ext_changes->changes[i].changes->changes);
4486-
free(ext_changes->changes[i].changes);
4481+
free(ext_changes->changes[i].changes.changes);
44874482
}
44884483
free(ext_changes->changes);
44894484
}
@@ -4495,6 +4490,7 @@ lysc_diff_erase(struct lys_diff_s *diff)
44954490

44964491
/* module */
44974492
free(diff->module_changes.changes);
4493+
lysc_diff_erase_ext_changes(&diff->mod_ext_changes);
44984494

44994495
for (i = 0; i < diff->ident_change_count; ++i) {
45004496
free(diff->ident_changes[i].changes.changes);
@@ -4528,8 +4524,6 @@ lysc_diff_erase(struct lys_diff_s *diff)
45284524
}
45294525
free(diff->dev_changes);
45304526

4531-
lysc_diff_erase_ext_changes(&diff->mod_ext_changes);
4532-
45334527
/* parsed node */
45344528
for (i = 0; i < diff->pnode_change_count; ++i) {
45354529
free(diff->pnode_changes[i].changes.changes);

src/schema_diff_tree.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ schema_diff_module_ident(const struct lys_diff_ident_change_s *change, ly_bool w
16181618
/* change info */
16191619
LY_CHECK_GOTO(rc = schema_diff_changes_info(&change->changes, mod_cmp_list), cleanup);
16201620
for (i = 0; i < change->ext_changes.count; ++i) {
1621-
LY_CHECK_GOTO(rc = schema_diff_changes_info(change->ext_changes.changes[i].changes, mod_cmp_list), cleanup);
1621+
LY_CHECK_GOTO(rc = schema_diff_changes_info(&change->ext_changes.changes[i].changes, mod_cmp_list), cleanup);
16221622
}
16231623

16241624
if (change->ident_old) {
@@ -2798,14 +2798,14 @@ schema_diff_module_ext_inst(const struct lys_diff_ext_change_s *change, struct l
27982798
struct lyd_node *mod_cmp_list, *cont;
27992799
uint32_t i;
28002800

2801-
assert(change->changes->count);
2801+
assert(change->changes.count);
28022802

28032803
/* module comparison */
28042804
LY_CHECK_GOTO(rc = lyd_new_list(diff_list, NULL, "module-comparison", 0, &mod_cmp_list), cleanup);
28052805

28062806
/* change info */
2807-
for (i = 0; i < change->changes->count; ++i) {
2808-
LY_CHECK_GOTO(rc = schema_diff_change_info(&change->changes->changes[i], mod_cmp_list), cleanup);
2807+
for (i = 0; i < change->changes.count; ++i) {
2808+
LY_CHECK_GOTO(rc = schema_diff_change_info(&change->changes.changes[i], mod_cmp_list), cleanup);
28092809
}
28102810

28112811
if (change->ext_old) {
@@ -3486,7 +3486,7 @@ schema_diff_node(const struct lys_diff_node_change_s *node_change, ly_bool with_
34863486

34873487
assert(node_change->snode_old || node_change->snode_new);
34883488

3489-
if (!node_change->changes.count) {
3489+
if (!node_change->changes.count && !node_change->ext_changes.count) {
34903490
/* no changes */
34913491
goto cleanup;
34923492
}
@@ -3513,7 +3513,7 @@ schema_diff_node(const struct lys_diff_node_change_s *node_change, ly_bool with_
35133513
/* change info */
35143514
LY_CHECK_GOTO(rc = schema_diff_changes_info(&node_change->changes, node_diff_list), cleanup);
35153515
for (i = 0; i < node_change->ext_changes.count; ++i) {
3516-
LY_CHECK_GOTO(rc = schema_diff_changes_info(node_change->ext_changes.changes[i].changes, node_diff_list), cleanup);
3516+
LY_CHECK_GOTO(rc = schema_diff_changes_info(&node_change->ext_changes.changes[i].changes, node_diff_list), cleanup);
35173517
}
35183518

35193519
/* old */

tests/utests/schema_comparison/bc/12 description/description_cmp.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
},
9898
{
9999
"stmt": "extension-instance",
100+
"parent-stmt": "description",
100101
"change": "added",
101102
"conformance": "backwards-compatible"
102103
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module ext-inst {
2+
namespace "urn:test:ext-inst";
3+
prefix exi;
4+
yang-version 1.1;
5+
6+
reference "no-ref";
7+
8+
revision 2000-01-01;
9+
10+
identity id;
11+
12+
extension ex {
13+
argument name;
14+
}
15+
16+
leaf l {
17+
type enumeration {
18+
enum e1 {
19+
exi:ex "my-ext";
20+
}
21+
enum e2;
22+
}
23+
}
24+
25+
leaf k {
26+
type string {
27+
pattern 'a';
28+
}
29+
}
30+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module ext-inst {
2+
namespace "urn:test:ext-inst";
3+
prefix exi;
4+
yang-version 1.1;
5+
6+
reference "no-ref" {
7+
exi:ex "ref-ext";
8+
}
9+
10+
revision 2000-01-02;
11+
12+
identity id {
13+
exi:ex "id-ext";
14+
}
15+
16+
extension ex {
17+
argument name;
18+
}
19+
20+
leaf l {
21+
type enumeration {
22+
enum e1;
23+
enum e2;
24+
}
25+
}
26+
27+
leaf k {
28+
type string {
29+
pattern 'a' {
30+
exi:ex "enum-ext";
31+
}
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)