Skip to content

Commit

Permalink
- yang sorting did not use "stable" qsort: fixed by using vector index
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Nov 26, 2021
1 parent 5388aac commit ee5c0a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
13 changes: 9 additions & 4 deletions lib/src/clixon_yang.c
Original file line number Diff line number Diff line change
Expand Up @@ -3761,12 +3761,12 @@ yang_sort_subelements_fn(const void* arg1,
w1 = yang_find(ys1, Y_WHEN, NULL) != NULL;
w2 = yang_find(ys2, Y_WHEN, NULL) != NULL;
if (w1 == w2)
return 0;
if (w1)
return ys1->_ys_vector_i - ys2->_ys_vector_i;
else if (w1)
return 1;
if (w2)
else if (w2)
return -1;
return 0;
else return ys1->_ys_vector_i - ys2->_ys_vector_i;
}
#endif

Expand All @@ -3786,9 +3786,14 @@ yang_sort_subelements(yang_stmt *ys)
#ifdef YANG_ORDERING_WHEN_LAST
if ((yang_keyword_get(ys) == Y_CONTAINER ||
yang_keyword_get(ys) == Y_LIST)){
yang_stmt *yc = NULL;

/* This enumerates _ys_vector_i in ys->ys_stmt vector */
while ((yc = yn_each(ys, yc)) != NULL) ;
qsort(ys->ys_stmt, ys->ys_len, sizeof(ys), yang_sort_subelements_fn);
}
#endif

retval = 0;
// done:
return retval;
Expand Down
3 changes: 2 additions & 1 deletion lib/src/clixon_yang_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ struct yang_stmt{
yang_type_cache *ys_typecache; /* If ys_keyword==Y_TYPE, cache all typedef data except unions */
char *ys_when_xpath; /* Special conditional for a "when"-associated augment/uses xpath */
cvec *ys_when_nsc; /* Special conditional for a "when"-associated augment/uses namespace ctx */
int _ys_vector_i; /* internal use: yn_each */
char *ys_filename; /* For debug/errors: filename (only (sub)modules) */
int ys_linenum; /* For debug/errors: line number (in ys_filename) */
/* Internal use */
int _ys_vector_i; /* internal use: yn_each */
};


Expand Down

0 comments on commit ee5c0a0

Please sign in to comment.