Skip to content

Commit 417a6bc

Browse files
committed
plugins REFACTOR various small changes
1 parent 9b7711a commit 417a6bc

14 files changed

+107
-95
lines changed

src/plugins.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ plugins_iter(const struct ly_ctx *ctx, enum LYPLG type, uint32_t *index)
198198
}
199199

200200
/**
201-
* @brief Find the give @p type plugin record.
201+
* @brief Find the given @p type plugin record.
202202
*
203-
* @param[in] ctx Context for which the plugin record is searched for, NULL for built-in plugins.
203+
* @param[in] ctx Context for which the plugin record is searched for, NULL for static plugins.
204204
* @param[in] type Type of the plugin record to find.
205205
* @param[in] module Module name of the plugin record.
206206
* @param[in] revision Revision of the @p module.
@@ -244,13 +244,13 @@ lyplg_record_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module,
244244
/**
245245
* @brief Find the plugin of the given @p type.
246246
*
247-
* @param[in] ctx Context for which the plugin record is searched for, NULL for built-in plugins.
247+
* @param[in] ctx Context for which the plugin record is searched for, NULL for static plugins.
248248
* @param[in] type Type of the plugin record to find.
249249
* @param[in] module Module name of the plugin.
250250
* @param[in] revision Revision of the @p module.
251251
* @param[in] name Name of the plugin.
252-
* @return Reference to the callbacks plugin structure. Use ::LYSC_GET_TYPE_PLG()
253-
* or ::LYSC_GET_EXT_PLG() on the returned value to get the actual plugin. 0 if not found.
252+
* @return Reference to the callbacks plugin structure. Use ::LYSC_GET_TYPE_PLG
253+
* or ::LYSC_GET_EXT_PLG on the returned value to get the actual plugin. 0 if not found.
254254
*/
255255
static uintptr_t
256256
lyplg_plugin_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module, const char *revision, const char *name)

src/plugins_exts.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,7 @@ struct lysp_ext_instance {
405405
const char *argument; /**< optional value of the extension's argument */
406406
LY_VALUE_FORMAT format; /**< prefix format of the extension name/argument (::LY_VALUE_XML is YIN format) */
407407
void *prefix_data; /**< format-specific data for prefix resolution (see ly_resolve_prefix()) */
408-
uintptr_t plugin_ref; /**< reference to extension's manipulation callbacks plugin,
409-
use ::lysc_get_ext_plugin() to get the plugin */
408+
uintptr_t plugin_ref; /**< reference to extension plugin, use ::lysc_get_ext_plugin() to get the plugin */
410409

411410
void *parent; /**< pointer to the parent statement holding the extension instance(s), use
412411
::lysp_ext_instance#parent_stmt to access the value/structure */

src/plugins_internal.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extern uint32_t ly_static_ext_plugins_count;
6666
/**
6767
* @brief Get a type plugin.
6868
*
69-
* @param[in] PLUGIN_REF Reference to a plugin. Either an index of a static plugin (offset by +1)
69+
* @param[in] PLUGIN_REF Reference to a type plugin. Either an index of a static plugin (offset by +1)
7070
* or a pointer to an external plugin.
7171
* @return Type plugin.
7272
*/
@@ -78,7 +78,7 @@ extern uint32_t ly_static_ext_plugins_count;
7878
/**
7979
* @brief Get an extension plugin.
8080
*
81-
* @param[in] PLUGIN_REF Reference to a plugin. Either an index of a static plugin (offset by +1)
81+
* @param[in] PLUGIN_REF Reference to an extension plugin. Either an index of a static plugin (offset by +1)
8282
* or a pointer to an external plugin.
8383
* @return Extension plugin.
8484
*/
@@ -115,7 +115,7 @@ void lyplg_clean(void);
115115
* only the plugins with NULL revision specified.
116116
* @param[in] name Name of the type which the plugin implements.
117117
* @return ID of the found type plugin, 0 if none found. The type plugin can be obtained
118-
* by passing the returned ID to ::lysc_get_type_plugin().
118+
* by passing the returned ID to ::lysc_get_type_plugin() or ::LYSC_GET_TYPE_PLG.
119119
*/
120120
uintptr_t lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name);
121121

