libyang CHANGE remove rarely used macro

Macro LY_ARRAY_RESIZE_ERR_RET was used just once and it can be replaced
by LY_ARRAY_CREATE_RET.
diff --git a/src/common.h b/src/common.h
index 0a80f5f..19ece23 100644
--- a/src/common.h
+++ b/src/common.h
@@ -588,7 +588,7 @@
  */
 #define LY_ARRAY_CREATE_GOTO(CTX, ARRAY, SIZE, RET, GOTO) \
         if (ARRAY) { \
-            ARRAY = ly_realloc(((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1), sizeof(LY_ARRAY_COUNT_TYPE) + ((*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1) + (SIZE)) * sizeof *(ARRAY))); \
+            ARRAY = ly_realloc(((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1), sizeof(LY_ARRAY_COUNT_TYPE) + ((LY_ARRAY_COUNT(ARRAY) + (SIZE)) * sizeof *(ARRAY))); \
             LY_CHECK_ERR_GOTO(!(ARRAY), LOGMEM(CTX); RET = LY_EMEM, GOTO); \
             ARRAY = (void*)((LY_ARRAY_COUNT_TYPE*)(ARRAY) + 1); \
             memset(&(ARRAY)[*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1)], 0, (SIZE) * sizeof *(ARRAY)); \
@@ -599,24 +599,6 @@
         }
 
 /**
- * @brief Resize a ([sized array](@ref sizedarrays)) to the the specified number of items.
- *
- * Does not change the count information, it is supposed to be incremented via ::LY_ARRAY_INCREMENT
- * when the items are filled.
- *
- * @param[in] CTX libyang context for logging.
- * @param[in,out] ARRAY Pointer to the array to create.
- * @param[in] SIZE Number of items the array is supposed to hold. The size of the allocated
- * space is then counted from the type of the ARRAY, so do not provide placeholder void pointers.
- * @param[in] ERR Additional action(s) in case of error (passed to LY_CHECK_ERR_RET).
- * @param[in] RETVAL Return value for the case of error (memory allocation failure).
- */
-#define LY_ARRAY_RESIZE_ERR_RET(CTX, ARRAY, SIZE, ERR, RETVAL) \
-        ARRAY = ly_realloc(((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1), sizeof(LY_ARRAY_COUNT_TYPE) + ((SIZE) * sizeof *(ARRAY))); \
-        LY_CHECK_ERR_RET(!(ARRAY), LOGMEM(CTX); ERR, RETVAL); \
-        ARRAY = (void*)((LY_ARRAY_COUNT_TYPE*)(ARRAY) + 1);
-
-/**
  * @brief Increment the items counter in a ([sized array](@ref sizedarrays)).
  *
  * Does not change the allocated memory used by the ARRAY. To do so, use LY_ARRAY_CREATE_RET,
diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c
index 53d73ec..50275d7 100644
--- a/src/schema_compile_node.c
+++ b/src/schema_compile_node.c
@@ -1314,6 +1314,73 @@
     return ret;
 }
 
+static LY_ERR
+lys_compile_type_union(struct lysc_ctx *ctx, struct lysp_type *ptypes, struct lysp_node *context_pnode, uint16_t context_flags,
+        struct lysp_module *context_mod, const char *context_name, struct lysc_type ***utypes_p)
+{
+    LY_ERR ret = LY_SUCCESS;
+    struct lysc_type **utypes = *utypes_p;
+    struct lysc_type_union *un_aux = NULL;
+
+    LY_ARRAY_CREATE_GOTO(ctx->ctx, utypes, LY_ARRAY_COUNT(ptypes), ret, error);
+    for (LY_ARRAY_COUNT_TYPE u = 0, additional = 0; u < LY_ARRAY_COUNT(ptypes); ++u) {
+        ret = lys_compile_type(ctx, context_pnode, context_flags, context_mod, context_name, &ptypes[u], &utypes[u + additional], NULL, NULL);
+        LY_CHECK_GOTO(ret, error);
+        if (utypes[u + additional]->basetype == LY_TYPE_UNION) {
+            /* add space for additional types from the union subtype */
+            un_aux = (struct lysc_type_union *)utypes[u + additional];
+            LY_ARRAY_CREATE_GOTO(ctx->ctx, utypes,
+                    LY_ARRAY_COUNT(ptypes) + additional + LY_ARRAY_COUNT(un_aux->types) - LY_ARRAY_COUNT(utypes), ret, error);
+
+            /* copy subtypes of the subtype union */
+            for (LY_ARRAY_COUNT_TYPE v = 0; v < LY_ARRAY_COUNT(un_aux->types); ++v) {
+                if (un_aux->types[v]->basetype == LY_TYPE_LEAFREF) {
+                    struct lysc_type_leafref *lref;
+
+                    /* duplicate the whole structure because of the instance-specific path resolving for realtype */
+                    utypes[u + additional] = calloc(1, sizeof(struct lysc_type_leafref));
+                    LY_CHECK_ERR_GOTO(!utypes[u + additional], LOGMEM(ctx->ctx); ret = LY_EMEM, error);
+                    lref = (struct lysc_type_leafref *)utypes[u + additional];
+
+                    lref->basetype = LY_TYPE_LEAFREF;
+                    ret = lyxp_expr_dup(ctx->ctx, ((struct lysc_type_leafref *)un_aux->types[v])->path, &lref->path);
+                    LY_CHECK_GOTO(ret, error);
+                    lref->refcount = 1;
+                    lref->cur_mod = ((struct lysc_type_leafref *)un_aux->types[v])->cur_mod;
+                    lref->require_instance = ((struct lysc_type_leafref *)un_aux->types[v])->require_instance;
+                    ret = lysc_prefixes_dup(((struct lysc_type_leafref *)un_aux->types[v])->prefixes, &lref->prefixes);
+                    LY_CHECK_GOTO(ret, error);
+                    /* TODO extensions */
+
+                } else {
+                    utypes[u + additional] = un_aux->types[v];
+                    ++un_aux->types[v]->refcount;
+                }
+                ++additional;
+                LY_ARRAY_INCREMENT(utypes);
+            }
+            /* compensate u increment in main loop */
+            --additional;
+
+            /* free the replaced union subtype */
+            lysc_type_free(ctx->ctx, (struct lysc_type *)un_aux);
+            un_aux = NULL;
+        } else {
+            LY_ARRAY_INCREMENT(utypes);
+        }
+    }
+
+    *utypes_p = utypes;
+    return LY_SUCCESS;
+
+error:
+    if (un_aux) {
+        lysc_type_free(ctx->ctx, (struct lysc_type *)un_aux);
+    }
+    *utypes_p = utypes;
+    return ret;
+}
+
 /**
  * @brief The core of the lys_compile_type() - compile information about the given type (from typedef or leaf/leaf-list).
  * @param[in] ctx Compile context.
@@ -1342,7 +1409,7 @@
     struct lysc_type_dec *dec;
     struct lysc_type_identityref *idref;
     struct lysc_type_leafref *lref;
-    struct lysc_type_union *un, *un_aux;
+    struct lysc_type_union *un;
 
     switch (basetype) {
     case LY_TYPE_BINARY:
@@ -1571,49 +1638,8 @@
                 return LY_EVALID;
             }
             /* compile the type */
