diff --git a/CMakeLists.txt b/CMakeLists.txt index cd8ed46..7e18196 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ find_package(Gint 2.9 REQUIRED) set(SOURCES src/main.c + src/malloc.c src/game.c src/linked_list.c src/texture_manager.c diff --git a/src/linked_list.c b/src/linked_list.c index 49504b1..4edc78b 100644 --- a/src/linked_list.c +++ b/src/linked_list.c @@ -1,7 +1,5 @@ -#include #include "linked_list.h" - -#include +#include "malloc.h" void linked_list_init(linked_list_t *linked_list, const size_t data_size) { @@ -13,13 +11,13 @@ void linked_list_init(linked_list_t *linked_list, const size_t data_size) elem_t *elem_create(linked_list_t *linked_list) { elem_t *elem; - elem = kmalloc(sizeof(elem_t), NULL); + elem = malloc(sizeof(elem_t)); if(!elem) return NULL; - elem->data = kmalloc(linked_list->data_size, NULL); + elem->data = malloc(linked_list->data_size); if(!elem->data) { - kfree(elem); + free(elem); return NULL; } @@ -68,12 +66,8 @@ void linked_list_pop_back(linked_list_t *linked_list) else linked_list->first = NULL; - kfree(tmp->data); - kfree(tmp); - if(tmp != NULL) - { - dtext(80, 80, C_RED, "WHAT THE HELLL ??"); - } + free(tmp->data); + free(tmp); } void linked_list_pop_front(linked_list_t *linked_list) @@ -88,8 +82,8 @@ void linked_list_pop_front(linked_list_t *linked_list) else linked_list->last = NULL; - kfree(tmp->data); - kfree(tmp); + free(tmp->data); + free(tmp); } size_t linked_list_get_size(linked_list_t *linked_list) diff --git a/src/main.c b/src/main.c index 858aa47..19be62a 100644 --- a/src/main.c +++ b/src/main.c @@ -17,9 +17,9 @@ int main(void) } */ -#include #include #include +#include "malloc.h" #include "linked_list.h" int main(void) diff --git a/src/malloc.c b/src/malloc.c new file mode 100644 index 0000000..e507c56 --- /dev/null +++ b/src/malloc.c @@ -0,0 +1,12 @@ +#include "malloc.h" + +inline void *malloc(size_t size) +{ + return kmalloc(size, NULL); +} + +inline void free(void *ptr) +{ + kfree(ptr); + ptr = NULL; +} diff --git a/src/malloc.h b/src/malloc.h new file mode 100644 index 0000000..d76a514 --- /dev/null +++ b/src/malloc.h @@ -0,0 +1,18 @@ +#ifndef MALLOC_H +#define MALLOC_H + +#include + +/* malloc(): Just call kmalloc from gint/kmalloc.h. + + @size Size of requested block + Returns address of allocated block, NULL on error. */ +inline void *malloc(size_t size); + +/* malloc(): Just call kmalloc from gint/kmalloc.h. + + @ptr Pointer to free + Free given ptr and reaffect to NULL. */ +inline void free(void *ptr); + +#endif // MALLOC_H \ No newline at end of file