Skip to content

Commit 6fd7764

Browse files
samuel-gauthierrjarry
authored andcommitted
context: add explicit_compile option
Today, loading modules in a context is very slow, because each time a module is added, the whole schema is recompiled. Libyang has a flag to defer the compilation later, when ly_ctx_compile is used. Let's expose this feature. Signed-off-by: Samuel Gauthier <samuel.gauthier@6wind.com>
1 parent d65dcca commit 6fd7764

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

cffi/cdefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ struct lys_module* ly_ctx_load_module(struct ly_ctx *, const char *, const char
205205
struct lys_module* ly_ctx_get_module(const struct ly_ctx *, const char *, const char *);
206206
struct lys_module* ly_ctx_get_module_iter(const struct ly_ctx *, uint32_t *);
207207
struct lys_module* ly_ctx_get_module_latest(const struct ly_ctx *, const char *);
208+
LY_ERR ly_ctx_compile(struct ly_ctx *);
208209

209210
LY_ERR lys_find_xpath(const struct ly_ctx *, const struct lysc_node *, const char *, uint32_t, struct ly_set **);
210211
void ly_set_free(struct ly_set *, void(*)(void *obj));

libyang/context.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def __init__(
2828
self,
2929
search_path: Optional[str] = None,
3030
disable_searchdir_cwd: bool = True,
31+
explicit_compile: Optional[bool] = False,
3132
yanglib_path: Optional[str] = None,
3233
yanglib_fmt: str = "json",
3334
cdata=None, # C type: "struct ly_ctx *"
@@ -39,6 +40,8 @@ def __init__(
3940
options = 0
4041
if disable_searchdir_cwd:
4142
options |= lib.LY_CTX_DISABLE_SEARCHDIR_CWD
43+
if explicit_compile:
44+
options |= lib.LY_CTX_EXPLICIT_COMPILE
4245
# force priv parsed
4346
options |= lib.LY_CTX_SET_PRIV_PARSED
4447

@@ -79,6 +82,11 @@ def __init__(
7982
if not self.cdata:
8083
raise self.error("cannot create context")
8184

85+
def compile_schema(self):
86+
ret = lib.ly_ctx_compile(self.cdata)
87+
if ret != lib.LY_SUCCESS:
88+
raise self.error("could not compile schema")
89+
8290
def get_yanglib_data(self, content_id_format=""):
8391
dnode = ffi.new("struct lyd_node **")
8492
ret = lib.ly_ctx_get_yanglib_data(self.cdata, dnode, str2c(content_id_format))

0 commit comments

Comments
 (0)