Skip to content

Commit f2852c7

Browse files
committed
cffi: allows to usage of libyang v4.1.0
This patch adjust cffi definitions and also all associated functions based on libyang v4.1.0. Signed-off-by: Stefan Gula <[email protected]>
1 parent 2cae616 commit f2852c7

File tree

6 files changed

+113
-57
lines changed

6 files changed

+113
-57
lines changed

cffi/cdefs.h

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ LY_ERR lyd_print_mem(char **, const struct lyd_node *, LYD_FORMAT, uint32_t);
316316
LY_ERR lyd_print_tree(struct ly_out *, const struct lyd_node *, LYD_FORMAT, uint32_t);
317317
LY_ERR lyd_print_all(struct ly_out *, const struct lyd_node *, LYD_FORMAT, uint32_t);
318318

319-
#define LYD_PARSE_LYB_MOD_UPDATE ...
320319
#define LYD_PARSE_NO_STATE ...
321320
#define LYD_PARSE_STORE_ONLY ...
322321
#define LYD_PARSE_JSON_NULL ...
@@ -350,7 +349,7 @@ LY_ERR ly_out_new_file(FILE *, struct ly_out **);
350349
LY_ERR ly_out_new_fd(int, struct ly_out **);
351350

352351
LY_ERR lyd_parse_data(const struct ly_ctx *, struct lyd_node *, struct ly_in *, LYD_FORMAT, uint32_t, uint32_t, struct lyd_node **);
353-
LY_ERR lyd_parse_op(const struct ly_ctx *, struct lyd_node *, struct ly_in *, LYD_FORMAT, enum lyd_type, struct lyd_node **, struct lyd_node **);
352+
LY_ERR lyd_parse_op(const struct ly_ctx *, struct lyd_node *, struct ly_in *, LYD_FORMAT, enum lyd_type, uint32_t, struct lyd_node **, struct lyd_node **);
354353

