Skip to content

Commit 72c3915

Browse files
context: fix creation failure with disable_searchdirs
Since libyang commit be5a07fea89d ("context UPDATE remove binary internal modules"), ly_ctx_new() reads its internal modules from the search dirs. When LY_CTX_DISABLE_SEARCHDIRS is set, it cannot find them and the context is not created. Set the option after the context is created. The internal modules are already loaded at this point, and later module lookups still skip the search dirs. With older libyang, the result is the same. The next commit fixes the same libyang change when the search path does not contain the libyang module dir. Closes: #172 Closes: #173 Suggested-by: Pepa Hajek <hajekpepa@gmail.com> Signed-off-by: Samuel Gauthier <samuel.gauthier@6wind.com>
1 parent 73ce8cd commit 72c3915

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎cffi/cdefs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef enum {
4040
LY_ERR ly_ctx_new(const char *, uint16_t, struct ly_ctx **);
4141
void ly_ctx_destroy(struct ly_ctx *);
4242
int ly_ctx_set_searchdir(struct ly_ctx *, const char *);
43+
LY_ERR ly_ctx_set_options(struct ly_ctx *, uint32_t);
4344

4445
typedef enum
4546
{

‎libyang/context.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ def __init__(
216216
return # already initialized
217217

218218
options = 0
219-
if disable_searchdirs:
220-
options |= lib.LY_CTX_DISABLE_SEARCHDIRS
221219
if disable_searchdir_cwd:
222220
options |= lib.LY_CTX_DISABLE_SEARCHDIR_CWD
223221
if explicit_compile:
@@ -274,6 +272,11 @@ def __init__(
274272
)
275273
if not self.cdata:
276274
raise self.error("cannot create context")
275+
# set after creation, internal modules are loaded from the search dirs
276+
if disable_searchdirs:
277+
ret = lib.ly_ctx_set_options(self.cdata, lib.LY_CTX_DISABLE_SEARCHDIRS)
278+
if ret != lib.LY_SUCCESS:
279+
raise self.error("cannot disable search dirs")
277280
self.external_module_loader = ContextExternalModuleLoader(self.cdata)
278281

279282
def compile_schema(self):

0 commit comments

Comments
 (0)