@@ -732,7 +732,7 @@ lys_parse_localfile(struct ly_ctx *ctx, const char *name, const char *revision,
732732 mod_data .path = filepath ;
733733 mod_data .submoduleof = main_name ;
734734 if (main_ctx ) {
735- ret = lys_parse_submodule (ctx , in , format , main_ctx , & mod_data , new_mods , (struct lysp_submodule * * )& mod );
735+ ret = lys_parse_submodule (ctx , in , format , main_ctx , & mod_data , 1 , new_mods , (struct lysp_submodule * * )& mod );
736736 } else {
737737 ret = lys_parse_in (ctx , in , format , & mod_data , new_mods , (struct lys_module * * )& mod );
738738
@@ -1166,7 +1166,7 @@ lysp_load_submod_from_clb_or_file(struct lysp_ctx *pctx, const char *name, const
11661166 mod_data .name = name ;
11671167 mod_data .revision = revision ;
11681168 mod_data .submoduleof = PARSER_CUR_PMOD (pctx )-> mod -> name ;
1169- r = lys_parse_submodule (ctx , in , format , pctx -> main_ctx , & mod_data , new_mods , submod );
1169+ r = lys_parse_submodule (ctx , in , format , pctx -> main_ctx , & mod_data , 0 , new_mods , submod );
11701170 ly_in_free (in , 0 );
11711171 if (submodule_data_free ) {
11721172 submodule_data_free ((void * )submodule_data , ctx -> imp_clb_data );
@@ -1188,12 +1188,6 @@ lysp_load_submod_from_clb_or_file(struct lysp_ctx *pctx, const char *name, const
11881188 return LY_ENOTFOUND ;
11891189 }
11901190
1191- if (!revision && ((* submod )-> latest_revision == 1 )) {
1192- /* update the latest_revision flag - here we have selected the latest available schema,
1193- * consider that even the callback provides correct latest revision */
1194- (* submod )-> latest_revision = 2 ;
1195- }
1196-
11971191 return LY_SUCCESS ;
11981192}
11991193
@@ -1220,12 +1214,21 @@ lysp_load_submodules(struct lysp_ctx *pctx, struct lysp_module *pmod, struct ly_
12201214 submod_included = 0 ;
12211215 } else if (r ) {
12221216 return r ;
1217+ } else if (inc -> submodule -> latest_revision == 2 ) {
1218+ /* submodule found and is the latest existing revision */
1219+ continue ;
12231220 }
12241221 }
12251222
12261223 /* try to use currently parsed submodule */
12271224 r = lysp_parsed_mods_get_submodule (pctx , inc );
1228- LY_CHECK_RET (r != LY_ENOT , r );
1225+ if (r && (r != LY_ENOT )) {
1226+ return r ;
1227+ } else if (!r && ((inc -> submodule -> latest_revision == 2 ) || inc -> submodule -> parsing )) {
1228+ /* use the module if we already have its latest revision or if it is being parsed, we have to stop looking
1229+ * recursively for latest revisions at some point to prevent infinite recursion */
1230+ continue ;
1231+ }
12291232
12301233 /* try to load the submodule */
12311234 LY_CHECK_RET (lysp_load_submod_from_clb_or_file (pctx , inc -> name , inc -> rev [0 ] ? inc -> rev : NULL , new_mods , & submod ));
0 commit comments