Skip to content

Commit bb7af76

Browse files
committed
extension: update the logic based on libyang v4
This patch updates the logic of extension to use updated version of libyang v4 API Signed-off-by: Stefan Gula <[email protected]>
1 parent d7b5fb4 commit bb7af76

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

cffi/cdefs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,11 @@ struct lysp_ext_instance {
467467
const char *argument;
468468
LY_VALUE_FORMAT format;
469469
void *prefix_data;
470-
struct lysp_ext *def;
470+
uintptr_t plugin_ref;
471471
void *parent;
472472
enum ly_stmt parent_stmt;
473473
uint64_t parent_stmt_index;
474474
uint16_t flags;
475-
const struct lyplg_ext_record *record;
476475
struct lysp_ext_substmt *substmts;
477476
void *parsed;
478477
struct lysp_stmt *child;
@@ -1325,13 +1324,14 @@ struct lyd_leafref_links_rec {
13251324

13261325
LY_ERR lyd_leafref_get_links(const struct lyd_node_term *, const struct lyd_leafref_links_rec **);
13271326
LY_ERR lyd_leafref_link_node_tree(struct lyd_node *);
1327+
struct lyplg_ext *lysc_get_ext_plugin(uintptr_t);
13281328
const char *lyplg_ext_stmt2str(enum ly_stmt stmt);
13291329
const struct lysp_module *lyplg_ext_parse_get_cur_pmod(const struct lysp_ctx *);
13301330
struct ly_ctx *lyplg_ext_compile_get_ctx(const struct lysc_ctx *);
13311331
void lyplg_ext_parse_log(const struct lysp_ctx *, const struct lysp_ext_instance *, LY_LOG_LEVEL, LY_ERR, const char *, ...);
13321332
void lyplg_ext_compile_log(const struct lysc_ctx *, const struct lysc_ext_instance *, LY_LOG_LEVEL, LY_ERR, const char *, ...);
13331333
LY_ERR lyplg_ext_parse_extension_instance(struct lysp_ctx *, struct lysp_ext_instance *);
1334-
LY_ERR lyplg_ext_compile_extension_instance(struct lysc_ctx *, const struct lysp_ext_instance *, struct lysc_ext_instance *);
1334+
LY_ERR lyplg_ext_compile_extension_instance(struct lysc_ctx *, const struct lysp_ext_instance *, struct lysc_ext_instance *, struct lysc_node *);
13351335
void lyplg_ext_pfree_instance_substatements(const struct ly_ctx *ctx, struct lysp_ext_substmt *substmts);
13361336
void lyplg_ext_cfree_instance_substatements(const struct ly_ctx *ctx, struct lysc_ext_substmt *substmts);
13371337
typedef LY_ERR (*lyplg_ext_parse_clb)(struct lysp_ctx *, struct lysp_ext_instance *);

libyang/extension.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from _libyang import ffi, lib
99
from .context import Context
1010
from .log import get_libyang_level
11-
from .schema import ExtensionCompiled, ExtensionParsed, Module
11+
from .schema import ExtensionCompiled, ExtensionParsed, Module, SNode
1212
from .util import LibyangError, c2str, str2c
1313

1414

@@ -25,7 +25,7 @@ def __init__(self, message: str, ret: int, log_level: int) -> None:
2525

2626
@ffi.def_extern(name="lypy_lyplg_ext_parse_clb")
2727
def libyang_c_lyplg_ext_parse_clb(pctx, pext):
28-
plugin = extensions_plugins[pext.record.plugin]
28+
plugin = extensions_plugins[lib.lysc_get_ext_plugin(pext.plugin_ref)]
2929
module_cdata = lib.lyplg_ext_parse_get_cur_pmod(pctx).mod
3030
context = Context(cdata=module_cdata.ctx)
3131
module = Module(context, module_cdata)
@@ -46,7 +46,7 @@ def libyang_c_lyplg_ext_parse_clb(pctx, pext):
4646

4747
@ffi.def_extern(name="lypy_lyplg_ext_compile_clb")
4848
def libyang_c_lyplg_ext_compile_clb(cctx, pext, cext):
49-
plugin = extensions_plugins[pext.record.plugin]
49+
plugin = extensions_plugins[lib.lysc_get_ext_plugin(pext.plugin_ref)]
5050
context = Context(cdata=lib.lyplg_ext_compile_get_ctx(cctx))
5151
module = Module(context, cext.module)
5252
parsed_ext = ExtensionParsed(context, pext, module)
@@ -67,7 +67,7 @@ def libyang_c_lyplg_ext_compile_clb(cctx, pext, cext):
6767

6868
@ffi.def_extern(name="lypy_lyplg_ext_parse_free_clb")
6969
def libyang_c_lyplg_ext_parse_free_clb(ctx, pext):
70-
plugin = extensions_plugins[pext.record.plugin]
70+
plugin = extensions_plugins[lib.lysc_get_ext_plugin(pext.plugin_ref)]
7171
context = Context(cdata=ctx)
7272
parsed_ext = ExtensionParsed(context, pext, None)
7373
plugin.parse_free_clb(parsed_ext)
@@ -200,9 +200,17 @@ def set_compile_ctx(self, cctx) -> None:
200200
def parse_substmts(self, ext: ExtensionParsed) -> int:
201201
return lib.lyplg_ext_parse_extension_instance(self._pctx, ext.cdata)
202202

203-
def compile_substmts(self, pext: ExtensionParsed, cext: ExtensionCompiled) -> int:
203+
def compile_substmts(
204+
self,
205+
pext: ExtensionParsed,
206+
cext: ExtensionCompiled,
207+
parent: Optional[SNode] = None,
208+
) -> int:
204209
return lib.lyplg_ext_compile_extension_instance(
205-
self._cctx, pext.cdata, cext.cdata
210+
self._cctx,
211+
pext.cdata,
212+
cext.cdata,
213+
ffi.NULL if parent is None else parent.cdata,
206214
)
207215

208216
def free_parse_substmts(self, ext: ExtensionParsed) -> None:

0 commit comments

Comments
 (0)