From 56f152cf57e0bd3491be74195905b863519d9fca Mon Sep 17 00:00:00 2001 From: Physick <96335032+DegustatorPonos@users.noreply.github.com> Date: Mon, 3 Aug 2026 00:46:21 +0500 Subject: memory leak issues + qol stull --- src/puzzles/puzzle.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/puzzles/puzzle.c') diff --git a/src/puzzles/puzzle.c b/src/puzzles/puzzle.c index 6d0a4a0..e14708f 100644 --- a/src/puzzles/puzzle.c +++ b/src/puzzles/puzzle.c @@ -5,6 +5,7 @@ #include #include #include +#include static const char *USER_MODULE_NAME = "main"; @@ -37,12 +38,20 @@ Puzzle *GetTestPuzzle() { return outp; } +void FreePuzzleIO(PuzzleIO *io) { + if (io->value != NULL) + free(io->value); +} + void FreeTests(Test *Tests, size_t TestC) { if (TestC == 0 || Tests == NULL) return; for (size_t i = 0; i < TestC; i++) { Test *t = &Tests[i]; if (t->RecieverName != NULL) free(t->RecieverName); if (t->MainMethodSignature != NULL) free(t->MainMethodSignature); + for (size_t j = 0; j < t->argc; j++) { + FreePuzzleIO(&t->argv[j]); + } if (t->argv != NULL) free(t->argv); } free(Tests); @@ -362,3 +371,44 @@ void FreeSunmitionResult(SubmitionResult *res) { if (res->stdout_sb != NULL) free(res->stdout_sb); free(res); } + +void PrintPuzzle(Puzzle *puzzle) { + printf("Puzzle name: %s\n", puzzle->Name); + printf("Puzzle description: %s\n", puzzle->Description); + printf("Puzzle code: %s\n", puzzle->InitialCode); + printf("Puzzle TestC: %zu\n", puzzle->TestC); + + for (int i = 0; i < puzzle->TestC; i++) { + Test t = puzzle->Tests[i]; + printf("\nTest %d:\n", i); + printf("\tTest rec: %s\n", t.RecieverName); + printf("\tTest sig: %s\n", t.MainMethodSignature); + printf("\tTest argc: %zu\n", t.argc); + printf("\tArguments:\n"); + + for (int j = 0; j < t.argc; j++) { + PuzzleIO io = t.argv[j]; + switch (io.type) { + case WREN_TYPE_BOOL: + printf("\t\t(bool)%s\n", *(bool *)io.value ? "true" : "false"); + break; + case WREN_TYPE_NUM: + printf("\t\t(num)%f\n", *(float *)io.value); + break; + case WREN_TYPE_LIST: + printf("\t\t(list)NOT SUPPORTED\n"); + break; + case WREN_TYPE_MAP: + printf("\t\t(list)NOT SUPPORTED\n"); + break; + case WREN_TYPE_NULL: + printf("\t\t(null)\n"); + break; + case WREN_TYPE_STRING: + printf("\t\t(string)%s\n", (char *)io.value); + break; + default: break; + } + } + } +} -- cgit v1.3