@@ -178,6 +178,7 @@ 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 ;
181182
182183 * err = NULL ;
183184
@@ -196,7 +197,7 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
196197
197198 assert (subvalue -> value .realtype );
198199 value = lysc_get_type_plugin (subvalue -> value .realtype -> plugin )-> print (ctx , & subvalue -> value ,
199- LY_VALUE_JSON , NULL , & dynamic , & value_len );
200+ LY_VALUE_JSON , NULL , & dynamic , & value_len );
200201
201202 /* to avoid leaks, free subvalue->value, but we need the value, which may be stored there */
202203 if (!dynamic ) {
@@ -225,7 +226,9 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
225226 opts |= LYPLG_TYPE_STORE_DYNAMIC ;
226227 }
227228
228- rc = lysc_get_type_plugin (type -> plugin )-> store (ctx , type , value , value_len , opts , format , prefix_data ,
229+ type_plugin = lysc_get_type_plugin (type -> plugin );
230+
231+ rc = type_plugin -> store (ctx , type , value , value_len , opts , format , prefix_data ,
229232 subvalue -> hints , subvalue -> ctx_node , & subvalue -> value , unres , err );
230233 if ((rc != LY_SUCCESS ) && (rc != LY_EINCOMPLETE )) {
231234 /* clear any leftover/freed garbage */
@@ -235,10 +238,10 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
235238
236239 if (validate && (rc == LY_EINCOMPLETE )) {
237240 /* we need the value validated */
238- rc = lysc_get_type_plugin ( type -> plugin ) -> validate (ctx , type , ctx_node , tree , & subvalue -> value , err );
241+ rc = type_plugin -> validate (ctx , type , ctx_node , tree , & subvalue -> value , err );
239242 if (rc ) {
240243 /* validate failed, we need to free the stored value */
241- lysc_get_type_plugin ( type -> plugin ) -> free (ctx , & subvalue -> value );
244+ type_plugin -> free (ctx , & subvalue -> value );
242245 }
243246 }
244247
@@ -271,6 +274,7 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct
271274 uint32_t * prev_lo , temp_lo = 0 ;
272275 char * msg = NULL ;
273276 int msg_len = 0 ;
277+ struct lyplg_type * type ;
274278
275279 * err = NULL ;
276280
@@ -308,9 +312,11 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct
308312 continue ;
309313 }
310314
311- msg = ly_realloc (msg , msg_len + 4 + strlen (lysc_get_type_plugin (type_u -> types [u ]-> plugin )-> id ) + 2 + strlen (errs [u ]-> msg ) + 2 );
315+ type = lysc_get_type_plugin (type_u -> types [u ]-> plugin );
316+
317+ msg = ly_realloc (msg , msg_len + 4 + strlen (type -> id ) + 2 + strlen (errs [u ]-> msg ) + 2 );
312318 LY_CHECK_ERR_GOTO (!msg , ret = LY_EMEM , cleanup );
313- msg_len += sprintf (msg + msg_len , " %s: %s\n" , lysc_get_type_plugin ( type_u -> types [ u ] -> plugin ) -> id , errs [u ]-> msg );
319+ msg_len += sprintf (msg + msg_len , " %s: %s\n" , type -> id , errs [u ]-> msg );
314320 }
315321
316322 ret = ly_err_new (err , LY_EVALID , LYVE_DATA , NULL , NULL , "%s" , msg );
@@ -445,14 +451,16 @@ lyplg_type_validate_union(const struct ly_ctx *ctx, const struct lysc_type *type
445451 struct lyd_value orig = {0 };
446452 uint32_t type_idx ;
447453 ly_bool validated = 0 ;
454+ struct lyplg_type * subvalue_type ;
448455
449456 * err = NULL ;
450457
451458 /* because of types that do not store their own type as realtype (leafref), we are not able to call their
452459 * validate callback (there is no way to get the type) but even if possible, the value may be invalid
453460 * for the type, so we may have to perform union value storing again from scratch, but keep a value backup */
454- LY_CHECK_RET (lysc_get_type_plugin (subvalue -> value .realtype -> plugin )-> duplicate (ctx , & subvalue -> value , & orig ));
455- lysc_get_type_plugin (subvalue -> value .realtype -> plugin )-> free (ctx , & subvalue -> value );
461+ subvalue_type = lysc_get_type_plugin (subvalue -> value .realtype -> plugin );
462+ LY_CHECK_RET (subvalue_type -> duplicate (ctx , & subvalue -> value , & orig ));
463+ subvalue_type -> free (ctx , & subvalue -> value );
456464
457465 if (subvalue -> format == LY_VALUE_LYB ) {
458466 /* use the specific type to store and validate the value */
@@ -492,7 +500,8 @@ lyplg_type_compare_union(const struct ly_ctx *ctx, const struct lyd_value *val1,
492500 if (val1 -> subvalue -> value .realtype != val2 -> subvalue -> value .realtype ) {
493501 return LY_ENOT ;
494502 }
495- return lysc_get_type_plugin (val1 -> subvalue -> value .realtype -> plugin )-> compare (ctx , & val1 -> subvalue -> value , & val2 -> subvalue -> value );
503+ return lysc_get_type_plugin (val1 -> subvalue -> value .realtype -> plugin )-> compare (ctx ,
504+ & val1 -> subvalue -> value , & val2 -> subvalue -> value );
496505}
497506
498507LIBYANG_API_DEF int
@@ -503,7 +512,8 @@ lyplg_type_sort_union(const struct ly_ctx *ctx, const struct lyd_value *val1, co
503512 struct lysc_type * * types ;
504513
505514 if (val1 -> subvalue -> value .realtype == val2 -> subvalue -> value .realtype ) {
506- return lysc_get_type_plugin (val1 -> subvalue -> value .realtype -> plugin )-> sort (ctx , & val1 -> subvalue -> value , & val2 -> subvalue -> value );
515+ return lysc_get_type_plugin (val1 -> subvalue -> value .realtype -> plugin )-> sort (ctx ,
516+ & val1 -> subvalue -> value , & val2 -> subvalue -> value );
507517 }
508518
509519 /* compare according to the order of types */
@@ -561,8 +571,8 @@ lyb_union_print(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct
561571 LY_CHECK_RET ((r != LY_SUCCESS ) && (r != LY_EINCOMPLETE ), NULL );
562572
563573 /* Print subvalue in LYB format. */
564- pval = (void * )lysc_get_type_plugin (subvalue -> value .realtype -> plugin )-> print (NULL , & subvalue -> value , LY_VALUE_LYB , prefix_data , & dynamic ,
565- & pval_len );
574+ pval = (void * )lysc_get_type_plugin (subvalue -> value .realtype -> plugin )-> print (NULL , & subvalue -> value , LY_VALUE_LYB ,
575+ prefix_data , & dynamic , & pval_len );
566576 LY_CHECK_RET (!pval , NULL );
567577
568578 /* Create LYB data. */
@@ -590,6 +600,7 @@ lyplg_type_print_union(const struct ly_ctx *ctx, const struct lyd_value *value,
590600 struct lyd_value_union * subvalue = value -> subvalue ;
591601 struct lysc_type_union * type_u = (struct lysc_type_union * )value -> realtype ;
592602 size_t lyb_data_len = 0 ;
603+ struct lyplg_type * type ;
593604
594605 if ((format == LY_VALUE_LYB ) && (subvalue -> format == LY_VALUE_LYB )) {
595606 /* The return value is already ready. */
@@ -609,7 +620,8 @@ lyplg_type_print_union(const struct ly_ctx *ctx, const struct lyd_value *value,
609620 }
610621
611622 assert (format != LY_VALUE_LYB );
612- ret = (void * )lysc_get_type_plugin (subvalue -> value .realtype -> plugin )-> print (ctx , & subvalue -> value , format , prefix_data , dynamic , value_len );
623+ type = lysc_get_type_plugin (subvalue -> value .realtype -> plugin );
624+ ret = (void * )type -> print (ctx , & subvalue -> value , format , prefix_data , dynamic , value_len );
613625 if (!value -> _canonical && (format == LY_VALUE_CANON )) {
614626 /* the canonical value is supposed to be stored now */
615627 lydict_insert (ctx , subvalue -> value ._canonical , 0 , (const char * * )& value -> _canonical );
0 commit comments