From 32ce7d3a700495f20292fae4ccc2ca90cfe4a81a Mon Sep 17 00:00:00 2001 From: timerix Date: Thu, 8 Jun 2023 15:59:52 +0600 Subject: [PATCH] some fixes --- .vscode/launch.json | 10 ---------- .vscode/tasks.json | 3 +-- src/base/cptr.c | 4 ++-- src/base/memory/StackingAllocator.c | 2 +- src/base/optime.h | 3 ++- src/base/type_system/unitype.c | 2 +- src/kprint/kprint.c | 1 - src/kprint/kprintf.c | 2 +- tests/test_autoarr-vs-vector.cpp | 2 +- tests/test_hash_functions.c | 25 +++++++++++++++---------- tests/tests.h | 22 +++++++++++----------- 11 files changed, 35 insertions(+), 41 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 44f903a..84446c4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -42,16 +42,6 @@ "pipeArgs": ["-c"], "pipeCwd": "${workspaceFolder}" } - }, - { - "name": "(msvc) Debug", - "type": "cppvsdbg", - "request": "launch", - "preLaunchTask": "build_dbg", - "program": "${workspaceFolder}\\bin\\kerep", - "cwd": "${workspaceFolder}\\bin", - "stopAtEntry": false, - "console": "integratedTerminal" } ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 4494a57..258e123 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -23,8 +23,7 @@ "reveal": "always", "focus": true, "panel": "shared", - "showReuseMessage": false, - "clean": true + "showReuseMessage": false } } ] diff --git a/src/base/cptr.c b/src/base/cptr.c index 038f0ab..071332e 100644 --- a/src/base/cptr.c +++ b/src/base/cptr.c @@ -158,8 +158,8 @@ char* __cptr_concat(allocator_ptr al, u32 n, ...){ totality+=lengths[k]; } - free(strs); - free(lengths); + allocator_free(al, lengths); + allocator_free(al, strs); return output; } diff --git a/src/base/memory/StackingAllocator.c b/src/base/memory/StackingAllocator.c index b1ae21c..3ca44aa 100644 --- a/src/base/memory/StackingAllocator.c +++ b/src/base/memory/StackingAllocator.c @@ -28,7 +28,7 @@ void StackingAllocator_free(allocator_ptr _self, void* data_ptr){ assert(data_ptr!=NULL); StackingAllocator* self = (StackingAllocator*)_self; AllocationHeader* header_ptr = data_ptr - sizeof(AllocationHeader); - + // TODO check is data_ptr pointer to the last allocation // chunk is empty if(curr_chunk->occupied_size==0){ // isn't the first chunk diff --git a/src/base/optime.h b/src/base/optime.h index 6b3e3b4..cfe072e 100644 --- a/src/base/optime.h +++ b/src/base/optime.h @@ -13,7 +13,8 @@ tni=1; \ } else tni=2; \ kprintf("\e[93moperation \e[94m%s\e[93m lasted \e[94m%f \e[93m%s\n", \ - opname, t, tnames[tni]); + opname, t, tnames[tni]); \ + fflush(stdout); #ifdef CLOCK_REALTIME /// executes codeblock and prints execution time diff --git a/src/base/type_system/unitype.c b/src/base/type_system/unitype.c index 85e7ebe..79fd2d7 100644 --- a/src/base/type_system/unitype.c +++ b/src/base/type_system/unitype.c @@ -91,7 +91,7 @@ char *Unitype_toString(allocator_ptr al, Unitype u, u32 fmt) void printuni(Unitype v) { LinearAllocator _al; - LinearAllocator_construct(&_al, 256); + LinearAllocator_construct(&_al, 128); allocator_ptr al=&_al.base; char *s = Unitype_toString(al, v, 0); fputs(s, stdout); diff --git a/src/kprint/kprint.c b/src/kprint/kprint.c index de5ed34..a700dcc 100644 --- a/src/kprint/kprint.c +++ b/src/kprint/kprint.c @@ -83,7 +83,6 @@ void __kprint(u8 n, kp_fmt* formats, __kp_value_union* objects){ kp_fmt fmt=formats[i]; kprint_setColor(fmt); tryLast(__next_toString(al, fmt, &objects[i]), maybeStr, - LinearAllocator_destruct(&_al); kprint_setColor(kp_bgBlack|kp_fgGray);); if(fputs(maybeStr.value.VoidPtr, stdout)==EOF) throw("can't write string to stdout"); diff --git a/src/kprint/kprintf.c b/src/kprint/kprintf.c index 114c0eb..1627af4 100644 --- a/src/kprint/kprintf.c +++ b/src/kprint/kprintf.c @@ -50,7 +50,7 @@ void kprintf(const char* format, ...){ va_start(vl, format); u32 i=0; LinearAllocator _al; - LinearAllocator_construct(&_al, 256); + LinearAllocator_construct(&_al, 128); allocator_ptr al=(allocator_ptr)&_al; for(char c=format[i++]; c!=0; c=format[i++]){ // value format specifiers diff --git a/tests/test_autoarr-vs-vector.cpp b/tests/test_autoarr-vs-vector.cpp index dd97b66..4368d52 100644 --- a/tests/test_autoarr-vs-vector.cpp +++ b/tests/test_autoarr-vs-vector.cpp @@ -29,6 +29,6 @@ void test_autoarrVsVector(){ _autoarrVsVector(64, 64); _autoarrVsVector(32, 1024); _autoarrVsVector(256, 256); - _autoarrVsVector(1024, 1024); + _autoarrVsVector(512, 4096); ); } diff --git a/tests/test_hash_functions.c b/tests/test_hash_functions.c index 93e6fef..4192b9a 100644 --- a/tests/test_hash_functions.c +++ b/tests/test_hash_functions.c @@ -1,26 +1,31 @@ #include "tests.h" #include "../src/HashFunctions/hash.h" #include "../src/Autoarr/Autoarr.h" +#include "../src/random/random.h" +#define SPEED_TESTS 1000000 +#define COLLISION_TESTS 64000 +char data[]="iojihi2ojo8la14nhvi3311pi[jiugbja38mo0ih6gfty88tryf-drh0lanvj03"; -#define SPEED_TESTS 100000 -#define COLLISION_TESTS 16000 - -char data[]="iojihiojopijiugbjmoihftytryfdrh"; +#define rng() splitmix64_next(&rng_state) #define test_hashfunc(hasht, hashf) { \ kprintf("\e[94mfunction: \e[92m" #hashf "\n"); \ hasht h=0; \ - optime("speed test", 1, \ - for(u32 i=0; i