From 3a2a80f70a7cddad471db95ba709543a849dd5e7 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Wed, 11 Sep 2024 01:04:18 +0200 Subject: [PATCH] add PTK_LIST_GROW --- src/ptk_list.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ptk_list.h b/src/ptk_list.h index d173c2f..6fa8910 100644 --- a/src/ptk_list.h +++ b/src/ptk_list.h @@ -23,11 +23,15 @@ #define PTK_LIST_REMOVE_AT(T, list, index) _remove_at_PtkList((void *)list.data, &list.size, index, sizeof(T)) -#define PTK_LIST_SET(T, list, index, elem) do {\ - while (list.allocated <= index) {\ +#define PTK_LIST_GROW(T, list, new_size) do {\ + while (list.allocated < new_size) {\ /* let's hope this doesn't fail !!! */\ _grow_PtkList((void *)&list.data, &list.allocated, sizeof(T));\ }\ +} while (0) + +#define PTK_LIST_SET(T, list, index, elem) do {\ + PTK_LIST_GROW(T, list, index + 1);\ list.data[index] = elem;\ } while (0)