-            LY_ARRAY_CREATE_RET(ctx->ctx, un->types, LY_ARRAY_COUNT(type_p->types), LY_EVALID);
-            for (LY_ARRAY_COUNT_TYPE u = 0, additional = 0; u < LY_ARRAY_COUNT(type_p->types); ++u) {
-                LY_CHECK_RET(lys_compile_type(ctx, context_pnode, context_flags, context_mod, context_name,
-                        &type_p->types[u], &un->types[u + additional], NULL, NULL));
-                if (un->types[u + additional]->basetype == LY_TYPE_UNION) {
-                    /* add space for additional types from the union subtype */
-                    un_aux = (struct lysc_type_union *)un->types[u + additional];
-                    LY_ARRAY_RESIZE_ERR_RET(ctx->ctx, un->types, (*((uint64_t *)(type_p->types) - 1)) + additional + LY_ARRAY_COUNT(un_aux->types) - 1,
-                            lysc_type_free(ctx->ctx, (struct lysc_type *)un_aux), LY_EMEM);
-
-                    /* copy subtypes of the subtype union */
-                    for (LY_ARRAY_COUNT_TYPE v = 0; v < LY_ARRAY_COUNT(un_aux->types); ++v) {
-                        if (un_aux->types[v]->basetype == LY_TYPE_LEAFREF) {
-                            /* duplicate the whole structure because of the instance-specific path resolving for realtype */
-                            un->types[u + additional] = calloc(1, sizeof(struct lysc_type_leafref));
-                            LY_CHECK_ERR_RET(!un->types[u + additional], LOGMEM(ctx->ctx); lysc_type_free(ctx->ctx, (struct lysc_type *)un_aux), LY_EMEM);
-                            lref = (struct lysc_type_leafref *)un->types[u + additional];
-
-                            lref->basetype = LY_TYPE_LEAFREF;
-                            LY_CHECK_RET(lyxp_expr_dup(ctx->ctx, ((struct lysc_type_leafref *)un_aux->types[v])->path, &lref->path));
-                            lref->refcount = 1;
-                            lref->cur_mod = ((struct lysc_type_leafref *)un_aux->types[v])->cur_mod;
-                            lref->require_instance = ((struct lysc_type_leafref *)un_aux->types[v])->require_instance;
-                            LY_CHECK_RET(lysc_prefixes_dup(((struct lysc_type_leafref *)un_aux->types[v])->prefixes,
-                                    &lref->prefixes));
-                            /* TODO extensions */
-
-                        } else {
-                            un->types[u + additional] = un_aux->types[v];
-                            ++un_aux->types[v]->refcount;
-                        }
-                        ++additional;
-                        LY_ARRAY_INCREMENT(un->types);
-                    }
-                    /* compensate u increment in main loop */
-                    --additional;
-
-                    /* free the replaced union subtype */
-                    lysc_type_free(ctx->ctx, (struct lysc_type *)un_aux);
-                } else {
-                    LY_ARRAY_INCREMENT(un->types);
-                }
-            }
+            LY_CHECK_RET(lys_compile_type_union(ctx, type_p->types, context_pnode, context_flags, context_mod, context_name,
+                    &un->types));
         }
 
         if (!base && !type_p->flags) {