From 1a583725be9e138d015af208b3790458682e7719 Mon Sep 17 00:00:00 2001 From: dzaima Date: Wed, 7 Sep 2022 17:59:17 +0300 Subject: [PATCH] use TALLOCP in other places --- src/builtins/sortTemplate.h | 3 +-- src/builtins/sysfn.c | 6 ++---- src/utils/file.c | 3 +-- src/utils/hash.c | 5 ++--- src/vm.c | 4 ++-- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/builtins/sortTemplate.h b/src/builtins/sortTemplate.h index 4c2c46b8..1d435385 100644 --- a/src/builtins/sortTemplate.h +++ b/src/builtins/sortTemplate.h @@ -261,8 +261,7 @@ typedef struct { static void TIM_SORT_RESIZE(TEMP_STORAGE_T *store, const size_t new_size) { if (store->storage == NULL) { - TALLOC(SORT_TYPE, tempstore, new_size); - store->storage = tempstore; + store->storage = TALLOCP(SORT_TYPE, new_size); } else if (store->alloc < new_size) { store->storage = (SORT_TYPE *)TREALLOC(store->storage, new_size * sizeof(SORT_TYPE)); } else return; diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index a4457d5a..dc8adad3 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -939,9 +939,8 @@ B sh_c2(B t, B w, B x) { iBufRaw = get_chars(inObj); iBuf = iBufRaw.data; } else { - TALLOC(char, iBufT, iLen); - toUTF8(inObj, iBufT); - iBuf = iBufT; + iBuf = TALLOCP(char, iLen); + toUTF8(inObj, iBuf); } } else iBuf = NULL; #define FREE_INPUT do { if (iLen>0) { if (raw) free_chars(iBufRaw); else TFREE(iBuf); } } while(0) @@ -953,7 +952,6 @@ B sh_c2(B t, B w, B x) { // polling mess const u64 bufsz = 1024; - // TALLOC(char, oBuf, bufsz); u8* oBuf; B oBufObj = m_c8arrv(&oBuf, bufsz); usz* oBufIA = &a(oBufObj)->ia; diff --git a/src/utils/file.c b/src/utils/file.c index 84d439a1..9e16ef57 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -175,8 +175,7 @@ CharBuf get_chars(B x) { buf = tyany_ptr(x); alloc = false; } else { - TALLOC(char, val, len); - buf = val; + buf = TALLOCP(char, len); alloc = true; SGetU(x) for (u64 i = 0; i < len; i++) { diff --git a/src/utils/hash.c b/src/utils/hash.c index a2c5bbb6..25e0a580 100644 --- a/src/utils/hash.c +++ b/src/utils/hash.c @@ -21,11 +21,10 @@ NOINLINE u64 bqn_hashArr(B x, const u64 secret[4]) { // TODO manual separation o case el_i32: case el_c32: data = tyany_ptr(x); bytes = xia*4; break; case el_f64: data = f64any_ptr(x); bytes = xia*8; break; case el_B:; - TALLOC(u64, dataTmp, xia); + data = TALLOCP(u64, xia); isTemp = true; SGetU(x) - for (usz i = 0; i < xia; i++) dataTmp[i] = bqn_hash(GetU(x, i), secret); - data = dataTmp; + for (usz i = 0; i < xia; i++) ((u64*)data)[i] = bqn_hash(GetU(x, i), secret); bytes = xia*sizeof(B); break; } diff --git a/src/vm.c b/src/vm.c index e6d99377..65bc912d 100644 --- a/src/vm.c +++ b/src/vm.c @@ -183,7 +183,7 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl mCount = IA(b1); SGetU(b1) dCount = IA(b2); SGetU(b2) mapLen = mCount+dCount; - TALLOC(i32, bodyPs_, mapLen+2); bodyPs = bodyPs_; + bodyPs = TALLOCP(i32, mapLen+2); i32* bodyM = bodyPs; i32* bodyD = bodyPs + mCount+1; for (i32 i = 0; i < mCount; i++) bodyM[i] = o2i(GetU(b1, i)); @@ -193,7 +193,7 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl bodyM[mCount] = bodyD[dCount] = I32_MAX; } else { mapLen = 2; - TALLOC(i32, bodyPs_, mapLen+2); bodyPs = bodyPs_; + bodyPs = TALLOCP(i32, mapLen+2); bodyPs[0] = bodyPs[2] = o2i(bodyObj); bodyPs[1] = bodyPs[3] = I32_MAX; mCount = dCount = 1;