compact_ext_list(struct ly_ctx *ctx, void *elem, LYEXT_PAR elem_type)
{
    int rt;
    uint8_t *ext_size = 0, orig_size, i = 0, j = 0;
    struct lys_ext_instance ***ext_list = NULL;

    rt = lyp_get_ext_list(ctx, elem, elem_type, &ext_list, &ext_size, NULL);
    LY_CHECK_RETURN(rt, -1);

    orig_size = *ext_size;

    while (i < *ext_size) {
        if (!(*ext_list)[i]) {
            /* this extension is skipped, move all extensions after it */
            for (j = i; j < *ext_size - 1; j++) {
                (*ext_list)[j] = (*ext_list)[j + 1];
            }
            --(*ext_size);
        } else {
            ++i;
        }
    }

    lyp_reduce_ext_list(ext_list, *ext_size, orig_size);

    return 0;
}
compact_ext_list(struct ly_ctx *ctx, void *elem, LYEXT_PAR elem_type)
{
    int rt;
    uint8_t *ext_size = 0, orig_size, i = 0, j = 0;
    struct lys_ext_instance ***ext_list = NULL;

    rt = lyp_get_ext_list(ctx, elem, elem_type, &ext_list, &ext_size, NULL);
    LY_CHECK_RETURN(rt, -1);

    orig_size = *ext_size;

    while (i < *ext_size) {
        if (!(*ext_list)[i]) {
             
            for (j = i; j < *ext_size - 1; j++) {
                (*ext_list)[j] = (*ext_list)[j + 1];
            }
            --(*ext_size);
        } else {
            ++i;
        }
    }

    lyp_reduce_ext_list(ext_list, *ext_size, orig_size);

    return 0;
}