Skip to content

Commit d240097

Browse files
committed
union REFACTOR major refactoring of the functions
1 parent ec28977 commit d240097

4 files changed

Lines changed: 338 additions & 266 deletions

File tree

‎src/ly_common.h‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ struct lysc_node;
6262
#define GETMACRO5(_1, _2, _3, _4, _5, NAME, ...) NAME
6363
#define GETMACRO6(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
6464
#define GETMACRO7(_1, _2, _3, _4, _5, _6, _7, NAME, ...) NAME
65+
#define GETMACRO8(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME
66+
#define GETMACRO9(_1, _2, _3, _4, _5, _6, _7, _8, _9, NAME, ...) NAME
6567

6668
/** optional in POSIX */
6769
#ifndef PATH_MAX
@@ -207,8 +209,14 @@ void ly_log_dbg(uint32_t group, const char *format, ...);
207209
LY_CHECK_ARG_RET1(CTX, ARG5, RETVAL)
208210
#define LY_CHECK_ARG_RET6(CTX, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, RETVAL) LY_CHECK_ARG_RET5(CTX, ARG1, ARG2, ARG3, ARG4, ARG5, RETVAL);\
209211
LY_CHECK_ARG_RET1(CTX, ARG6, RETVAL)
210-
#define LY_CHECK_ARG_RET(CTX, ...) GETMACRO7(__VA_ARGS__, LY_CHECK_ARG_RET6, LY_CHECK_ARG_RET5, LY_CHECK_ARG_RET4, \
211-
LY_CHECK_ARG_RET3, LY_CHECK_ARG_RET2, LY_CHECK_ARG_RET1, DUMMY) (CTX, __VA_ARGS__)
212+
#define LY_CHECK_ARG_RET7(CTX, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, RETVAL)\
213+
LY_CHECK_ARG_RET6(CTX, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, RETVAL);\
214+
LY_CHECK_ARG_RET1(CTX, ARG7, RETVAL)
215+
#define LY_CHECK_ARG_RET8(CTX, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8, RETVAL)\
216+
LY_CHECK_ARG_RET7(CTX, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, RETVAL);\
217+
LY_CHECK_ARG_RET1(CTX, ARG8, RETVAL)
218+
#define LY_CHECK_ARG_RET(CTX, ...) GETMACRO9(__VA_ARGS__, LY_CHECK_ARG_RET8, LY_CHECK_ARG_RET7, LY_CHECK_ARG_RET6, \
219+
LY_CHECK_ARG_RET5, LY_CHECK_ARG_RET4, LY_CHECK_ARG_RET3, LY_CHECK_ARG_RET2, LY_CHECK_ARG_RET1, DUMMY) (CTX, __VA_ARGS__)
212220

213221
#define LY_CHECK_CTX_EQUAL_RET2(FUNC, CTX1, CTX2, RETVAL) if ((CTX1) && (CTX2) && ((CTX1) != (CTX2))) \
214222
{LOGERR(CTX1, LY_EINVAL, "Different contexts mixed in a \"%s\" function call.", FUNC); return RETVAL;}

