From 89762b9934a7c78b9b28784860638e904d02609e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Vennstr=C3=B6m?= <6706447+avennstrom@users.noreply.github.com> Date: Tue, 11 May 2021 22:44:08 +0200 Subject: [PATCH 1/3] Fix stb_ds custom allocator --- stb_ds.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stb_ds.h b/stb_ds.h index d1e0c75..36a84c2 100644 --- a/stb_ds.h +++ b/stb_ds.h @@ -489,6 +489,7 @@ extern void stbds_unit_tests(void); // extern void * stbds_arrgrowf(void *a, size_t elemsize, size_t addlen, size_t min_cap); +extern void stbds_arrfreef(void *a); extern void stbds_hmfree_func(void *p, size_t elemsize); extern void * stbds_hmget_key(void *a, size_t elemsize, void *key, size_t keysize, int mode); extern void * stbds_hmget_key_ts(void *a, size_t elemsize, void *key, size_t keysize, ptrdiff_t *temp, int mode); @@ -543,7 +544,7 @@ extern void * stbds_shmode_func(size_t elemsize, int mode); #define stbds_arraddnptr(a,n) (stbds_arrmaybegrow(a,n), stbds_header(a)->length += (n), &(a)[stbds_header(a)->length-(n)]) #define stbds_arraddnoff(a,n) (stbds_arrmaybegrow(a,n), stbds_header(a)->length += (n), stbds_header(a)->length-(n)) #define stbds_arrlast(a) ((a)[stbds_header(a)->length-1]) -#define stbds_arrfree(a) ((void) ((a) ? STBDS_FREE(NULL,stbds_header(a)) : (void)0), (a)=NULL) +#define stbds_arrfree(a) ((void) ((a) ? stbds_arrfreef(a) : (void)0), (a)=NULL) #define stbds_arrdel(a,i) stbds_arrdeln(a,i,1) #define stbds_arrdeln(a,i,n) (memmove(&(a)[i], &(a)[(i)+(n)], sizeof *(a) * (stbds_header(a)->length-(n)-(i))), stbds_header(a)->length -= (n)) #define stbds_arrdelswap(a,i) ((a)[i] = stbds_arrlast(a), stbds_header(a)->length -= 1) @@ -789,6 +790,11 @@ void *stbds_arrgrowf(void *a, size_t elemsize, size_t addlen, size_t min_cap) return b; } +void stbds_arrfreef(void *a) +{ + STBDS_FREE(NULL, stbds_header(a)); +} + // // stbds_hm hash table implementation // From fcd86e8f576dab10a25bdbe9cf813751f565769e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Vennstr=C3=B6m?= <6706447+avennstrom@users.noreply.github.com> Date: Tue, 11 May 2021 22:50:11 +0200 Subject: [PATCH 2/3] credits --- stb_ds.h | 1 + 1 file changed, 1 insertion(+) diff --git a/stb_ds.h b/stb_ds.h index 36a84c2..bb57fc9 100644 --- a/stb_ds.h +++ b/stb_ds.h @@ -379,6 +379,7 @@ CREDITS Andreas Molzer github:hashitaku github:srdjanstipic + Andreas Vennström */ #ifdef STBDS_UNIT_TESTS From 579ace225f2fda79f98e72bc25dfe2b43434bbd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Vennstr=C3=B6m?= <6706447+avennstrom@users.noreply.github.com> Date: Tue, 11 May 2021 22:56:27 +0200 Subject: [PATCH 3/3] fix indentation --- stb_ds.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb_ds.h b/stb_ds.h index bb57fc9..dd2a03f 100644 --- a/stb_ds.h +++ b/stb_ds.h @@ -793,7 +793,7 @@ void *stbds_arrgrowf(void *a, size_t elemsize, size_t addlen, size_t min_cap) void stbds_arrfreef(void *a) { - STBDS_FREE(NULL, stbds_header(a)); + STBDS_FREE(NULL, stbds_header(a)); } //