Skip to content

Commit d3b351a

Browse files
irfanHaslandedIrfanMohammad
and
IrfanMohammad
authored
tree data UPDATE standard functions from static functions (#2101)
We need certain functions to be exposed via a public API to make it possible to use in other languages such as Rust. lyd_parent, lyd_child, and lyd_get_value are defined as static inline and is difficult for tools to wrap them. Co-authored-by: IrfanMohammad <[email protected]>
1 parent 0119b92 commit d3b351a

File tree

2 files changed

+55
-49
lines changed

2 files changed

+55
-49
lines changed

src/tree_data.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3056,3 +3056,55 @@ lyd_find_target(const struct ly_path *path, const struct lyd_node *tree, struct
30563056
}
30573057
return LY_SUCCESS;
30583058
}
3059+
3060+
LIBYANG_API_DEF struct lyd_node *
3061+
lyd_parent(const struct lyd_node *node)
3062+
{
3063+
if (!node || !node->parent) {
3064+
return NULL;
3065+
}
3066+
3067+
return &node->parent->node;
3068+
}
3069+
3070+
LIBYANG_API_DEF struct lyd_node *
3071+
lyd_child(const struct lyd_node *node)
3072+
{
3073+
if (!node) {
3074+
return NULL;
3075+
}
3076+
3077+
if (!node->schema) {
3078+
/* opaq node */
3079+
return ((const struct lyd_node_opaq *)node)->child;
3080+
}
3081+
3082+
switch (node->schema->nodetype) {
3083+
case LYS_CONTAINER:
3084+
case LYS_LIST:
3085+
case LYS_RPC:
3086+
case LYS_ACTION:
3087+
case LYS_NOTIF:
3088+
return ((const struct lyd_node_inner *)node)->child;
3089+
default:
3090+
return NULL;
3091+
}
3092+
}
3093+
3094+
LIBYANG_API_DEF const char *
3095+
lyd_get_value(const struct lyd_node *node)
3096+
{
3097+
if (!node) {
3098+
return NULL;
3099+
}
3100+
3101+
if (!node->schema) {
3102+
return ((const struct lyd_node_opaq *)node)->value;
3103+
} else if (node->schema->nodetype & LYD_NODE_TERM) {
3104+
const struct lyd_value *value = &((const struct lyd_node_term *)node)->value;
3105+
3106+
return value->_canonical ? value->_canonical : lyd_value_get_canonical(LYD_CTX(node), value);
3107+
}
3108+
3109+
return NULL;
3110+
}

src/tree_data.h

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,15 +1004,7 @@ struct lyd_node_opaq {
10041004
* @return Pointer to the parent node of the @p node.
10051005
* @return NULL in case of the top-level node or if the @p node is NULL itself.
10061006
*/
1007-
static inline struct lyd_node *
1008-
lyd_parent(const struct lyd_node *node)
1009-
{
1010-
if (!node || !node->parent) {
1011-
return NULL;
1012-
}
1013-
1014-
return &node->parent->node;
1015-
}
1007+
LIBYANG_API_DECL struct lyd_node *lyd_parent(const struct lyd_node *node);
10161008

10171009
/**
10181010
* @brief Get the child pointer of a generic data node.
@@ -1024,29 +1016,7 @@ lyd_parent(const struct lyd_node *node)
10241016
* @param[in] node Node to use.
10251017
* @return Pointer to the first child node (if any) of the @p node.
10261018
*/
1027-
static inline struct lyd_node *
1028-
lyd_child(const struct lyd_node *node)
1029-
{
1030-
if (!node) {
1031-
return NULL;
1032-
}
1033-
1034-
if (!node->schema) {
1035-
/* opaq node */
1036-
return ((const struct lyd_node_opaq *)node)->child;
1037-
}
1038-
1039-
switch (node->schema->nodetype) {
1040-
case LYS_CONTAINER:
1041-
case LYS_LIST:
1042-
case LYS_RPC:
1043-
case LYS_ACTION:
1044-
case LYS_NOTIF:
1045-
return ((const struct lyd_node_inner *)node)->child;
1046-
default:
1047-
return NULL;
1048-
}
1049-
}
1019+
LIBYANG_API_DECL struct lyd_node *lyd_child(const struct lyd_node *node);
10501020

10511021
/**
10521022
* @brief Get the child pointer of a generic data node but skip its keys in case it is ::LYS_LIST.
@@ -1141,23 +1111,7 @@ LIBYANG_API_DECL const char *lyd_value_get_canonical(const struct ly_ctx *ctx, c
11411111
* @param[in] node Data node to use.
11421112
* @return Canonical value.
11431113
*/
1144-
static inline const char *
1145-
lyd_get_value(const struct lyd_node *node)
1146-
{
1147-
if (!node) {
1148-
return NULL;
1149-
}
1150-
1151-
if (!node->schema) {
1152-
return ((const struct lyd_node_opaq *)node)->value;
1153-
} else if (node->schema->nodetype & LYD_NODE_TERM) {
1154-
const struct lyd_value *value = &((const struct lyd_node_term *)node)->value;
1155-
1156-
return value->_canonical ? value->_canonical : lyd_value_get_canonical(LYD_CTX(node), value);
1157-
}
1158-
1159-
return NULL;
1160-
}
1114+
LIBYANG_API_DECL const char *lyd_get_value(const struct lyd_node *node);
11611115

11621116
/**
11631117
* @brief Get anydata string value.

0 commit comments

Comments
 (0)