From 40c7d2d06aa390ae65b98990f08bc8bf6e95a441 Mon Sep 17 00:00:00 2001 From: wing Date: Wed, 29 Apr 2015 09:36:24 -0700 Subject: [PATCH 1/2] Removed fclose() in yangFileParse This call resulted in a double fclose(), when the main routine later on does the same. Seems, the caller of yangFileParse 'owns' the FILE pointer, so remove this one. --- libyang/yangloader.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libyang/yangloader.c b/libyang/yangloader.c index f258054..2596815 100644 --- a/libyang/yangloader.c +++ b/libyang/yangloader.c @@ -290,8 +290,6 @@ yangFileParse (yang_file_list_t *listp, const char *template, yfp = yangFileLoadContents(listp, template, name, filename, sourcefile, dict, partial); - fclose(sourcefile); - #if 0 yfp->yf_main = yangFindMain(yfp); if (yfp->yf_main == NULL) { From 4fcdf7f573648b1e8dd8d9bdd611a931e1d284d0 Mon Sep 17 00:00:00 2001 From: wing Date: Wed, 29 Apr 2015 19:55:36 -0700 Subject: [PATCH 2/2] Instantiate template call under stylesheet node The following yang would incorrectly compile the 'gen-foo' template at the same level as 'module' module unit-test { ... grouping ut-group1 { call gen-foo($help = "Test foo", $hidden = "internal"); } } template gen-foo ($help, $mandatory) { leaf foo { help $help; if ($mandatory) { mandatory $mandatory; } } } Previously it was instantiated under the 'feature' template, like this. stylesheet { template "/features" { module { ... } template "gen-leaf {} } } It needed to be at the same level as '/features' stylesheet { template "/features" { module { } } template "gen-leaf {} } otherwise xsltproc barfs. compilation error: file foo.xslt line 49 element template element template only allowed as child of stylesheet --- libyang/yangparser.y | 8 ++++++++ libyang/yangstmt.c | 14 ++++++++++++++ libyang/yangstmt.h | 3 +++ 3 files changed, 25 insertions(+) diff --git a/libyang/yangparser.y b/libyang/yangparser.y index ea9dfd9..9a0525c 100644 --- a/libyang/yangparser.y +++ b/libyang/yangparser.y @@ -1085,6 +1085,14 @@ explicit_named_template : K_TEMPLATE template_name { ALL_KEYWORDS_ON(); + + /* + * making a template, it has to be a child of the + * 'root' node which is the stylesheet + * note that this means that template procs must come + * after modules + */ + slaxPopToRoot(slax_data); slaxElementPush(slax_data, ELT_TEMPLATE, ATT_NAME, $2->ss_token); $$ = NULL; diff --git a/libyang/yangstmt.c b/libyang/yangstmt.c index 80da60c..1f6d80e 100644 --- a/libyang/yangstmt.c +++ b/libyang/yangstmt.c @@ -487,3 +487,17 @@ yangStmtInit (void) TAILQ_INIT(&yangStmtList); yangStmtInitBuiltin(); } + +xmlNodePtr +slaxPopToRoot (slax_data_t *sdp) +{ + xmlNodePtr node, node_save; + + node = node_save = sdp->sd_ctxt->node; + while (node && node->parent && node->parent->parent) + node = node->parent; + + sdp->sd_ctxt->node = node; + + return node_save; +} diff --git a/libyang/yangstmt.h b/libyang/yangstmt.h index 4816437..e25b0e6 100644 --- a/libyang/yangstmt.h +++ b/libyang/yangstmt.h @@ -164,3 +164,6 @@ yangStmtGetValue (slax_data_t *sdp, xmlNodePtr nodep, yang_stmt_t *ysp); void yangStmtCheckArgument (slax_data_t *sdp, slax_string_t *sp); + +xmlNodePtr +slaxPopToRoot (slax_data_t *sdp);