Skip to content

Commit 206e72a

Browse files
committed
context UPDATE store context module hash
1 parent da7272e commit 206e72a

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

src/context.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ ly_ctx_load_module(struct ly_ctx *ctx, const char *name, const char *revision, c
246246
lys_unres_glob_erase(&ctx->unres);
247247
}
248248

249+
/* new context state */
250+
ly_ctx_new_change(ctx);
251+
249252
cleanup:
250253
if (ret) {
251254
lys_unres_glob_revert(ctx, &ctx->unres);
@@ -752,13 +755,23 @@ ly_ctx_get_change_count(const struct ly_ctx *ctx)
752755

753756
LIBYANG_API_DEF uint32_t
754757
ly_ctx_get_modules_hash(const struct ly_ctx *ctx)
758+
{
759+
LY_CHECK_ARG_RET(ctx, ctx, 0);
760+
761+
return ctx->mod_hash;
762+
}
763+
764+
void
765+
ly_ctx_new_change(struct ly_ctx *ctx)
755766
{
756767
const struct lys_module *mod;
757768
uint32_t i = ly_ctx_internal_modules_count(ctx), hash = 0, fi = 0;
758769
struct lysp_feature *f = NULL;
759770

760-
LY_CHECK_ARG_RET(ctx, ctx, 0);
771+
/* change counter */
772+
ctx->change_count++;
761773

774+
/* module hash */
762775
while ((mod = ly_ctx_get_module_iter(ctx, &i))) {
763776
/* name */
764777
hash = lyht_hash_multi(hash, mod->name, strlen(mod->name));
@@ -779,8 +792,7 @@ ly_ctx_get_modules_hash(const struct ly_ctx *ctx)
779792
hash = lyht_hash_multi(hash, (char *)&mod->implemented, sizeof mod->implemented);
780793
}
781794

782-
hash = lyht_hash_multi(hash, NULL, 0);
783-
return hash;
795+
ctx->mod_hash = lyht_hash_multi(hash, NULL, 0);
784796
}
785797

786798
LIBYANG_API_DEF ly_module_imp_clb

src/ly_common.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ struct ly_ctx {
349349
compilation if ::LY_CTX_EXPLICIT_COMPILE flag is set */
350350
uint16_t change_count; /**< count of changes of the context, on some changes it could be incremented
351351
more times */
352+
uint32_t mod_hash; /**< hash of the current context, includes name/revision/enabled features/implement state
353+
of every loaded module */
352354
uint16_t flags; /**< context settings, see @ref contextoptions */
353355

354356
ly_ext_data_clb ext_clb; /**< optional callback for providing extension-specific run-time data for extensions */
@@ -360,6 +362,13 @@ struct ly_ctx {
360362
struct ly_set plugins_extensions; /**< contets specific set of extension plugins */
361363
};
362364

365+
/**
366+
* @brief Record a change of the context, its modules.
367+
*
368+
* @param[in] ctx Changed context.
369+
*/
370+
void ly_ctx_new_change(struct ly_ctx *ctx);
371+
363372
/**
364373
* @brief Get the (only) implemented YANG module specified by its name.
365374
*

src/schema_compile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,6 @@ lys_compile(struct lys_module *mod, struct lys_depset_unres *unres)
17321732
LYSC_CTX_INIT_PMOD(ctx, sp, NULL);
17331733
ctx.unres = unres;
17341734

1735-
++mod->ctx->change_count;
17361735
mod->compiled = mod_c = calloc(1, sizeof *mod_c);
17371736
LY_CHECK_ERR_RET(!mod_c, LOGMEM(mod->ctx), LY_EMEM);
17381737
mod_c->mod = mod;
@@ -1822,6 +1821,8 @@ lys_compile(struct lys_module *mod, struct lys_depset_unres *unres)
18221821
/* finish compilation for all unresolved module items in the context */
18231822
LY_CHECK_GOTO(ret = lys_compile_unres_mod(&ctx), cleanup);
18241823

1824+
ly_ctx_new_change(mod->ctx);
1825+
18251826
cleanup:
18261827
ly_log_location_revert(0, 0, 1, 0);
18271828
lys_compile_unres_mod_erase(&ctx, ret);

src/tree_schema.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ _lys_set_implemented(struct lys_module *mod, const char **features, struct lys_g
846846
}
847847
}
848848

849-
/* Try to find module with LYS_MOD_IMPORTED_REV flag. */
849+
/* try to find module with LYS_MOD_IMPORTED_REV flag */
850850
i = 0;
851851
while ((mod_iter = ly_ctx_get_module_iter(mod->ctx, &i))) {
852852
if (!strcmp(mod_iter->name, mod->name) && (mod_iter != mod) && (mod_iter->latest_revision & LYS_MOD_IMPORTED_REV)) {
@@ -1198,6 +1198,9 @@ lys_set_implemented(struct lys_module *mod, const char **features)
11981198
lys_unres_glob_erase(unres);
11991199
}
12001200

1201+
/* new context state */
1202+
ly_ctx_new_change(mod->ctx);
1203+
12011204
cleanup:
12021205
if (ret) {
12031206
lys_unres_glob_revert(mod->ctx, unres);
@@ -2190,7 +2193,6 @@ lys_parse_in(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, const st
21902193
/* add into context */
21912194
rc = ly_set_add(&ctx->list, mod, 1, NULL);
21922195
LY_CHECK_GOTO(rc, cleanup);
2193-
ctx->change_count++;
21942196

21952197
/* resolve includes and all imports */
21962198
LY_CHECK_GOTO(rc = lysp_resolve_import_include(pctx, mod->parsed, new_mods), cleanup);
@@ -2299,6 +2301,9 @@ lys_parse(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, const char
22992301
lys_unres_glob_erase(&ctx->unres);
23002302
}
23012303

2304+
/* new context state */
2305+
ly_ctx_new_change(ctx);
2306+
23022307
cleanup:
23032308
if (ret) {
23042309
lys_unres_glob_revert(ctx, &ctx->unres);

0 commit comments

Comments
 (0)