355354
typedef enum {
356355
LYS_OUT_UNKNOWN,
@@ -368,6 +367,7 @@ LY_ERR lys_print_module(struct ly_out *, const struct lys_module *, LYS_OUTFORMA
368367

369368
struct lysc_module {
370369
struct lys_module *mod;
370+
const char **features;
371371
struct lysc_node *data;
372372
struct lysc_node_action *rpcs;
373373
struct lysc_node_notif *notifs;
@@ -387,13 +387,15 @@ struct lys_module {
387387
const char *ref;
388388
struct lysp_module *parsed;
389389
struct lysc_module *compiled;
390+
struct lysc_ext *extensions;
390391
struct lysc_ident *identities;
392+
struct lysc_submodule *submodules;
391393
struct lys_module **augmented_by;
392394
struct lys_module **deviated_by;
393395
ly_bool implemented;
394396
ly_bool to_compile;
395-
uint8_t latest_revision;
396-
...;
397+
uint8_t version : 2;
398+
uint8_t latest_revision : 4;
397399
};
398400

399401
struct lysp_module {
@@ -466,12 +468,11 @@ struct lysp_ext_instance {
466468
const char *argument;
467469
LY_VALUE_FORMAT format;
468470
void *prefix_data;
469-
struct lysp_ext *def;
471+
uintptr_t plugin_ref;
470472
void *parent;
471473
enum ly_stmt parent_stmt;
472474
uint64_t parent_stmt_index;
473475
uint16_t flags;
474-
const struct lyplg_ext_record *record;
475476
struct lysp_ext_substmt *substmts;
476477
void *parsed;
477478
struct lysp_stmt *child;
@@ -609,6 +610,11 @@ struct lysp_node_container {
609610
...;
610611
};
611612

613+
struct lysc_value {
614+
const char *str;
615+
struct lysc_prefix *prefixes;
616+
};
617+
612618
struct lysc_node_leaf {
613619
union {
614620
struct lysc_node node;
@@ -622,7 +628,7 @@ struct lysc_node_leaf {
622628
struct lysc_when **when;
623629
struct lysc_type *type;
624630
const char *units;
625-
struct lyd_value *dflt;
631+
struct lysc_value dflt;
626632
...;
627633
};
628634

@@ -652,7 +658,7 @@ struct lysc_node_leaflist {
652658
struct lysc_when **when;
653659
struct lysc_type *type;
654660
const char *units;
655-
struct lyd_value **dflts;
661+
struct lysc_value *dflts;
656662
uint32_t min;
657663
uint32_t max;
658664
...;
@@ -782,7 +788,7 @@ struct lysp_node_augment {
782788
struct lysc_type {
783789
const char *name;
784790
struct lysc_ext_instance *exts;
785-
struct lyplg_type *plugin;
791+
uintptr_t plugin_ref;
786792
LY_DATA_TYPE basetype;
787793
uint32_t refcount;
788794
};
@@ -858,7 +864,7 @@ struct lysc_ext {
858864
const char *name;
859865
const char *argname;
860866
struct lysc_ext_instance *exts;
861-
struct lyplg_ext *plugin;
867+
uintptr_t plugin_ref;
862868
struct lys_module *module;
863869
uint16_t flags;
864870
};
@@ -981,7 +987,6 @@ typedef struct pcre2_real_code pcre2_code;
981987

982988
struct lysc_pattern {
983989
const char *expr;
984-
pcre2_code *code;
985990
const char *dsc;
986991
const char *ref;
987992
const char *emsg;
@@ -1016,7 +1021,7 @@ struct lysc_ident {
10161021
struct lysc_type_num {
10171022
const char *name;
10181023
struct lysc_ext_instance *exts;
1019-
struct lyplg_type *plugin;
1024+
uintptr_t plugin_ref;
10201025
LY_DATA_TYPE basetype;
10211026
uint32_t refcount;
10221027
struct lysc_range *range;
@@ -1025,7 +1030,7 @@ struct lysc_type_num {
10251030
struct lysc_type_dec {
10261031
const char *name;
10271032
struct lysc_ext_instance *exts;
1028-
struct lyplg_type *plugin;
1033+
uintptr_t plugin_ref;
10291034
LY_DATA_TYPE basetype;
10301035
uint32_t refcount;
10311036
uint8_t fraction_digits;
@@ -1035,7 +1040,7 @@ struct lysc_type_dec {
10351040
struct lysc_type_str {
10361041
const char *name;
10371042
struct lysc_ext_instance *exts;
1038-
struct lyplg_type *plugin;
1043+
uintptr_t plugin_ref;
10391044
LY_DATA_TYPE basetype;
10401045
uint32_t refcount;
10411046
struct lysc_range *length;
@@ -1057,7 +1062,7 @@ struct lysc_type_bitenum_item {
10571062
struct lysc_type_enum {
10581063
const char *name;
10591064
struct lysc_ext_instance *exts;
1060-
struct lyplg_type *plugin;
1065+
uintptr_t plugin_ref;
10611066
LY_DATA_TYPE basetype;
10621067
uint32_t refcount;
10631068
struct lysc_type_bitenum_item *enums;
@@ -1066,7 +1071,7 @@ struct lysc_type_enum {
10661071
struct lysc_type_bits {
10671072
const char *name;
10681073
struct lysc_ext_instance *exts;
1069-
struct lyplg_type *plugin;
1074+
uintptr_t plugin_ref;
10701075
LY_DATA_TYPE basetype;
10711076
uint32_t refcount;
10721077
struct lysc_type_bitenum_item *bits;
@@ -1075,7 +1080,7 @@ struct lysc_type_bits {
10751080
struct lysc_type_leafref {
10761081
const char *name;
10771082
struct lysc_ext_instance *exts;
1078-
struct lyplg_type *plugin;
1083+
uintptr_t plugin_ref;
10791084
LY_DATA_TYPE basetype;
10801085
uint32_t refcount;
10811086
struct lyxp_expr *path;
@@ -1087,7 +1092,7 @@ struct lysc_type_leafref {
10871092
struct lysc_type_identityref {
10881093
const char *name;
10891094
struct lysc_ext_instance *exts;
1090-
struct lyplg_type *plugin;
1095+
uintptr_t plugin_ref;
10911096
LY_DATA_TYPE basetype;
10921097
uint32_t refcount;
10931098
struct lysc_ident **bases;
@@ -1096,7 +1101,7 @@ struct lysc_type_identityref {
10961101
struct lysc_type_instanceid {
10971102
const char *name;
10981103
struct lysc_ext_instance *exts;
1099-
struct lyplg_type *plugin;
1104+
uintptr_t plugin_ref;
11001105
LY_DATA_TYPE basetype;
11011106
uint32_t refcount;
11021107
uint8_t require_instance;
@@ -1105,7 +1110,7 @@ struct lysc_type_instanceid {
11051110
struct lysc_type_union {
11061111
const char *name;
11071112
struct lysc_ext_instance *exts;
1108-
struct lyplg_type *plugin;
1113+
uintptr_t plugin_ref;
11091114
LY_DATA_TYPE basetype;
11101115
uint32_t refcount;
11111116
struct lysc_type **types;
@@ -1114,7 +1119,7 @@ struct lysc_type_union {
11141119
struct lysc_type_bin {
11151120
const char *name;
11161121
struct lysc_ext_instance *exts;
1117-
struct lyplg_type *plugin;
1122+
uintptr_t plugin_ref;
11181123
LY_DATA_TYPE basetype;
11191124
uint32_t refcount;
11201125
struct lysc_range *length;
@@ -1158,16 +1163,14 @@ typedef enum {
11581163
LYD_ANYDATA_DATATREE,
11591164
LYD_ANYDATA_STRING,
11601165
LYD_ANYDATA_XML,
1161-
LYD_ANYDATA_JSON,
1162-
LYD_ANYDATA_LYB
1166+
LYD_ANYDATA_JSON
11631167
} LYD_ANYDATA_VALUETYPE;
11641168

11651169
union lyd_any_value {
11661170
struct lyd_node *tree;
11671171
const char *str;
11681172
const char *xml;
11691173
const char *json;
1170-
char *mem;
11711174
};
11721175

11731176
struct lyd_node_any {
@@ -1319,6 +1322,8 @@ struct lyd_attr {
13191322
LY_ERR lyd_new_attr(struct lyd_node *, const char *, const char *, const char *, struct lyd_attr **);
13201323
void lyd_free_attr_single(const struct ly_ctx *ctx, struct lyd_attr *attr);
13211324

1325+
LY_ERR lyd_value_validate_dflt(const struct lysc_node *, const char *, struct lysc_prefix *, const struct lyd_node *, const struct lysc_type **, const char **);
1326+
13221327
struct lyd_leafref_links_rec {
13231328
const struct lyd_node_term *node;
13241329
const struct lyd_node_term **leafref_nodes;
@@ -1327,13 +1332,14 @@ struct lyd_leafref_links_rec {
13271332

13281333
LY_ERR lyd_leafref_get_links(const struct lyd_node_term *, const struct lyd_leafref_links_rec **);
13291334
LY_ERR lyd_leafref_link_node_tree(struct lyd_node *);
1335+
struct lyplg_ext *lysc_get_ext_plugin(uintptr_t);
13301336
const char *lyplg_ext_stmt2str(enum ly_stmt stmt);
13311337
const struct lysp_module *lyplg_ext_parse_get_cur_pmod(const struct lysp_ctx *);
13321338
struct ly_ctx *lyplg_ext_compile_get_ctx(const struct lysc_ctx *);
13331339
void lyplg_ext_parse_log(const struct lysp_ctx *, const struct lysp_ext_instance *, LY_LOG_LEVEL, LY_ERR, const char *, ...);
13341340
void lyplg_ext_compile_log(const struct lysc_ctx *, const struct lysc_ext_instance *, LY_LOG_LEVEL, LY_ERR, const char *, ...);
13351341
LY_ERR lyplg_ext_parse_extension_instance(struct lysp_ctx *, struct lysp_ext_instance *);
1336-
LY_ERR lyplg_ext_compile_extension_instance(struct lysc_ctx *, const struct lysp_ext_instance *, struct lysc_ext_instance *);
1342+
LY_ERR lyplg_ext_compile_extension_instance(struct lysc_ctx *, const struct lysp_ext_instance *, struct lysc_ext_instance *, struct lysc_node *);
13371343
void lyplg_ext_pfree_instance_substatements(const struct ly_ctx *ctx, struct lysp_ext_substmt *substmts);
13381344
void lyplg_ext_cfree_instance_substatements(const struct ly_ctx *ctx, struct lysc_ext_substmt *substmts);
13391345
typedef LY_ERR (*lyplg_ext_parse_clb)(struct lysp_ctx *, struct lysp_ext_instance *);

cffi/source.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
#include <libyang/libyang.h>
77
#include <libyang/version.h>
88

9-
#if LY_VERSION_MAJOR * 10000 + LY_VERSION_MINOR * 100 + LY_VERSION_MICRO < 30801
10-
#error "This version of libyang bindings only works with libyang soversion 3.8.1+"
9+
#if LY_VERSION_MAJOR * 10000 + LY_VERSION_MINOR * 100 + LY_VERSION_MICRO < 40100
10+
#error "This version of libyang bindings only works with libyang soversion 4.1.0+"
1111
#endif

libyang/context.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ def parse_op(
536536
in_data: Union[IO, str],
537537
dtype: DataType,
538538
parent: DNode = None,
539+
opaq: bool = False,
540+
strict: bool = False,
539541
) -> DNode:
540542
fmt = data_format(fmt)
541543
data = ffi.new("struct ly_in **")
@@ -545,13 +547,14 @@ def parse_op(
545547
if ret != lib.LY_SUCCESS:
546548
raise self.error("failed to read input data")
547549

550+
flags = parser_flags(opaq=opaq, strict=strict)
548551
tree = ffi.new("struct lyd_node **", ffi.NULL)
549552
op = ffi.new("struct lyd_node **", ffi.NULL)
550553
par = ffi.new("struct lyd_node **", ffi.NULL)
551554
if parent is not None:
552555
par[0] = parent.cdata
553556

554-
ret = lib.lyd_parse_op(self.cdata, par[0], data[0], fmt, dtype, tree, op)
557+
ret = lib.lyd_parse_op(self.cdata, par[0], data[0], fmt, dtype, flags, tree, op)
555558
lib.ly_in_free(data[0], 0)
556559
if ret != lib.LY_SUCCESS:
557560
raise self.error("failed to parse input data")
@@ -564,9 +567,17 @@ def parse_op_mem(
564567
data: str,
565568
dtype: DataType = DataType.DATA_YANG,
566569
parent: DNode = None,
570+
opaq: bool = False,
571+
strict: bool = False,
567572
):
568573
return self.parse_op(
569-
fmt, in_type=IOType.MEMORY, in_data=data, dtype=dtype, parent=parent
574+
fmt,
575+
in_type=IOType.MEMORY,
576+
in_data=data,
577+
dtype=dtype,
578+
parent=parent,
579+
opaq=opaq,
580+
strict=strict,
570581
)
571582

572583
def parse_data(
@@ -575,7 +586,6 @@ def parse_data(
575586
in_type: IOType,
576587
in_data: Union[str, bytes, IO],
577588
parent: DNode = None,
578-
lyb_mod_update: bool = False,
579589
no_state: bool = False,
580590
parse_only: bool = False,
581591
opaq: bool = False,
@@ -590,7 +600,6 @@ def parse_data(
590600
if self.cdata is None:
591601
raise RuntimeError("context already destroyed")
592602
parser_flgs = parser_flags(
593-
lyb_mod_update=lyb_mod_update,
594603
no_state=no_state,
595604
parse_only=parse_only,
596605
opaq=opaq,
@@ -648,7 +657,6 @@ def parse_data_mem(
648657
data: Union[str, bytes],
649658
fmt: str,
650659
parent: DNode = None,
651-
lyb_mod_update: bool = False,
652660
no_state: bool = False,
653661
parse_only: bool = False,
654662
opaq: bool = False,
@@ -665,7 +673,6 @@ def parse_data_mem(
665673
in_type=IOType.MEMORY,
666674
in_data=data,
667675
parent=parent,
668-
lyb_mod_update=lyb_mod_update,
669676
no_state=no_state,
670677
parse_only=parse_only,
671678
opaq=opaq,
@@ -683,7 +690,6 @@ def parse_data_file(
683690
fileobj: IO,
684691
fmt: str,
685692
parent: DNode = None,
686-
lyb_mod_update: bool = False,
687693
no_state: bool = False,
688694
parse_only: bool = False,
689695
opaq: bool = False,
@@ -700,7 +706,6 @@ def parse_data_file(
700706
in_type=IOType.FD,
701707
in_data=fileobj,
702708
parent=parent,
703-
lyb_mod_update=lyb_mod_update,
704709
no_state=no_state,
705710
parse_only=parse_only,
706711
opaq=opaq,

libyang/data.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ def newval_flags(
109109

110110
# -------------------------------------------------------------------------------------
111111
def parser_flags(
112-
lyb_mod_update: bool = False,
113112
no_state: bool = False,
114113
parse_only: bool = False,
115114
opaq: bool = False,
@@ -120,8 +119,6 @@ def parser_flags(
120119
json_string_datatypes: bool = False,
121120
) -> int:
122121
flags = 0
123-
if lyb_mod_update:
124-
flags |= lib.LYD_PARSE_LYB_MOD_UPDATE
125122
if no_state:
126123
flags |= lib.LYD_PARSE_NO_STATE
127124
if parse_only:

0 commit comments

Comments
 (0)