From ee5c0a08d5e67174f96d8210b4085ec8128969d4 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Fri, 26 Nov 2021 15:17:23 +0100 Subject: [PATCH] - yang sorting did not use "stable" qsort: fixed by using vector index --- lib/src/clixon_yang.c | 13 +++++++++---- lib/src/clixon_yang_internal.h | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index 4c6021d4..3a102af2 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -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 @@ -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; diff --git a/lib/src/clixon_yang_internal.h b/lib/src/clixon_yang_internal.h index 4fb3a489..84b4f274 100644 --- a/lib/src/clixon_yang_internal.h +++ b/lib/src/clixon_yang_internal.h @@ -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 */ };