context FEATURE explicit compilation when creating from yanglib data
diff --git a/src/context.c b/src/context.c
index 5ff7380..9d38d98 100644
--- a/src/context.c
+++ b/src/context.c
@@ -389,21 +389,26 @@
LY_ERR ret = LY_SUCCESS;
const struct lys_module *mod;
struct ly_ctx *ctx_yl = NULL, *ctx_new = NULL;
+ ly_bool no_expl_compile = 0;
/* create a seperate context in case it is LY_CTX_NO_YANGLIBRARY since it needs it for parsing */
if (options & LY_CTX_NO_YANGLIBRARY) {
LY_CHECK_GOTO(ret = ly_ctx_new(search_dir, 0, &ctx_yl), cleanup);
LY_CHECK_GOTO(ret = ly_ctx_new(search_dir, options, &ctx_new), cleanup);
} else {
- LY_CHECK_GOTO(ret = ly_ctx_new(search_dir, options, &ctx_yl), cleanup);
- ctx_new = ctx_yl;
+ LY_CHECK_GOTO(ret = ly_ctx_new(search_dir, options, &ctx_new), cleanup);
}
/* parse yang library data tree */
- LY_CHECK_GOTO(ret = parser_func(ctx_yl, input, format, 0, LYD_VALIDATE_PRESENT, &yltree), cleanup);
+ LY_CHECK_GOTO(ret = parser_func(ctx_yl ? ctx_yl : ctx_new, input, format, 0, LYD_VALIDATE_PRESENT, &yltree), cleanup);
+
+ /* redundant to compile modules one-by-one */
+ if (!(options & LY_CTX_EXPLICIT_COMPILE)) {
+ ctx_new->flags |= LY_CTX_EXPLICIT_COMPILE;
+ no_expl_compile = 1;
+ }
LY_CHECK_GOTO(ret = lyd_find_xpath(yltree, "/ietf-yang-library:yang-library/module-set[1]/module", &set), cleanup);
-
if (set->count == 0) {
/* perhaps a legacy data tree? */
LY_CHECK_GOTO(ret = ly_ctx_new_yl_legacy(ctx_new, yltree), cleanup);
@@ -441,20 +446,31 @@
mod = ly_ctx_load_module(ctx_new, name, revision, feature_arr);
free(feature_arr);
if (!mod) {
- LOGERR(NULL, LY_EINVAL, "Unable to load module specified by yang library data.");
+ LOGERR(NULL, LY_EINVAL, "Unable to load module %s@%s specified by yang library data.", name,
+ revision ? revision : "<none>");
ret = LY_EINVAL;
goto cleanup;
}
}
}
+ /* free data because their context may be recompiled */
+ lyd_free_all(yltree);
+ yltree = NULL;
+
+ /* compile */
+ LY_CHECK_GOTO(ret = ly_ctx_compile(ctx_new), cleanup);
+
+ if (no_expl_compile) {
+ /* unset flag */
+ ctx_new->flags &= ~LY_CTX_EXPLICIT_COMPILE;
+ }
+
cleanup:
lyd_free_all(yltree);
ly_set_free(set, NULL);
ly_set_erase(&features, NULL);
- if (ctx_yl != ctx_new) {
- ly_ctx_destroy(ctx_yl);
- }
+ ly_ctx_destroy(ctx_yl);
*ctx = ctx_new;
if (ret) {
ly_ctx_destroy(*ctx);
diff --git a/tests/utests/basic/test_context.c b/tests/utests/basic/test_context.c
index 86735a6..9a74863 100644
--- a/tests/utests/basic/test_context.c
+++ b/tests/utests/basic/test_context.c
@@ -658,23 +658,23 @@
/* basic test with ietf-yang-library-only */
assert_int_equal(LY_SUCCESS, ly_ctx_new_ylmem(TESTS_SRC "/modules/yang/", yanglibrary_only, LYD_XML, 0, &ctx_test));
- assert_ptr_not_equal(NULL, ly_ctx_get_module(ctx_test, "ietf-yang-library", "2019-01-04"));
+ assert_non_null(ly_ctx_get_module(ctx_test, "ietf-yang-library", "2019-01-04"));
assert_null(ly_ctx_get_module(ctx_test, "ietf-netconf", "2011-06-01"));
ly_ctx_destroy(ctx_test);
/* test loading module, should also import other module */
assert_int_equal(LY_SUCCESS, ly_ctx_new_ylmem(TESTS_SRC "/modules/yang/", with_netconf, LYD_XML, 0, &ctx_test));
- assert_int_not_equal(NULL, ly_ctx_get_module(ctx_test, "ietf-netconf", "2011-06-01"));
+ assert_non_null(ly_ctx_get_module(ctx_test, "ietf-netconf", "2011-06-01"));
assert_int_equal(1, ly_ctx_get_module(ctx_test, "ietf-netconf", "2011-06-01")->implemented);
- assert_int_not_equal(NULL, ly_ctx_get_module(ctx_test, "ietf-netconf-acm", "2018-02-14"));
+ assert_non_null(ly_ctx_get_module(ctx_test, "ietf-netconf-acm", "2018-02-14"));
assert_int_equal(0, ly_ctx_get_module(ctx_test, "ietf-netconf-acm", "2018-02-14")->implemented);
assert_int_equal(LY_ENOT, lys_feature_value(ly_ctx_get_module(ctx_test, "ietf-netconf", "2011-06-01"), "url"));
ly_ctx_destroy(ctx_test);
/* test loading module with feature if they are present */
assert_int_equal(LY_SUCCESS, ly_ctx_new_ylmem(TESTS_SRC "/modules/yang/", with_netconf_features, LYD_XML, 0, &ctx_test));
- assert_ptr_not_equal(NULL, ly_ctx_get_module(ctx_test, "ietf-netconf", "2011-06-01"));
- assert_ptr_not_equal(NULL, ly_ctx_get_module(ctx_test, "ietf-netconf-acm", "2018-02-14"));
+ assert_non_null(ly_ctx_get_module(ctx_test, "ietf-netconf", "2011-06-01"));
+ assert_non_null(ly_ctx_get_module(ctx_test, "ietf-netconf-acm", "2018-02-14"));
assert_int_equal(LY_SUCCESS, lys_feature_value(ly_ctx_get_module(ctx_test, "ietf-netconf", "2011-06-01"), "url"));
ly_ctx_destroy(ctx_test);