Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# set version of the project
set(LIBYANG_MAJOR_VERSION 6)
set(LIBYANG_MINOR_VERSION 4)
set(LIBYANG_MICRO_VERSION 3)
set(LIBYANG_MICRO_VERSION 4)
set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION})

# set version of the library
set(LIBYANG_MAJOR_SOVERSION 5)
set(LIBYANG_MINOR_SOVERSION 11)
set(LIBYANG_MICRO_SOVERSION 1)
set(LIBYANG_MICRO_SOVERSION 2)
set(LIBYANG_SOVERSION_FULL ${LIBYANG_MAJOR_SOVERSION}.${LIBYANG_MINOR_SOVERSION}.${LIBYANG_MICRO_SOVERSION})
set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_SOVERSION})

Expand Down
2 changes: 1 addition & 1 deletion src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ lyd_diff_userord_attrs(const struct lyd_node *first, const struct lyd_node *seco
*/
if (*op == LYD_DIFF_OP_CREATE) {
/* insert the instance */
LYA_PREALLOC(userord_item->inst, 1, LOGMEM(schema->module->ctx); rc = LY_EMEM; goto cleanup);
LYA_PREALLOC(userord_item->inst, LYA_COUNT(userord_item->inst) + 1, LOGMEM(schema->module->ctx); rc = LY_EMEM; goto cleanup);
if (second_pos < LYA_COUNT(userord_item->inst)) {
memmove(userord_item->inst + second_pos + 1, userord_item->inst + second_pos,
(LYA_COUNT(userord_item->inst) - second_pos) * sizeof *userord_item->inst);
Expand Down
24 changes: 13 additions & 11 deletions src/ly_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,28 @@ extern "C" {
* Does not set the size information, it is supposed to be incremented via ::LYA_INCREMENT
* when the items are filled.
*
* Any new memory is zeroed.
* Any new memory is zeroed. The array is never shrunk below its current count.
*
* @param[in,out] ARRAY Sized array to manipulate.
* @param[in] COUNT New count (size) of the items in the array.
* @param[in] EACTION Error action on memory allocation error, must include 'return' or 'goto' commands.
*/
#define LYA_PREALLOC(ARRAY, COUNT, EACTION) \
{ \
LYA_COUNT_T orig_count = LYA_COUNT(ARRAY); \
void *mem = realloc((ARRAY) ? (LYA_COUNT_T *)(ARRAY) - 1 : NULL, \
sizeof(LYA_COUNT_T) + (orig_count + COUNT) * sizeof *(ARRAY)); \
if (!mem) { \
EACTION; \
LYA_COUNT_T lya_prealloc_orig = LYA_COUNT(ARRAY); \
LYA_COUNT_T lya_prealloc_count = (COUNT); \
if (lya_prealloc_count < lya_prealloc_orig) { \
lya_prealloc_count = lya_prealloc_orig; \
} \
void *new_array = (LYA_COUNT_T *)mem + 1; \
memcpy(&(ARRAY), &new_array, sizeof(ARRAY)); \
LYA_COUNT_(ARRAY) = orig_count; \
if ((COUNT) > orig_count) { \
memset((ARRAY) + orig_count, 0, ((COUNT) - orig_count) * sizeof *(ARRAY)); \
void *lya_prealloc_mem = realloc((ARRAY) ? (LYA_COUNT_T *)(ARRAY) - 1 : NULL, \
sizeof(LYA_COUNT_T) + lya_prealloc_count * sizeof *(ARRAY)); \
if (!lya_prealloc_mem) { \
EACTION; \
} \
void *lya_prealloc_array = (LYA_COUNT_T *)lya_prealloc_mem + 1; \
memcpy(&(ARRAY), &lya_prealloc_array, sizeof(ARRAY)); \
LYA_COUNT_(ARRAY) = lya_prealloc_orig; \
memset((ARRAY) + lya_prealloc_orig, 0, (lya_prealloc_count - lya_prealloc_orig) * sizeof *(ARRAY)); \
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ ly_path_append(const struct ly_ctx *ctx, const struct ly_path *src, struct ly_pa
return LY_SUCCESS;
}

LYA_PREALLOC(*dst, LYA_COUNT(src), LOGMEM(ctx); return LY_EMEM);
LYA_PREALLOC(*dst, LYA_COUNT(*dst) + LYA_COUNT(src), LOGMEM(ctx); return LY_EMEM);
LYA_FOR(src, u) {
LYA_ADD_ITEM(*dst, p, LOGMEM(ctx); rc = LY_EMEM; goto cleanup);
p->node = src[u].node;
Expand Down
2 changes: 1 addition & 1 deletion src/schema_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ struct lysc_unres_dflt {
if (ORIG_ARRAY) { \
LYA_COUNT_T __u, __new_start; \
__new_start = LYA_COUNT(NEW_ARRAY); \
LYA_PREALLOC(NEW_ARRAY, LYA_COUNT(ORIG_ARRAY), LOGMEM(CTX); return LY_EMEM); \
LYA_PREALLOC(NEW_ARRAY, __new_start + LYA_COUNT(ORIG_ARRAY), LOGMEM(CTX); return LY_EMEM); \
LYA_FOR(ORIG_ARRAY, __u) { \
LYA_INCREMENT(NEW_ARRAY); \
LY_CHECK_RET(DUP_FUNC(CTX, PMOD, PARENT, PARENT_STMT, &(ORIG_ARRAY)[__u], &(NEW_ARRAY)[__new_start + __u])); \
Expand Down
4 changes: 2 additions & 2 deletions src/schema_compile_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -1450,8 +1450,8 @@ lys_compile_type_union(struct lysc_ctx *ctx, struct lysp_type *ptypes, struct ly
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];
LYA_PREALLOC(utypes, LYA_COUNT(ptypes) + additional + LYA_COUNT(un_aux->types) - LYA_COUNT(utypes),
LOGMEM(ctx->ctx); rc = LY_EMEM; goto cleanup);
LYA_PREALLOC(utypes, LYA_COUNT(ptypes) + additional + LYA_COUNT(un_aux->types), LOGMEM(ctx->ctx);
rc = LY_EMEM; goto cleanup);

/* copy subtypes of the subtype union */
for (v = 0; v < LYA_COUNT(un_aux->types); ++v) {
Expand Down
Loading