Skip to content

Commit 750c5f3

Browse files
author
roman
committed
plugins REFACTOR s/plugin_id/plugin_ref
1 parent f5b9361 commit 750c5f3

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

src/plugins.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,42 +135,43 @@ static struct ly_set plugins_extensions = {0};
135135
/**
136136
* @brief Get the plugin of the given @p type.
137137
*
138-
* @param[in] plugin_id Either an index of the built-in plugin (offset by +1) or a pointer to the external plugin.
138+
* @param[in] plugin_ref Reference to a plugin. Either an index of a built-in plugin (offset by +1)
139+
* or a pointer to an external plugin.
139140
* @param[in] type Type of the plugin to get.
140-
* @param[in] plugins Array of the built-in plugins used in case @p plugin_id is an index of a built-in plugin.
141+
* @param[in] plugins Array of the built-in plugins used in case @p plugin_ref is an index of a built-in plugin.
141142
* @return Plugin of the given @p type or NULL if not found.
142143
*/
143144
static void *
144-
lysc_get_plugin(uintptr_t plugin_id, enum LYPLG type, const struct ly_set *plugins)
145+
lysc_get_plugin(uintptr_t plugin_ref, enum LYPLG type, const struct ly_set *plugins)
145146
{
146-
/* plugin_id is offset by +1, so 0 is invalid (NULL ptr equivalent) */
147-
if (!plugin_id) {
147+
/* plugin_ref is offset by +1, so 0 is invalid (NULL ptr equivalent) */
148+
if (!plugin_ref) {
148149
return NULL;
149150
}
150151

151-
if (plugin_id <= plugins->count) {
152+
if (plugin_ref <= plugins->count) {
152153
/* plugin is built-in, fetch it from the global list */
153154
if (type == LYPLG_EXTENSION) {
154-
return &((struct lyplg_ext_record *)plugins->objs[plugin_id - 1])->plugin;
155+
return &((struct lyplg_ext_record *)plugins->objs[plugin_ref - 1])->plugin;
155156
} else {
156-
return &((struct lyplg_type_record *)plugins->objs[plugin_id - 1])->plugin;
157+
return &((struct lyplg_type_record *)plugins->objs[plugin_ref - 1])->plugin;
157158
}
158159
} else {
159160
/* plugin is external, return the pointer */
160-
return (void *)plugin_id;
161+
return (void *)plugin_ref;
161162
}
162163
}
163164

164165
LIBYANG_API_DEF struct lyplg_type *
165-
lysc_get_type_plugin(uintptr_t plugin_id)
166+
lysc_get_type_plugin(uintptr_t plugin_ref)
166167
{
167-
return lysc_get_plugin(plugin_id, LYPLG_TYPE, &plugins_types);
168+
return lysc_get_plugin(plugin_ref, LYPLG_TYPE, &plugins_types);
168169
}
169170

170171
LIBYANG_API_DEF struct lyplg_ext *
171-
lysc_get_ext_plugin(uintptr_t plugin_id)
172+
lysc_get_ext_plugin(uintptr_t plugin_ref)
172173
{
173-
return lysc_get_plugin(plugin_id, LYPLG_EXTENSION, &plugins_extensions);
174+
return lysc_get_plugin(plugin_ref, LYPLG_EXTENSION, &plugins_extensions);
174175
}
175176

176177
/**

src/schema_compile_node.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ lys_new_type(const struct ly_ctx *ctx, LY_DATA_TYPE basetype, const char *tpdf_n
17641764
* @param[in] basetype Base YANG built-in type of the type to compile.
17651765
* @param[in] tpdfname Name of the type's typedef, serves as a flag - if it is leaf/leaf-list's type, it is NULL.
17661766
* @param[in] base Latest base (compiled) type from which the current type is being derived.
1767-
* @param[in] plugin Type plugin to use.
1767+
* @param[in] plugin_ref Reference to the type plugin to use.
17681768
* @param[in] tpdf_chain Chain of the used typedefs, traversed backwards.
17691769
* @param[in] tpdf_chain_last Index of the last (backwards) typedef in @p tpdf_chain to use.
17701770
* @param[out] type Compiled type.
@@ -1773,7 +1773,7 @@ lys_new_type(const struct ly_ctx *ctx, LY_DATA_TYPE basetype, const char *tpdf_n
17731773
static LY_ERR
17741774
lys_compile_type_(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t context_flags, const char *context_name,
17751775
const struct lysp_type *type_p, LY_DATA_TYPE basetype, const char *tpdfname, const struct lysc_type *base,
1776-
uintptr_t plugin, struct ly_set *tpdf_chain, uint32_t tpdf_chain_last, struct lysc_type **type)
1776+
uintptr_t plugin_ref, struct ly_set *tpdf_chain, uint32_t tpdf_chain_last, struct lysc_type **type)
17771777
{
17781778
LY_ERR rc = LY_SUCCESS;
17791779
struct lysc_type_bin *bin;
@@ -1794,7 +1794,7 @@ lys_compile_type_(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_
17941794
LY_CHECK_GOTO(rc, cleanup);
17951795

17961796
(*type)->basetype = basetype;
1797-
(*type)->plugin = plugin;
1797+
(*type)->plugin = plugin_ref;
17981798

17991799
switch (basetype) {
18001800
case LY_TYPE_BINARY:
@@ -2141,7 +2141,7 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t
21412141
struct lysc_type_union *base_un;
21422142
LY_ARRAY_COUNT_TYPE u;
21432143
struct ly_set tpdf_chain = {0};
2144-
uintptr_t plugin_id = 0;
2144+
uintptr_t plugin_ref = 0;
21452145

21462146
*type = NULL;
21472147
if (dflt) {
@@ -2264,19 +2264,19 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t
22642264
}
22652265

22662266
/* try to find loaded user type plugins */
2267-
plugin_id = lyplg_type_plugin_find(ctx->ctx, tctx->tpdf->type.pmod->mod->name, tctx->tpdf->type.pmod->mod->revision,
2267+
plugin_ref = lyplg_type_plugin_find(ctx->ctx, tctx->tpdf->type.pmod->mod->name, tctx->tpdf->type.pmod->mod->revision,
22682268
tctx->tpdf->name);
2269-
if (!plugin_id && base) {
2270-
plugin_id = base->plugin;
2269+
if (!plugin_ref && base) {
2270+
plugin_ref = base->plugin;
22712271
}
2272-
if (!plugin_id) {
2272+
if (!plugin_ref) {
22732273
/* use the internal built-in type implementation */
2274-
plugin_id = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]);
2274+
plugin_ref = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]);
22752275
}
2276-
assert(plugin_id);
2276+
assert(plugin_ref);
22772277

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

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

23032303
/* store separately compiled typedef type to be reused */
@@ -2329,12 +2329,12 @@ lys_compile_type(struct lysc_ctx *ctx, struct lysp_node *context_pnode, uint16_t
23292329
if (type_p->flags || type_p->exts || !base || has_leafref) {
23302330
/* leaf type has changes that need to be compiled into the type */
23312331
if (base) {
2332-
plugin_id = base->plugin;
2332+
plugin_ref = base->plugin;
23332333
} else {
2334-
plugin_id = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]);
2334+
plugin_ref = lyplg_type_plugin_find(ctx->ctx, "", NULL, ly_data_type2str[basetype]);
23352335
}
23362336
ret = lys_compile_type_(ctx, context_pnode, context_flags, context_name, (struct lysp_type *)type_p, basetype,
2337-
NULL, base, plugin_id, &tpdf_chain, 0, type);
2337+
NULL, base, plugin_ref, &tpdf_chain, 0, type);
23382338
LY_CHECK_GOTO(ret, cleanup);
23392339
} else {
23402340
/* no changes of the type in the leaf, just use the base compiled type */

src/tree_schema.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,20 +1800,20 @@ struct lysc_module {
18001800
/**
18011801
* @brief Get a type plugin.
18021802
*
1803-
* @param[in] plugin_id Either an index in the type plugins array (e.g. 1 -> binary type)
1804-
* or a pointer to the user defined plugin. Indexes start at 1.
1803+
* @param[in] plugin_ref Reference to a type plugin. Either an index in the type plugins
1804+
* array (e.g. 1 -> binary type) or a pointer to the user defined plugin. Indexes start at 1.
18051805
* @return Type plugin or NULL.
18061806
*/
1807-
LIBYANG_API_DECL struct lyplg_type *lysc_get_type_plugin(uintptr_t plugin_id);
1807+
LIBYANG_API_DECL struct lyplg_type *lysc_get_type_plugin(uintptr_t plugin_ref);
18081808

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

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

0 commit comments

Comments
 (0)