@@ -128,7 +128,7 @@ uintptr_t lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, c
128128
* only the plugins with NULL revision specified.
129129
* @param[in] name Name of the extension which the plugin implements.
130130
* @return ID of the found extension plugin, 0 if none found. The extension plugin can be obtained
131-
* by passing the returned ID to ::lysc_get_ext_plugin().
131+
* by passing the returned ID to ::lysc_get_ext_plugin() or ::LYSC_GET_EXT_PLG.
132132
*/
133133
uintptr_t lyplg_ext_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name);
134134

src/plugins_types.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -900,13 +900,13 @@ lyplg_type_print_val(const struct lysc_node *node, const char *canon, LY_VALUE_F
900900
struct ly_err_item *err = NULL;
901901
const char *v;
902902
ly_bool dyn;
903-
struct lyplg_type *type_plugin;
903+
struct lyplg_type *type_plg;
904904

905905
type = ((struct lysc_node_leaf *)node)->type;
906-
type_plugin = LYSC_GET_TYPE_PLG(type->plugin_ref);
906+
type_plg = LYSC_GET_TYPE_PLG(type->plugin_ref);
907907

908908
/* store the value */
909-
r = type_plugin->store(node->module->ctx, type, canon, strlen(canon), LYPLG_TYPE_STORE_ONLY, LY_VALUE_CANON,
909+
r = type_plg->store(node->module->ctx, type, canon, strlen(canon), LYPLG_TYPE_STORE_ONLY, LY_VALUE_CANON,
910910
NULL, LYD_HINT_DATA, node, &storage, NULL, &err);
911911
if (r && (r != LY_EINCOMPLETE)) {
912912
if (err) {
@@ -917,7 +917,7 @@ lyplg_type_print_val(const struct lysc_node *node, const char *canon, LY_VALUE_F
917917
}
918918

919919
/* print it in the specific format */
920-
v = type_plugin->print(node->module->ctx, &storage, format, prefix_data, &dyn, NULL);
920+
v = type_plg->print(node->module->ctx, &storage, format, prefix_data, &dyn, NULL);
921921

922922
/* store it in the dictionary, storage will be freed */
923923
if (dyn) {
@@ -926,7 +926,7 @@ lyplg_type_print_val(const struct lysc_node *node, const char *canon, LY_VALUE_F
926926
lydict_dup(node->module->ctx, v, value);
927927
}
928928

929-
type_plugin->free(node->module->ctx, &storage);
929+
type_plg->free(node->module->ctx, &storage);
930930
return LY_SUCCESS;
931931
}
932932

@@ -1052,7 +1052,7 @@ lyplg_type_resolve_leafref(const struct lysc_type_leafref *lref, const struct ly
10521052
const char *val_str, *xp_err_msg;
10531053
uint32_t i;
10541054
int r;
1055-
struct lyplg_type *type;
1055+
struct lyplg_type *type_plg;
10561056

10571057
LY_CHECK_ARG_RET(NULL, lref, node, value, errmsg, LY_EINVAL);
10581058

@@ -1099,7 +1099,7 @@ lyplg_type_resolve_leafref(const struct lysc_type_leafref *lref, const struct ly
10991099
goto cleanup;
11001100
}
11011101

1102-
type = LYSC_GET_TYPE_PLG(lref->plugin_ref);
1102+
type_plg = LYSC_GET_TYPE_PLG(lref->plugin_ref);
11031103

11041104
/* check the result */
11051105
if (target_path) {
@@ -1115,7 +1115,7 @@ lyplg_type_resolve_leafref(const struct lysc_type_leafref *lref, const struct ly
11151115
continue;
11161116
}
11171117

1118-
if (!type->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) {
1118+
if (!type_plg->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) {
11191119
break;
11201120
}
11211121
}
@@ -1140,7 +1140,7 @@ lyplg_type_resolve_leafref(const struct lysc_type_leafref *lref, const struct ly
11401140
continue;
11411141
}
11421142

1143-
if (!type->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) {
1143+
if (!type_plg->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) {
11441144
rc = ly_set_add(*targets, set.val.nodes[i].node, 0, NULL);
11451145
LY_CHECK_GOTO(rc, cleanup);
11461146
}

src/plugins_types/union.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,16 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
178178
LY_VALUE_FORMAT format;
179179
void *prefix_data;
180180
uint32_t opts = 0, ti;
181-
struct lyplg_type *type_plugin;
181+
struct lyplg_type *type_plg;
182182

183183
*err = NULL;
184184

185185
if (subvalue->format == LY_VALUE_LYB) {
186186
lyb_parse_union(subvalue->original, subvalue->orig_len, &ti, &value, &value_len);
187187
if (ti != type_idx) {
188188
/* value of another type, first store the value properly and then use its JSON value for parsing */
189-
rc = LYSC_GET_TYPE_PLG(type_u->types[ti]->plugin_ref)->store(ctx, type_u->types[ti], value, value_len,
189+
type_plg = LYSC_GET_TYPE_PLG(type_u->types[ti]->plugin_ref);
190+
rc = type_plg->store(ctx, type_u->types[ti], value, value_len,
190191
LYPLG_TYPE_STORE_ONLY, subvalue->format, subvalue->prefix_data, subvalue->hints,
191192
subvalue->ctx_node, &subvalue->value, unres, err);
192193
if ((rc != LY_SUCCESS) && (rc != LY_EINCOMPLETE)) {
@@ -204,7 +205,7 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
204205
value = strndup(value, value_len);
205206
dynamic = 1;
206207
}
207-
LYSC_GET_TYPE_PLG(type_u->types[ti]->plugin_ref)->free(ctx, &subvalue->value);
208+
type_plg->free(ctx, &subvalue->value);
208209

209210
format = LY_VALUE_JSON;
210211
prefix_data = NULL;
@@ -226,9 +227,9 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
226227
opts |= LYPLG_TYPE_STORE_DYNAMIC;
227228
}
228229

229-
type_plugin = LYSC_GET_TYPE_PLG(type->plugin_ref);
230+
type_plg = LYSC_GET_TYPE_PLG(type->plugin_ref);
230231

231-
rc = type_plugin->store(ctx, type, value, value_len, opts, format, prefix_data,
232+
rc = type_plg->store(ctx, type, value, value_len, opts, format, prefix_data,
232233
subvalue->hints, subvalue->ctx_node, &subvalue->value, unres, err);
233234
if ((rc != LY_SUCCESS) && (rc != LY_EINCOMPLETE)) {
234235
/* clear any leftover/freed garbage */
@@ -238,10 +239,10 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
238239

239240
if (validate && (rc == LY_EINCOMPLETE)) {
240241
/* we need the value validated */
241-
rc = type_plugin->validate(ctx, type, ctx_node, tree, &subvalue->value, err);
242+
rc = type_plg->validate(ctx, type, ctx_node, tree, &subvalue->value, err);
242243
if (rc) {
243244
/* validate failed, we need to free the stored value */
244-
type_plugin->free(ctx, &subvalue->value);
245+
type_plg->free(ctx, &subvalue->value);
245246
}
246247
}
247248

@@ -274,7 +275,7 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct
274275
uint32_t *prev_lo, temp_lo = 0;
275276
char *msg = NULL;
276277
int msg_len = 0;
277-
struct lyplg_type *type;
278+
struct lyplg_type *type_plg;
278279

279280
*err = NULL;
280281

@@ -312,11 +313,11 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct
312313
continue;
313314
}
314315

315-
type = LYSC_GET_TYPE_PLG(type_u->types[u]->plugin_ref);
316+
type_plg = LYSC_GET_TYPE_PLG(type_u->types[u]->plugin_ref);
316317

317-
msg = ly_realloc(msg, msg_len + 4 + strlen(type->id) + 2 + strlen(errs[u]->msg) + 2);
318+
msg = ly_realloc(msg, msg_len + 4 + strlen(type_plg->id) + 2 + strlen(errs[u]->msg) + 2);
318319
LY_CHECK_ERR_GOTO(!msg, ret = LY_EMEM, cleanup);
319-
msg_len += sprintf(msg + msg_len, " %s: %s\n", type->id, errs[u]->msg);
320+
msg_len += sprintf(msg + msg_len, " %s: %s\n", type_plg->id, errs[u]->msg);
320321
}
321322

322323
ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "%s", msg);
@@ -451,16 +452,16 @@ lyplg_type_validate_union(const struct ly_ctx *ctx, const struct lysc_type *type
451452
struct lyd_value orig = {0};
452453
uint32_t type_idx;
453454
ly_bool validated = 0;
454-
struct lyplg_type *subvalue_type;
455+
struct lyplg_type *subvalue_type_plg;
455456

456457
*err = NULL;
457458

458459
/* because of types that do not store their own type as realtype (leafref), we are not able to call their
459460
* validate callback (there is no way to get the type) but even if possible, the value may be invalid
460461
* for the type, so we may have to perform union value storing again from scratch, but keep a value backup */
461-
subvalue_type = LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref);
462-
LY_CHECK_RET(subvalue_type->duplicate(ctx, &subvalue->value, &orig));
463-
subvalue_type->free(ctx, &subvalue->value);
462+
subvalue_type_plg = LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref);
463+
LY_CHECK_RET(subvalue_type_plg->duplicate(ctx, &subvalue->value, &orig));
464+
subvalue_type_plg->free(ctx, &subvalue->value);
464465

465466
if (subvalue->format == LY_VALUE_LYB) {
466467
/* use the specific type to store and validate the value */
@@ -600,7 +601,6 @@ lyplg_type_print_union(const struct ly_ctx *ctx, const struct lyd_value *value,
600601
struct lyd_value_union *subvalue = value->subvalue;
601602
struct lysc_type_union *type_u = (struct lysc_type_union *)value->realtype;
602603
size_t lyb_data_len = 0;
603-
struct lyplg_type *type;
604604

605605
if ((format == LY_VALUE_LYB) && (subvalue->format == LY_VALUE_LYB)) {
606606
/* The return value is already ready. */
@@ -620,8 +620,8 @@ lyplg_type_print_union(const struct ly_ctx *ctx, const struct lyd_value *value,
620620
}
621621

622622
assert(format != LY_VALUE_LYB);
623-
type = LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref);
624-
ret = (void *)type->print(ctx, &subvalue->value, format, prefix_data, dynamic, value_len);
623+
ret = (void *)LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref)->print(ctx, &subvalue->value,
624+
format, prefix_data, dynamic, value_len);
625625
if (!value->_canonical && (format == LY_VALUE_CANON)) {
626626
/* the canonical value is supposed to be stored now */
627627
lydict_insert(ctx, subvalue->value._canonical, 0, (const char **)&value->_canonical);

src/printer_context.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static void
113113
ctxs_exts(const struct lysc_ext_instance *exts, struct ly_ht *ht, int *size)
114114
{
115115
LY_ARRAY_COUNT_TYPE u;
116-
struct lyplg_ext *ext;
116+
struct lyplg_ext *ext_plg;
117117

118118
/* sized array */
119119
*size += CTXS_SIZED_ARRAY(exts);
@@ -125,9 +125,9 @@ ctxs_exts(const struct lysc_ext_instance *exts, struct ly_ht *ht, int *size)
125125
*size += CTXS_SIZED_ARRAY(exts[u].substmts);
126126

127127
/* compiled, substmts storage */
128-
ext = LYSC_GET_EXT_PLG(exts[u].def->plugin_ref);
129-
if (ext && ext->compiled_size) {
130-
*size += ext->compiled_size(&exts[u], ht);
128+
ext_plg = LYSC_GET_EXT_PLG(exts[u].def->plugin_ref);
129+
if (ext_plg && ext_plg->compiled_size) {
130+
*size += ext_plg->compiled_size(&exts[u], ht);
131131
}
132132
}
133133
}
@@ -789,6 +789,7 @@ ctxp_ext(const struct lysc_ext_instance *orig_ext, struct lysc_ext_instance *ext
789789
struct ly_set *ptr_set, void **mem)
790790
{
791791
LY_ARRAY_COUNT_TYPE u;
792+
struct lyplg_ext *ext_plg;
792793

793794
if (orig_ext->exts) {
794795
/* may be referenced in the parent */
@@ -822,8 +823,8 @@ ctxp_ext(const struct lysc_ext_instance *orig_ext, struct lysc_ext_instance *ext
822823
}
823824

824825
/* compiled, substmts storage, use the plugin */
825-
if (ext->def->plugin_ref && LYSC_GET_EXT_PLG(ext->def->plugin_ref)->compiled_print) {
826-
LYSC_GET_EXT_PLG(ext->def->plugin_ref)->compiled_print(orig_ext, ext, addr_ht, ptr_set, mem);
826+
if (ext->def->plugin_ref && (ext_plg = LYSC_GET_EXT_PLG(ext->def->plugin_ref))->compiled_print) {
827+
ext_plg->compiled_print(orig_ext, ext, addr_ht, ptr_set, mem);
827828
} else {
828829
ext->compiled = NULL;
829830
}

src/schema_compile.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ LY_ERR
114114
lys_compile_ext(struct lysc_ctx *ctx, struct lysp_ext_instance *extp, struct lysc_ext_instance *ext, void *parent)
115115
{
116116
LY_ERR ret = LY_SUCCESS;
117+
struct lyplg_ext *ext_plg;
117118

118119
DUP_STRING_GOTO(ctx->ctx, extp->argument, ext->argument, ret, cleanup);
119120
ext->module = ctx->cur_mod;
@@ -132,11 +133,11 @@ lys_compile_ext(struct lysc_ctx *ctx, struct lysp_ext_instance *extp, struct lys
132133
COMPILE_EXTS_GOTO(ctx, extp->exts, ext->exts, ext, ret, cleanup);
133134

134135
/* compile this extension */
135-
if (ext->def->plugin_ref && LYSC_GET_EXT_PLG(ext->def->plugin_ref)->compile) {
136+
if (ext->def->plugin_ref && (ext_plg = LYSC_GET_EXT_PLG(ext->def->plugin_ref))->compile) {
136137
if (ext->argument) {
137138
lysc_update_path(ctx, ext->module, ext->argument);
138139
}
139-
ret = LYSC_GET_EXT_PLG(ext->def->plugin_ref)->compile(ctx, extp, ext);
140+
ret = ext_plg->compile(ctx, extp, ext);
140141
if (ret == LY_ENOT) {
141142
lysc_ext_instance_free(ctx->ctx, ext);
142143
}
@@ -896,11 +897,11 @@ lys_compile_unres_dflt(struct lysc_ctx *ctx, struct lysc_node *node, struct lysc
896897
struct lyd_value storage = {0};
897898
struct ly_err_item *err = NULL;
898899
LY_VALUE_FORMAT format;
899-
struct lyplg_type *type_plugin;
900+
struct lyplg_type *type_plg;
900901

901902
options = (ctx->ctx->opts & LY_CTX_REF_IMPLEMENTED) ? LYPLG_TYPE_STORE_IMPLEMENT : 0;
902-
type_plugin = LYSC_GET_TYPE_PLG(type->plugin_ref);
903-
rc = type_plugin->store(ctx->ctx, type, dflt, strlen(dflt), options, LY_VALUE_SCHEMA, (void *)dflt_pmod,
903+
type_plg = LYSC_GET_TYPE_PLG(type->plugin_ref);
904+
rc = type_plg->store(ctx->ctx, type, dflt, strlen(dflt), options, LY_VALUE_SCHEMA, (void *)dflt_pmod,
904905
LYD_HINT_SCHEMA, node, &storage, unres, &err);
905906
if (rc == LY_ERECOMPILE) {
906907
/* fine, but we need to recompile */
@@ -927,7 +928,7 @@ lys_compile_unres_dflt(struct lysc_ctx *ctx, struct lysc_node *node, struct lysc
927928
}
928929

929930
cleanup:
930-
type_plugin->free(ctx->ctx, &storage);
931+
type_plg->free(ctx->ctx, &storage);
931932
return rc;
932933
}
933934

src/schema_compile_amend.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ lysp_ext_dup(const struct ly_ctx *ctx, const struct lysp_module *pmod, void *par
473473
LY_ERR ret = LY_SUCCESS;
474474
struct ly_set pmods = {0};
475475
struct lysp_ctx pctx = {.parsed_mods = &pmods};
476+
struct lyplg_ext *ext_plg;
476477

477478
DUP_STRING_GOTO(ctx, orig_ext->name, ext->name, ret, cleanup);
478479
DUP_STRING_GOTO(ctx, orig_ext->argument, ext->argument, ret, cleanup);
@@ -486,10 +487,10 @@ lysp_ext_dup(const struct ly_ctx *ctx, const struct lysp_module *pmod, void *par
486487
ext->flags = orig_ext->flags;
487488

488489
LY_CHECK_GOTO(ret = lysp_ext_children_dup(ctx, orig_ext->child, &ext->child), cleanup);
489-
if (ext->plugin_ref && LYSC_GET_EXT_PLG(ext->plugin_ref)->parse) {
490+
if (ext->plugin_ref && (ext_plg = LYSC_GET_EXT_PLG(ext->plugin_ref))->parse) {
490491
/* parse again */
491492
LY_CHECK_GOTO(ret = ly_set_add(&pmods, pmod, 1, NULL), cleanup);
492-
LY_CHECK_GOTO(ret = LYSC_GET_EXT_PLG(ext->plugin_ref)->parse(&pctx, ext), cleanup);
493+
LY_CHECK_GOTO(ret = ext_plg->parse(&pctx, ext), cleanup);
493494
}
494495

495496
cleanup:

0 commit comments

Comments
 (0)