plugins types CHANGE compare function callback

The function now has a new context parameter that may be needed when
getting the canonical value. Type API version number has increased.
diff --git a/src/diff.c b/src/diff.c
index e522c9e..14d3bb6 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -1651,7 +1651,7 @@
                 sleaf = (struct lysc_node_leaf *)src_diff->schema;
             }
 
-            if (sleaf && sleaf->dflt && !sleaf->dflt->realtype->plugin->compare(sleaf->dflt,
+            if (sleaf && sleaf->dflt && !sleaf->dflt->realtype->plugin->compare(ctx, sleaf->dflt,
                     &((struct lyd_node_term *)src_diff)->value)) {
                 /* we deleted it, so a default value was in-use, and it matches the created value -> operation NONE */
                 LY_CHECK_RET(lyd_diff_change_op(*diff_match, LYD_DIFF_OP_NONE));
diff --git a/src/plugins_types.c b/src/plugins_types.c
index 4af984e..9ebcf48 100644
--- a/src/plugins_types.c
+++ b/src/plugins_types.c
@@ -301,9 +301,13 @@
 }
 
 LIBYANG_API_DEF LY_ERR
-lyplg_type_compare_simple(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_simple(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
 {
-    if (val1->_canonical == val2->_canonical) {
+    const char *can1, *can2;
+
+    can1 = lyd_value_get_canonical(ctx, val1);
+    can2 = lyd_value_get_canonical(ctx, val2);
+    if (can1 == can2) {
         return LY_SUCCESS;
     }
 
@@ -1057,7 +1061,7 @@
                 continue;
             }
 
-            if (!lref->plugin->compare(&((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) {
+            if (!lref->plugin->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) {
                 break;
             }
         }
@@ -1082,7 +1086,7 @@
                 continue;
             }
 
-            if (!lref->plugin->compare(&((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) {
+            if (!lref->plugin->compare(LYD_CTX(node), &((struct lyd_node_term *)set.val.nodes[i].node)->value, value)) {
                 rc = ly_set_add(*targets, set.val.nodes[i].node, 0, NULL);
                 LY_CHECK_GOTO(rc, cleanup);
             }
diff --git a/src/plugins_types.h b/src/plugins_types.h
index 81edee1..1b92cb7 100644
--- a/src/plugins_types.h
+++ b/src/plugins_types.h
@@ -162,7 +162,7 @@
 /**
  * @brief Type API version
  */
-#define LYPLG_TYPE_API_VERSION 1
+#define LYPLG_TYPE_API_VERSION 2
 
 /**
  * @brief Macro to define plugin information in external plugins
@@ -537,23 +537,27 @@
  * It can be assumed that the same context (dictionary) was used for storing both values and the realtype
  * member of both the values is the same.
  *
+ * @param[in] ctx libyang context.
  * @param[in] val1 First value to compare.
  * @param[in] val2 Second value to compare.
  * @return LY_SUCCESS if values are considered equal.
  * @return LY_ENOT if values differ.
  */
-typedef LY_ERR (*lyplg_type_compare_clb)(const struct lyd_value *val1, const struct lyd_value *val2);
+typedef LY_ERR (*lyplg_type_compare_clb)(const struct ly_ctx *ctx, const struct lyd_value *val1,
+        const struct lyd_value *val2);
 
 /**
  * @brief Unused callback for sorting values.
  *
+ * @param[in] ctx libyang context.
  * @param[in] val1 First value to compare.
  * @param[in] val2 Second value to compare.
  * @return -1 if val1 < val2,
  * @return 0 if val1 == val2,
  * @return 1 if val1 > val2.
  */
-typedef int (*lyplg_type_sort_clb)(const struct lyd_value *val1, const struct lyd_value *val2);
+typedef int (*lyplg_type_sort_clb)(const struct ly_ctx *ctx, const struct lyd_value *val1,
+        const struct lyd_value *val2);
 
 /**
  * @brief Callback for getting the value of the data stored in @p value.
@@ -647,7 +651,8 @@
 /**
  * @brief Implementation of ::lyplg_type_compare_clb for a generic simple type.
  */
-LIBYANG_API_DECL LY_ERR lyplg_type_compare_simple(const struct lyd_value *val1, const struct lyd_value *val2);
+LIBYANG_API_DECL LY_ERR lyplg_type_compare_simple(const struct ly_ctx *ctx, const struct lyd_value *val1,
+        const struct lyd_value *val2);
 
 /**
  * @brief Implementation of ::lyplg_type_print_clb for a generic simple type.
@@ -686,7 +691,8 @@
 /**
  * @brief Implementation of ::lyplg_type_compare_clb for the built-in binary type.
  */
-LIBYANG_API_DECL LY_ERR lyplg_type_compare_binary(const struct lyd_value *val1, const struct lyd_value *val2);
+LIBYANG_API_DECL LY_ERR lyplg_type_compare_binary(const struct ly_ctx *ctx, const struct lyd_value *val1,
+        const struct lyd_value *val2);
 
 /**
  * @brief Implementation of ::lyplg_type_print_clb for the built-in binary type.
@@ -725,7 +731,8 @@
 /**
  * @brief Implementation of the ::lyplg_type_compare_clb for the built-in bits type.
  */
-LIBYANG_API_DECL LY_ERR lyplg_type_compare_bits(const struct lyd_value *val1, const struct lyd_value *val2);
+LIBYANG_API_DECL LY_ERR lyplg_type_compare_bits(const struct ly_ctx *ctx, const struct lyd_value *val1,
+        const struct lyd_value *val2);
 
 /**
  * @brief Implementation of the ::lyplg_type_print_clb for the built-in bits type.
@@ -764,7 +771,8 @@
 /**
  * @brief Implementation of ::lyplg_type_compare_clb for the built-in boolean type.
  */
-LIBYANG_API_DECL LY_ERR lyplg_type_compare_boolean(const struct lyd_value *val1, const struct lyd_value *val2);
+LIBYANG_API_DECL LY_ERR lyplg_type_compare_boolean(const struct ly_ctx *ctx, const struct lyd_value *val1,
+        const struct lyd_value *val2);
 
 /**
  * @brief Implementation of ::lyplg_type_print_clb for the built-in boolean type.
@@ -792,7 +800,8 @@
 /**
  * @brief Implementation of ::lyplg_type_compare_clb for the built-in decimal64 type.
  */
-LIBYANG_API_DECL LY_ERR lyplg_type_compare_decimal64(const struct lyd_value *val1, const struct lyd_value *val2);
+LIBYANG_API_DECL LY_ERR lyplg_type_compare_decimal64(const struct ly_ctx *ctx, const struct lyd_value *val1,
+        const struct lyd_value *val2);
 
 /**
  * @brief Implementation of ::lyplg_type_print_clb for the built-in decimal64 type.
@@ -860,7 +869,8 @@
 /**
  * @brief Implementation of ::lyplg_type_compare_clb for the built-in identityref type.
  */
-LIBYANG_API_DECL LY_ERR lyplg_type_compare_identityref(const struct lyd_value *val1, const struct lyd_value *val2);
+LIBYANG_API_DECL LY_ERR lyplg_type_compare_identityref(const struct ly_ctx *ctx, const struct lyd_value *val1,
+        const struct lyd_value *val2);
 
 /**
  * @brief Implementation of ::lyplg_type_print_clb for the built-in identityref type.
@@ -894,7 +904,8 @@
 /**
  * @brief Implementation of ::lyplg_type_compare_clb for the built-in instance-identifier type.
  */
-LIBYANG_API_DECL LY_ERR lyplg_type_compare_instanceid(const struct lyd_value *val1, const struct lyd_value *val2);
+LIBYANG_API_DECL LY_ERR lyplg_type_compare_instanceid(const struct ly_ctx *ctx, const struct lyd_value *val1,
+        const struct lyd_value *val2);
 
 /**
  * @brief Implementation of ::lyplg_type_print_clb for the built-in instance-identifier type.
@@ -933,7 +944,8 @@
 /**
  * @brief Implementation of ::lyplg_type_compare_clb for the built-in signed integer types.
  */
-LIBYANG_API_DECL LY_ERR lyplg_type_compare_int(const struct lyd_value *val1, const struct lyd_value *val2);
+LIBYANG_API_DECL LY_ERR lyplg_type_compare_int(const struct ly_ctx *ctx, const struct lyd_value *val1,
+        const struct lyd_value *val2);
 
 /**
  * @brief Implementation of ::lyplg_type_print_clb for the built-in signed integer types.
@@ -951,7 +963,8 @@
 /**
  * @brief Implementation of ::lyplg_type_compare_clb for the built-in unsigned integer types.
  */
-LIBYANG_API_DECL LY_ERR lyplg_type_compare_uint(const struct lyd_value *val1, const struct lyd_value *val2);
+LIBYANG_API_DECL LY_ERR lyplg_type_compare_uint(const struct ly_ctx *ctx, const struct lyd_value *val1,
+        const struct lyd_value *val2);
 
 /**
  * @brief Implementation of ::lyplg_type_print_clb for the built-in unsigned integer types.
@@ -979,7 +992,8 @@
 /**
  * @brief Implementation of ::lyplg_type_compare_clb for the built-in leafref type.
  */
-LIBYANG_API_DECL LY_ERR lyplg_type_compare_leafref(const struct lyd_value *val1, const struct lyd_value *val2);
+LIBYANG_API_DECL LY_ERR lyplg_type_compare_leafref(const struct ly_ctx *ctx, const struct lyd_value *val1,
+        const struct lyd_value *val2);
 
 /**
  * @brief Implementation of ::lyplg_type_print_clb for the built-in leafref type.
@@ -1041,7 +1055,8 @@
 /**
  * @brief Implementation of ::lyplg_type_compare_clb for the built-in union type.
  */
-LIBYANG_API_DECL LY_ERR lyplg_type_compare_union(const struct lyd_value *val1, const struct lyd_value *val2);
+LIBYANG_API_DECL LY_ERR lyplg_type_compare_union(const struct ly_ctx *ctx, const struct lyd_value *val1,
+        const struct lyd_value *val2);
 
 /**
  * @brief Implementation of ::lyplg_type_print_clb for the built-in union type.
@@ -1086,7 +1101,8 @@
 /**
  * @brief Implementation of ::lyplg_type_compare_clb for the ietf-yang-types xpath1.0 type.
  */
-LIBYANG_API_DECL LY_ERR lyplg_type_compare_xpath10(const struct lyd_value *val1, const struct lyd_value *val2);
+LIBYANG_API_DECL LY_ERR lyplg_type_compare_xpath10(const struct ly_ctx *ctx, const struct lyd_value *val1,
+        const struct lyd_value *val2);
 
 /**
  * @brief Implementation of ::lyplg_type_print_clb for the ietf-yang-types xpath1.0 type.
diff --git a/src/plugins_types/binary.c b/src/plugins_types/binary.c
index bb407e2..9edc811 100644
--- a/src/plugins_types/binary.c
+++ b/src/plugins_types/binary.c
@@ -336,7 +336,7 @@
 }
 
 LIBYANG_API_DEF LY_ERR
-lyplg_type_compare_binary(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_binary(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2)
 {
     struct lyd_value_binary *v1, *v2;
 
diff --git a/src/plugins_types/bits.c b/src/plugins_types/bits.c
index c6bdd70..44736da 100644
--- a/src/plugins_types/bits.c
+++ b/src/plugins_types/bits.c
@@ -368,7 +368,7 @@
 }
 
 LIBYANG_API_DEF LY_ERR
-lyplg_type_compare_bits(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_bits(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2)
 {
     struct lyd_value_bits *v1, *v2;
     struct lysc_type_bits *type_bits = (struct lysc_type_bits *)val1->realtype;
diff --git a/src/plugins_types/boolean.c b/src/plugins_types/boolean.c
index d8276b3..ea8f7d2 100644
--- a/src/plugins_types/boolean.c
+++ b/src/plugins_types/boolean.c
@@ -104,7 +104,7 @@
 }
 
 LIBYANG_API_DEF LY_ERR
-lyplg_type_compare_boolean(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_boolean(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2)
 {
     if (val1->boolean != val2->boolean) {
         return LY_ENOT;
diff --git a/src/plugins_types/date_and_time.c b/src/plugins_types/date_and_time.c
index 596bb9c..b60bf55 100644
--- a/src/plugins_types/date_and_time.c
+++ b/src/plugins_types/date_and_time.c
@@ -150,7 +150,8 @@
  * @brief Implementation of ::lyplg_type_compare_clb for ietf-yang-types date-and-time type.
  */
 static LY_ERR
-lyplg_type_compare_date_and_time(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_date_and_time(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1,
+        const struct lyd_value *val2)
 {
     struct lyd_value_date_and_time *v1, *v2;
 
diff --git a/src/plugins_types/decimal64.c b/src/plugins_types/decimal64.c
index 22f3ed0..d28d24c 100644
--- a/src/plugins_types/decimal64.c
+++ b/src/plugins_types/decimal64.c
@@ -159,7 +159,8 @@
 }
 
 LIBYANG_API_DEF LY_ERR
-lyplg_type_compare_decimal64(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1,
+        const struct lyd_value *val2)
 {
     /* if type is the same, the fraction digits are, too */
     if (val1->dec64 != val2->dec64) {
diff --git a/src/plugins_types/identityref.c b/src/plugins_types/identityref.c
index 39c9412..843cc77 100644
--- a/src/plugins_types/identityref.c
+++ b/src/plugins_types/identityref.c
@@ -301,7 +301,8 @@
 }
 
 LIBYANG_API_DEF LY_ERR
-lyplg_type_compare_identityref(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_identityref(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1,
+        const struct lyd_value *val2)
 {
     if (val1->ident == val2->ident) {
         return LY_SUCCESS;
diff --git a/src/plugins_types/instanceid.c b/src/plugins_types/instanceid.c
index fba3787..bf23df9 100644
--- a/src/plugins_types/instanceid.c
+++ b/src/plugins_types/instanceid.c
@@ -253,7 +253,7 @@
 }
 
 LIBYANG_API_DEF LY_ERR
-lyplg_type_compare_instanceid(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_instanceid(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
 {
     LY_ARRAY_COUNT_TYPE u, v;
 
@@ -288,13 +288,13 @@
             case LY_PATH_PREDTYPE_LIST:
                 /* key-predicate */
                 if ((pred1->key != pred2->key) ||
-                        ((struct lysc_node_leaf *)pred1->key)->type->plugin->compare(&pred1->value, &pred2->value)) {
+                        ((struct lysc_node_leaf *)pred1->key)->type->plugin->compare(ctx, &pred1->value, &pred2->value)) {
                     return LY_ENOT;
                 }
                 break;
             case LY_PATH_PREDTYPE_LEAFLIST:
                 /* leaf-list predicate */
-                if (((struct lysc_node_leaflist *)s1->node)->type->plugin->compare(&pred1->value, &pred2->value)) {
+                if (((struct lysc_node_leaflist *)s1->node)->type->plugin->compare(ctx, &pred1->value, &pred2->value)) {
                     return LY_ENOT;
                 }
                 break;
diff --git a/src/plugins_types/integer.c b/src/plugins_types/integer.c
index de36339..68178d1 100644
--- a/src/plugins_types/integer.c
+++ b/src/plugins_types/integer.c
@@ -173,7 +173,7 @@
 }
 
 LIBYANG_API_DEF LY_ERR
-lyplg_type_compare_int(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_int(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2)
 {
     if (val1->realtype != val2->realtype) {
         return LY_ENOT;
@@ -371,7 +371,7 @@
 }
 
 LIBYANG_API_DEF LY_ERR
-lyplg_type_compare_uint(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_uint(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2)
 {
     switch (val1->realtype->basetype) {
     case LY_TYPE_UINT8:
diff --git a/src/plugins_types/ipv4_address.c b/src/plugins_types/ipv4_address.c
index 1e485f3..946968c 100644
--- a/src/plugins_types/ipv4_address.c
+++ b/src/plugins_types/ipv4_address.c
@@ -210,7 +210,8 @@
  * @brief Implementation of ::lyplg_type_compare_clb for the ipv4-address ietf-inet-types type.
  */
 static LY_ERR
-lyplg_type_compare_ipv4_address(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_ipv4_address(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1,
+        const struct lyd_value *val2)
 {
     struct lyd_value_ipv4_address *v1, *v2;
 
diff --git a/src/plugins_types/ipv4_address_no_zone.c b/src/plugins_types/ipv4_address_no_zone.c
index 28331fc..67db22b 100644
--- a/src/plugins_types/ipv4_address_no_zone.c
+++ b/src/plugins_types/ipv4_address_no_zone.c
@@ -128,7 +128,8 @@
  * @brief Implementation of ::lyplg_type_compare_clb for the ipv4-address-no-zone ietf-inet-types type.
  */
 static LY_ERR
-lyplg_type_compare_ipv4_address_no_zone(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_ipv4_address_no_zone(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1,
+        const struct lyd_value *val2)
 {
     struct lyd_value_ipv4_address_no_zone *v1, *v2;
 
diff --git a/src/plugins_types/ipv4_prefix.c b/src/plugins_types/ipv4_prefix.c
index 6571590..d4fb785 100644
--- a/src/plugins_types/ipv4_prefix.c
+++ b/src/plugins_types/ipv4_prefix.c
@@ -199,7 +199,8 @@
  * @brief Implementation of ::lyplg_type_compare_clb for the ietf-inet-types ipv4-prefix type.
  */
 static LY_ERR
-lyplg_type_compare_ipv4_prefix(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_ipv4_prefix(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1,
+        const struct lyd_value *val2)
 {
     struct lyd_value_ipv4_prefix *v1, *v2;
 
diff --git a/src/plugins_types/ipv6_address.c b/src/plugins_types/ipv6_address.c
index 26197d8..9a2c31a 100644
--- a/src/plugins_types/ipv6_address.c
+++ b/src/plugins_types/ipv6_address.c
@@ -212,7 +212,8 @@
  * @brief Implementation of ::lyplg_type_compare_clb for the ipv6-address ietf-inet-types type.
  */
 static LY_ERR
-lyplg_type_compare_ipv6_address(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_ipv6_address(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1,
+        const struct lyd_value *val2)
 {
     struct lyd_value_ipv6_address *v1, *v2;
 
diff --git a/src/plugins_types/ipv6_address_no_zone.c b/src/plugins_types/ipv6_address_no_zone.c
index ee3934d..56e0760 100644
--- a/src/plugins_types/ipv6_address_no_zone.c
+++ b/src/plugins_types/ipv6_address_no_zone.c
@@ -176,7 +176,8 @@
  * @brief Implementation of ::lyplg_type_compare_clb for the ipv6-address-no-zone ietf-inet-types type.
  */
 static LY_ERR
-lyplg_type_compare_ipv6_address_no_zone(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_ipv6_address_no_zone(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1,
+        const struct lyd_value *val2)
 {
     struct lyd_value_ipv6_address_no_zone *v1, *v2;
 
diff --git a/src/plugins_types/ipv6_prefix.c b/src/plugins_types/ipv6_prefix.c
index cc48991..d6823ad 100644
--- a/src/plugins_types/ipv6_prefix.c
+++ b/src/plugins_types/ipv6_prefix.c
@@ -213,7 +213,8 @@
  * @brief Implementation of ::lyplg_type_compare_clb for the ietf-inet-types ipv6-prefix type.
  */
 static LY_ERR
-lyplg_type_compare_ipv6_prefix(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_ipv6_prefix(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1,
+        const struct lyd_value *val2)
 {
     struct lyd_value_ipv6_prefix *v1, *v2;
 
diff --git a/src/plugins_types/leafref.c b/src/plugins_types/leafref.c
index 80ffcfc..8350da8 100644
--- a/src/plugins_types/leafref.c
+++ b/src/plugins_types/leafref.c
@@ -101,9 +101,9 @@
 }
 
 LIBYANG_API_DEF LY_ERR
-lyplg_type_compare_leafref(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_leafref(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
 {
-    return val1->realtype->plugin->compare(val1, val2);
+    return val1->realtype->plugin->compare(ctx, val1, val2);
 }
 
 LIBYANG_API_DEF const void *
diff --git a/src/plugins_types/union.c b/src/plugins_types/union.c
index 6be269d..eae2348 100644
--- a/src/plugins_types/union.c
+++ b/src/plugins_types/union.c
@@ -421,12 +421,12 @@
 }
 
 LIBYANG_API_DEF LY_ERR
-lyplg_type_compare_union(const struct lyd_value *val1, const struct lyd_value *val2)
+lyplg_type_compare_union(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
 {
     if (val1->subvalue->value.realtype != val2->subvalue->value.realtype) {
         return LY_ENOT;
     }
-    return val1->subvalue->value.realtype->plugin->compare(&val1->subvalue->value, &val2->subvalue->value);
+    return val1->subvalue->value.realtype->plugin->compare(ctx, &val1->subvalue->value, &val2->subvalue->value);
 }
 
 /**
diff --git a/src/schema_compile.c b/src/schema_compile.c
index 9d71afc..83851bf 100644
--- a/src/schema_compile.c
+++ b/src/schema_compile.c
@@ -1046,7 +1046,7 @@
         /* configuration data values must be unique - so check the default values */
         for (u = orig_count; u < LY_ARRAY_COUNT(llist->dflts); ++u) {
             for (v = 0; v < u; ++v) {
-                if (!llist->dflts[u]->realtype->plugin->compare(llist->dflts[u], llist->dflts[v])) {
+                if (!llist->dflts[u]->realtype->plugin->compare(ctx->ctx, llist->dflts[u], llist->dflts[v])) {
                     lysc_update_path(ctx, llist->parent ? llist->parent->module : NULL, llist->name);
                     LOGVAL(ctx->ctx, LYVE_SEMANTICS, "Configuration leaf-list has multiple defaults of the same value \"%s\".",
                             (char *)llist->dflts[u]->realtype->plugin->print(ctx->ctx, llist->dflts[u], LY_VALUE_CANON,
diff --git a/src/tree_data.c b/src/tree_data.c
index 59b44d8..0d10d72 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -1589,6 +1589,8 @@
 LIBYANG_API_DEF LY_ERR
 lyd_compare_meta(const struct lyd_meta *meta1, const struct lyd_meta *meta2)
 {
+    const struct ly_ctx *ctx;
+
     if (!meta1 || !meta2) {
         if (meta1 == meta2) {
             return LY_SUCCESS;
@@ -1597,11 +1599,12 @@
         }
     }
 
-    if ((meta1->annotation->module->ctx != meta2->annotation->module->ctx) || (meta1->annotation != meta2->annotation)) {
+    ctx = meta1->annotation->module->ctx;
+    if ((ctx != meta2->annotation->module->ctx) || (meta1->annotation != meta2->annotation)) {
         return LY_ENOT;
     }
 
-    return meta1->value.realtype->plugin->compare(&meta1->value, &meta2->value);
+    return meta1->value.realtype->plugin->compare(ctx, &meta1->value, &meta2->value);
 }
 
 /**
diff --git a/src/tree_data_common.c b/src/tree_data_common.c
index 85744e7..e1973cc 100644
--- a/src/tree_data_common.c
+++ b/src/tree_data_common.c
@@ -693,7 +693,7 @@
     LY_CHECK_RET(ret);
 
     /* compare values */
-    ret = type->plugin->compare(&node->value, &val);
+    ret = type->plugin->compare(ctx, &node->value, &val);
 
     type->plugin->free(ctx, &val);
     return ret;
@@ -720,7 +720,7 @@
         }
 
         /* compare with the default value */
-        if (!leaf->type->plugin->compare(&term->value, leaf->dflt)) {
+        if (!leaf->type->plugin->compare(LYD_CTX(node), &term->value, leaf->dflt)) {
             return 1;
         }
     } else {
@@ -731,7 +731,7 @@
 
         LY_ARRAY_FOR(llist->dflts, u) {
             /* compare with each possible default value */
-            if (!llist->type->plugin->compare(&term->value, llist->dflts[u])) {
+            if (!llist->type->plugin->compare(LYD_CTX(node), &term->value, llist->dflts[u])) {
                 return 1;
             }
         }
diff --git a/src/tree_data_new.c b/src/tree_data_new.c
index caa26b1..13bb9bc 100644
--- a/src/tree_data_new.c
+++ b/src/tree_data_new.c
@@ -1345,7 +1345,7 @@
     LY_CHECK_GOTO(ret, cleanup);
 
     /* compare original and new value */
-    if (type->plugin->compare(&t->value, &val)) {
+    if (type->plugin->compare(LYD_CTX(term), &t->value, &val)) {
         /* values differ, switch them */
         lyd_change_term_value(t, &val);
         /* make the node non-validated */
diff --git a/src/validation.c b/src/validation.c
index 93a79c7..74653a7 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -1173,7 +1173,7 @@
                 val2 = slist->uniques[u][v]->dflt;
             }
 
-            if (!val1 || !val2 || val1->realtype->plugin->compare(val1, val2)) {
+            if (!val1 || !val2 || val1->realtype->plugin->compare(ctx, val1, val2)) {
                 /* values differ or either one is not set */
                 break;
             }