Skip to content

Commit

Permalink
Fixed: Duplicates in autocli expansion of leafs and treeref includes:
Browse files Browse the repository at this point in the history
  * #73
  * clicon/clixon#301
  * This was introduced in CLIgen 5.4
  • Loading branch information
olofhagsand committed Feb 10, 2022
1 parent 8d3a83f commit c98a1bd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
## 5.6.0
Expected: March 2022

### Corrected Bugs

* Fixed: Duplicates in autocli expansion of leafs and treeref includes:
* https://github.com/clicon/cligen/issues/73
* https://github.com/clicon/clixon/issues/301
* This was introduced in CLIgen 5.4

## 5.5.0
20 January 2022

Expand Down
10 changes: 6 additions & 4 deletions cligen_expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,12 @@ pt_expand1_co(cligen_handle h,
con = NULL;
if (co_expand_sub(co, NULL, &con) < 0)
goto done;
/* con may be deleted in the call and need to be replaced */
if ((con = co_insert1(ptn, con, 0)) == NULL)
goto done;
if (transient && con->co_ref){
con->co_ref = co->co_ref;
}
if (pt_vec_append(ptn, con) < 0)
goto done;
if (cvv_filter && cvec_len(cvv_filter))
if ((con->co_filter = cvec_dup(cvv_filter)) == NULL)
goto done;
Expand Down Expand Up @@ -720,6 +721,7 @@ pt_expand(cligen_handle h,
goto done;
if (co_find_label_filters(h, co, cvv2) < 0)
goto done;
/* Expand ptref to pttmp */
if (co_expand_treeref_copy_shallow(h, co, cvv2, ptref, pttmp) < 0)
goto done;
/* Copy the expand tree to the final tree.
Expand All @@ -744,9 +746,9 @@ pt_expand(cligen_handle h,
} /* for */
} /* for */
/* Sorting (Alt: ensure all elements are inserted properly)
* Sorting is disabled for now. Left this comment but seems to work fine without
* cligen_parsetree_sort(ptn, 1);
* Sorting must be here so that duplicates can be detected
*/
cligen_parsetree_sort(ptn, 0);
if (cligen_logsyntax(h) > 0){
fprintf(stderr, "%s:\n", __FUNCTION__);
pt_print1(stderr, ptn, 0);
Expand Down
18 changes: 14 additions & 4 deletions cligen_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,15 +1089,17 @@ co_insert_pos(parse_tree *pt,
* There is som complexity if co == NULL.
* @param[in] pt Parse-tree
* @param[in] co1 CLIgen object
* @param[in] recursive Recursive delete?
* @retval co object if found (old _or_ new). NOTE: you must replace calling
* cg_obj with return.
* @retval NULL error
* @note co1 maye be deleted in this call. Dont use co after this call,use retval
* @note co1 may be deleted in this call. Dont use co after this call,use retval
* XXX: pt=[a b] + co1=[b] -> [a b] but children of one b is lost,..
*/
cg_obj*
co_insert(parse_tree *pt,
cg_obj *co1)
co_insert1(parse_tree *pt,
cg_obj *co1,
int recursive)
{
int pos;
cg_obj *co2;
Expand All @@ -1111,7 +1113,7 @@ co_insert(parse_tree *pt,
return NULL;
if (co1 && co2 && co_eq(co1, co2)==0){
cligen_parsetree_merge(co_pt_get(co2), co2, co_pt_get(co1));
co_free(co1, 1);
co_free(co1, recursive);
return co2;
}
}
Expand All @@ -1120,6 +1122,14 @@ co_insert(parse_tree *pt,
return co1;
}

/* Backward compatible */
cg_obj*
co_insert(parse_tree *pt,
cg_obj *co1)
{
return co_insert1(pt, co1, 1);
}

/*! Given a parse tree, find the first CLIgen object that matches
* @param[in] pt CLIgen parse-tree
* @param[in] name Name of node
Expand Down
1 change: 1 addition & 0 deletions cligen_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ int co_copy(cg_obj *co, cg_obj *parent, uint32_t flags, cg_obj **conp);
int co_copy1(cg_obj *co, cg_obj *parent, int recursive, uint32_t flags, cg_obj **conp);
int co_eq(cg_obj *co1, cg_obj *co2);
int co_free(cg_obj *co, int recursive);
cg_obj *co_insert1(parse_tree *pt, cg_obj *co, int recursive);
cg_obj *co_insert(parse_tree *pt, cg_obj *co);
cg_obj *co_find_one(parse_tree *pt, char *name);
int co_value_set(cg_obj *co, char *str);
Expand Down

0 comments on commit c98a1bd

Please sign in to comment.