From 902bc6d7f00996e08c09eb9dbd226e0e53b4cacb Mon Sep 17 00:00:00 2001 From: Gregory Date: Sat, 4 May 2019 20:23:32 +0300 Subject: [PATCH] base for malloc --- .gitignore | 1 + build.sh | 18 ++- inc/ft_malloc.h | 1 + inc/ft_malloc_internal.h | 37 ++++++ inc/meson.build | 1 - meson.build | 26 ++++- src/malloc.c | 105 +++++++++++++++++- src/meson.build | 12 -- {lib => subprojects}/libft/Makefile | 0 {lib => subprojects}/libft/author | 0 {lib => subprojects}/libft/ft_atof.c | 0 {lib => subprojects}/libft/ft_atoi.c | 0 {lib => subprojects}/libft/ft_bzero.c | 0 {lib => subprojects}/libft/ft_isalnum.c | 0 {lib => subprojects}/libft/ft_isalpha.c | 0 {lib => subprojects}/libft/ft_isascii.c | 0 {lib => subprojects}/libft/ft_isdigit.c | 0 {lib => subprojects}/libft/ft_isprint.c | 0 {lib => subprojects}/libft/ft_isspace.c | 0 {lib => subprojects}/libft/ft_itoa.c | 0 {lib => subprojects}/libft/ft_lst_at.c | 0 {lib => subprojects}/libft/ft_lst_len.c | 0 .../libft/ft_lst_merge_sort.c | 4 +- {lib => subprojects}/libft/ft_lst_rev.c | 0 {lib => subprojects}/libft/ft_lst_search.c | 0 {lib => subprojects}/libft/ft_lstadd.c | 0 {lib => subprojects}/libft/ft_lstadd_back.c | 0 {lib => subprojects}/libft/ft_lstdel.c | 0 {lib => subprojects}/libft/ft_lstdelone.c | 0 {lib => subprojects}/libft/ft_lstfind.c | 0 {lib => subprojects}/libft/ft_lstiter.c | 0 {lib => subprojects}/libft/ft_lstmap.c | 0 {lib => subprojects}/libft/ft_lstnew.c | 0 {lib => subprojects}/libft/ft_lstreduce.c | 0 {lib => subprojects}/libft/ft_lststrsplit.c | 0 {lib => subprojects}/libft/ft_memalloc.c | 0 {lib => subprojects}/libft/ft_memccpy.c | 0 {lib => subprojects}/libft/ft_memchr.c | 0 {lib => subprojects}/libft/ft_memcmp.c | 0 {lib => subprojects}/libft/ft_memcpy.c | 0 {lib => subprojects}/libft/ft_memdel.c | 0 {lib => subprojects}/libft/ft_memmove.c | 0 {lib => subprojects}/libft/ft_memset.c | 0 {lib => subprojects}/libft/ft_num_len.c | 0 {lib => subprojects}/libft/ft_putchar.c | 0 {lib => subprojects}/libft/ft_putchar_fd.c | 0 {lib => subprojects}/libft/ft_putendl.c | 0 {lib => subprojects}/libft/ft_putendl_fd.c | 0 {lib => subprojects}/libft/ft_putnbr.c | 0 {lib => subprojects}/libft/ft_putnbr_fd.c | 0 {lib => subprojects}/libft/ft_putstr.c | 0 {lib => subprojects}/libft/ft_putstr_fd.c | 0 {lib => subprojects}/libft/ft_read_file.c | 0 {lib => subprojects}/libft/ft_realloc.c | 0 {lib => subprojects}/libft/ft_str_table_len.c | 0 {lib => subprojects}/libft/ft_strcat.c | 0 {lib => subprojects}/libft/ft_strchr.c | 0 {lib => subprojects}/libft/ft_strclr.c | 0 {lib => subprojects}/libft/ft_strcmp.c | 0 {lib => subprojects}/libft/ft_strcmp_lex.c | 0 {lib => subprojects}/libft/ft_strcpy.c | 0 {lib => subprojects}/libft/ft_strdel.c | 0 {lib => subprojects}/libft/ft_strdup.c | 0 {lib => subprojects}/libft/ft_strequ.c | 0 {lib => subprojects}/libft/ft_striter.c | 0 {lib => subprojects}/libft/ft_striteri.c | 0 {lib => subprojects}/libft/ft_strjoin.c | 0 {lib => subprojects}/libft/ft_strlcat.c | 0 {lib => subprojects}/libft/ft_strlen.c | 0 {lib => subprojects}/libft/ft_strmap.c | 0 {lib => subprojects}/libft/ft_strmapi.c | 0 {lib => subprojects}/libft/ft_strncat.c | 0 {lib => subprojects}/libft/ft_strncmp.c | 0 {lib => subprojects}/libft/ft_strncpy.c | 0 {lib => subprojects}/libft/ft_strnequ.c | 0 {lib => subprojects}/libft/ft_strnew.c | 0 {lib => subprojects}/libft/ft_strnstr.c | 0 {lib => subprojects}/libft/ft_strrchr.c | 0 {lib => subprojects}/libft/ft_strsplit.c | 0 {lib => subprojects}/libft/ft_strstr.c | 0 {lib => subprojects}/libft/ft_strsub.c | 0 {lib => subprojects}/libft/ft_strtol.c | 0 {lib => subprojects}/libft/ft_strtrim.c | 0 {lib => subprojects}/libft/ft_tolower.c | 0 {lib => subprojects}/libft/ft_toupper.c | 0 {lib => subprojects}/libft/get_next_line.c | 0 {lib => subprojects}/libft/includes/libft.h | 0 subprojects/libft/meson.build | 95 ++++++++++++++++ t/malloc_tests.c | 21 +++- 89 files changed, 291 insertions(+), 30 deletions(-) create mode 100644 inc/ft_malloc_internal.h delete mode 100644 inc/meson.build delete mode 100644 src/meson.build rename {lib => subprojects}/libft/Makefile (100%) rename {lib => subprojects}/libft/author (100%) rename {lib => subprojects}/libft/ft_atof.c (100%) rename {lib => subprojects}/libft/ft_atoi.c (100%) rename {lib => subprojects}/libft/ft_bzero.c (100%) rename {lib => subprojects}/libft/ft_isalnum.c (100%) rename {lib => subprojects}/libft/ft_isalpha.c (100%) rename {lib => subprojects}/libft/ft_isascii.c (100%) rename {lib => subprojects}/libft/ft_isdigit.c (100%) rename {lib => subprojects}/libft/ft_isprint.c (100%) rename {lib => subprojects}/libft/ft_isspace.c (100%) rename {lib => subprojects}/libft/ft_itoa.c (100%) rename {lib => subprojects}/libft/ft_lst_at.c (100%) rename {lib => subprojects}/libft/ft_lst_len.c (100%) rename {lib => subprojects}/libft/ft_lst_merge_sort.c (92%) rename {lib => subprojects}/libft/ft_lst_rev.c (100%) rename {lib => subprojects}/libft/ft_lst_search.c (100%) rename {lib => subprojects}/libft/ft_lstadd.c (100%) rename {lib => subprojects}/libft/ft_lstadd_back.c (100%) rename {lib => subprojects}/libft/ft_lstdel.c (100%) rename {lib => subprojects}/libft/ft_lstdelone.c (100%) rename {lib => subprojects}/libft/ft_lstfind.c (100%) rename {lib => subprojects}/libft/ft_lstiter.c (100%) rename {lib => subprojects}/libft/ft_lstmap.c (100%) rename {lib => subprojects}/libft/ft_lstnew.c (100%) rename {lib => subprojects}/libft/ft_lstreduce.c (100%) rename {lib => subprojects}/libft/ft_lststrsplit.c (100%) rename {lib => subprojects}/libft/ft_memalloc.c (100%) rename {lib => subprojects}/libft/ft_memccpy.c (100%) rename {lib => subprojects}/libft/ft_memchr.c (100%) rename {lib => subprojects}/libft/ft_memcmp.c (100%) rename {lib => subprojects}/libft/ft_memcpy.c (100%) rename {lib => subprojects}/libft/ft_memdel.c (100%) rename {lib => subprojects}/libft/ft_memmove.c (100%) rename {lib => subprojects}/libft/ft_memset.c (100%) rename {lib => subprojects}/libft/ft_num_len.c (100%) rename {lib => subprojects}/libft/ft_putchar.c (100%) rename {lib => subprojects}/libft/ft_putchar_fd.c (100%) rename {lib => subprojects}/libft/ft_putendl.c (100%) rename {lib => subprojects}/libft/ft_putendl_fd.c (100%) rename {lib => subprojects}/libft/ft_putnbr.c (100%) rename {lib => subprojects}/libft/ft_putnbr_fd.c (100%) rename {lib => subprojects}/libft/ft_putstr.c (100%) rename {lib => subprojects}/libft/ft_putstr_fd.c (100%) rename {lib => subprojects}/libft/ft_read_file.c (100%) rename {lib => subprojects}/libft/ft_realloc.c (100%) rename {lib => subprojects}/libft/ft_str_table_len.c (100%) rename {lib => subprojects}/libft/ft_strcat.c (100%) rename {lib => subprojects}/libft/ft_strchr.c (100%) rename {lib => subprojects}/libft/ft_strclr.c (100%) rename {lib => subprojects}/libft/ft_strcmp.c (100%) rename {lib => subprojects}/libft/ft_strcmp_lex.c (100%) rename {lib => subprojects}/libft/ft_strcpy.c (100%) rename {lib => subprojects}/libft/ft_strdel.c (100%) rename {lib => subprojects}/libft/ft_strdup.c (100%) rename {lib => subprojects}/libft/ft_strequ.c (100%) rename {lib => subprojects}/libft/ft_striter.c (100%) rename {lib => subprojects}/libft/ft_striteri.c (100%) rename {lib => subprojects}/libft/ft_strjoin.c (100%) rename {lib => subprojects}/libft/ft_strlcat.c (100%) rename {lib => subprojects}/libft/ft_strlen.c (100%) rename {lib => subprojects}/libft/ft_strmap.c (100%) rename {lib => subprojects}/libft/ft_strmapi.c (100%) rename {lib => subprojects}/libft/ft_strncat.c (100%) rename {lib => subprojects}/libft/ft_strncmp.c (100%) rename {lib => subprojects}/libft/ft_strncpy.c (100%) rename {lib => subprojects}/libft/ft_strnequ.c (100%) rename {lib => subprojects}/libft/ft_strnew.c (100%) rename {lib => subprojects}/libft/ft_strnstr.c (100%) rename {lib => subprojects}/libft/ft_strrchr.c (100%) rename {lib => subprojects}/libft/ft_strsplit.c (100%) rename {lib => subprojects}/libft/ft_strstr.c (100%) rename {lib => subprojects}/libft/ft_strsub.c (100%) rename {lib => subprojects}/libft/ft_strtol.c (100%) rename {lib => subprojects}/libft/ft_strtrim.c (100%) rename {lib => subprojects}/libft/ft_tolower.c (100%) rename {lib => subprojects}/libft/ft_toupper.c (100%) rename {lib => subprojects}/libft/get_next_line.c (100%) rename {lib => subprojects}/libft/includes/libft.h (100%) create mode 100644 subprojects/libft/meson.build diff --git a/.gitignore b/.gitignore index c6911d8..523a56a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ *.so .vscode /bld +/debug_bld /out diff --git a/build.sh b/build.sh index ebb351f..75b4f44 100755 --- a/build.sh +++ b/build.sh @@ -2,8 +2,18 @@ PWD=$(pwd) OUT_DIR="$PWD/out" -BLD_DIR="$PWD/bld" +RELEASE_BLD_DIR="$PWD/bld" +DEBUG_BLD_DIR="$PWD/debug_bld" -meson $BLD_DIR --includedir=$OUT_DIR --libdir=$OUT_DIR --bindir=$OUT_DIR --prefix=$OUT_DIR -ninja -C $BLD_DIR -ninja -C $BLD_DIR install \ No newline at end of file +LIB="libft_malloc.dylib" +LINK="libft_malloc.so" + + +meson $RELEASE_BLD_DIR --prefix=$OUT_DIR --libdir=$OUT_DIR --includedir=$OUT_DIR --buildtype=release +meson $DEBUG_BLD_DIR --buildtype=debug + +ninja -C $DEBUG_BLD_DIR +ninja -C $RELEASE_BLD_DIR +ninja -C $RELEASE_BLD_DIR install + +ln -sf "$OUT_DIR/$LIB" "$PWD/$LINK" diff --git a/inc/ft_malloc.h b/inc/ft_malloc.h index 2ee14f5..252b60c 100644 --- a/inc/ft_malloc.h +++ b/inc/ft_malloc.h @@ -6,5 +6,6 @@ void free(void *ptr); void *malloc(size_t size); void *realloc(void *ptr, size_t size); +void show_alloc_mem(void); #endif diff --git a/inc/ft_malloc_internal.h b/inc/ft_malloc_internal.h new file mode 100644 index 0000000..224b40a --- /dev/null +++ b/inc/ft_malloc_internal.h @@ -0,0 +1,37 @@ +#ifndef FT_MALLOC_INTERNAL_H +# define FT_MALLOC_INTERNAL_H + +# include +# include + +# define TINY 512 +# define SMALL 1024 +# define LARGE 1025 +# define START -1 +# define MAGIC 0xDEADBEEF +# define NALLOC 100 + +typedef struct s_chunk +{ + uint8_t is_free; + size_t size; + struct s_chunk *next; + struct s_chunk *prev; + uint32_t magic; +} t_chunk; + +# define CHUNK_SIZE(size) ((size) + sizeof(t_chunk)) + +typedef struct s_arena +{ + int type; + size_t size; + struct s_arena *next; + t_chunk *heap; +} t_arena; + +# define HEAP_SIZE(size) ((size) - sizeof(t_arena)) + +extern t_arena g_base; + +#endif \ No newline at end of file diff --git a/inc/meson.build b/inc/meson.build deleted file mode 100644 index f127a63..0000000 --- a/inc/meson.build +++ /dev/null @@ -1 +0,0 @@ -install_headers('ft_malloc.h') \ No newline at end of file diff --git a/meson.build b/meson.build index 935140a..0511040 100644 --- a/meson.build +++ b/meson.build @@ -2,7 +2,7 @@ project( 'malloc', 'c', default_options: [ - 'buildtype=release', + 'buildtype=plain', ], ) @@ -10,7 +10,6 @@ add_global_arguments( '-Wall', '-Wextra', '-Werror', - '-Wpointer-arith', '-Wcast-align', '-Wwrite-strings', '-Wunreachable-code', @@ -24,6 +23,25 @@ add_global_arguments( ) inc = include_directories('inc') -subdir('inc') -subdir('src') + +install_headers('inc/ft_malloc.h') + +sources = [ + 'src/malloc.c', + 'src/free.c', + 'src/realloc.c', +] + +libft = subproject('libft') + +libft_dep = libft.get_variable('libft_dep') + +ft_malloc = shared_library( + 'ft_malloc', + sources, + include_directories: inc, + dependencies: libft_dep, + install: true, +) + subdir('t') \ No newline at end of file diff --git a/src/malloc.c b/src/malloc.c index 6128222..4ddf5e1 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -1,7 +1,106 @@ +#include #include "ft_malloc.h" +#include "ft_malloc_internal.h" +#include "libft.h" -void *malloc(size_t size) +t_arena g_base = { .type = START, .size = 0, .next = &g_base, .heap = NULL}; + +static void add_arena(t_arena *arena, size_t size, int arena_type) { - (void)size; - return (NULL); + arena->size = size; + arena->type = arena_type; + arena->heap = (t_chunk *)(arena + 1); + arena->heap->is_free = 1; + arena->heap->magic = MAGIC; + arena->heap->size = HEAP_SIZE(size); + arena->heap->next = NULL; + arena->heap->prev = NULL; + arena->next = g_base.next; + g_base.next = arena; +} + +static size_t get_actual_size(size_t size, int type) +{ + size_t minimum; + int page; + + page = getpagesize(); + if (type == LARGE) + minimum = size; + else + minimum = (type * NALLOC); + return ((minimum + sizeof(t_arena) + page - 1) / page * page); +} + +static int get_arena_type(size_t size) +{ + if (size <= TINY) + return (TINY); + if (size <= SMALL) + return (SMALL); + return (LARGE); +} + +static t_arena *get_more_arena(size_t size, int type) +{ + t_arena *arena; + int prot; + int flags; + + size = get_actual_size(size, type); + prot = PROT_WRITE | PROT_READ; + flags = MAP_ANON | MAP_PRIVATE; + if ((arena = mmap(NULL, size, prot, flags, -1, 0)) == MAP_FAILED) + return (NULL); + add_arena(arena, size, type); + return (arena); +} + +static t_chunk *chunk_heap(t_chunk *chunk, size_t size) +{ + t_chunk *new_chunk; + + if (chunk->size == size) + { + chunk->is_free = 0; + return (chunk); + } + chunk->size -= size; + new_chunk = (t_chunk *)((uint8_t *)chunk + chunk->size); + new_chunk->is_free = 0; + new_chunk->magic = MAGIC; + new_chunk->size = size; + new_chunk->next = chunk->next; + new_chunk->prev = chunk; + if (new_chunk->next) + new_chunk->next->prev = new_chunk; + return (chunk); +} + +void *malloc(size_t size) +{ + void *space; + t_arena *arena; + t_chunk *chunk; + int arena_type; + + space = NULL; + size = CHUNK_SIZE(size); + arena = g_base.next; + arena_type = get_arena_type(size); + while(!space) + { + if(arena->type == arena_type && (chunk = arena->heap)) + while(!space && chunk) + { + if (chunk->size >= size && chunk->is_free) + space = chunk_heap(chunk, size); + chunk = chunk->next; + } + arena = arena->next; + if (!space && arena == &g_base) + if ((arena = get_more_arena(size, arena_type)) == NULL) + return (NULL); + } + return (space + 1); } \ No newline at end of file diff --git a/src/meson.build b/src/meson.build deleted file mode 100644 index 063f400..0000000 --- a/src/meson.build +++ /dev/null @@ -1,12 +0,0 @@ -srcs = [ - 'malloc.c', - 'free.c', - 'realloc.c', -] - -ft_malloc = shared_library( - 'ft_malloc', - srcs, - include_directories: inc, - install: true, -) \ No newline at end of file diff --git a/lib/libft/Makefile b/subprojects/libft/Makefile similarity index 100% rename from lib/libft/Makefile rename to subprojects/libft/Makefile diff --git a/lib/libft/author b/subprojects/libft/author similarity index 100% rename from lib/libft/author rename to subprojects/libft/author diff --git a/lib/libft/ft_atof.c b/subprojects/libft/ft_atof.c similarity index 100% rename from lib/libft/ft_atof.c rename to subprojects/libft/ft_atof.c diff --git a/lib/libft/ft_atoi.c b/subprojects/libft/ft_atoi.c similarity index 100% rename from lib/libft/ft_atoi.c rename to subprojects/libft/ft_atoi.c diff --git a/lib/libft/ft_bzero.c b/subprojects/libft/ft_bzero.c similarity index 100% rename from lib/libft/ft_bzero.c rename to subprojects/libft/ft_bzero.c diff --git a/lib/libft/ft_isalnum.c b/subprojects/libft/ft_isalnum.c similarity index 100% rename from lib/libft/ft_isalnum.c rename to subprojects/libft/ft_isalnum.c diff --git a/lib/libft/ft_isalpha.c b/subprojects/libft/ft_isalpha.c similarity index 100% rename from lib/libft/ft_isalpha.c rename to subprojects/libft/ft_isalpha.c diff --git a/lib/libft/ft_isascii.c b/subprojects/libft/ft_isascii.c similarity index 100% rename from lib/libft/ft_isascii.c rename to subprojects/libft/ft_isascii.c diff --git a/lib/libft/ft_isdigit.c b/subprojects/libft/ft_isdigit.c similarity index 100% rename from lib/libft/ft_isdigit.c rename to subprojects/libft/ft_isdigit.c diff --git a/lib/libft/ft_isprint.c b/subprojects/libft/ft_isprint.c similarity index 100% rename from lib/libft/ft_isprint.c rename to subprojects/libft/ft_isprint.c diff --git a/lib/libft/ft_isspace.c b/subprojects/libft/ft_isspace.c similarity index 100% rename from lib/libft/ft_isspace.c rename to subprojects/libft/ft_isspace.c diff --git a/lib/libft/ft_itoa.c b/subprojects/libft/ft_itoa.c similarity index 100% rename from lib/libft/ft_itoa.c rename to subprojects/libft/ft_itoa.c diff --git a/lib/libft/ft_lst_at.c b/subprojects/libft/ft_lst_at.c similarity index 100% rename from lib/libft/ft_lst_at.c rename to subprojects/libft/ft_lst_at.c diff --git a/lib/libft/ft_lst_len.c b/subprojects/libft/ft_lst_len.c similarity index 100% rename from lib/libft/ft_lst_len.c rename to subprojects/libft/ft_lst_len.c diff --git a/lib/libft/ft_lst_merge_sort.c b/subprojects/libft/ft_lst_merge_sort.c similarity index 92% rename from lib/libft/ft_lst_merge_sort.c rename to subprojects/libft/ft_lst_merge_sort.c index 5b4c1c2..532be9d 100644 --- a/lib/libft/ft_lst_merge_sort.c +++ b/subprojects/libft/ft_lst_merge_sort.c @@ -12,7 +12,7 @@ #include "libft.h" -static t_list *merge(t_list *a, t_list *b, int (*cmp)()) +static t_list *merge(t_list *a, t_list *b, int (*cmp)(void *, void *)) { t_list *result; @@ -63,7 +63,7 @@ static void split(t_list *source, t_list **front_ptr, t_list **back_ptr) } } -void ft_lst_merge_sort(t_list **head_ptr, int (*cmp)()) +void ft_lst_merge_sort(t_list **head_ptr, int (*cmp)(void *, void *)) { t_list *head; t_list *a; diff --git a/lib/libft/ft_lst_rev.c b/subprojects/libft/ft_lst_rev.c similarity index 100% rename from lib/libft/ft_lst_rev.c rename to subprojects/libft/ft_lst_rev.c diff --git a/lib/libft/ft_lst_search.c b/subprojects/libft/ft_lst_search.c similarity index 100% rename from lib/libft/ft_lst_search.c rename to subprojects/libft/ft_lst_search.c diff --git a/lib/libft/ft_lstadd.c b/subprojects/libft/ft_lstadd.c similarity index 100% rename from lib/libft/ft_lstadd.c rename to subprojects/libft/ft_lstadd.c diff --git a/lib/libft/ft_lstadd_back.c b/subprojects/libft/ft_lstadd_back.c similarity index 100% rename from lib/libft/ft_lstadd_back.c rename to subprojects/libft/ft_lstadd_back.c diff --git a/lib/libft/ft_lstdel.c b/subprojects/libft/ft_lstdel.c similarity index 100% rename from lib/libft/ft_lstdel.c rename to subprojects/libft/ft_lstdel.c diff --git a/lib/libft/ft_lstdelone.c b/subprojects/libft/ft_lstdelone.c similarity index 100% rename from lib/libft/ft_lstdelone.c rename to subprojects/libft/ft_lstdelone.c diff --git a/lib/libft/ft_lstfind.c b/subprojects/libft/ft_lstfind.c similarity index 100% rename from lib/libft/ft_lstfind.c rename to subprojects/libft/ft_lstfind.c diff --git a/lib/libft/ft_lstiter.c b/subprojects/libft/ft_lstiter.c similarity index 100% rename from lib/libft/ft_lstiter.c rename to subprojects/libft/ft_lstiter.c diff --git a/lib/libft/ft_lstmap.c b/subprojects/libft/ft_lstmap.c similarity index 100% rename from lib/libft/ft_lstmap.c rename to subprojects/libft/ft_lstmap.c diff --git a/lib/libft/ft_lstnew.c b/subprojects/libft/ft_lstnew.c similarity index 100% rename from lib/libft/ft_lstnew.c rename to subprojects/libft/ft_lstnew.c diff --git a/lib/libft/ft_lstreduce.c b/subprojects/libft/ft_lstreduce.c similarity index 100% rename from lib/libft/ft_lstreduce.c rename to subprojects/libft/ft_lstreduce.c diff --git a/lib/libft/ft_lststrsplit.c b/subprojects/libft/ft_lststrsplit.c similarity index 100% rename from lib/libft/ft_lststrsplit.c rename to subprojects/libft/ft_lststrsplit.c diff --git a/lib/libft/ft_memalloc.c b/subprojects/libft/ft_memalloc.c similarity index 100% rename from lib/libft/ft_memalloc.c rename to subprojects/libft/ft_memalloc.c diff --git a/lib/libft/ft_memccpy.c b/subprojects/libft/ft_memccpy.c similarity index 100% rename from lib/libft/ft_memccpy.c rename to subprojects/libft/ft_memccpy.c diff --git a/lib/libft/ft_memchr.c b/subprojects/libft/ft_memchr.c similarity index 100% rename from lib/libft/ft_memchr.c rename to subprojects/libft/ft_memchr.c diff --git a/lib/libft/ft_memcmp.c b/subprojects/libft/ft_memcmp.c similarity index 100% rename from lib/libft/ft_memcmp.c rename to subprojects/libft/ft_memcmp.c diff --git a/lib/libft/ft_memcpy.c b/subprojects/libft/ft_memcpy.c similarity index 100% rename from lib/libft/ft_memcpy.c rename to subprojects/libft/ft_memcpy.c diff --git a/lib/libft/ft_memdel.c b/subprojects/libft/ft_memdel.c similarity index 100% rename from lib/libft/ft_memdel.c rename to subprojects/libft/ft_memdel.c diff --git a/lib/libft/ft_memmove.c b/subprojects/libft/ft_memmove.c similarity index 100% rename from lib/libft/ft_memmove.c rename to subprojects/libft/ft_memmove.c diff --git a/lib/libft/ft_memset.c b/subprojects/libft/ft_memset.c similarity index 100% rename from lib/libft/ft_memset.c rename to subprojects/libft/ft_memset.c diff --git a/lib/libft/ft_num_len.c b/subprojects/libft/ft_num_len.c similarity index 100% rename from lib/libft/ft_num_len.c rename to subprojects/libft/ft_num_len.c diff --git a/lib/libft/ft_putchar.c b/subprojects/libft/ft_putchar.c similarity index 100% rename from lib/libft/ft_putchar.c rename to subprojects/libft/ft_putchar.c diff --git a/lib/libft/ft_putchar_fd.c b/subprojects/libft/ft_putchar_fd.c similarity index 100% rename from lib/libft/ft_putchar_fd.c rename to subprojects/libft/ft_putchar_fd.c diff --git a/lib/libft/ft_putendl.c b/subprojects/libft/ft_putendl.c similarity index 100% rename from lib/libft/ft_putendl.c rename to subprojects/libft/ft_putendl.c diff --git a/lib/libft/ft_putendl_fd.c b/subprojects/libft/ft_putendl_fd.c similarity index 100% rename from lib/libft/ft_putendl_fd.c rename to subprojects/libft/ft_putendl_fd.c diff --git a/lib/libft/ft_putnbr.c b/subprojects/libft/ft_putnbr.c similarity index 100% rename from lib/libft/ft_putnbr.c rename to subprojects/libft/ft_putnbr.c diff --git a/lib/libft/ft_putnbr_fd.c b/subprojects/libft/ft_putnbr_fd.c similarity index 100% rename from lib/libft/ft_putnbr_fd.c rename to subprojects/libft/ft_putnbr_fd.c diff --git a/lib/libft/ft_putstr.c b/subprojects/libft/ft_putstr.c similarity index 100% rename from lib/libft/ft_putstr.c rename to subprojects/libft/ft_putstr.c diff --git a/lib/libft/ft_putstr_fd.c b/subprojects/libft/ft_putstr_fd.c similarity index 100% rename from lib/libft/ft_putstr_fd.c rename to subprojects/libft/ft_putstr_fd.c diff --git a/lib/libft/ft_read_file.c b/subprojects/libft/ft_read_file.c similarity index 100% rename from lib/libft/ft_read_file.c rename to subprojects/libft/ft_read_file.c diff --git a/lib/libft/ft_realloc.c b/subprojects/libft/ft_realloc.c similarity index 100% rename from lib/libft/ft_realloc.c rename to subprojects/libft/ft_realloc.c diff --git a/lib/libft/ft_str_table_len.c b/subprojects/libft/ft_str_table_len.c similarity index 100% rename from lib/libft/ft_str_table_len.c rename to subprojects/libft/ft_str_table_len.c diff --git a/lib/libft/ft_strcat.c b/subprojects/libft/ft_strcat.c similarity index 100% rename from lib/libft/ft_strcat.c rename to subprojects/libft/ft_strcat.c diff --git a/lib/libft/ft_strchr.c b/subprojects/libft/ft_strchr.c similarity index 100% rename from lib/libft/ft_strchr.c rename to subprojects/libft/ft_strchr.c diff --git a/lib/libft/ft_strclr.c b/subprojects/libft/ft_strclr.c similarity index 100% rename from lib/libft/ft_strclr.c rename to subprojects/libft/ft_strclr.c diff --git a/lib/libft/ft_strcmp.c b/subprojects/libft/ft_strcmp.c similarity index 100% rename from lib/libft/ft_strcmp.c rename to subprojects/libft/ft_strcmp.c diff --git a/lib/libft/ft_strcmp_lex.c b/subprojects/libft/ft_strcmp_lex.c similarity index 100% rename from lib/libft/ft_strcmp_lex.c rename to subprojects/libft/ft_strcmp_lex.c diff --git a/lib/libft/ft_strcpy.c b/subprojects/libft/ft_strcpy.c similarity index 100% rename from lib/libft/ft_strcpy.c rename to subprojects/libft/ft_strcpy.c diff --git a/lib/libft/ft_strdel.c b/subprojects/libft/ft_strdel.c similarity index 100% rename from lib/libft/ft_strdel.c rename to subprojects/libft/ft_strdel.c diff --git a/lib/libft/ft_strdup.c b/subprojects/libft/ft_strdup.c similarity index 100% rename from lib/libft/ft_strdup.c rename to subprojects/libft/ft_strdup.c diff --git a/lib/libft/ft_strequ.c b/subprojects/libft/ft_strequ.c similarity index 100% rename from lib/libft/ft_strequ.c rename to subprojects/libft/ft_strequ.c diff --git a/lib/libft/ft_striter.c b/subprojects/libft/ft_striter.c similarity index 100% rename from lib/libft/ft_striter.c rename to subprojects/libft/ft_striter.c diff --git a/lib/libft/ft_striteri.c b/subprojects/libft/ft_striteri.c similarity index 100% rename from lib/libft/ft_striteri.c rename to subprojects/libft/ft_striteri.c diff --git a/lib/libft/ft_strjoin.c b/subprojects/libft/ft_strjoin.c similarity index 100% rename from lib/libft/ft_strjoin.c rename to subprojects/libft/ft_strjoin.c diff --git a/lib/libft/ft_strlcat.c b/subprojects/libft/ft_strlcat.c similarity index 100% rename from lib/libft/ft_strlcat.c rename to subprojects/libft/ft_strlcat.c diff --git a/lib/libft/ft_strlen.c b/subprojects/libft/ft_strlen.c similarity index 100% rename from lib/libft/ft_strlen.c rename to subprojects/libft/ft_strlen.c diff --git a/lib/libft/ft_strmap.c b/subprojects/libft/ft_strmap.c similarity index 100% rename from lib/libft/ft_strmap.c rename to subprojects/libft/ft_strmap.c diff --git a/lib/libft/ft_strmapi.c b/subprojects/libft/ft_strmapi.c similarity index 100% rename from lib/libft/ft_strmapi.c rename to subprojects/libft/ft_strmapi.c diff --git a/lib/libft/ft_strncat.c b/subprojects/libft/ft_strncat.c similarity index 100% rename from lib/libft/ft_strncat.c rename to subprojects/libft/ft_strncat.c diff --git a/lib/libft/ft_strncmp.c b/subprojects/libft/ft_strncmp.c similarity index 100% rename from lib/libft/ft_strncmp.c rename to subprojects/libft/ft_strncmp.c diff --git a/lib/libft/ft_strncpy.c b/subprojects/libft/ft_strncpy.c similarity index 100% rename from lib/libft/ft_strncpy.c rename to subprojects/libft/ft_strncpy.c diff --git a/lib/libft/ft_strnequ.c b/subprojects/libft/ft_strnequ.c similarity index 100% rename from lib/libft/ft_strnequ.c rename to subprojects/libft/ft_strnequ.c diff --git a/lib/libft/ft_strnew.c b/subprojects/libft/ft_strnew.c similarity index 100% rename from lib/libft/ft_strnew.c rename to subprojects/libft/ft_strnew.c diff --git a/lib/libft/ft_strnstr.c b/subprojects/libft/ft_strnstr.c similarity index 100% rename from lib/libft/ft_strnstr.c rename to subprojects/libft/ft_strnstr.c diff --git a/lib/libft/ft_strrchr.c b/subprojects/libft/ft_strrchr.c similarity index 100% rename from lib/libft/ft_strrchr.c rename to subprojects/libft/ft_strrchr.c diff --git a/lib/libft/ft_strsplit.c b/subprojects/libft/ft_strsplit.c similarity index 100% rename from lib/libft/ft_strsplit.c rename to subprojects/libft/ft_strsplit.c diff --git a/lib/libft/ft_strstr.c b/subprojects/libft/ft_strstr.c similarity index 100% rename from lib/libft/ft_strstr.c rename to subprojects/libft/ft_strstr.c diff --git a/lib/libft/ft_strsub.c b/subprojects/libft/ft_strsub.c similarity index 100% rename from lib/libft/ft_strsub.c rename to subprojects/libft/ft_strsub.c diff --git a/lib/libft/ft_strtol.c b/subprojects/libft/ft_strtol.c similarity index 100% rename from lib/libft/ft_strtol.c rename to subprojects/libft/ft_strtol.c diff --git a/lib/libft/ft_strtrim.c b/subprojects/libft/ft_strtrim.c similarity index 100% rename from lib/libft/ft_strtrim.c rename to subprojects/libft/ft_strtrim.c diff --git a/lib/libft/ft_tolower.c b/subprojects/libft/ft_tolower.c similarity index 100% rename from lib/libft/ft_tolower.c rename to subprojects/libft/ft_tolower.c diff --git a/lib/libft/ft_toupper.c b/subprojects/libft/ft_toupper.c similarity index 100% rename from lib/libft/ft_toupper.c rename to subprojects/libft/ft_toupper.c diff --git a/lib/libft/get_next_line.c b/subprojects/libft/get_next_line.c similarity index 100% rename from lib/libft/get_next_line.c rename to subprojects/libft/get_next_line.c diff --git a/lib/libft/includes/libft.h b/subprojects/libft/includes/libft.h similarity index 100% rename from lib/libft/includes/libft.h rename to subprojects/libft/includes/libft.h diff --git a/subprojects/libft/meson.build b/subprojects/libft/meson.build new file mode 100644 index 0000000..063ac96 --- /dev/null +++ b/subprojects/libft/meson.build @@ -0,0 +1,95 @@ +project('libft', 'c') + +srcs = [ + 'ft_memset.c', + 'ft_bzero.c', + 'ft_memcpy.c', + 'ft_memccpy.c', + 'ft_memmove.c', + 'ft_memchr.c', + 'ft_memcmp.c', + 'ft_strlen.c', + 'ft_strdup.c', + 'ft_strcpy.c', + 'ft_strncpy.c', + 'ft_strcat.c', + 'ft_strncat.c', + 'ft_strlcat.c', + 'ft_strchr.c', + 'ft_strrchr.c', + 'ft_strstr.c', + 'ft_strnstr.c', + 'ft_strcmp.c', + 'ft_strcmp_lex.c', + 'ft_strncmp.c', + 'ft_strtol.c', + 'ft_atoi.c', + 'ft_atof.c', + 'ft_isalpha.c', + 'ft_isspace.c', + 'ft_isdigit.c', + 'ft_isalnum.c', + 'ft_isascii.c', + 'ft_isprint.c', + 'ft_toupper.c', + 'ft_tolower.c', + 'ft_memalloc.c', + 'ft_memdel.c', + 'ft_strnew.c', + 'ft_strdel.c', + 'ft_strclr.c', + 'ft_striter.c', + 'ft_striteri.c', + 'ft_strmap.c', + 'ft_strmap.c', + 'ft_strmapi.c', + 'ft_strequ.c', + 'ft_strnequ.c', + 'ft_strsub.c', + 'ft_strjoin.c', + 'ft_strtrim.c', + 'ft_strsplit.c', + 'ft_itoa.c', + 'ft_putchar.c', + 'ft_putstr.c', + 'ft_putendl.c', + 'ft_putnbr.c', + 'ft_putchar_fd.c', + 'ft_putstr_fd.c', + 'ft_putendl_fd.c', + 'ft_putnbr_fd.c', + 'ft_lstnew.c', + 'ft_lstdelone.c', + 'ft_lstdel.c', + 'ft_lstadd.c', + 'ft_lstiter.c', + 'ft_lstmap.c', + 'ft_lstreduce.c', + 'ft_lststrsplit.c', + 'ft_lstfind.c', + 'ft_lst_at.c', + 'ft_lstadd_back.c', + 'ft_lst_len.c', + 'ft_lst_merge_sort.c', + 'ft_lst_rev.c', + 'ft_lst_search.c', + 'ft_realloc.c', + 'ft_read_file.c', + 'get_next_line.c', + 'ft_num_len.c', + 'ft_str_table_len.c', +] + +inc = include_directories('includes') + +libft = static_library( + 'ft', + srcs, + include_directories: inc, + # install : true, +) + +libft_dep = declare_dependency( + include_directories : inc, + link_with : libft, +) diff --git a/t/malloc_tests.c b/t/malloc_tests.c index 36f552c..bdf569d 100644 --- a/t/malloc_tests.c +++ b/t/malloc_tests.c @@ -1,13 +1,26 @@ #include "t.h" +#include "ft_malloc.h" +#include "ft_malloc_internal.h" -int return_null_on_zero_size(void) + +int inital_base_next_point_to_itself(void) { - _IS(1 == 1); - _END("return null on zero size"); + _IS(g_base.next == &g_base); + _END("inital_base_next_point_to_itself"); +} + +int returns_not_null_pointer(void) +{ + void *ptr; + + ptr = malloc(10); + _IS(ptr != NULL); + _END("returns_not_null_pointer"); } int main(void) { - _SHOULD(return_null_on_zero_size); + _SHOULD(inital_base_next_point_to_itself); + _SHOULD(returns_not_null_pointer); return 0; } \ No newline at end of file