‎src/plugins_types.h‎

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ LIBYANG_API_DECL LY_ERR lyplg_type_check_value_size(const char *type_name, LY_VA
262262
* @param[in] hints Bitmap of [value hints](@ref lydvalhints) of all the allowed value types provided by parsers
263263
* to ::lyplg_type_store_clb.
264264
* @param[in] value Lexical representation of the value to be stored.
265-
* @param[in] value_len Length (number of bytes) of the given \p value.
265+
* @param[in] value_len Length (number of bytes) of the given @p value.
266266
* @param[in] type Expected base type of the @p value by the caller.
267267
* @param[out] base Pointer to store the numeric base for parsing numeric values using strtol()/strtoll() function.
268268
* Returned (and required) only for numeric @p type values.
@@ -275,6 +275,8 @@ LIBYANG_API_DECL LY_ERR lyplg_type_check_hints(uint32_t hints, const char *value
275275
/**
276276
* @brief Check that the value of a type is allowed based on its status.
277277
*
278+
* Performs the check only if @p format is ::LY_VALUE_SCHEMA.
279+
*
278280
* @param[in] ctx_node Context node (which references the value).
279281
* @param[in] val_flags Flags fo the value.
280282
* @param[in] format Format of the value.
@@ -289,6 +291,8 @@ LIBYANG_API_DECL LY_ERR lyplg_type_check_status(const struct lysc_node *ctx_node
289291
/**
290292
* @brief Check that the lypath instance-identifier value is allowed based on the status of the nodes.
291293
*
294+
* Performs the check only if @p format is ::LY_VALUE_SCHEMA.
295+
*
292296
* @param[in] ctx_node Context node (which references the value).
293297
* @param[in] path Path of the instance-identifier.
294298
* @param[in] format Format of the value.
@@ -412,7 +416,8 @@ LIBYANG_API_DECL void lyplg_type_prefix_data_free(LY_VALUE_FORMAT format, void *
412416
* @param[in] format Input format of the value.
413417
* @param[in] prefix_data Format-specific data for resolving any prefixes (see ly_resolve_prefix()).
414418
* @param[in] ctx_node The @p value schema context node.
415-
* @param[in,out] unres Global unres structure for newly implemented modules.
419+
* @param[in,out] unres Global unres structure for newly implemented modules. Used only if @p options include
420+
* ::LYPLG_TYPE_STORE_IMPLEMENT.
416421
* @param[out] path Pointer to store the created structure representing the schema path from the @p value.
417422
* @param[out] err Pointer to store the error information provided in case of failure.
418423
* @return LY_SUCCESS on success,
@@ -449,38 +454,28 @@ LIBYANG_API_DECL void lyplg_type_lypath_free(struct ly_path *path);
449454
* @brief Store a union value with a specific member type index, keeping that member resolved (pinned),
450455
* so it is not re-resolved to the first matching member during later validation.
451456
*
452-
* Equivalent to storing the value through the member type plugin and then the union type plugin with
453-
* the value in the LYB format, except the caller does not need to handle the binary LYB format at all.
454-
* Meaning of the parameters follows ::lyplg_type_store_clb unless stated otherwise.
455-
*
456-
* Suitable for datastore plugins that persist the resolved member type index of union values and need
457-
* to restore the values resolved as exactly the same member (e.g. when several member types share the
458-
* same base type). The resulting value is identical to a value stored from the LYB format.
457+
* The union value is effectively stored in LYB format.
459458
*
460-
* @param[in] ctx libyang context.
461-
* @param[in] type Union schema type, MUST be a union (basetype ::LY_TYPE_UNION).
462-
* @param[in] type_idx Index of the union member type to use (into ::lysc_type_union::types).
463-
* @param[in] value Value to store, is always consumed.
459+
* @param[in] ctx Context to use.
460+
* @param[in] type Union type to use.
461+
* @param[in] type_idx Index of the union member type to use.
462+
* @param[in] value Value to store as the specific type at @p type_idx.
464463
* @param[in] value_size_bits Size of @p value in bits.
465-
* @param[in] options [Type plugin store options](@ref plugintypestoreopts), may be updated by the member store.
466-
* @param[in] format Input format of @p value, even ::LY_VALUE_LYB of the member type value itself (the
467-
* 1-byte member index prefix is handled internally and must not be included).
464+
* @param[in] options [Type plugin store options](@ref plugintypestoreopts).
465+
* @param[in] format Input format of @p value.
468466
* @param[in] prefix_data Format-specific data for resolving any prefixes (see ly_resolve_prefix()).
469-
* @param[in] hints Bitmap of value hints.
470-
* @param[in] ctx_node The @p value schema context node.
471-
* @param[in,out] storage Value storage to fill identically to ::lyplg_type_store_clb, on failure it is
472-
* freeded and MUST NOT be freed again.
473-
* @param[in,out] unres Global unres structure for newly implemented modules.
467+
* @param[in] hints Bitmap of value hints to use.
468+
* @param[in] ctx_node Schema context node of @p value.
469+
* @param[in,out] storage Value storage to fill.
474470
* @param[out] err Pointer to store the error information provided in case of failure.
475471
* @return LY_SUCCESS on success,
476472
* @return LY_EINCOMPLETE in case the value requires validation of its instance in the data tree,
477-
* @return LY_EVALID in/out-of-range @p type_idx or if the member type does not accept the @p value,
478-
* @return LY_ERR value on other error.
473+
* @return LY_ERR value on error.
479474
*/
480475
LIBYANG_API_DECL LY_ERR lyplg_type_store_union_idx(const struct ly_ctx *ctx, const struct lysc_type *type,
481476
uint32_t type_idx, const void *value, uint64_t value_size_bits, uint32_t options, LY_VALUE_FORMAT format,
482477
void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node, struct lyd_value *storage,
483-
struct lys_glob_unres *unres, struct ly_err_item **err);
478+
struct ly_err_item **err);
484479

485480
/**
486481
* @brief Print xpath1.0 value in the specific format.

0 commit comments

Comments
 (0)