Skip to content

Commit f69b5a0

Browse files
cristina-defranrjarry
authored andcommitted
Add implementation for lyd_new_meta() as DNode.new_meta()
1 parent 0bcd3fc commit f69b5a0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

cffi/cdefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ LY_ERR lyd_merge_module(struct lyd_node **, const struct lyd_node *, const struc
10021002

10031003
LY_ERR lyd_new_implicit_all(struct lyd_node **, const struct ly_ctx *, uint32_t, struct lyd_node **);
10041004

1005+
LY_ERR lyd_new_meta(const struct ly_ctx *, struct lyd_node *, const struct lys_module *, const char *, const char *, ly_bool, struct lyd_meta **);
10051006

10061007
/* from libc, needed to free allocated strings */
10071008
void free(void *);

libyang/data.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,19 @@ def meta_free(self, name):
256256
lib.lyd_free_meta_single(item)
257257
break
258258

259+
def new_meta(self, name: str, value: str, clear_dflt: bool = False):
260+
ret = lib.lyd_new_meta(
261+
ffi.NULL,
262+
self.cdata,
263+
ffi.NULL,
264+
str2c(name),
265+
str2c(value),
266+
clear_dflt,
267+
ffi.NULL,
268+
)
269+
if ret != lib.LY_SUCCESS:
270+
raise self.context.error("cannot create meta")
271+
259272
def add_defaults(
260273
self,
261274
no_config: bool = False,

0 commit comments

Comments
 (0)