diff --git a/Minishell.mk b/Minishell.mk index 89878306..2ba96cca 100644 --- a/Minishell.mk +++ b/Minishell.mk @@ -6,7 +6,7 @@ # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/04/28 17:28:30 by maiboyer #+# #+# # -# Updated: 2024/05/14 18:38:18 by maiboyer ### ########.fr # +# Updated: 2024/05/18 14:36:04 by maiboyer ### ########.fr # # # # **************************************************************************** # @@ -61,21 +61,21 @@ all: @$(MAKE) -f./Minishell.mk $(NAME) # Bonus (make bonus) -bonus: $(OBJ) $(LIB_OBJ) $(OBJDIRNAME)/libme.a $(OBJDIRNAME)/libgmr.a +bonus: $(OBJ) $(LIB_OBJ) $(OBJDIRNAME)/libme.a $(OBJDIRNAME)/libgmr.a $(OBJDIRNAME)/libaq.a @mkdir -p $(OBJDIRNAME) @mkdir -p $(OBJDIRNAME)/$(LIBDIRNAME) @mkdir -p $(OBJDIRNAME)/$(SRCDIRNAME) @echo -e '$(GREY) Be Carefull ur in $(END)$(GREEN)Debug Mode$(END)' @echo -e '$(GREY) Linking\t$(END)$(GREEN)$(NAME)$(END)' - @$(CC) $(CFLAGS) -D DEBUG=42 -o $(NAME) $(OBJ) -L$(OBJDIRNAME) -lgmr -lme -laq + @$(CC) $(CFLAGS) -D DEBUG=42 -o $(NAME) $(OBJ) -L$(OBJDIRNAME) -lgmr -lme -laq -lme # Dependences for all -$(NAME): $(OBJ) $(LIB_OBJ) $(OBJDIRNAME)/libgmr.a $(OBJDIRNAME)/libme.a +$(NAME): $(OBJ) $(LIB_OBJ) $(OBJDIRNAME)/libgmr.a $(OBJDIRNAME)/libme.a $(OBJDIRNAME)/libaq.a @mkdir -p $(OBJDIRNAME) @mkdir -p $(OBJDIRNAME)/$(LIBDIRNAME) @mkdir -p $(OBJDIRNAME)/$(SRCDIRNAME) @echo -e '$(GREY) Linking\t$(END)$(GREEN)$(NAME)$(END)' - @$(CC) $(CFLAGS) -o $(NAME) $(OBJ) $(LIB_OBJ) -L$(OBJDIRNAME) -lgmr -lme -laq + @$(CC) $(CFLAGS) -o $(NAME) $(OBJ) $(LIB_OBJ) -L$(OBJDIRNAME) -lgmr -lme -laq -lme # Creating the objects $(OBJDIRNAME)/%.o: %.c diff --git a/allocator/Makefile b/allocator/Makefile index 3920c5be..7e731039 100644 --- a/allocator/Makefile +++ b/allocator/Makefile @@ -6,7 +6,7 @@ # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/03 13:20:01 by maiboyer #+# #+# # -# Updated: 2024/05/14 18:44:53 by maiboyer ### ########.fr # +# Updated: 2024/05/16 16:06:36 by maiboyer ### ########.fr # # # # **************************************************************************** # @@ -23,7 +23,7 @@ NAME = libaq.a LIB_NAME ?= TARGET = $(BUILD_DIR)/$(NAME) CC ?= clang -CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -g3 -L$(BUILD_DIR) -MMD -rdynamic -DBASE_PATH='"$(BASE_PATH)/"' +CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -g3 -L$(BUILD_DIR) -MMD -rdynamic -DBASE_PATH='"$(BASE_PATH)/"' -O0 # CFLAGS += -fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-return=runtime -fno-common -fsanitize-address-use-after-scope BONUS_FILES = LIBS_NAME = @@ -55,7 +55,6 @@ $(NAME): $(TARGET) $(TARGET): $(OBJ) @echo -e '$(COL_GRAY) Linking\t$(COL_GREEN)$(TARGET)$(COL_RESET)' - @#$(CC) $(INCLUDES) $(OBJ) $(CFLAGS) -o $(NAME) @ar rcs $(BUILD_DIR)/$(NAME) $(OBJ) $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c diff --git a/allocator/include/aq/internal_vg_funcs.h b/allocator/include/aq/internal_vg_funcs.h index c3650fd8..6a4e2cbd 100644 --- a/allocator/include/aq/internal_vg_funcs.h +++ b/allocator/include/aq/internal_vg_funcs.h @@ -6,15 +6,13 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/12 22:20:30 by maiboyer #+# #+# */ -/* Updated: 2024/05/14 16:17:25 by maiboyer ### ########.fr */ +/* Updated: 2024/05/17 15:34:26 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef INTERNAL_VG_FUNCS_H #define INTERNAL_VG_FUNCS_H -#include "aq/alloc_internal.h" - #include "me/types.h" #if !defined(NVALGRIND) || defined(VGHEADER) # ifdef NVALGRIND @@ -30,7 +28,7 @@ static inline t_usize redzone_size(void) { - return (sizeof(t_mblock)); + return (8); } #ifdef VGFUNCS diff --git a/allocator/include/aq/melloc.h b/allocator/include/aq/melloc.h index 765b2d02..7a46757c 100644 --- a/allocator/include/aq/melloc.h +++ b/allocator/include/aq/melloc.h @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/14 17:54:03 by maiboyer #+# #+# */ -/* Updated: 2024/05/14 18:08:16 by maiboyer ### ########.fr */ +/* Updated: 2024/05/16 15:43:00 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,4 +23,6 @@ void *m_realloc_array(t_allocator *self, void *ptr, t_usize size, void m_free(t_allocator *self, void *ptr); void m_uninit(t_allocator *self); +t_allocator m_init(void); + #endif /* MELLOC_H */ diff --git a/allocator/include/aq/melloc_interal.h b/allocator/include/aq/melloc_interal.h new file mode 100644 index 00000000..7a798496 --- /dev/null +++ b/allocator/include/aq/melloc_interal.h @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* melloc_interal.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/15 15:27:46 by maiboyer #+# #+# */ +/* Updated: 2024/05/16 14:58:27 by maiboyer ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MELLOC_INTERAL_H +#define MELLOC_INTERAL_H + +#include "aq/allocator.h" +#include "me/types.h" + +#define PAGE_LIST_MAX 255 +#define PAGE_POW_2 12 +#define PAGE_ALIGN 3 + +typedef struct s_chunk +{ + bool used : 1; + t_u64 size : 63; +} t_chunk; + +typedef struct s_page +{ + t_usize size; + void *data; +} t_page; + +typedef struct s_page_list +{ + t_usize len; + t_page pages[PAGE_LIST_MAX]; + struct s_page_list *next; +} t_page_list; + +struct s_allocator_melloc +{ + t_allocator_alloc alloc; + t_allocator_alloc_array alloc_array; + t_allocator_realloc realloc; + t_allocator_realloc_array realloc_array; + t_allocator_free free; + t_allocator_uninit uninit; + t_page_list *list; +}; + +t_error alloc_page_list(t_page_list **out); + +void *m_malloc(struct s_allocator_melloc *self, t_usize size); +void *m_alloc_array(struct s_allocator_melloc *self, t_usize size, + t_usize count); +void *m_realloc(struct s_allocator_melloc *self, void *ptr, t_usize min_size); +void *m_realloc_array(struct s_allocator_melloc *self, void *ptr, t_usize size, + t_usize count); +void m_free(struct s_allocator_melloc *self, void *ptr); +void m_uninit(struct s_allocator_melloc *self); + +#endif /* MELLOC_INTERAL_H */ diff --git a/allocator/src.list b/allocator/src.list index e4935bda..6be242f4 100644 --- a/allocator/src.list +++ b/allocator/src.list @@ -4,6 +4,9 @@ lc_alloc/functions1 lc_alloc/functions2 me_alloc/functions1 me_alloc/functions2 +vg/dummy_block +vg/dummy_mempool +vg/dummy_mem_status vg/valgrind_block vg/valgrind_mempool vg/valgrind_mem_status diff --git a/allocator/src/me_alloc/functions1.c b/allocator/src/me_alloc/functions1.c index 67bbeea0..c765f705 100644 --- a/allocator/src/me_alloc/functions1.c +++ b/allocator/src/me_alloc/functions1.c @@ -6,47 +6,375 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/14 18:02:12 by maiboyer #+# #+# */ -/* Updated: 2024/05/14 18:21:16 by maiboyer ### ########.fr */ +/* Updated: 2024/05/17 15:21:57 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ -#include "aq/allocator.h" -#include "aq/libc_wrapper.h" +#include "me/mem/mem_copy.h" +#include "me/mem/mem_set_zero.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_realloc_array(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_realloc_array(ptr, size, elem)); -// } -// -// void lc_free(t_allocator *self, void *ptr) -// { -// (void)(self); -// return (__libc_free(ptr)); -// } +#include "aq/allocator.h" +#include "aq/internal_vg_funcs.h" +#include "aq/melloc_interal.h" +#include "valgrind/valgrind.h" +#include +#include +#include + +#define eprintf(...) fprintf(stderr, __VA_ARGS__) + +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_realloc_array(void *ptr, t_usize size, t_usize elem); +void __libc_free(void *ptr); + +t_chunk *get_first_block(t_page *page) +{ + t_chunk *chunk; + if (page == NULL) + return (NULL); + vg_mem_defined(page, sizeof(*page)); + chunk = page->data; + vg_mem_no_access(page, sizeof(*page)); + return (chunk); +} + +t_chunk *get_next_block(t_chunk *chunk, bool find_zero) +{ + t_chunk *next; + + if (chunk == NULL) + return (NULL); + vg_mem_defined(chunk, sizeof(*chunk)); + next = (void *)(chunk) + sizeof(*chunk) + chunk->size; + vg_mem_no_access(chunk, sizeof(*chunk)); + vg_mem_defined(next, sizeof(*next)); + if (!find_zero && next->size == 0) + { + vg_mem_no_access(next, sizeof(*next)); + return (NULL); + } + vg_mem_no_access(next, sizeof(*next)); + return (next); +} + +t_usize round_to_pow2(t_usize val, t_usize pow) +{ + pow = (1 << pow) - 1; + + return ((val + pow) & (~pow)); +} + +t_error alloc_page_list(t_page_list **out) +{ + t_page_list *val; + + if (out == NULL) + return (ERROR); + val = __libc_calloc(sizeof(*val), 1); + if (val == NULL) + return (ERROR); + *out = val; + vg_mem_no_access(val, sizeof(*val)); + vg_mempool_create_ext(val, MEMPOOL_FLAG_MALLOCLIKE); + return (NO_ERROR); +} + +void merge_blocks(t_page *page) +{ + t_chunk *cur; + t_chunk *next; + bool did_merge; + + did_merge = true; + while (did_merge) + { + cur = get_first_block(page); + next = get_next_block(cur, false); + did_merge = false; + while (cur != NULL && next != NULL) + { + (vg_mem_defined(cur, sizeof(*cur)), + vg_mem_defined(next, sizeof(*next))); + if (!cur->used && !next->used) + { + did_merge = true; + cur->size += sizeof(*cur); + cur->size += next->size; + (vg_mem_no_access(cur, sizeof(*cur)), + vg_mem_no_access(next, sizeof(*next))); + next = get_next_block(cur, false); + } + else + { + (vg_mem_no_access(cur, sizeof(*cur)), + vg_mem_no_access(next, sizeof(*next))); + cur = next; + next = get_next_block(cur, false); + } + } + } +} + +t_chunk *split_block(t_chunk *chunk, t_usize size) +{ + t_usize remaining; + t_chunk *next; + t_chunk *ac_next; + + if (chunk == NULL) + return (NULL); + vg_mem_defined(chunk, sizeof(*chunk)); + if (chunk->size > size + sizeof(*chunk) + (2 << PAGE_ALIGN)) + { + remaining = chunk->size - size - sizeof(*chunk); + next = get_next_block(chunk, true); + vg_mem_defined(chunk, sizeof(*chunk)); + // eprintf("before size = %zu\n", (t_usize)chunk->size); + chunk->size = size; + // eprintf("after size = %zu\n", (t_usize)chunk->size); + ac_next = get_next_block(chunk, true); + // eprintf("chunk = %p\n", chunk); + // eprintf("next = %p\n", next); + // eprintf("ac_next = %p\n", ac_next); + // eprintf("get_next_block(ac_next, true) = %p\n", + // get_next_block(ac_next, true)); + vg_mem_defined(ac_next, sizeof(*ac_next)); + ac_next->used = false; + ac_next->size = remaining; + assert(next == get_next_block(ac_next, true)); + vg_mem_no_access(ac_next, sizeof(*ac_next)); + } + vg_mem_no_access(chunk, sizeof(*chunk)); + return (chunk); +} + +t_chunk *find_chunk_of_size(struct s_allocator_melloc *alloc, t_usize size) +{ + t_page_list *list; + t_page_list *list_next; + t_usize idx; + t_chunk *chunk; + + list = alloc->list; + while (list != NULL) + { + vg_mem_defined(list, sizeof(*list)); + idx = 0; + while (idx < list->len) + { + // printf("[%zu]list\n", idx); + chunk = get_first_block(&list->pages[idx++]); + while (chunk) + { + vg_mem_defined(chunk, sizeof(*chunk)); + if (!chunk->used && chunk->size >= size) + { + vg_mem_no_access(chunk, sizeof(*chunk)); + vg_mem_no_access(list, sizeof(*list)); + return (split_block(chunk, size)); + } + vg_mem_no_access(chunk, sizeof(*chunk)); + chunk = get_next_block(chunk, false); + } + } + list_next = list->next; + vg_mem_no_access(list, sizeof(*list)); + list = list_next; + } + return (NULL); +} + +t_error alloc_new_page(struct s_allocator_melloc *alloc, t_usize page_size) +{ + t_page_list *list; + t_page_list *list_bis; + t_chunk *chunk; + + page_size = round_to_pow2(page_size, PAGE_POW_2); + if (alloc->list == NULL && alloc_page_list(&alloc->list)) + return (eprintf("Oups\n"), ERROR); + list = alloc->list; + while (list) + { + vg_mem_defined(list, sizeof(*list)); + if (list->len != PAGE_LIST_MAX) + break; + if (list->next == NULL && alloc_page_list(&list->next)) + return (vg_mem_no_access(list, sizeof(*list)), ERROR); + list_bis = list; + list = list->next; + vg_mem_no_access(list_bis, sizeof(*list_bis)); + } + if (list == NULL) + return (ERROR); + vg_mem_defined(list, sizeof(*list)); + list->pages[list->len].data = __libc_calloc(page_size, 1); + if (list->pages[list->len].data == NULL) + return (ERROR); + list->pages[list->len].size = page_size; + + // eprintf("thingy!\n"); + // eprintf("(%p)pool_exist = %s\n", list, + // VALGRIND_MEMPOOL_EXISTS(list) ? "true" : "false"); + vg_mempool_alloc(list, list->pages[list->len].data, page_size); + chunk = get_first_block(&list->pages[list->len]); + chunk->used = false; + chunk->size = page_size - sizeof(*chunk) * 2; + vg_mem_no_access(chunk, sizeof(*chunk)); + list->len++; + vg_mem_no_access(list, sizeof(*list)); + return (NO_ERROR); +} + +void *m_alloc_error(struct s_allocator_melloc *self, t_str msg) +{ + (void)(self); + me_abort(msg); + return (NULL); +} + +void *m_malloc(struct s_allocator_melloc *self, t_usize size) +{ + return (m_realloc(self, NULL, size)); +} + +void *m_alloc_array(struct s_allocator_melloc *self, t_usize size, + t_usize count) +{ + if (size != 0 && count > SIZE_MAX / size) + return (m_alloc_error(self, "Alloc array overflow")); + return (m_realloc(self, NULL, size * count)); +} + +void *m_realloc(struct s_allocator_melloc *self, void *ptr, t_usize size) +{ + t_chunk *chunk; + t_chunk *next; + t_usize old_size; + + // eprintf("M_REALLOC\n"); + // if (self->list == NULL && alloc_page_list(&self->list)) + // return (m_alloc_error(self, "Unable to alloc page list")); + size = round_to_pow2(size, PAGE_ALIGN); + if (ptr == NULL) + { + chunk = find_chunk_of_size(self, size); + if (chunk == NULL) + { + if (alloc_new_page(self, size + sizeof(t_chunk) * 2)) + return (m_alloc_error(self, "Unable to alloc page")); + chunk = find_chunk_of_size(self, size); + if (chunk == NULL) + return (m_alloc_error(self, "Unable to find block")); + } + vg_mem_defined((void *)chunk, sizeof(*chunk)); + chunk->used = true; + vg_mem_defined((void *)chunk + sizeof(*chunk), chunk->size); + mem_set_zero((void *)chunk + sizeof(*chunk), chunk->size); + vg_block_malloc((void *)chunk + sizeof(*chunk), chunk->size); + vg_mem_no_access((void *)chunk, sizeof(*chunk)); + return ((void *)chunk + sizeof(*chunk)); + } + else + { + chunk = ptr - sizeof(*chunk); + vg_mem_defined(chunk, sizeof(*chunk)); + if (chunk->size >= size) + return (vg_mem_no_access(chunk, sizeof(*chunk)), ptr); + next = get_next_block(chunk, false); + vg_mem_defined(next, sizeof(*next)); + vg_mem_defined(chunk, sizeof(*chunk)); + if (next != NULL && !next->used && + chunk->size + next->size + sizeof(*next) >= size) + { + old_size = chunk->size; + chunk->size += next->size + sizeof(*next); + vg_mem_defined(next, next->size + sizeof(*next)); + mem_set_zero(next, next->size + sizeof(*next)); + vg_block_resize((void *)chunk + sizeof(*chunk), old_size, + chunk->size); + vg_mem_no_access(chunk, sizeof(*chunk)); + return (ptr); + } + else + { + vg_mem_no_access(next, sizeof(*next)); + next = m_realloc(self, NULL, size); + vg_mem_defined(chunk, sizeof(*chunk)); + mem_copy(ptr, next, chunk->size); + vg_mem_no_access(chunk, sizeof(*chunk)); + m_free(self, ptr); + return (next); + } + } +} + +void *m_realloc_array(struct s_allocator_melloc *self, void *ptr, t_usize size, + t_usize count) +{ + if (size != 0 && count > SIZE_MAX / size) + return (m_alloc_error(self, "Realloc array overflow")); + return (m_realloc(self, ptr, size * count)); +} + +void m_free(struct s_allocator_melloc *self, void *ptr) +{ + t_chunk *chunk; + + (void)(self); + if (ptr == NULL) + return; + vg_block_free(ptr); + chunk = ptr - sizeof(*chunk); + vg_mem_defined(chunk, sizeof(*chunk)); + chunk->used = false; + vg_mem_no_access(chunk, sizeof(*chunk)); +} + +void m_uninit(struct s_allocator_melloc *self) +{ + t_page_list *list; + t_page_list *list_next; + t_usize idx; + + list = self->list; + while (list) + { + vg_mem_defined(list, sizeof(*list)); + idx = 0; + while (idx < list->len) + { + if (list->pages[idx].data != NULL) + { + vg_mempool_free(list, list->pages[idx].data); + __libc_free(list->pages[idx].data); + list->pages[idx].size = 0; + list->pages[idx].data = NULL; + } + idx++; + } + list_next = list->next; + __libc_free(list); + vg_mempool_destroy(list); + vg_mem_no_access(list, sizeof(*list)); + list = list_next; + } +} + +t_allocator m_init(void) +{ + t_allocator out; + + out.free = (t_allocator_free)m_free; + out.alloc = (t_allocator_alloc)m_malloc; + out.alloc_array = (t_allocator_alloc_array)m_alloc_array; + out.realloc = (t_allocator_realloc)m_realloc; + out.realloc_array = (t_allocator_realloc_array)m_realloc_array; + out.uninit = (t_allocator_uninit)m_uninit; + out.alloc_data = NULL; + return (out); +} diff --git a/allocator/src/vg/dummy_block.c b/allocator/src/vg/dummy_block.c new file mode 100644 index 00000000..e8769f1e --- /dev/null +++ b/allocator/src/vg/dummy_block.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* dummy_block.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/12 22:51:55 by maiboyer #+# #+# */ +/* Updated: 2024/05/17 15:28:09 by maiboyer ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "aq/internal_vg_funcs.h" + +#ifndef VGFUNCS + +void vg_block_malloc(void *ptr, t_usize size) +{ + (void)(ptr); + (void)(size); +} + +void vg_block_resize(void *ptr, t_usize oldsize, t_usize newsize) +{ + (void)(ptr); + (void)(oldsize); + (void)(newsize); +} + +void vg_block_free(void *ptr) +{ + (void)(ptr); +} + +#endif diff --git a/allocator/src/vg/dummy_mem_status.c b/allocator/src/vg/dummy_mem_status.c new file mode 100644 index 00000000..123604c5 --- /dev/null +++ b/allocator/src/vg/dummy_mem_status.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* dummy_mem_status.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/12 23:08:47 by maiboyer #+# #+# */ +/* Updated: 2024/05/17 15:28:52 by maiboyer ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "aq/internal_vg_funcs.h" + +#ifndef VGFUNCS + +void vg_mem_no_access(void *ptr, t_usize size) +{ + (void)(ptr); + (void)(size); +} + +void vg_mem_undefined(void *ptr, t_usize size) +{ + (void)(ptr); + (void)(size); +} + +void vg_mem_defined(void *ptr, t_usize size) +{ + (void)(ptr); + (void)(size); +} + +#endif diff --git a/allocator/src/vg/dummy_mempool.c b/allocator/src/vg/dummy_mempool.c new file mode 100644 index 00000000..68d5f617 --- /dev/null +++ b/allocator/src/vg/dummy_mempool.c @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* dummy_mempool.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/12 22:33:30 by maiboyer #+# #+# */ +/* Updated: 2024/05/17 15:29:59 by maiboyer ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "aq/internal_vg_funcs.h" + +#ifndef VGFUNCS + +void vg_mempool_create_ext(void *pool, t_usize flags) +{ + (void)(pool); + (void)(flags); +} + +void vg_mempool_resize(void *pool, void *ptr, t_usize size) +{ + (void)(pool); + (void)(ptr); + (void)(size); +} + +void vg_mempool_create(void *pool) +{ + (void)(pool); +} + +void vg_mempool_destroy(void *pool) +{ + (void)(pool); +} + +void vg_mempool_alloc(void *pool, void *addr, t_usize size) +{ + (void)(pool); + (void)(addr); + (void)(size); +} + +void vg_mempool_free(void *pool, void *addr) +{ + (void)(pool); + (void)(addr); +} + +#endif diff --git a/allocator/src/vg/valgrind_mempool.c b/allocator/src/vg/valgrind_mempool.c index c70360d0..80b46f8f 100644 --- a/allocator/src/vg/valgrind_mempool.c +++ b/allocator/src/vg/valgrind_mempool.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/12 22:33:30 by maiboyer #+# #+# */ -/* Updated: 2024/05/14 16:17:37 by maiboyer ### ########.fr */ +/* Updated: 2024/05/17 15:30:09 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,8 +25,7 @@ void vg_mempool_create_ext(void *pool, t_usize flags) if (flags & MEMPOOL_FLAG_AUTOFREE) actual_flags |= VALGRIND_MEMPOOL_AUTO_FREE; - VALGRIND_CREATE_MEMPOOL_EXT(pool, redzone_size(), ZEROED_POOL, - actual_flags); + VALGRIND_CREATE_MEMPOOL_EXT(pool, 0, ZEROED_POOL, actual_flags); } void vg_mempool_resize(void *pool, void *ptr, t_usize size) @@ -36,7 +35,8 @@ void vg_mempool_resize(void *pool, void *ptr, t_usize size) void vg_mempool_create(void *pool) { - VALGRIND_CREATE_MEMPOOL(pool, redzone_size(), ZEROED_POOL); + VALGRIND_CREATE_MEMPOOL(pool, 0, ZEROED_POOL); + } void vg_mempool_destroy(void *pool) @@ -46,7 +46,6 @@ void vg_mempool_destroy(void *pool) void vg_mempool_alloc(void *pool, void *addr, t_usize size) { - VALGRIND_CREATE_BLOCK(addr, size, "mempool"); VALGRIND_MEMPOOL_ALLOC(pool, addr, size); } diff --git a/parser/Makefile b/parser/Makefile index c716e513..40844684 100644 --- a/parser/Makefile +++ b/parser/Makefile @@ -6,7 +6,7 @@ # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/03 13:20:01 by maiboyer #+# #+# # -# Updated: 2024/05/14 15:26:21 by maiboyer ### ########.fr # +# Updated: 2024/05/18 14:36:37 by maiboyer ### ########.fr # # # # **************************************************************************** # @@ -28,11 +28,11 @@ OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(SRC_FILES))) DEPS = $(addsuffix .d,$(addprefix $(BUILD_DIR)/,$(SRC_FILES))) INCLUDES = -COL_GRAY = \\e[90m -COL_WHITE = \\e[37m -COL_GREEN = \\e[32m -COL_BOLD = \\e[1m -COL_RESET = \\e[0m +GREEN = \033[32m +GREY = \033[0;90m +RED = \033[0;31m +GOLD = \033[38;5;220m +END = \033[0m .PHONY: all .PHONY: libs_build @@ -50,12 +50,14 @@ all: $(NAME) $(NAME): $(TARGET) $(TARGET): $(OBJ) - @echo "ar rcs $(BUILD_DIR)/$(NAME) " + @#echo "ar rcs $(BUILD_DIR)/$(NAME) " + @echo -e '$(GREY) Linking\t$(END)$(GREEN)$(NAME)$(END)' @ar rcs $(BUILD_DIR)/$(NAME) $(OBJ) $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ + @echo -e '$(GREY) Compiling\t$(END)$(GREEN)$<$(END)' + @$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ clean: @- $(foreach LIB,$(LIBS), \ diff --git a/parser/src/api.h b/parser/src/api.h index 9ee2524d..2d121dc7 100644 --- a/parser/src/api.h +++ b/parser/src/api.h @@ -45,7 +45,7 @@ # undef realloc # undef free -# define malloc(s) me_malloc((s)) +# define malloc(s) mem_alloc((s)) # define calloc(s, l) mem_alloc_array((s), (l)) # define realloc(p, t) mem_realloc((p), (t)) # define free(p) mem_free((p)) diff --git a/sources/exec/separator/semicolon.c b/sources/exec/separator/semicolon.c index 1f9f3ba4..426207d8 100644 --- a/sources/exec/separator/semicolon.c +++ b/sources/exec/separator/semicolon.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/12 16:00:33 by rparodi #+# #+# */ -/* Updated: 2024/05/12 19:13:26 by rparodi ### ########.fr */ +/* Updated: 2024/05/17 15:33:34 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,8 @@ #include "minishell.h" #include "me/string/str_clone.h" +t_error ft_command_exec(t_node *self, t_i32 *ret); + t_error semicolon_exec(t_node *first, t_node *second, t_i32 *ret_value) { if (!first && !second) diff --git a/sources/exec/separator/simple_cmd.c b/sources/exec/separator/simple_cmd.c index 92bb46a1..f973c553 100644 --- a/sources/exec/separator/simple_cmd.c +++ b/sources/exec/separator/simple_cmd.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/12 19:13:42 by rparodi #+# #+# */ -/* Updated: 2024/05/12 19:14:19 by rparodi ### ########.fr */ +/* Updated: 2024/05/17 15:33:13 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,6 @@ t_error ft_command_exec(t_node *node, t_i32 *ret_value) { printf("execve : %s\n", node->single_str); - + (void)(ret_value); return (NO_ERROR); } diff --git a/src.list b/src.list index 7a7d017a..3d7efcb7 100644 --- a/src.list +++ b/src.list @@ -5,6 +5,10 @@ exec/handle_expension.c exec/handle_program.c exec/handle_raw_word.c exec/handle_word.c +exec/separator/and_and.c +exec/separator/pipe_pipe.c +exec/separator/semicolon.c +exec/separator/simple_cmd.c ft_cmd.c ft_echo.c ft_exit.c diff --git a/stdme/include/me/types.h b/stdme/include/me/types.h index c1f5551c..5cac0bc5 100644 --- a/stdme/include/me/types.h +++ b/stdme/include/me/types.h @@ -6,13 +6,17 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/03 14:31:12 by maiboyer #+# #+# */ -/* Updated: 2024/05/14 18:41:05 by maiboyer ### ########.fr */ +/* Updated: 2024/05/16 16:12:21 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef TYPES_H #define TYPES_H +#ifdef _FORTIFY_SOURCE +# undef _FORTIFY_SOURCE +#endif + #include #include #include diff --git a/stdme/src/mem/allocator.c b/stdme/src/mem/allocator.c index e9cdfb6f..44a90418 100644 --- a/stdme/src/mem/allocator.c +++ b/stdme/src/mem/allocator.c @@ -6,12 +6,17 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/14 18:26:27 by maiboyer #+# #+# */ -/* Updated: 2024/05/14 18:28:24 by maiboyer ### ########.fr */ +/* Updated: 2024/05/16 16:24:54 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ +#include "aq/internal_vg_funcs.h" +#include "me/types.h" #include "aq/allocator.h" #include "aq/libc_wrapper.h" +#include "aq/melloc.h" + + t_allocator *global_allocator(void) { @@ -20,7 +25,7 @@ t_allocator *global_allocator(void) if (!init) { init = true; - global_alloc = lc_init(); + global_alloc = m_init(); } return (&global_alloc); } @@ -30,5 +35,6 @@ void uninit_global_allocator(void) t_allocator *allocator; allocator = global_allocator(); + vg_mem_defined(allocator, sizeof(*allocator)); allocator->uninit(allocator); } diff --git a/stdme/src/os/abort.c b/stdme/src/os/abort.c index 347ed425..f2c1cc42 100644 --- a/stdme/src/os/abort.c +++ b/stdme/src/os/abort.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/07 11:08:03 by maiboyer #+# #+# */ -/* Updated: 2024/05/14 18:42:15 by maiboyer ### ########.fr */ +/* Updated: 2024/05/16 17:26:27 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ @@ -93,5 +93,6 @@ void me_abort(t_str msg) me_putstr_fd("Abort: ", 2); me_putendl_fd(msg, 2); print_trace(); - me_exit(1); + // me_exit(1); + abort(); } diff --git a/stdme/src/os/exit.c b/stdme/src/os/exit.c index d878e4ae..f522571e 100644 --- a/stdme/src/os/exit.c +++ b/stdme/src/os/exit.c @@ -6,7 +6,7 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/07 13:08:52 by maiboyer #+# #+# */ -/* Updated: 2024/05/14 18:42:41 by maiboyer ### ########.fr */ +/* Updated: 2024/05/16 17:12:46 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */