Skip to content

Commit

Permalink
plugins REFACTOR s/plugin_id/plugin_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
roman committed Jan 22, 2025
1 parent f5b9361 commit 750c5f3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
27 changes: 14 additions & 13 deletions src/plugins.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,42 +135,43 @@ static struct ly_set plugins_extensions = {0};
/**
* @brief Get the plugin of the given @p type.
*
* @param[in] plugin_id Either an index of the built-in plugin (offset by +1) or a pointer to the external plugin.
* @param[in] plugin_ref Reference to a plugin. Either an index of a built-in plugin (offset by +1)
* or a pointer to an external plugin.
* @param[in] type Type of the plugin to get.
* @param[in] plugins Array of the built-in plugins used in case @p plugin_id is an index of a built-in plugin.
* @param[in] plugins Array of the built-in plugins used in case @p plugin_ref is an index of a built-in plugin.
* @return Plugin of the given @p type or NULL if not found.
*/
static void *
lysc_get_plugin(uintptr_t plugin_id, enum LYPLG type, const struct ly_set *plugins)
lysc_get_plugin(uintptr_t plugin_ref, enum LYPLG type, const struct ly_set *plugins)
{
/* plugin_id is offset by +1, so 0 is invalid (NULL ptr equivalent) */
if (!plugin_id) {
/* plugin_ref is offset by +1, so 0 is invalid (NULL ptr equivalent) */
if (!plugin_ref) {
return NULL;
}

if (plugin_id <= plugins->count) {
if (plugin_ref <= plugins->count) {
/* plugin is built-in, fetch it from the global list */
if (type == LYPLG_EXTENSION) {
return &((struct lyplg_ext_record *)plugins->objs[plugin_id - 1])->plugin;
return &((struct lyplg_ext_record *)plugins->objs[plugin_ref - 1])->plugin;
} else {
return &((struct lyplg_type_record *)plugins->objs[plugin_id - 1])->plugin;
return &((struct lyplg_type_record *)plugins->objs[plugin_ref - 1])->plugin;
}
} else {
/* plugin is external, return the pointer */
return (void *)plugin_id;
return (void *)plugin_ref;
}
}

LIBYANG_API_DEF struct lyplg_type *
lysc_get_type_plugin(uintptr_t plugin_id)
lysc_get_type_plugin(uintptr_t plugin_ref)
{
return lysc_get_plugin(plugin_id, LYPLG_TYPE, &plugins_types);
return lysc_get_plugin(plugin_ref, LYPLG_TYPE, &plugins_types);
}

LIBYANG_API_DEF struct lyplg_ext *
lysc_get_ext_plugin(uintptr_t plugin_id)
lysc_get_ext_plugin(uintptr_t plugin_ref)
{
return lysc_get_plugin(plugin_id, LYPLG_EXTENSION, &plugins_extensions);
return lysc_get_plugin(plugin_ref, LYPLG_EXTENSION, &plugins_extensions);
}

/**
Expand Down
30 changes: 15 additions & 15 deletions src/schema_compile_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ lys_new_type(const struct ly_ctx *ctx, LY_DATA_TYPE basetype, const char *tpdf_n
* @param[in] basetype Base YANG built-in type of the type to compile.
* @param[in] tpdfname Name of the type's typedef, serves as a flag - if it is leaf/leaf-list's type, it is NULL.
* @param[in] base Latest base (compiled) type from which the current type is being derived.
* @param[in] plugin Type plugin to use.
* @param[in] plugin_ref Reference to the type plugin to use.
* @param[in] tpdf_chain Chain of the used typedefs, traversed backwards.
* @param[in] tpdf_chain_last Index of the last (backwards) typedef in @p tpdf_chain to use.
* @param[out] type Compiled type.
Expand All @@ -1773,7 +1773,7 @@ lys_new_type(const struct ly_ctx *ctx, LY_DATA_TYPE basetype, const char *tpdf_n
static LY_ERR
lys_compile_type_(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t context_flags, const char *context_name,
const struct lysp_type *type_p, LY_DATA_TYPE basetype, const char *tpdfname, const struct lysc_type *base,
uintptr_t plugin, struct ly_set *tpdf_chain, uint32_t tpdf_chain_last, struct lysc_type **type)
uintptr_t plugin_ref, struct ly_set *tpdf_chain, uint32_t tpdf_chain_last, struct lysc_type **type)
{
LY_ERR rc = LY_SUCCESS;
struct lysc_type_bin *bin;
Expand All @@ -1794,7 +1794,7 @@ lys_compile_type_(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_
LY_CHECK_GOTO(rc, cleanup);

(*type)->basetype = basetype;
(*type)->plugin = plugin;
(*type)->plugin = plugin_ref;

switch (basetype) {
case LY_TYPE_BINARY:
Expand Down Expand Up @@ -2141,7 +2141,7 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t
struct lysc_type_union *base_un;
LY_ARRAY_COUNT_TYPE u;
struct ly_set tpdf_chain = {0};
uintptr_t plugin_id = 0;
uintptr_t plugin_ref = 0;

*type = NULL;
if (dflt) {
Expand Down Expand Up @@ -2264,19 +2264,19 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t
}

/* try to find loaded user type plugins */
plugin_id = lyplg_type_plugin_find(ctx->ctx, tctx->tpdf->type.pmod->mod->name, tctx->tpdf->type.pmod->mod->revision,
plugin_ref = lyplg_type_plugin_find(ctx->ctx, tctx->tpdf->type.pmod->mod->name, tctx->tpdf->type.pmod->mod->revision,
tctx->tpdf->name);
if (!plugin_id && base) {
plugin_id = base->plugin;
if (!plugin_ref && base) {
plugin_ref = base->plugin;
}
if (!plugin_id) {
if (!plugin_ref) {
/* use the internal built-in type implementation */
plugin_id = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]);
plugin_ref = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]);
}
assert(plugin_id);
assert(plugin_ref);

if ((basetype != LY_TYPE_LEAFREF) && (u != tpdf_chain.count - 1) && !tctx->tpdf->type.flags &&
!tctx->tpdf->type.exts && (plugin_id == base->plugin)) {
!tctx->tpdf->type.exts && (plugin_ref == base->plugin)) {
/* no change, reuse the compiled base */
((struct lysp_tpdf *)tctx->tpdf)->type.compiled = base;
LY_ATOMIC_INC_BARRIER(base->refcount);
Expand All @@ -2297,7 +2297,7 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t

/* compile the typedef type */
ret = lys_compile_type_(ctx, tctx->node, tctx->tpdf->flags, tctx->tpdf->name, &tctx->tpdf->type, basetype,
tctx->tpdf->name, base, plugin_id, &tpdf_chain, u + 1, &base);
tctx->tpdf->name, base, plugin_ref, &tpdf_chain, u + 1, &base);
LY_CHECK_GOTO(ret, cleanup);

/* store separately compiled typedef type to be reused */
Expand Down Expand Up @@ -2329,12 +2329,12 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t
if (type_p->flags || type_p->exts || !base || has_leafref) {
/* leaf type has changes that need to be compiled into the type */
if (base) {
plugin_id = base->plugin;
plugin_ref = base->plugin;
} else {
plugin_id = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]);
plugin_ref = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]);
}
ret = lys_compile_type_(ctx, context_pnode, context_flags, context_name, (struct lysp_type *)type_p, basetype,
NULL, base, plugin_id, &tpdf_chain, 0, type);
NULL, base, plugin_ref, &tpdf_chain, 0, type);
LY_CHECK_GOTO(ret, cleanup);
} else {
/* no changes of the type in the leaf, just use the base compiled type */
Expand Down
12 changes: 6 additions & 6 deletions src/tree_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -1800,20 +1800,20 @@ struct lysc_module {
/**
* @brief Get a type plugin.
*
* @param[in] plugin_id Either an index in the type plugins array (e.g. 1 -> binary type)
* or a pointer to the user defined plugin. Indexes start at 1.
* @param[in] plugin_ref Reference to a type plugin. Either an index in the type plugins
* array (e.g. 1 -> binary type) or a pointer to the user defined plugin. Indexes start at 1.
* @return Type plugin or NULL.
*/
LIBYANG_API_DECL struct lyplg_type *lysc_get_type_plugin(uintptr_t plugin_id);
LIBYANG_API_DECL struct lyplg_type *lysc_get_type_plugin(uintptr_t plugin_ref);

/**
* @brief Get an extension plugin.
*
* @param[in] plugin_id Either an index in the extension plugins array (e.g. 1 -> metadata extension)
* or a pointer to the user defined plugin. Indexes start at 1.
* @param[in] plugin_ref Reference to an extension plugin. Either an index in the extension plugins
* array (e.g. 1 -> metadata extension) or a pointer to the user defined plugin. Indexes start at 1.
* @return Extension plugin or NULL.
*/
LIBYANG_API_DECL struct lyplg_ext *lysc_get_ext_plugin(uintptr_t plugin_id);
LIBYANG_API_DECL struct lyplg_ext *lysc_get_ext_plugin(uintptr_t plugin_ref);

/**
* @brief Get nearest @p schema parent (including the node itself) that can be instantiated in data.
Expand Down

0 comments on commit 750c5f3

Please sign in to comment.