Put the custom allocator in its own lib, as to lessen the difficulty to switch between libc's allocator and a custom one (#7)

This commit is contained in:
Maix0 2024-05-14 18:56:53 +02:00 committed by GitHub
parent 713f0f0302
commit cb7f3c3fdf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
85 changed files with 1121 additions and 877 deletions

View file

@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* functions1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/14 18:02:12 by maiboyer #+# #+# */
/* Updated: 2024/05/14 18:49:50 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "aq/allocator.h"
#include "aq/libc_wrapper.h"
#include "me/types.h"
void *__libc_malloc(t_usize size);
void *__libc_calloc(t_usize size, t_usize elem);
void *__libc_realloc(void *ptr, t_usize size);
void *__libc_reallocarray(void *ptr, t_usize size, t_usize elem);
void __libc_free(void *ptr);
void *lc_malloc(t_allocator *self, t_usize size)
{
(void)(self);
return (__libc_malloc(size));
}
void *lc_calloc(t_allocator *self, t_usize size, t_usize elem)
{
(void)(self);
return (__libc_calloc(size, elem));
}
void *lc_realloc(t_allocator *self, void *ptr, t_usize size)
{
(void)(self);
return (__libc_realloc(ptr, size));
}
void *lc_realloc_array(t_allocator *self, void *ptr, t_usize size, t_usize elem)
{
(void)(self);
return (__libc_reallocarray(ptr, size, elem));
}
void lc_free(t_allocator *self, void *ptr)
{
(void)(self);
return (__libc_free(ptr));
}

View file

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* functions2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/14 18:06:34 by maiboyer #+# #+# */
/* Updated: 2024/05/14 18:48:41 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "aq/allocator.h"
#include "aq/libc_wrapper.h"
void lc_uninit(t_allocator *self)
{
(void)(self);
}
t_allocator lc_init(void)
{
return ((t_allocator){
.alloc = lc_malloc,
.alloc_array = lc_calloc,
.realloc = lc_realloc,
.realloc_array = lc_realloc_array,
.free = lc_free,
.uninit = lc_uninit,
.alloc_data = NULL,
});
}