From 7657ad1b58c3b13fd9ee05be3db2883804c50894 Mon Sep 17 00:00:00 2001
From: Abdelrahman <said.abdelrahman89@gmail.com>
Date: Sat, 1 Feb 2025 21:39:27 +0000
Subject: [PATCH] Remove libc allocator

---
 src/core/mem/libc/mem_libc_allocator.c | 62 --------------------------
 src/core/mem/libc/mem_libc_allocator.h | 16 -------
 tests/allocator/test_allocator.c       | 17 -------
 tests/allocator/test_allocator.h       |  1 -
 tests/wapptest.c                       |  5 +--
 5 files changed, 2 insertions(+), 99 deletions(-)
 delete mode 100644 src/core/mem/libc/mem_libc_allocator.c
 delete mode 100644 src/core/mem/libc/mem_libc_allocator.h

diff --git a/src/core/mem/libc/mem_libc_allocator.c b/src/core/mem/libc/mem_libc_allocator.c
deleted file mode 100644
index 88b4e82..0000000
--- a/src/core/mem/libc/mem_libc_allocator.c
+++ /dev/null
@@ -1,62 +0,0 @@
-#include "mem_libc_allocator.h"
-#include "aliases.h"
-#include "mem_allocator.h"
-#include <stdlib.h>
-#include <string.h>
-
-internal inline void *mem_libc_alloc(u64 size, void *alloc_obj);
-// TODO (Abdelrahman): aligned_alloc isn't implemented on Windows. Revisit later
-#if 0
-internal inline void *mem_libc_alloc_aligned(u64 size, u64 alignment, void *alloc_obj);
-#endif
-internal inline void *mem_libc_realloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj);
-internal inline void mem_libc_free(void **ptr, void *alloc_obj);
-
-Allocator wapp_mem_libc_allocator(void) {
-  return (Allocator){
-      .obj             = NULL,
-      .alloc           = mem_libc_alloc,
-      .alloc_aligned   = NULL,
-      .realloc         = mem_libc_realloc,
-      .realloc_aligned = NULL,
-      .free            = mem_libc_free,
-  };
-}
-
-internal inline void *mem_libc_alloc(u64 size, void *alloc_obj) {
-  (void)alloc_obj; // Silence unused warnings
-  return calloc(1, size);
-}
-
-#if 0
-internal inline void *mem_libc_alloc_aligned(u64 size, u64 alignment,
-                                             void *alloc_obj) {
-  (void)alloc_obj; // Silence unused warnings
-
-  void *output = aligned_alloc(alignment, size);
-  if (output) {
-    memset(output, 0, size);
-  }
-
-  return output;
-}
-#endif
-
-internal inline void *mem_libc_realloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj) {
-  // Silence unused warnings
-  (void)alloc_obj;
-  (void)new_size;
-
-  return realloc(ptr, old_size);
-}
-
-internal inline void mem_libc_free(void **ptr, void *alloc_obj) {
-  (void)alloc_obj; // Silence unused warnings
-
-  if (!ptr || !(*ptr)) {
-    return;
-  }
-
-  free(*ptr);
-  *ptr = NULL;
-}
diff --git a/src/core/mem/libc/mem_libc_allocator.h b/src/core/mem/libc/mem_libc_allocator.h
deleted file mode 100644
index 0c0491e..0000000
--- a/src/core/mem/libc/mem_libc_allocator.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef MEM_LIBC_H
-#define MEM_LIBC_H
-
-#include "mem_allocator.h"
-
-#ifdef __cplusplus
-BEGIN_C_LINKAGE
-#endif // __cplusplus
-
-Allocator wapp_mem_libc_allocator(void);
-
-#ifdef __cplusplus
-END_C_LINKAGE
-#endif // __cplusplus
-
-#endif // !MEM_LIBC_H
diff --git a/tests/allocator/test_allocator.c b/tests/allocator/test_allocator.c
index 3ad304d..5291d2a 100644
--- a/tests/allocator/test_allocator.c
+++ b/tests/allocator/test_allocator.c
@@ -1,27 +1,10 @@
 #include "test_allocator.h"
-#include "libc/mem_libc_allocator.h"
 #include "mem_allocator.h"
 #include "mem_arena_allocator.h"
 #include "tester.h"
 #include <stdbool.h>
 #include <stdlib.h>
 
-TestFuncResult test_libc_allocator(void) {
-  Allocator allocator = wapp_mem_libc_allocator();
-  bool result         = allocator.obj == NULL && allocator.alloc != NULL &&
-                        allocator.alloc_aligned == NULL && allocator.realloc != NULL &&
-                        allocator.realloc_aligned == NULL && allocator.free != NULL;
-  void *ptr           = wapp_mem_allocator_alloc(&allocator, 20);
-  result              = result && (ptr != NULL);
-
-  if (ptr != NULL) {
-    wapp_mem_allocator_free(&allocator, &ptr);
-    result = result && (ptr == NULL);
-  }
-
-  return wapp_tester_result(result);
-}
-
 TestFuncResult test_arena_allocator(void) {
   Allocator allocator = wapp_mem_arena_allocator_init(4096);
   bool result         = allocator.obj != NULL && allocator.alloc != NULL &&
diff --git a/tests/allocator/test_allocator.h b/tests/allocator/test_allocator.h
index 7b28de2..4e74555 100644
--- a/tests/allocator/test_allocator.h
+++ b/tests/allocator/test_allocator.h
@@ -7,7 +7,6 @@
 BEGIN_C_LINKAGE
 #endif // __cplusplus
 
-TestFuncResult test_libc_allocator(void);
 TestFuncResult test_arena_allocator(void);
 
 #ifdef __cplusplus
diff --git a/tests/wapptest.c b/tests/wapptest.c
index 3167607..8e5352a 100644
--- a/tests/wapptest.c
+++ b/tests/wapptest.c
@@ -9,9 +9,8 @@
 
 
 int main(void) {
-  wapp_tester_run_tests(test_libc_allocator, test_arena_allocator, test_arena_init,
-                        test_arena_init_succeeds_when_reserving_very_large_size, test_str8_lit,
-                        test_str8_buf, test_str8_get_index_within_bounds, test_str8_get_index_out_of_bounds,
+  wapp_tester_run_tests(test_arena_allocator, test_arena_init, test_arena_init_succeeds_when_reserving_very_large_size,
+                        test_str8_lit, test_str8_buf, test_str8_get_index_within_bounds, test_str8_get_index_out_of_bounds,
                         test_str8_set, test_cpath_join_path, test_cpath_dirname, test_cpath_dirup,
                         test_arena_alloc_succeeds_when_within_capacity, test_arena_alloc_fails_when_over_capacity,
                         test_arena_realloc_bigger_size, test_arena_realloc_smaller_size, test_arena_clear,