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:
parent
713f0f0302
commit
cb7f3c3fdf
85 changed files with 1121 additions and 877 deletions
13
.clangd
13
.clangd
|
|
@ -2,15 +2,17 @@ CompileFlags: # Tweak the parse settings
|
|||
Add:
|
||||
- "-I/usr/include/"
|
||||
- "-I/home/maiboyer/Documents/ring-2/shcat/vendor/"
|
||||
- "-I/home/maiboyer/Documents/ring-2/shcat/mecstd/include/"
|
||||
- "-I/home/maiboyer/Documents/ring-2/shcat/mecstd/vendor/"
|
||||
- "-I/home/maiboyer/Documents/ring-2/shcat/mecstd/output/include/"
|
||||
- "-I/home/maiboyer/Documents/ring-2/shcat/mecstd/generic_sources/header/"
|
||||
- "-I/home/maiboyer/Documents/ring-2/shcat/stdme/include/"
|
||||
- "-I/home/maiboyer/Documents/ring-2/shcat/allocator/include/"
|
||||
- "-I/home/maiboyer/Documents/ring-2/shcat/stdme/vendor/"
|
||||
- "-I/home/maiboyer/Documents/ring-2/shcat/stdme/output/include/"
|
||||
- "-I/home/maiboyer/Documents/ring-2/shcat/stdme/generic_sources/header/"
|
||||
- "-I/home/maiboyer/Documents/ring-2/shcat/includes/"
|
||||
- "-I/home/maiboyer/Documents/ring-2/shcat/output/include/"
|
||||
- "-I/home/maiboyer/Documents/ring-2/shcat/generic_sources/header/"
|
||||
- "-I/home/maix/school/shcat/vendor/"
|
||||
- "-I/home/maix/school/shcat/stdme/include/"
|
||||
- "-I/home/maix/school/shcat/allocator/include/"
|
||||
- "-I/home/maix/school/shcat/stdme/vendor/"
|
||||
- "-I/home/maix/school/shcat/stdme/output/include/"
|
||||
- "-I/home/maix/school/shcat/stdme/generic_sources/header/"
|
||||
|
|
@ -19,6 +21,7 @@ CompileFlags: # Tweak the parse settings
|
|||
- "-I/home/maix/school/shcat/generic_sources/header/"
|
||||
- "-I/home/raphael/42/shcat/vendor/"
|
||||
- "-I/home/raphael/42/shcat/stdme/include/"
|
||||
- "-I/home/raphael/42/shcat/allocator/include/"
|
||||
- "-I/home/raphael/42/shcat/stdme/vendor/"
|
||||
- "-I/home/raphael/42/shcat/stdme/output/include/"
|
||||
- "-I/home/raphael/42/shcat/stdme/generic_sources/header/"
|
||||
|
|
@ -26,6 +29,7 @@ CompileFlags: # Tweak the parse settings
|
|||
- "-I/home/raphael/42/shcat/output/include/"
|
||||
- "-I/home/rparodi/Documents/shcat/vendor/"
|
||||
- "-I/home/rparodi/Documents/shcat/stdme/include/"
|
||||
- "-I/home/rparodi/Documents/shcat/allocator/include/"
|
||||
- "-I/home/rparodi/Documents/shcat/stdme/vendor/"
|
||||
- "-I/home/rparodi/Documents/shcat/stdme/output/include/"
|
||||
- "-I/home/rparodi/Documents/shcat/stdme/generic_sources/header/"
|
||||
|
|
@ -33,6 +37,7 @@ CompileFlags: # Tweak the parse settings
|
|||
- "-I/home/rparodi/Documents/shcat/output/include/"
|
||||
- "-I/Users/raphael/Documents/42/cursus/shcat/vendor/"
|
||||
- "-I/Users/raphael/Documents/42/cursus/shcat/stdme/include/"
|
||||
- "-I/Users/raphael/Documents/42/cursus/shcat/allocator/include/"
|
||||
- "-I/Users/raphael/Documents/42/cursus/shcat/stdme/vendor/"
|
||||
- "-I/Users/raphael/Documents/42/cursus/shcat/stdme/output/include/"
|
||||
- "-I/Users/raphael/Documents/42/cursus/shcat/stdme/generic_sources/header/"
|
||||
|
|
|
|||
11
Minishell.mk
11
Minishell.mk
|
|
@ -6,7 +6,7 @@
|
|||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/04/28 17:28:30 by maiboyer #+# #+# #
|
||||
# Updated: 2024/05/09 21:24:34 by maiboyer ### ########.fr #
|
||||
# Updated: 2024/05/14 18:38:18 by maiboyer ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ LIBDIRNAME = libft
|
|||
SRCDIRNAME = sources
|
||||
|
||||
# Commands
|
||||
CC = cc
|
||||
CC ?= clang
|
||||
RM = rm -rf
|
||||
|
||||
# Objects
|
||||
|
|
@ -56,6 +56,7 @@ END = \033[0m
|
|||
|
||||
all:
|
||||
@$(MAKE) -C ./stdme/ LIB_NAME="$(shell realpath ./stdme)/" "BUILD_DIR=$(shell realpath ./$(OBJDIRNAME))" CC=$(CC) libme.a
|
||||
@$(MAKE) -C ./allocator/ LIB_NAME="$(shell realpath ./parser)/" -j "BUILD_DIR=$(shell realpath ./$(OBJDIRNAME))" libaq.a
|
||||
@$(MAKE) -C ./parser/ LIB_NAME="$(shell realpath ./parser)/" -j "BUILD_DIR=$(shell realpath ./$(OBJDIRNAME))" libgmr.a
|
||||
@$(MAKE) -f./Minishell.mk $(NAME)
|
||||
|
||||
|
|
@ -66,7 +67,7 @@ bonus: $(OBJ) $(LIB_OBJ) $(OBJDIRNAME)/libme.a $(OBJDIRNAME)/libgmr.a
|
|||
@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
|
||||
@$(CC) $(CFLAGS) -D DEBUG=42 -o $(NAME) $(OBJ) -L$(OBJDIRNAME) -lgmr -lme -laq
|
||||
|
||||
# Dependences for all
|
||||
$(NAME): $(OBJ) $(LIB_OBJ) $(OBJDIRNAME)/libgmr.a $(OBJDIRNAME)/libme.a
|
||||
|
|
@ -74,12 +75,12 @@ $(NAME): $(OBJ) $(LIB_OBJ) $(OBJDIRNAME)/libgmr.a $(OBJDIRNAME)/libme.a
|
|||
@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
|
||||
@$(CC) $(CFLAGS) -o $(NAME) $(OBJ) $(LIB_OBJ) -L$(OBJDIRNAME) -lgmr -lme -laq
|
||||
|
||||
# Creating the objects
|
||||
$(OBJDIRNAME)/%.o: %.c
|
||||
@mkdir -p $(dir $@)
|
||||
@echo -e '$(GREY) Compiling\t$(END)$(GREEN)$<$(END)'
|
||||
@cc $(CFLAGS) -o $@ -c $<
|
||||
@$(CC) $(CFLAGS) -o $@ -c $<
|
||||
|
||||
-include ${OBJ:.o=.d}
|
||||
|
|
|
|||
96
allocator/Makefile
Normal file
96
allocator/Makefile
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||
# Updated: 2024/05/14 18:44:53 by maiboyer ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
BUILD_DIR ?= build
|
||||
SRC_DIR = src
|
||||
INCLUDE_DIR = include output/include ../stdme/include
|
||||
LIBS_DIR = .
|
||||
GENERIC_DIR = output/src
|
||||
GENERIC_INCLUDE = output/include
|
||||
|
||||
|
||||
BASE_PATH ?= $(shell pwd)
|
||||
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 += -fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-return=runtime -fno-common -fsanitize-address-use-after-scope
|
||||
BONUS_FILES =
|
||||
LIBS_NAME =
|
||||
SUBJECT_URL =
|
||||
|
||||
SRC_FILES = $(shell cat src.list)
|
||||
|
||||
SRC = $(addsuffix .c,$(addprefix $(SRC_DIR)/,$(SRC_FILES)))
|
||||
OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(SRC_FILES)))
|
||||
DEPS = $(addsuffix .d,$(addprefix $(BUILD_DIR)/,$(SRC_FILES)))
|
||||
|
||||
LIBS = $(addprefix $(LIBS_DIR)/,$(LIBS_NAME))
|
||||
INCLUDES = $(addprefix -I,$(foreach P,$(INCLUDE_DIR) $(LIBS) $(addsuffix /include,$(LIBS)) vendor $(addsuffix /vendor,$(LIBS)),$(realpath $(P))))
|
||||
COL_GRAY = \033[90m
|
||||
COL_WHITE = \033[37m
|
||||
COL_GREEN = \033[32m
|
||||
COL_BOLD = \033[1m
|
||||
COL_RESET = \033[0m
|
||||
|
||||
# TODO: REMOVE FOR RENDU !!!!!
|
||||
CFLAGS += -DPRINT_BACKTRACE
|
||||
|
||||
|
||||
.PHONY = all bonus clean re subject
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(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
|
||||
@mkdir -p $(dir $@)
|
||||
@echo -e '$(COL_GRAY) Building\t$(COL_GREEN)$<$(COL_RESET)'
|
||||
@$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@
|
||||
|
||||
$(BUILD_DIR)/%.o: $(GENERIC_DIR)/%.c
|
||||
@mkdir -p $(dir $@)
|
||||
@echo -e '$(COL_GRAY) Building\t$(COL_GREEN)$<$(COL_RESET)'
|
||||
@$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@
|
||||
|
||||
clean:
|
||||
@- $(foreach LIB,$(LIBS), \
|
||||
make clean LIB_NAME=$(LIB)/ BUILD_DIR=$(realpath $(BUILD_DIR)) -C $(LIB) --no-print-directory || true;\
|
||||
)
|
||||
@- $(if $(LIB_NAME),,echo -e '$(COL_WHITE)Clearing Artefacts';rm -rf $(BUILD_DIR))
|
||||
|
||||
fclean: clean
|
||||
@- $(foreach LIB,$(LIBS), \
|
||||
make fclean LIB_NAME=$(LIB)/ BUILD_DIR=$(shell realpath $(BUILD_DIR)) -C $(LIB) --no-print-directory || true;\
|
||||
)
|
||||
@echo -e '$(COL_WHITE)Clearing Output $(COL_GRAY)$(LIB_NAME)$(NAME)'
|
||||
@rm -f $(BUILD_DIR)$(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
subject: subject.txt
|
||||
bat --plain ./subject.txt
|
||||
|
||||
subject.txt:
|
||||
@curl $(SUBJECT_URL) | pdftotext -layout -nopgbrk -q - subject.txt
|
||||
|
||||
generate_filelist::
|
||||
@/usr/bin/env zsh -c "tree -iFf --noreport output | rg '^output/src/(.*)\.c\$$' --replace '\$$1' | sort -u" > ./gen.list
|
||||
@/usr/bin/env zsh -c "tree -iFf --noreport src | rg '^src/(.*)\.c\$$' --replace '\$$1' | sort -u" > ./src.list
|
||||
|
||||
-include $(DEPS)
|
||||
0
allocator/gen.list
Normal file
0
allocator/gen.list
Normal file
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/07 09:42:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/12 17:10:51 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 17:44:38 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,5 +19,6 @@ void *me_malloc(t_usize size);
|
|||
void *me_calloc(t_usize elem_count, t_usize elem_size);
|
||||
void *me_realloc(void *ptr, t_usize size);
|
||||
void *me_realloc_array(void *ptr, t_usize elem_size, t_usize elem_count);
|
||||
void uninit_allocator(void);
|
||||
|
||||
#endif /* ALLOC_H */
|
||||
|
|
@ -6,26 +6,26 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/07 09:48:17 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/12 14:02:32 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 16:12:54 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ALLOC_INTERNAL_H
|
||||
#define ALLOC_INTERNAL_H
|
||||
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "aq/alloc.h"
|
||||
#include "me/types.h"
|
||||
#include <stdalign.h>
|
||||
|
||||
#define PAGE_SIZE_DEFAULT 4096
|
||||
#define BLOCK_PADDING "\xFE\xDC\xAB\xC0\xFE\xEE\x66"
|
||||
#define POOL_ADDR (void *)0xDeadBeef
|
||||
|
||||
typedef struct s_mblock
|
||||
{
|
||||
struct s_mblock *next;
|
||||
struct s_mpage *page;
|
||||
t_usize size;
|
||||
t_usize offset;
|
||||
bool used;
|
||||
t_u8 padding[7];
|
||||
} t_mblock;
|
||||
|
|
@ -33,7 +33,6 @@ typedef struct s_mblock
|
|||
typedef struct s_mpage
|
||||
{
|
||||
t_usize page_size;
|
||||
void *data;
|
||||
t_mblock *first;
|
||||
struct s_mpage *next;
|
||||
} t_mpage;
|
||||
|
|
@ -42,11 +41,10 @@ typedef struct s_mpage
|
|||
t_mpage *get_head_arena(void);
|
||||
|
||||
// Will return ERROR if it couldn't malloc the page
|
||||
t_error alloc_arena_page(t_usize min_size, t_mpage **out);
|
||||
t_error alloc_arena_page(t_usize min_size, t_mpage **out);
|
||||
|
||||
t_mblock *get_block_for_size(t_usize size);
|
||||
void print_pages_info(void);
|
||||
t_mpage *get_page_from_ptr(void *ptr);
|
||||
t_mblock *get_block_from_ptr(void *ptr);
|
||||
t_error merge_next_block(t_mblock *self, t_usize min_size);
|
||||
bool merge_block(t_mblock *self, t_usize min_size);
|
||||
|
||||
#endif /* ALLOC_INTERNAL_H */
|
||||
42
allocator/include/aq/allocator.h
Normal file
42
allocator/include/aq/allocator.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* allocator.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/14 17:52:31 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 17:55:36 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ALLOCATOR_H
|
||||
#define ALLOCATOR_H
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
typedef struct s_allocator t_allocator;
|
||||
|
||||
typedef void *(*t_allocator_alloc)(t_allocator *self, t_usize size);
|
||||
typedef void *(*t_allocator_alloc_array)(t_allocator *self, t_usize size,
|
||||
t_usize count);
|
||||
typedef void *(*t_allocator_realloc)(t_allocator *self, void *ptr,
|
||||
t_usize requested_size);
|
||||
typedef void *(*t_allocator_realloc_array)(t_allocator *self, void *ptr,
|
||||
t_usize requested_size,
|
||||
t_usize requested_count);
|
||||
typedef void (*t_allocator_free)(t_allocator *self, void *ptr);
|
||||
typedef void (*t_allocator_uninit)(t_allocator *self);
|
||||
|
||||
struct s_allocator
|
||||
{
|
||||
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;
|
||||
void *alloc_data;
|
||||
};
|
||||
|
||||
#endif /* ALLOCATOR_H */
|
||||
66
allocator/include/aq/internal_vg_funcs.h
Normal file
66
allocator/include/aq/internal_vg_funcs.h
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* internal_vg_funcs.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/12 22:20:30 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 16:17:25 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
|
||||
# undef NVALGRIND
|
||||
# endif
|
||||
# define VGFUNCS
|
||||
# include <valgrind/memcheck.h>
|
||||
# include <valgrind/valgrind.h>
|
||||
#endif
|
||||
|
||||
#define ZEROED_POOL 1
|
||||
#define ZEROED_ALLOC 1
|
||||
|
||||
static inline t_usize redzone_size(void)
|
||||
{
|
||||
return (sizeof(t_mblock));
|
||||
}
|
||||
|
||||
#ifdef VGFUNCS
|
||||
static inline bool vg_running(void)
|
||||
{
|
||||
return (RUNNING_ON_VALGRIND != 0);
|
||||
}
|
||||
#else
|
||||
static inline bool vg_running(void)
|
||||
{
|
||||
return (false);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define MEMPOOL_FLAG_MALLOCLIKE 1
|
||||
#define MEMPOOL_FLAG_AUTOFREE 2
|
||||
|
||||
void vg_block_malloc(void *ptr, t_usize size);
|
||||
void vg_block_resize(void *ptr, t_usize oldsize, t_usize newsize);
|
||||
void vg_block_free(void *ptr);
|
||||
|
||||
void vg_mem_no_access(void *ptr, t_usize size);
|
||||
void vg_mem_undefined(void *ptr, t_usize size);
|
||||
void vg_mem_defined(void *ptr, t_usize size);
|
||||
|
||||
void vg_mempool_create(void *pool);
|
||||
void vg_mempool_create_ext(void *pool, t_usize flags);
|
||||
void vg_mempool_destroy(void *pool);
|
||||
void vg_mempool_alloc(void *pool, void *addr, t_usize size);
|
||||
void vg_mempool_free(void *pool, void *addr);
|
||||
void vg_mempool_resize(void *pool, void *psrc, t_usize size);
|
||||
|
||||
#endif /* INTERNAL_VG_FUNCS_H */
|
||||
29
allocator/include/aq/libc_wrapper.h
Normal file
29
allocator/include/aq/libc_wrapper.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libc_wrapper.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/14 17:52:11 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:48:06 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBC_WRAPPER_H
|
||||
#define LIBC_WRAPPER_H
|
||||
|
||||
#include "aq/allocator.h"
|
||||
#include "me/types.h"
|
||||
|
||||
void *lc_malloc(t_allocator *self, t_usize size);
|
||||
void *lc_calloc(t_allocator *self, t_usize size, t_usize count);
|
||||
void *lc_realloc(t_allocator *self, void *ptr, t_usize min_size);
|
||||
void *lc_realloc_array(t_allocator *self, void *ptr, t_usize size,
|
||||
t_usize count);
|
||||
void lc_free(t_allocator *self, void *ptr);
|
||||
void lc_uninit(t_allocator *self);
|
||||
|
||||
t_allocator lc_init(void);
|
||||
|
||||
#endif /* LIBC_WRAPPER_H */
|
||||
26
allocator/include/aq/melloc.h
Normal file
26
allocator/include/aq/melloc.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* melloc.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/14 17:54:03 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:08:16 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MELLOC_H
|
||||
#define MELLOC_H
|
||||
|
||||
#include "aq/allocator.h"
|
||||
|
||||
void *m_malloc(t_allocator *self, t_usize size);
|
||||
void *m_alloc_array(t_allocator *self, t_usize size, t_usize count);
|
||||
void *m_realloc(t_allocator *self, void *ptr, t_usize min_size);
|
||||
void *m_realloc_array(t_allocator *self, void *ptr, t_usize size,
|
||||
t_usize count);
|
||||
void m_free(t_allocator *self, void *ptr);
|
||||
void m_uninit(t_allocator *self);
|
||||
|
||||
#endif /* MELLOC_H */
|
||||
9
allocator/src.list
Normal file
9
allocator/src.list
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
alloc
|
||||
get_arena
|
||||
lc_alloc/functions1
|
||||
lc_alloc/functions2
|
||||
me_alloc/functions1
|
||||
me_alloc/functions2
|
||||
vg/valgrind_block
|
||||
vg/valgrind_mempool
|
||||
vg/valgrind_mem_status
|
||||
196
allocator/src/alloc.c
Normal file
196
allocator/src/alloc.c
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* alloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/07 10:13:06 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:26:01 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "aq/allocator.h"
|
||||
#include "aq/libc_wrapper.h"
|
||||
|
||||
typedef struct s_allocator_page
|
||||
{
|
||||
void *data;
|
||||
t_usize size;
|
||||
} t_allocator_page;
|
||||
|
||||
typedef struct s_page_list
|
||||
{
|
||||
t_usize allocated;
|
||||
t_allocator_page a[10];
|
||||
struct s_page_list *next;
|
||||
} t_page_list;
|
||||
|
||||
/*
|
||||
void *me_malloc(t_usize size)
|
||||
{
|
||||
t_mblock *block;
|
||||
|
||||
size = usize_round_up_to(size, 16);
|
||||
block = get_block_for_size(size);
|
||||
if (block == NULL)
|
||||
return (me_abort("Found no page for me_malloc"), NULL);
|
||||
vg_mem_defined(block, sizeof(*block));
|
||||
vg_mempool_alloc(POOL_ADDR, (void *)(((t_usize)block) + sizeof(*block)),
|
||||
block->size); block->used = true; mem_set_zero((t_u8 *)block + sizeof(*block),
|
||||
block->size); vg_mem_no_access(block, sizeof(*block)); return ((void
|
||||
*)(((t_usize)block) + sizeof(*block)));
|
||||
}
|
||||
|
||||
void *me_calloc(t_usize elem_size, t_usize elem_count)
|
||||
{
|
||||
if (elem_size != 0 && elem_count > SIZE_MAX / elem_size)
|
||||
me_abort("calloc overflow !");
|
||||
return (me_malloc(elem_size * elem_count));
|
||||
}
|
||||
|
||||
void *me_realloc(void *ptr, t_usize new_size)
|
||||
{
|
||||
t_mblock *block;
|
||||
void *ret;
|
||||
t_usize old_size;
|
||||
|
||||
if (ptr == NULL)
|
||||
return (me_malloc(new_size));
|
||||
block = (void *)((t_usize)(ptr) - sizeof(*block));
|
||||
vg_mem_defined(block, sizeof(*block));
|
||||
VALGRIND_CHECK_MEM_IS_ADDRESSABLE(ptr, block->size);
|
||||
block->used = true;
|
||||
if (block->size <= new_size)
|
||||
return (vg_mem_no_access(block, sizeof(*block)), ptr);
|
||||
old_size = block->size;
|
||||
vg_mem_no_access(block, sizeof(*block));
|
||||
if (false && merge_block(block, new_size))
|
||||
{
|
||||
vg_mem_defined(block, sizeof(*block));
|
||||
vg_mempool_resize(POOL_ADDR, ptr, block->size);
|
||||
VALGRIND_CHECK_MEM_IS_ADDRESSABLE(ptr, block->size);
|
||||
mem_set_zero((t_u8 *)ptr + old_size, block->size - old_size);
|
||||
vg_mem_no_access(block, sizeof(*block));
|
||||
return (ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = me_malloc(new_size);
|
||||
mem_copy(ret, ptr, block->size);
|
||||
mem_free(ptr);
|
||||
return (ret);
|
||||
}
|
||||
}
|
||||
|
||||
void *me_realloc_array(void *ptr, t_usize elem_size, t_usize elem_count)
|
||||
{
|
||||
if (elem_size != 0 && elem_count > SIZE_MAX / elem_size)
|
||||
me_abort("realloc_array overflow !");
|
||||
return (me_realloc(ptr, elem_size * elem_count));
|
||||
}
|
||||
|
||||
void mem_free(void *ptr)
|
||||
{
|
||||
t_mblock *cur;
|
||||
|
||||
if (ptr == NULL)
|
||||
return;
|
||||
cur = (void *)(((t_usize)ptr) - sizeof(t_mblock));
|
||||
vg_mempool_free(POOL_ADDR, ptr);
|
||||
vg_mem_defined(cur, sizeof(*cur));
|
||||
cur->used = false;
|
||||
merge_block(cur, ~(t_usize)0);
|
||||
vg_mem_no_access(cur, sizeof(*cur));
|
||||
}
|
||||
*/
|
||||
// void uninit_allocator(void)
|
||||
// {
|
||||
// t_ptr_table *table;
|
||||
// t_ptr_table *table_next;
|
||||
// t_usize i;
|
||||
// t_usize unfree_count;
|
||||
//
|
||||
// unfree_count = 0;
|
||||
// table = get_table();
|
||||
//
|
||||
// while (table)
|
||||
// {
|
||||
// i = 0;
|
||||
// while (i < PTR_LENS)
|
||||
// {
|
||||
// if (table->table[i].ptr != NULL)
|
||||
// {
|
||||
// __libc_free(table->table[i].ptr);
|
||||
// unfree_count++;
|
||||
// }
|
||||
// i++;
|
||||
// }
|
||||
// table_next = table->next;
|
||||
// __libc_free(table);
|
||||
// table = table_next;
|
||||
// }
|
||||
// if (unfree_count != 0)
|
||||
// {
|
||||
// me_putstr_fd("A total of ", 2);
|
||||
// me_putnbr_fd(unfree_count, 2);
|
||||
// me_putendl_fd(" blocks weren't freed !", 2);
|
||||
// }
|
||||
// }
|
||||
// void *me_malloc(t_usize size)
|
||||
// {
|
||||
// t_mblock *block;
|
||||
// void *ret;
|
||||
//
|
||||
// size = usize_round_up_to(size, 16);
|
||||
// printf("Allocating %zu.\n", size);
|
||||
// block = get_block_for_size(size);
|
||||
// if (block
|
||||
// == NULL)
|
||||
// return (me_abort("Found no page for me_malloc"), NULL);
|
||||
// block->used = true;
|
||||
// ret = ((t_u8 *)block->page->data) + block->offset;
|
||||
// mem_set_zero(ret, block->size);
|
||||
// return (ret);
|
||||
// }
|
||||
//
|
||||
// void *me_calloc(t_usize elem_size, t_usize elem_count)
|
||||
// {
|
||||
// if (elem_size != 0 && elem_count > SIZE_MAX / elem_size)
|
||||
// return (NULL);
|
||||
// return (me_malloc(elem_size * elem_count));
|
||||
// }
|
||||
//
|
||||
// void *me_realloc(void *ptr, t_usize new_size)
|
||||
// {
|
||||
// t_mblock *block;
|
||||
// void *ret;
|
||||
//
|
||||
// if (ptr == NULL)
|
||||
// return (me_malloc(new_size));
|
||||
// block = get_block_from_ptr(ptr);
|
||||
// if (block == NULL || block->size <= new_size)
|
||||
// return (ptr);
|
||||
// if (!merge_next_block(block, new_size))
|
||||
// return (ptr);
|
||||
// else
|
||||
// {
|
||||
// ret = me_malloc(new_size);
|
||||
// mem_copy(ret, ptr, block->size);
|
||||
// mem_free(ptr);
|
||||
// return (ret);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// void mem_free(void *ptr)
|
||||
// {
|
||||
// t_mblock *cur;
|
||||
//
|
||||
// if (ptr == NULL)
|
||||
// return;
|
||||
// cur = get_block_from_ptr(ptr);
|
||||
// if (cur == NULL)
|
||||
// return (me_abort("Invalid free (not allocated with me_*alloc)!"));
|
||||
// cur->used = false;
|
||||
// merge_next_block(cur, ~(t_usize)0);
|
||||
// }
|
||||
|
|
@ -6,12 +6,13 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/07 09:47:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/12 15:02:02 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 16:52:37 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/alloc/alloc_internal.h"
|
||||
#include "aq/alloc.h"
|
||||
#include "aq/alloc_internal.h"
|
||||
#include "aq/internal_vg_funcs.h"
|
||||
#include "me/fs/putendl_fd.h"
|
||||
#include "me/fs/putnbr_fd.h"
|
||||
#include "me/fs/putstr_fd.h"
|
||||
|
|
@ -21,10 +22,180 @@
|
|||
#include "me/num/usize.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
/*
|
||||
|
||||
void *__libc_malloc(size_t size);
|
||||
void __libc_free(void *ptr);
|
||||
|
||||
t_mpage *alloc_page(t_usize size)
|
||||
{
|
||||
t_mpage *val;
|
||||
|
||||
size = usize_round_up_to(size + sizeof(t_mpage), PAGE_SIZE_DEFAULT);
|
||||
val = __libc_malloc(size);
|
||||
if (val == NULL)
|
||||
return (NULL);
|
||||
mem_set_zero(val, size);
|
||||
val->next = NULL;
|
||||
val->page_size = size - sizeof(*val);
|
||||
val->first = (t_mblock *)(((t_usize)val) + sizeof(t_mpage));
|
||||
val->first->page = val;
|
||||
val->first->next = NULL;
|
||||
val->first->used = false;
|
||||
val->first->size = size - sizeof(t_mpage) - sizeof(t_mblock) * 2;
|
||||
mem_copy(val->first->padding, BLOCK_PADDING, 7);
|
||||
vg_mem_no_access(val, size);
|
||||
return (val);
|
||||
}
|
||||
|
||||
t_mpage *get_head_arena(void)
|
||||
{
|
||||
static t_mpage *val = NULL;
|
||||
|
||||
if (val == NULL &&
|
||||
PAGE_SIZE_DEFAULT > sizeof(t_mpage) + sizeof(t_mblock) * 2 + 16)
|
||||
{
|
||||
vg_mempool_create(POOL_ADDR);
|
||||
val = alloc_page(PAGE_SIZE_DEFAULT - sizeof(t_mpage));
|
||||
}
|
||||
if (val == NULL)
|
||||
(me_putstr_fd("Failed to alloc first page", 2), exit(1));
|
||||
return (val);
|
||||
}
|
||||
|
||||
t_mblock *split_block(t_mblock *self, t_usize min_size)
|
||||
{
|
||||
t_usize remaining;
|
||||
t_mblock *old_next;
|
||||
|
||||
vg_mem_defined(self, sizeof(*self));
|
||||
min_size = usize_round_up_to(min_size, 16);
|
||||
if (self->size > (min_size + sizeof(t_mblock) + 16))
|
||||
{
|
||||
remaining = self->size - min_size - sizeof(t_mblock);
|
||||
printf("splitting %zu into %zu and %zu\n", self->size, min_size,
|
||||
remaining);
|
||||
self->size = min_size;
|
||||
old_next = self->next;
|
||||
self->next = (t_mblock *)(((t_usize)self) + sizeof(*self) + self->size);
|
||||
vg_mem_defined(self->next, sizeof(*self->next));
|
||||
self->next->page = self->page;
|
||||
self->next->next = old_next;
|
||||
self->next->used = false;
|
||||
self->next->size = remaining;
|
||||
mem_copy(self->next->padding, BLOCK_PADDING, 7);
|
||||
vg_mem_no_access(self->next, sizeof(*self->next));
|
||||
}
|
||||
vg_mem_no_access(self, sizeof(*self));
|
||||
return (self);
|
||||
}
|
||||
|
||||
t_mblock *get_block_for_size(t_usize size)
|
||||
{
|
||||
t_mblock *last;
|
||||
t_mblock *cur;
|
||||
t_mpage *head;
|
||||
|
||||
last = NULL;
|
||||
head = get_head_arena();
|
||||
vg_mem_defined(head, sizeof(*head));
|
||||
cur = head->first;
|
||||
vg_mem_no_access(head, sizeof(*head));
|
||||
while (cur)
|
||||
{
|
||||
vg_mem_defined(cur, sizeof(*cur));
|
||||
if (!cur->used && cur->size >= size)
|
||||
return (split_block(cur, size));
|
||||
last = cur;
|
||||
cur = cur->next;
|
||||
vg_mem_no_access(last, sizeof(*last));
|
||||
}
|
||||
if (last == NULL)
|
||||
return (NULL);
|
||||
vg_mem_defined(last, sizeof(*last));
|
||||
vg_mem_defined(last->page, sizeof(*last->page));
|
||||
last->page->next = alloc_page(size + sizeof(t_mblock));
|
||||
if (last->page->next == NULL)
|
||||
me_abort("Failed to alloc page!");
|
||||
vg_mem_defined(last->page->next, sizeof(*last->page->next));
|
||||
last->next = last->page->next->first;
|
||||
cur = last->page->next->first;
|
||||
vg_mem_no_access(last->page->next, sizeof(*last->page->next));
|
||||
vg_mem_no_access(last->page, sizeof(*last->page));
|
||||
vg_mem_no_access(last, sizeof(*last));
|
||||
return (split_block(cur, size));
|
||||
}
|
||||
|
||||
void print_pages_info(void)
|
||||
{
|
||||
t_mpage *page;
|
||||
t_mpage *old;
|
||||
t_i32 page_nb;
|
||||
|
||||
page = get_head_arena();
|
||||
page_nb = 0;
|
||||
while (page != NULL)
|
||||
{
|
||||
vg_mem_defined(page, sizeof(*page));
|
||||
me_putstr_fd("Page ", 2);
|
||||
me_putnbr_fd(page_nb++, 2);
|
||||
me_putstr_fd(" with size ", 2);
|
||||
me_putnbr_fd((t_i32)page->page_size, 2);
|
||||
me_putstr_fd("\n", 2);
|
||||
old = page;
|
||||
page = page->next;
|
||||
vg_mem_no_access(old, sizeof(*old));
|
||||
}
|
||||
}
|
||||
|
||||
bool merge_block(t_mblock *self, t_usize min_size)
|
||||
{
|
||||
t_mblock *old_next;
|
||||
|
||||
vg_mem_defined(self, sizeof(*self));
|
||||
vg_mem_defined(self->next, sizeof(*self->next));
|
||||
if (!(self->next && !self->next->used && self->next->page == self->page &&
|
||||
self->size + self->next->size + sizeof(t_mblock) >= min_size))
|
||||
return (vg_mem_no_access(self->next, sizeof(*self->next)),
|
||||
vg_mem_no_access(self, sizeof(*self)), false);
|
||||
old_next = self->next;
|
||||
self->size += sizeof(*self) + self->next->size;
|
||||
self->next = self->next->next;
|
||||
vg_mem_no_access(self, sizeof(*self));
|
||||
vg_mem_no_access(old_next, sizeof(*old_next));
|
||||
return (true);
|
||||
}
|
||||
|
||||
void uninit_allocator(void)
|
||||
{
|
||||
t_mpage *page;
|
||||
void *tmp;
|
||||
t_mblock *block;
|
||||
t_usize count_block;
|
||||
|
||||
page = get_head_arena();
|
||||
count_block = 0;
|
||||
vg_mem_defined(page, sizeof(*page));
|
||||
block = page->first;
|
||||
while (block)
|
||||
{
|
||||
vg_mem_defined(block, sizeof(*block));
|
||||
if (block->used)
|
||||
count_block += 1;
|
||||
block = block->next;
|
||||
}
|
||||
while (page)
|
||||
{
|
||||
vg_mem_defined(page, sizeof(*page));
|
||||
tmp = page->next;
|
||||
__libc_free(page);
|
||||
page = tmp;
|
||||
}
|
||||
if (count_block != 0)
|
||||
(me_putnbr_fd(count_block, 2),
|
||||
me_putendl_fd(" Blocks weren't freed when exiting !", 2));
|
||||
}*/
|
||||
|
||||
//
|
||||
// void free_ifn(void *ptr)
|
||||
// {
|
||||
52
allocator/src/lc_alloc/functions1.c
Normal file
52
allocator/src/lc_alloc/functions1.c
Normal 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));
|
||||
}
|
||||
|
||||
|
|
@ -1,34 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* alloc_dumb_internal.h :+: :+: :+: */
|
||||
/* functions2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/12 15:03:59 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/12 16:42:39 by maiboyer ### ########.fr */
|
||||
/* Created: 2024/05/14 18:06:34 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:48:41 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ALLOC_DUMB_INTERNAL_H
|
||||
#define ALLOC_DUMB_INTERNAL_H
|
||||
#include "aq/allocator.h"
|
||||
#include "aq/libc_wrapper.h"
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
#define PTR_LENS 255
|
||||
|
||||
typedef struct s_ptr
|
||||
void lc_uninit(t_allocator *self)
|
||||
{
|
||||
void *ptr;
|
||||
t_usize size;
|
||||
} t_ptr;
|
||||
(void)(self);
|
||||
}
|
||||
|
||||
typedef struct s_ptr_table
|
||||
t_allocator lc_init(void)
|
||||
{
|
||||
t_ptr table[PTR_LENS];
|
||||
struct s_ptr_table *next;
|
||||
} t_ptr_table;
|
||||
|
||||
t_ptr_table *get_table(void);
|
||||
|
||||
#endif /* ALLOC_DUMB_INTERNAL_H */
|
||||
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,
|
||||
});
|
||||
}
|
||||
52
allocator/src/me_alloc/functions1.c
Normal file
52
allocator/src/me_alloc/functions1.c
Normal 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:21:16 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_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));
|
||||
// }
|
||||
|
||||
|
|
@ -1,20 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_get_last.h :+: :+: :+: */
|
||||
/* functions2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 20:37:08 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:29:37 by maiboyer ### ########.fr */
|
||||
/* Created: 2024/05/14 18:06:34 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:21:21 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_GET_LAST_H
|
||||
# define LIST_GET_LAST_H
|
||||
#include "aq/allocator.h"
|
||||
#include "aq/libc_wrapper.h"
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_list *list_get_last(t_list *list);
|
||||
|
||||
#endif
|
||||
// void lc_uninit(t_allocator *self)
|
||||
// {
|
||||
// (void)(self);
|
||||
// }
|
||||
|
|
@ -1,20 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_alloc_node.h :+: :+: :+: */
|
||||
/* valgrind_block.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 19:57:28 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:28:30 by maiboyer ### ########.fr */
|
||||
/* Created: 2024/05/12 22:51:55 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/12 22:55:45 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_ALLOC_NODE_H
|
||||
# define LIST_ALLOC_NODE_H
|
||||
#include "aq/internal_vg_funcs.h"
|
||||
#include "valgrind/valgrind.h"
|
||||
|
||||
# include "me/types.h"
|
||||
#ifdef VGFUNCS
|
||||
|
||||
t_list *list_alloc_node(void *content);
|
||||
void vg_block_malloc(void *ptr, t_usize size)
|
||||
{
|
||||
VALGRIND_MALLOCLIKE_BLOCK(ptr, size, redzone_size(), ZEROED_ALLOC);
|
||||
}
|
||||
|
||||
void vg_block_resize(void *ptr, t_usize oldsize, t_usize newsize)
|
||||
{
|
||||
VALGRIND_RESIZEINPLACE_BLOCK(ptr, oldsize, newsize, redzone_size());
|
||||
}
|
||||
|
||||
void vg_block_free(void *ptr)
|
||||
{
|
||||
VALGRIND_FREELIKE_BLOCK(ptr, redzone_size());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_free_one.h :+: :+: :+: */
|
||||
/* valgrind_mem_status.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 21:30:20 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:29:15 by maiboyer ### ########.fr */
|
||||
/* Created: 2024/05/12 23:08:47 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/12 23:22:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_FREE_ONE_H
|
||||
# define LIST_FREE_ONE_H
|
||||
#include "aq/internal_vg_funcs.h"
|
||||
|
||||
# include "me/types.h"
|
||||
#ifdef VGFUNCS
|
||||
|
||||
void list_free_one(t_list *lst, void (*del)(void *));
|
||||
void vg_mem_no_access(void *ptr, t_usize size)
|
||||
{
|
||||
VALGRIND_MAKE_MEM_NOACCESS(ptr, size);
|
||||
}
|
||||
|
||||
void vg_mem_undefined(void *ptr, t_usize size)
|
||||
{
|
||||
VALGRIND_MAKE_MEM_UNDEFINED(ptr, size);
|
||||
}
|
||||
|
||||
void vg_mem_defined(void *ptr, t_usize size)
|
||||
{
|
||||
VALGRIND_MAKE_MEM_DEFINED(ptr, size);
|
||||
}
|
||||
|
||||
#endif
|
||||
58
allocator/src/vg/valgrind_mempool.c
Normal file
58
allocator/src/vg/valgrind_mempool.c
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* valgrind_mempool.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/12 22:33:30 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 16:17:37 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "aq/internal_vg_funcs.h"
|
||||
#include "valgrind/valgrind.h"
|
||||
|
||||
#ifdef VGFUNCS
|
||||
|
||||
void vg_mempool_create_ext(void *pool, t_usize flags)
|
||||
{
|
||||
t_usize actual_flags;
|
||||
|
||||
actual_flags = 0;
|
||||
if (flags & MEMPOOL_FLAG_MALLOCLIKE)
|
||||
actual_flags |= VALGRIND_MEMPOOL_METAPOOL;
|
||||
if (flags & MEMPOOL_FLAG_AUTOFREE)
|
||||
actual_flags |= VALGRIND_MEMPOOL_AUTO_FREE;
|
||||
|
||||
VALGRIND_CREATE_MEMPOOL_EXT(pool, redzone_size(), ZEROED_POOL,
|
||||
actual_flags);
|
||||
}
|
||||
|
||||
void vg_mempool_resize(void *pool, void *ptr, t_usize size)
|
||||
{
|
||||
VALGRIND_MEMPOOL_CHANGE(pool, ptr, ptr, size);
|
||||
}
|
||||
|
||||
void vg_mempool_create(void *pool)
|
||||
{
|
||||
VALGRIND_CREATE_MEMPOOL(pool, redzone_size(), ZEROED_POOL);
|
||||
}
|
||||
|
||||
void vg_mempool_destroy(void *pool)
|
||||
{
|
||||
VALGRIND_DESTROY_MEMPOOL(pool);
|
||||
}
|
||||
|
||||
void vg_mempool_alloc(void *pool, void *addr, t_usize size)
|
||||
{
|
||||
VALGRIND_CREATE_BLOCK(addr, size, "mempool");
|
||||
VALGRIND_MEMPOOL_ALLOC(pool, addr, size);
|
||||
}
|
||||
|
||||
void vg_mempool_free(void *pool, void *addr)
|
||||
{
|
||||
VALGRIND_MEMPOOL_FREE(pool, addr);
|
||||
}
|
||||
|
||||
#endif
|
||||
14
flake.nix
14
flake.nix
|
|
@ -15,8 +15,18 @@
|
|||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in {
|
||||
devShell = pkgs.mkShell {
|
||||
packages = with pkgs; [clang valgrind gnumake readline.out readline.dev generic_c.packages.${system}.default llvmPackages.bintools];
|
||||
ASAN_OPTIONS="strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1";
|
||||
packages = with pkgs; [
|
||||
valgrind.dev
|
||||
clang
|
||||
valgrind
|
||||
gnumake
|
||||
readline.out
|
||||
readline.dev
|
||||
generic_c.packages.${system}.default
|
||||
llvmPackages.bintools
|
||||
];
|
||||
VALGRIND_INC_OPT = "${pkgs.valgrind.dev}/include";
|
||||
ASAN_OPTIONS = "strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1";
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
|
|||
18
output/src/hashmap/env/env.c
vendored
18
output/src/hashmap/env/env.c
vendored
|
|
@ -1,21 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* hashmap_env.c :+: :+: :+: */
|
||||
/* env.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/06 10:58:20 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 15:32:51 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:46:51 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/hash/hasher.h"
|
||||
#include "me/hash/sip.h"
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
#include "me/mem/mem_alloc.h"
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -43,7 +41,7 @@ t_hashmap_env *new_hashmap_with_buckets_env(
|
|||
hmap->cfunc = cfunc;
|
||||
hmap->drop = drop;
|
||||
if (hmap->buckets == NULL)
|
||||
return ((void)me_free(hmap), NULL);
|
||||
return ((void)mem_free(hmap), NULL);
|
||||
return (hmap);
|
||||
}
|
||||
|
||||
|
|
@ -57,13 +55,13 @@ void drop_hashmap_env(t_hashmap_env *hmap)
|
|||
if (hmap->buckets[index])
|
||||
{
|
||||
hmap->drop(hmap->buckets[index]->kv);
|
||||
me_free(hmap->buckets[index]);
|
||||
mem_free(hmap->buckets[index]);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
hasher_finish(&hmap->hasher);
|
||||
me_free(hmap->buckets);
|
||||
me_free(hmap);
|
||||
mem_free(hmap->buckets);
|
||||
mem_free(hmap);
|
||||
}
|
||||
|
||||
t_entry_env *hashmap_get_entry_env(t_hashmap_env *hmap,
|
||||
|
|
@ -82,9 +80,7 @@ t_entry_env *hashmap_get_entry_env(t_hashmap_env *hmap,
|
|||
entry = entry->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (entry);
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
|
|
|||
9
output/src/hashmap/env/env_utils.c
vendored
9
output/src/hashmap/env/env_utils.c
vendored
|
|
@ -1,19 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* hashmap_env_utils.c :+: :+: :+: */
|
||||
/* env_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/06 10:58:20 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 15:35:37 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:47:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/hash/sip.h"
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
#include "me/mem/mem_alloc.h"
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/types.h"
|
||||
#include <stdlib.h>
|
||||
|
|
@ -51,6 +50,6 @@ void remove_hashmap_env(t_hashmap_env *hmap, t_str *key)
|
|||
else
|
||||
prev->next = entry->next;
|
||||
hmap->drop(entry->kv);
|
||||
me_free(entry);
|
||||
mem_free(entry);
|
||||
hmap->buckets[hashed_key % hmap->num_buckets] = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/types.h"
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_parser_heredoc.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ t_error vec_parser_heredoc_push(t_vec_parser_heredoc *vec, t_heredoc element)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (vec->len + 1 > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(t_heredoc));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_heredoc));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
vec->buffer[vec->len] = element;
|
||||
|
|
@ -63,7 +63,7 @@ t_error vec_parser_heredoc_reserve(t_vec_parser_heredoc *vec, t_usize wanted_cap
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (wanted_capacity > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(t_heredoc));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_heredoc));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -100,5 +100,5 @@ void vec_parser_heredoc_free(t_vec_parser_heredoc vec)
|
|||
vec.len--;
|
||||
}
|
||||
}
|
||||
me_free(vec.buffer);
|
||||
mem_free(vec.buffer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/types.h"
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_parser_range.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ t_error vec_parser_range_push(t_vec_parser_range *vec, t_parser_range element)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (vec->len + 1 > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(t_parser_range));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_parser_range));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
vec->buffer[vec->len] = element;
|
||||
|
|
@ -63,7 +63,7 @@ t_error vec_parser_range_reserve(t_vec_parser_range *vec, t_usize wanted_capacit
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (wanted_capacity > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(t_parser_range));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_parser_range));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -100,5 +100,5 @@ void vec_parser_range_free(t_vec_parser_range vec)
|
|||
vec.len--;
|
||||
}
|
||||
}
|
||||
me_free(vec.buffer);
|
||||
mem_free(vec.buffer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/types.h"
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_reduce_action.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ t_error vec_reduce_action_push(t_vec_reduce_action *vec, t_reduce_action element
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (vec->len + 1 > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(t_reduce_action));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_reduce_action));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
vec->buffer[vec->len] = element;
|
||||
|
|
@ -63,7 +63,7 @@ t_error vec_reduce_action_reserve(t_vec_reduce_action *vec, t_usize wanted_capac
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (wanted_capacity > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(t_reduce_action));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_reduce_action));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -100,5 +100,5 @@ void vec_reduce_action_free(t_vec_reduce_action vec)
|
|||
vec.len--;
|
||||
}
|
||||
}
|
||||
me_free(vec.buffer);
|
||||
mem_free(vec.buffer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/types.h"
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ t_error vec_str_push(t_vec_str *vec, t_str element)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (vec->len + 1 > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(t_str));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_str));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
vec->buffer[vec->len] = element;
|
||||
|
|
@ -63,7 +63,7 @@ t_error vec_str_reserve(t_vec_str *vec, t_usize wanted_capacity)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (wanted_capacity > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(t_str));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_str));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -100,5 +100,5 @@ void vec_str_free(t_vec_str vec)
|
|||
vec.len--;
|
||||
}
|
||||
}
|
||||
me_free(vec.buffer);
|
||||
mem_free(vec.buffer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||
# Updated: 2024/05/12 17:13:38 by maiboyer ### ########.fr #
|
||||
# Updated: 2024/05/14 15:26:21 by maiboyer ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -78,4 +78,4 @@ re:
|
|||
generate_filelist:
|
||||
@/usr/bin/env zsh -c "tree -iFf --noreport $(SRC_DIR) | rg '^$(SRC_DIR)/(.*)\.c\$$' --replace '\$$1' | sort -u" > ./source_files.list
|
||||
|
||||
# -include $(DEPS)
|
||||
-include $(DEPS)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef TREE_SITTER_ARRAY_H_
|
||||
#define TREE_SITTER_ARRAY_H_
|
||||
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
|
|
@ -39,16 +39,16 @@
|
|||
#define STACK_VERSION_NONE ((t_stack_version)-1)
|
||||
#define TS_DECODE_ERROR (-1)
|
||||
|
||||
#if true
|
||||
#if false
|
||||
# undef malloc
|
||||
# undef calloc
|
||||
# undef realloc
|
||||
# undef free
|
||||
|
||||
# define malloc(s) me_malloc((s))
|
||||
# define calloc(s, l) me_calloc((s), (l))
|
||||
# define realloc(p, t) me_realloc((p), (t))
|
||||
# define free(p) me_free((p))
|
||||
# define calloc(s, l) mem_alloc_array((s), (l))
|
||||
# define realloc(p, t) mem_realloc((p), (t))
|
||||
# define free(p) mem_free((p))
|
||||
#endif
|
||||
|
||||
#define Array(T) \
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/04 18:32:50 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/10 21:48:31 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:46:13 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
#include "me/string/str_compare.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static void _hash_str(t_hasher *hasher, t_str *s)
|
||||
|
|
@ -62,7 +63,7 @@ t_error build_envp(t_hashmap_env *envs, t_vec_str *envp)
|
|||
{
|
||||
struct s_build_envp_state state;
|
||||
|
||||
state.out = vec_str_new(envs->num_buckets, (void (*)(t_str))me_free);
|
||||
state.out = vec_str_new(envs->num_buckets, (void (*)(t_str))mem_free);
|
||||
state.buf = alloc_new_buffer(50);
|
||||
if (hashmap_env_iter(envs, _build_envp_iterator, &state))
|
||||
return (ERROR);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ t_error handle_command(t_node *self, t_utils *shcat, t_i32 *out_exit_code)
|
|||
t_spawn_info spawn_info;
|
||||
t_str tmp;
|
||||
|
||||
spawn_info.arguments = vec_str_new(self->childs_count, (void (*)(t_str))me_free);
|
||||
spawn_info.arguments = vec_str_new(self->childs_count, (void (*)(t_str))mem_free);
|
||||
if (self->kind != sym_command)
|
||||
return (ERROR);
|
||||
i = 0;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ t_error handle_concat(t_node *self, t_utils *shcat, t_str *ret)
|
|||
if (node_get_string(&self->childs[i], shcat, &tmp))
|
||||
return (str_free(out), ERROR);
|
||||
push_str_buffer(&out, tmp);
|
||||
me_free(tmp);
|
||||
mem_free(tmp);
|
||||
i++;
|
||||
}
|
||||
*ret = out.buf;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/29 11:35:51 by rparodi #+# #+# */
|
||||
/* Updated: 2024/05/08 19:07:54 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:46:30 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,7 +14,6 @@
|
|||
#include "app/env.h"
|
||||
#include "me/hashmap/hashmap_env.h"
|
||||
|
||||
#include "me/alloc/alloc_internal.h"
|
||||
|
||||
void ts_parser_delete(t_first_parser *self);
|
||||
|
||||
|
|
@ -50,6 +49,5 @@ void ft_exit(t_utils *maiboyerlpb, t_u8 exit_status)
|
|||
{
|
||||
if (maiboyerlpb != NULL)
|
||||
ft_free_utils(maiboyerlpb);
|
||||
print_pages_info();
|
||||
me_exit(exit_status);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
#include "app/node/handle_program.h"
|
||||
#include "app/signal_handler.h"
|
||||
#include "gmr/symbols.h"
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "minishell.h"
|
||||
#include "parser/api.h"
|
||||
|
|
|
|||
|
|
@ -86,10 +86,10 @@ void free_node(t_node self)
|
|||
t_usize idx;
|
||||
|
||||
if (self.single_str)
|
||||
me_free(self.single_str);
|
||||
mem_free(self.single_str);
|
||||
idx = 0;
|
||||
while (idx < self.childs_count)
|
||||
free_node(self.childs[idx++]);
|
||||
if (self.childs_count != 0)
|
||||
me_free(self.childs);
|
||||
mem_free(self.childs);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||
# Updated: 2024/05/09 21:27:31 by maiboyer ### ########.fr #
|
||||
# Updated: 2024/05/14 18:41:46 by maiboyer ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
BUILD_DIR ?= build
|
||||
SRC_DIR = src
|
||||
INCLUDE_DIR = include output/include
|
||||
INCLUDE_DIR = include output/include ../allocator/include
|
||||
LIBS_DIR = .
|
||||
GENERIC_DIR = output/src
|
||||
GENERIC_INCLUDE = output/include
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ t_hashmap_C__PREFIX__ *new_hashmap_with_buckets_C__PREFIX__(
|
|||
hmap->cfunc = cfunc;
|
||||
hmap->drop = drop;
|
||||
if (hmap->buckets == NULL)
|
||||
return ((void)me_free(hmap), NULL);
|
||||
return ((void)mem_free(hmap), NULL);
|
||||
return (hmap);
|
||||
}
|
||||
|
||||
|
|
@ -57,13 +57,13 @@ void drop_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap)
|
|||
if (hmap->buckets[index])
|
||||
{
|
||||
hmap->drop(hmap->buckets[index]->kv);
|
||||
me_free(hmap->buckets[index]);
|
||||
mem_free(hmap->buckets[index]);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
hasher_finish(&hmap->hasher);
|
||||
me_free(hmap->buckets);
|
||||
me_free(hmap);
|
||||
mem_free(hmap->buckets);
|
||||
mem_free(hmap);
|
||||
}
|
||||
|
||||
t_entry_C__PREFIX__ *hashmap_get_entry_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap,
|
||||
|
|
|
|||
|
|
@ -51,6 +51,6 @@ void remove_hashmap_C__PREFIX__(t_hashmap_C__PREFIX__ *hmap, C__KEYTYPE__ *key)
|
|||
else
|
||||
prev->next = entry->next;
|
||||
hmap->drop(entry->kv);
|
||||
me_free(entry);
|
||||
mem_free(entry);
|
||||
hmap->buckets[hashed_key % hmap->num_buckets] = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/types.h"
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_C__PREFIX__.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ t_error vec_C__PREFIX___push(t_vec_C__PREFIX__ *vec, C__TYPENAME__ element)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (vec->len + 1 > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(C__TYPENAME__));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(C__TYPENAME__));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
vec->buffer[vec->len] = element;
|
||||
|
|
@ -63,7 +63,7 @@ t_error vec_C__PREFIX___reserve(t_vec_C__PREFIX__ *vec, t_usize wanted_capacity)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (wanted_capacity > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(C__TYPENAME__));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(C__TYPENAME__));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -100,5 +100,5 @@ void vec_C__PREFIX___free(t_vec_C__PREFIX__ vec)
|
|||
vec.len--;
|
||||
}
|
||||
}
|
||||
me_free(vec.buffer);
|
||||
mem_free(vec.buffer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ typedef struct s_blx
|
|||
void *win;
|
||||
t_blx_input inputs;
|
||||
t_run_function func;
|
||||
t_free_function me_free;
|
||||
t_free_function mem_free;
|
||||
t_blx_app app;
|
||||
t_blx_data _data;
|
||||
} t_blx;
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ t_error str_reserve(t_buffer_str *buf, t_usize size);
|
|||
|
||||
static inline void str_free(t_buffer_str buf)
|
||||
{
|
||||
void me_free(void *);
|
||||
void mem_free(void *);
|
||||
|
||||
me_free(buf.buf);
|
||||
mem_free(buf.buf);
|
||||
}
|
||||
|
||||
static inline char str_pop(t_buffer_str *buf)
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ See the function declaration below for the signature and more information.
|
|||
If you don't want/need the qoi_read and qoi_write functions, you can define
|
||||
QOI_NO_STDIO before including this library.
|
||||
|
||||
This library uses malloc() and me_free(). To supply your own malloc implementation
|
||||
This library uses malloc() and mem_free(). To supply your own malloc implementation
|
||||
you can define QOI_MALLOC and QOI_FREE before including this library.
|
||||
|
||||
This library uses memset() to zero-initialize the index. To supply your own
|
||||
|
|
@ -273,7 +273,7 @@ The function either returns NULL on failure (invalid data, or malloc or fopen
|
|||
failed) or a pot_i32er to the decoded pixels. On success, the t_qoi_desc struct
|
||||
will be filled with the description from the file header.
|
||||
|
||||
The returned pixel data should be me_free()d after use. */
|
||||
The returned pixel data should be mem_free()d after use. */
|
||||
|
||||
void *qoi_read(t_const_str filename, t_qoi_desc *desc,
|
||||
t_i32 channels);
|
||||
|
|
@ -286,7 +286,7 @@ The function either returns NULL on failure (invalid parameters or malloc
|
|||
failed) or a pot_i32er to the encoded data on success. On success the out_len
|
||||
is set to the size in bytes of the encoded data.
|
||||
|
||||
The returned qoi data should be me_free()d after use. */
|
||||
The returned qoi data should be mem_free()d after use. */
|
||||
|
||||
void *qoi_encode(const void *data, const t_qoi_desc *desc,
|
||||
t_i32 *out_len);
|
||||
|
|
@ -297,7 +297,7 @@ The function either returns NULL on failure (invalid parameters or malloc
|
|||
failed) or a pot_i32er to the decoded pixels. On success, the t_qoi_desc struct
|
||||
is filled with the description from the file header.
|
||||
|
||||
The returned pixel data should be me_free()d after use. */
|
||||
The returned pixel data should be mem_free()d after use. */
|
||||
|
||||
void *qoi_decode(const void *data, t_i32 size, t_qoi_desc *desc,
|
||||
t_i32 channels);
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_add_front.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 20:15:23 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:28:15 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_ADD_FRONT_H
|
||||
# define LIST_ADD_FRONT_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void list_add_front(t_list **lst, t_list *new);
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_iter.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 21:39:05 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:29:51 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_ITER_H
|
||||
# define LIST_ITER_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
void list_iter(t_list *list, void (*f)(void *));
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_map.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 21:40:24 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:30:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_MAP_H
|
||||
# define LIST_MAP_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_list *list_map(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_size.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 20:23:19 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:30:23 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_SIZE_H
|
||||
# define LIST_SIZE_H
|
||||
|
||||
# include "me/types.h"
|
||||
|
||||
t_usize list_size(t_list *lst);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,20 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_free_all.h :+: :+: :+: */
|
||||
/* _allocator.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 21:35:20 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:28:47 by maiboyer ### ########.fr */
|
||||
/* Created: 2024/05/14 18:27:07 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:27:40 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_FREE_ALL_H
|
||||
# define LIST_FREE_ALL_H
|
||||
#ifndef _ALLOCATOR_H
|
||||
#define _ALLOCATOR_H
|
||||
|
||||
# include "me/types.h"
|
||||
#include "aq/allocator.h"
|
||||
|
||||
void list_free_all(t_list **lst, void (*del)(void *));
|
||||
t_allocator *global_allocator(void);
|
||||
void uninit_global_allocator(void);
|
||||
|
||||
#endif
|
||||
#endif /* _ALLOCATOR_H */
|
||||
|
|
@ -1,20 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_add_back.h :+: :+: :+: */
|
||||
/* mem.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 20:38:45 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:27:56 by maiboyer ### ########.fr */
|
||||
/* Created: 2024/05/14 18:32:57 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:39:13 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIST_ADD_BACK_H
|
||||
# define LIST_ADD_BACK_H
|
||||
#ifndef MEM_H
|
||||
#define MEM_H
|
||||
|
||||
# include "me/types.h"
|
||||
#include "me/types.h"
|
||||
|
||||
void list_add_back(t_list **list, t_list *new);
|
||||
void *mem_alloc(t_usize size);
|
||||
void *mem_alloc_array(t_usize size, t_usize count);
|
||||
void *mem_realloc(void *ptr, t_usize size);
|
||||
void *mem_realloc_array(void *ptr, t_usize size, t_usize count);
|
||||
void mem_free(void *ptr);
|
||||
|
||||
#endif
|
||||
#endif /* MEM_H */
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/03 14:31:12 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/08 19:27:44 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:41:05 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -35,18 +35,11 @@ typedef size_t t_usize;
|
|||
typedef float t_f32;
|
||||
typedef double t_f64;
|
||||
|
||||
typedef int t_file;
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
typedef int t_file;
|
||||
typedef bool t_error;
|
||||
|
||||
void me_abort(t_str msg);
|
||||
void me_exit(t_i32 code);
|
||||
void me_free(void *ptr);
|
||||
void print_trace(void);
|
||||
|
||||
#define ERROR 1
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/types.h"
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_buf_str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ t_error vec_buf_str_push(t_vec_buf_str *vec, t_buffer_str element)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (vec->len + 1 > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(t_buffer_str));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_buffer_str));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
vec->buffer[vec->len] = element;
|
||||
|
|
@ -63,7 +63,7 @@ t_error vec_buf_str_reserve(t_vec_buf_str *vec, t_usize wanted_capacity)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (wanted_capacity > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(t_buffer_str));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_buffer_str));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -100,5 +100,5 @@ void vec_buf_str_free(t_vec_buf_str vec)
|
|||
vec.len--;
|
||||
}
|
||||
}
|
||||
me_free(vec.buffer);
|
||||
mem_free(vec.buffer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/types.h"
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ t_error vec_str_push(t_vec_str *vec, t_str element)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (vec->len + 1 > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(t_str));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_str));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
vec->buffer[vec->len] = element;
|
||||
|
|
@ -63,7 +63,7 @@ t_error vec_str_reserve(t_vec_str *vec, t_usize wanted_capacity)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (wanted_capacity > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(t_str));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_str));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -100,5 +100,5 @@ void vec_str_free(t_vec_str vec)
|
|||
vec.len--;
|
||||
}
|
||||
}
|
||||
me_free(vec.buffer);
|
||||
mem_free(vec.buffer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/types.h"
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_u8.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ t_error vec_u8_push(t_vec_u8 *vec, t_u8 element)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (vec->len + 1 > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(t_u8));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_u8));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
vec->buffer[vec->len] = element;
|
||||
|
|
@ -63,7 +63,7 @@ t_error vec_u8_reserve(t_vec_u8 *vec, t_usize wanted_capacity)
|
|||
new_capacity = (vec->capacity * 3) / 2 + 1;
|
||||
while (wanted_capacity > new_capacity)
|
||||
new_capacity = (new_capacity * 3) / 2 + 1;
|
||||
vec->buffer = me_realloc_array(vec->buffer, new_capacity, sizeof(t_u8));
|
||||
vec->buffer = mem_realloc_array(vec->buffer, new_capacity, sizeof(t_u8));
|
||||
vec->capacity = new_capacity;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
|
|
@ -100,5 +100,5 @@ void vec_u8_free(t_vec_u8 vec)
|
|||
vec.len--;
|
||||
}
|
||||
}
|
||||
me_free(vec.buffer);
|
||||
mem_free(vec.buffer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
alloc/alloc
|
||||
alloc/alloc_dumb
|
||||
alloc/alloc_get_page_from_bloc
|
||||
alloc/get_arena
|
||||
blx/blx
|
||||
blx/blx_create_fontsheet
|
||||
blx/blx_handlers
|
||||
|
|
@ -54,15 +50,7 @@ img/qoi/qoi_decode
|
|||
img/qoi/qoi_encode
|
||||
img/qoi/qoi_fs
|
||||
img/qoi/qoi_utils
|
||||
list/list_add_back
|
||||
list/list_add_front
|
||||
list/list_alloc_node
|
||||
list/list_free_all
|
||||
list/list_free_one
|
||||
list/list_get_last
|
||||
list/list_iter
|
||||
list/list_map
|
||||
list/list_size
|
||||
mem/allocator
|
||||
mem/mem_alloc
|
||||
mem/mem_alloc_array
|
||||
mem/mem_compare
|
||||
|
|
|
|||
|
|
@ -1,83 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* alloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/07 10:13:06 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/12 15:02:27 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/alloc/alloc_internal.h"
|
||||
#include "me/fs/putstr_fd.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/num/usize.h"
|
||||
#include <stdalign.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void __libc_free(void *ptr);
|
||||
|
||||
// void *me_malloc(t_usize size)
|
||||
// {
|
||||
// t_mblock *block;
|
||||
// void *ret;
|
||||
//
|
||||
// size = usize_round_up_to(size, 16);
|
||||
// printf("Allocating %zu.\n", size);
|
||||
// block = get_block_for_size(size);
|
||||
// if (block
|
||||
// == NULL)
|
||||
// return (me_abort("Found no page for me_malloc"), NULL);
|
||||
// block->used = true;
|
||||
// ret = ((t_u8 *)block->page->data) + block->offset;
|
||||
// mem_set_zero(ret, block->size);
|
||||
// return (ret);
|
||||
// }
|
||||
//
|
||||
// void *me_calloc(t_usize elem_size, t_usize elem_count)
|
||||
// {
|
||||
// if (elem_size != 0 && elem_count > SIZE_MAX / elem_size)
|
||||
// return (NULL);
|
||||
// return (me_malloc(elem_size * elem_count));
|
||||
// }
|
||||
//
|
||||
// void *me_realloc(void *ptr, t_usize new_size)
|
||||
// {
|
||||
// t_mblock *block;
|
||||
// void *ret;
|
||||
//
|
||||
// if (ptr == NULL)
|
||||
// return (me_malloc(new_size));
|
||||
// block = get_block_from_ptr(ptr);
|
||||
// if (block == NULL || block->size <= new_size)
|
||||
// return (ptr);
|
||||
// if (!merge_next_block(block, new_size))
|
||||
// return (ptr);
|
||||
// else
|
||||
// {
|
||||
// ret = me_malloc(new_size);
|
||||
// mem_copy(ret, ptr, block->size);
|
||||
// me_free(ptr);
|
||||
// return (ret);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// void me_free(void *ptr)
|
||||
// {
|
||||
// t_mblock *cur;
|
||||
//
|
||||
// if (ptr == NULL)
|
||||
// return;
|
||||
// cur = get_block_from_ptr(ptr);
|
||||
// if (cur == NULL)
|
||||
// return (me_abort("Invalid free (not allocated with me_*alloc)!"));
|
||||
// cur->used = false;
|
||||
// merge_next_block(cur, ~(t_usize)0);
|
||||
// }
|
||||
|
|
@ -1,140 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* alloc_dumb.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/12 15:02:37 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/12 17:09:41 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/alloc/alloc_dumb_internal.h"
|
||||
#include "me/fs/putendl_fd.h"
|
||||
#include "me/mem/mem_copy.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void *__libc_malloc(size_t size);
|
||||
void __libc_free(void *ptr);
|
||||
|
||||
t_ptr_table *get_table(void)
|
||||
{
|
||||
static t_ptr_table *table = NULL;
|
||||
|
||||
if (table == NULL)
|
||||
{
|
||||
table = __libc_malloc(sizeof(*table));
|
||||
if (table == NULL)
|
||||
(me_putendl_fd("Failed to alloc ptr array", 2), exit(1));
|
||||
mem_set_zero(table, sizeof(*table));
|
||||
}
|
||||
return (table);
|
||||
}
|
||||
|
||||
t_ptr *find_ptr(void *ptr)
|
||||
{
|
||||
t_usize i;
|
||||
t_ptr_table *t;
|
||||
|
||||
t = get_table();
|
||||
i = 0;
|
||||
while (t)
|
||||
{
|
||||
while (i < PTR_LENS)
|
||||
{
|
||||
if (t->table[i].ptr == ptr)
|
||||
return (&t->table[i]);
|
||||
i++;
|
||||
}
|
||||
t = t->next;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void print_pages_info(void)
|
||||
{
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void *me_malloc(t_usize size)
|
||||
{
|
||||
t_ptr_table *table;
|
||||
t_ptr *ret;
|
||||
|
||||
// printf("ALLOC %zu\n", size);
|
||||
ret = find_ptr(NULL);
|
||||
if (ret == NULL)
|
||||
{
|
||||
table = get_table();
|
||||
while (table->next != NULL)
|
||||
table = table->next;
|
||||
table->next = __libc_malloc(size);
|
||||
if (table->next == NULL)
|
||||
(me_abort("Failed to alloc ptr array"));
|
||||
mem_set_zero(table->next, sizeof(*table));
|
||||
ret = &table->next->table[0];
|
||||
}
|
||||
ret->ptr = __libc_malloc(size);
|
||||
if (ret->ptr == NULL)
|
||||
me_abort("Failed to malloc!");
|
||||
ret->size = size;
|
||||
mem_set_zero(ret->ptr, size);
|
||||
return (ret->ptr);
|
||||
}
|
||||
|
||||
void *me_calloc(t_usize elem_count, t_usize elem_size)
|
||||
{
|
||||
// printf("CALLOC %zu * %zu\n", elem_count, elem_size);
|
||||
if (elem_size != 0 && elem_count > SIZE_MAX / elem_size)
|
||||
return (me_abort("calloc overflow!"), NULL);
|
||||
return (me_malloc(elem_size * elem_count));
|
||||
}
|
||||
|
||||
void *me_realloc(void *ptr, t_usize size)
|
||||
{
|
||||
t_ptr *p;
|
||||
t_ptr tmp;
|
||||
|
||||
if (ptr == NULL)
|
||||
return (me_malloc(size));
|
||||
// printf("REALLOC %p %zu\n", ptr, size);
|
||||
p = find_ptr(ptr);
|
||||
if (p == NULL)
|
||||
return (me_abort("realloc with wrong ptr"), NULL);
|
||||
if (p->size >= size)
|
||||
return (p->ptr);
|
||||
tmp.size = size;
|
||||
tmp.ptr = __libc_malloc(size);
|
||||
if (tmp.ptr == NULL)
|
||||
me_abort("failed to malloc...");
|
||||
mem_copy(tmp.ptr, p->ptr, p->size);
|
||||
__libc_free(p->ptr);
|
||||
*p = tmp;
|
||||
return (tmp.ptr);
|
||||
}
|
||||
|
||||
void *me_realloc_array(void *ptr, t_usize elem_size, t_usize elem_count)
|
||||
{
|
||||
// printf("CALLOC %zu * %zu\n", elem_count, elem_size);
|
||||
if (elem_size != 0 && elem_count > SIZE_MAX / elem_size)
|
||||
return (me_abort("realloc_array overflow !"), NULL);
|
||||
return (me_realloc(ptr, elem_size * elem_count));
|
||||
}
|
||||
|
||||
void me_free(void *ptr)
|
||||
{
|
||||
t_ptr *p;
|
||||
|
||||
// printf("FREE\n");
|
||||
p = find_ptr(ptr);
|
||||
if (p != NULL)
|
||||
{
|
||||
__libc_free(p->ptr);
|
||||
p->ptr = NULL;
|
||||
p->size = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* alloc_get_page_from_bloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/08 19:11:20 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/09 08:04:37 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/14 18:01:06 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/31 20:14:31 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:39:41 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
#include "me/blx/inputs.h"
|
||||
#include "me/blx/xdata.h"
|
||||
#include "me/types.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/vec/vec_u8.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include <mlx.h>
|
||||
|
|
@ -29,7 +30,7 @@ t_blx blx_initialize(t_run_function func, t_free_function free_fn,
|
|||
{
|
||||
t_blx ctx;
|
||||
|
||||
ctx = (t_blx){.func = func, .app = data, .me_free = free_fn};
|
||||
ctx = (t_blx){.func = func, .app = data, .mem_free = free_fn};
|
||||
ctx.mlx = mlx_init();
|
||||
if (ctx.mlx == NULL)
|
||||
(me_eprintf("Error:\nfailed to inialize blx (mlx) !\n"), exit(1));
|
||||
|
|
@ -59,14 +60,14 @@ void blx_free(t_blx app)
|
|||
blx_sprite_free(app._data.screen);
|
||||
blx_sprite_free(app._data.font);
|
||||
mlx_do_key_autorepeaton(app.mlx);
|
||||
if (app.me_free)
|
||||
app.me_free(app.app);
|
||||
if (app.mem_free)
|
||||
app.mem_free(app.app);
|
||||
if (app.win)
|
||||
mlx_destroy_window(app.mlx, app.win);
|
||||
if (app.mlx)
|
||||
{
|
||||
mlx_destroy_display(app.mlx);
|
||||
me_free(app.mlx);
|
||||
mem_free(app.mlx);
|
||||
}
|
||||
vec_u8_free(app.inputs.keysyms_held);
|
||||
vec_u8_free(app.inputs.keysyms_pressed);
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/16 17:52:12 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/07 15:04:07 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 15:33:43 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/buffered_str/buf_str.h"
|
||||
#include "me/mem/mem_alloc.h"
|
||||
#include "me/mem/mem_realloc.h"
|
||||
#include "me/mem/mem_set_zero.h"
|
||||
#include "me/string/str_l_cat.h"
|
||||
#include "me/string/str_len.h"
|
||||
|
|
@ -26,39 +25,30 @@ t_error str_reserve(t_buffer_str *buf, t_usize size)
|
|||
|
||||
if (buf == NULL)
|
||||
return (ERROR);
|
||||
if (buf->capacity >= size)
|
||||
return (NO_ERROR);
|
||||
while (size > buf->capacity)
|
||||
{
|
||||
new_capacity = (buf->capacity * 3) / 2 + 1;
|
||||
temp_buffer = mem_realloc(buf->buf, new_capacity);
|
||||
if (temp_buffer == NULL)
|
||||
return (true);
|
||||
buf->buf = temp_buffer;
|
||||
buf->capacity = new_capacity;
|
||||
}
|
||||
temp_buffer = mem_realloc_array(buf->buf, new_capacity, sizeof(char));
|
||||
if (temp_buffer == NULL)
|
||||
return (ERROR);
|
||||
buf->buf = temp_buffer;
|
||||
buf->capacity = new_capacity;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
bool push_str_buffer(t_buffer_str *buf, t_const_str to_push)
|
||||
t_error push_str_buffer(t_buffer_str *buf, t_const_str to_push)
|
||||
{
|
||||
t_usize to_push_len;
|
||||
t_str temp_buffer;
|
||||
t_usize new_capacity;
|
||||
|
||||
if (buf == NULL || to_push == NULL)
|
||||
return (true);
|
||||
return (ERROR);
|
||||
to_push_len = str_len(to_push);
|
||||
while (buf->len + to_push_len + 2 > buf->capacity)
|
||||
{
|
||||
new_capacity = (buf->capacity * 3) / 2 + 1;
|
||||
temp_buffer = mem_realloc(buf->buf, new_capacity);
|
||||
if (temp_buffer == NULL)
|
||||
return (true);
|
||||
buf->buf = temp_buffer;
|
||||
buf->capacity = new_capacity;
|
||||
}
|
||||
if (str_reserve(buf, buf->len + to_push_len + 2))
|
||||
return (ERROR);
|
||||
buf->len += to_push_len;
|
||||
str_l_cat(buf->buf, to_push, buf->capacity);
|
||||
return (false);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
bool push_str_char(t_buffer_str *buf, char to_push)
|
||||
|
|
@ -84,7 +74,7 @@ t_buffer_str alloc_new_buffer(t_usize capacity)
|
|||
|
||||
if (capacity == 0)
|
||||
capacity = 16;
|
||||
buf = mem_alloc(sizeof(char) * capacity);
|
||||
buf = mem_alloc_array(sizeof(char), capacity);
|
||||
if (buf == NULL)
|
||||
{
|
||||
out.buf = NULL;
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/23 17:38:21 by maix #+# #+# */
|
||||
/* Updated: 2023/12/11 19:10:26 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:39:59 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/buffered_str/buf_str.h"
|
||||
#include "me/gnl/gnl.h"
|
||||
#include "me/mem/mem_alloc.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem_move.h"
|
||||
#include "me/string/str_len.h"
|
||||
#include "me/types.h"
|
||||
|
|
@ -92,7 +92,7 @@ static bool handle_leftovers(t_file fd, char *temp_buffer, t_buffer_str *buf)
|
|||
if (copy_next_line_into_buffer(fd, buf, temp_buffer,
|
||||
str_len(static_buffer->buf)))
|
||||
{
|
||||
me_free(temp_buffer);
|
||||
mem_free(temp_buffer);
|
||||
return (true);
|
||||
}
|
||||
}
|
||||
|
|
@ -118,10 +118,10 @@ t_buffer_str get_next_line(t_file fd, bool *error)
|
|||
return (buf);
|
||||
while (!read_and_copy(fd, &buf, temp_buffer, &flags) && !flags.empty_read)
|
||||
;
|
||||
me_free(temp_buffer);
|
||||
mem_free(temp_buffer);
|
||||
if (flags.error || flags.empty_read)
|
||||
{
|
||||
me_free(buf.buf);
|
||||
mem_free(buf.buf);
|
||||
return (*error = true, (t_buffer_str){0});
|
||||
}
|
||||
return (buf);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/10 20:02:12 by maix #+# #+# */
|
||||
/* Updated: 2023/12/11 19:09:32 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:40:16 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
#include "me/hash/sip/sip_utils.h"
|
||||
#include "me/num/u64.h"
|
||||
#include "me/num/usize.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
@ -101,6 +102,6 @@ t_u64 sip13_finish(t_sip13 *self)
|
|||
state.v2 ^= 0xff;
|
||||
compress(&state);
|
||||
compress(&state);
|
||||
me_free(self);
|
||||
mem_free(self);
|
||||
return (state.v0 ^ state.v1 ^ state.v2 ^ state.v3);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/24 19:06:05 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/24 19:18:01 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:40:29 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
#include "me/fs/read_to_vec.h"
|
||||
#include "me/fs/write.h"
|
||||
#include "me/img/qoi.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_i32 qoi_write(t_const_str filename, const void *data,
|
||||
|
|
@ -32,7 +33,7 @@ t_i32 qoi_write(t_const_str filename, const void *data,
|
|||
if (me_write(f, encoded, size))
|
||||
return (me_close(f, NULL), 0);
|
||||
me_close(f, NULL);
|
||||
me_free(encoded);
|
||||
mem_free(encoded);
|
||||
return (size);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_add_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 20:38:45 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 15:02:42 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/list/list_add_back.h"
|
||||
#include "me/list/list_get_last.h"
|
||||
|
||||
void list_add_back(t_list **list, t_list *new)
|
||||
{
|
||||
if (*list)
|
||||
list_get_last(*list)->next = new;
|
||||
else
|
||||
*list = new;
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_add_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 20:15:23 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 15:02:50 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/list/list_add_front.h"
|
||||
#include "me/list/list_alloc_node.h"
|
||||
|
||||
void list_add_front(t_list **lst, t_list *new)
|
||||
{
|
||||
new->next = *lst;
|
||||
*lst = new;
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_alloc_node.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 19:57:28 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 18:13:05 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/list/list_alloc_node.h"
|
||||
#include "me/mem/mem_alloc.h"
|
||||
|
||||
t_list *list_alloc_node(void *content)
|
||||
{
|
||||
t_list *out;
|
||||
|
||||
out = mem_alloc(sizeof(t_list) * 1);
|
||||
if (out == NULL)
|
||||
return (NULL);
|
||||
out->content = content;
|
||||
out->next = NULL;
|
||||
return (out);
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_free_one.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 21:30:20 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 15:03:42 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/list/list_free_one.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void list_free_one(t_list *lst, void (*del)(void *))
|
||||
{
|
||||
if (lst == NULL || del == NULL)
|
||||
return ;
|
||||
del(lst->content);
|
||||
me_free(lst);
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_get_last.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 20:37:08 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 15:03:49 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/list/list_get_last.h"
|
||||
|
||||
t_list *list_get_last(t_list *list)
|
||||
{
|
||||
t_list *head;
|
||||
|
||||
head = list;
|
||||
if (head == NULL)
|
||||
return (NULL);
|
||||
while (head->next)
|
||||
head = head->next;
|
||||
return (head);
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_iter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 21:39:05 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 15:03:55 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/list/list_iter.h"
|
||||
|
||||
void list_iter(t_list *list, void (*f)(void *))
|
||||
{
|
||||
while (list)
|
||||
{
|
||||
f(list->content);
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_map.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 21:40:24 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 15:05:20 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/list/list_alloc_node.h"
|
||||
#include "me/list/list_free_all.h"
|
||||
#include "me/list/list_map.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_list *list_map(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
{
|
||||
void *data;
|
||||
t_list new;
|
||||
t_list *cursor;
|
||||
|
||||
new = (t_list){.next = NULL, .content = NULL};
|
||||
cursor = &new;
|
||||
while (lst)
|
||||
{
|
||||
data = f(lst->content);
|
||||
cursor->next = list_alloc_node(data);
|
||||
if (cursor->next == NULL)
|
||||
{
|
||||
del(data);
|
||||
list_free_all(&new.next, del);
|
||||
return (NULL);
|
||||
}
|
||||
cursor = cursor->next;
|
||||
lst = lst->next;
|
||||
}
|
||||
return (new.next);
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_size.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 20:23:19 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 15:05:00 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/list/list_size.h"
|
||||
|
||||
t_usize list_size(t_list *lst)
|
||||
{
|
||||
t_list *head;
|
||||
t_usize idx;
|
||||
|
||||
head = lst;
|
||||
idx = 0;
|
||||
while (head)
|
||||
{
|
||||
head = head->next;
|
||||
idx++;
|
||||
}
|
||||
return (idx);
|
||||
}
|
||||
|
|
@ -1,30 +1,34 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* list_free_all.c :+: :+: :+: */
|
||||
/* allocator.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/09 21:35:20 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 15:03:34 by maiboyer ### ########.fr */
|
||||
/* Created: 2024/05/14 18:26:27 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:28:24 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/list/list_free_all.h"
|
||||
#include <stdlib.h>
|
||||
#include "aq/allocator.h"
|
||||
#include "aq/libc_wrapper.h"
|
||||
|
||||
void list_free_all(t_list **lst, void (*del)(void *))
|
||||
t_allocator *global_allocator(void)
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
if (lst == NULL || del == NULL)
|
||||
return ;
|
||||
while (*lst)
|
||||
static t_allocator global_alloc = {};
|
||||
static bool init = false;
|
||||
if (!init)
|
||||
{
|
||||
del((*lst)->content);
|
||||
tmp = *lst;
|
||||
*lst = (*lst)->next;
|
||||
me_free(tmp);
|
||||
init = true;
|
||||
global_alloc = lc_init();
|
||||
}
|
||||
*lst = NULL;
|
||||
return (&global_alloc);
|
||||
}
|
||||
|
||||
void uninit_global_allocator(void)
|
||||
{
|
||||
t_allocator *allocator;
|
||||
|
||||
allocator = global_allocator();
|
||||
allocator->uninit(allocator);
|
||||
}
|
||||
|
|
@ -6,14 +6,25 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/06 14:47:49 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/07 12:45:31 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:32:31 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc.h"
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/mem/_allocator.h"
|
||||
|
||||
void *mem_alloc(t_usize size)
|
||||
void *mem_alloc(t_usize size)
|
||||
{
|
||||
return (me_malloc(size));
|
||||
t_allocator *a;
|
||||
|
||||
a = global_allocator();
|
||||
return (a->alloc(a, size));
|
||||
}
|
||||
|
||||
void mem_free(void *ptr)
|
||||
{
|
||||
t_allocator *a;
|
||||
|
||||
a = global_allocator();
|
||||
return (a->free(a, ptr));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,15 +6,17 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 15:53:21 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/07 12:46:04 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:30:27 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include <stdlib.h>
|
||||
#include "me/mem/_allocator.h"
|
||||
|
||||
void *mem_alloc_array(t_usize item_count, t_usize item_size)
|
||||
void *mem_alloc_array(t_usize size, t_usize count)
|
||||
{
|
||||
return (me_calloc(item_count, item_size));
|
||||
t_allocator *a;
|
||||
|
||||
a = global_allocator();
|
||||
return (a->alloc_array(a, size, count));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,24 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/07 12:46:18 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/07 12:47:12 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:32:06 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_realloc.h"
|
||||
#include "me/alloc/alloc.h"
|
||||
#include "me/mem/_allocator.h"
|
||||
|
||||
void *mem_realloc(void *ptr, t_usize size)
|
||||
{
|
||||
return (me_realloc(ptr, size));
|
||||
t_allocator *a;
|
||||
|
||||
a = global_allocator();
|
||||
return (a->realloc(a, ptr, size));
|
||||
}
|
||||
|
||||
void *mem_realloc_array(void *ptr, t_usize size, t_usize count)
|
||||
{
|
||||
t_allocator *a;
|
||||
|
||||
a = global_allocator();
|
||||
return (a->realloc_array(a, ptr, size, count));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/07 11:08:03 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/09 07:43:10 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:42:15 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include "me/alloc/alloc_internal.h"
|
||||
#include "me/fs/putendl_fd.h"
|
||||
#include "me/fs/putstr_fd.h"
|
||||
#include "me/types.h"
|
||||
|
|
@ -91,7 +90,6 @@ void me_abort(t_str msg)
|
|||
if (msg == NULL)
|
||||
msg = "No message (msg was NULL)";
|
||||
me_putendl_fd("Memory information:", 2);
|
||||
print_pages_info();
|
||||
me_putstr_fd("Abort: ", 2);
|
||||
me_putendl_fd(msg, 2);
|
||||
print_trace();
|
||||
|
|
|
|||
|
|
@ -6,86 +6,16 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/07 13:08:52 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/12 17:05:27 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:42:41 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/alloc/alloc_dumb_internal.h"
|
||||
#include "me/alloc/alloc_internal.h"
|
||||
#include "me/fs/putendl_fd.h"
|
||||
#include "me/fs/putnbr_fd.h"
|
||||
#include "me/fs/putstr_fd.h"
|
||||
#include "me/mem/_allocator.h"
|
||||
#include "me/types.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void __libc_free(void *ptr);
|
||||
|
||||
// void uninit_allocator(void)
|
||||
// {
|
||||
// t_mpage *page;
|
||||
// void *tmp;
|
||||
// t_mblock *block;
|
||||
// t_usize count_block;
|
||||
//
|
||||
// page = get_head_arena();
|
||||
// count_block = 0;
|
||||
// block = page->first;
|
||||
// while (block)
|
||||
// {
|
||||
// if (block->used)
|
||||
// count_block += 1;
|
||||
// tmp = block->next;
|
||||
// __libc_free(block);
|
||||
// block = tmp;
|
||||
// }
|
||||
// while (page)
|
||||
// {
|
||||
// tmp = page->next;
|
||||
// __libc_free(page->data);
|
||||
// __libc_free(page);
|
||||
// page = tmp;
|
||||
// }
|
||||
// if (count_block != 0)
|
||||
// (me_putnbr_fd(count_block, 2),
|
||||
// me_putendl_fd(" Blocks weren't freed when exiting !", 2));
|
||||
// }
|
||||
|
||||
void uninit_allocator(void)
|
||||
{
|
||||
t_ptr_table *table;
|
||||
t_ptr_table *table_next;
|
||||
t_usize i;
|
||||
t_usize unfree_count;
|
||||
|
||||
unfree_count = 0;
|
||||
table = get_table();
|
||||
|
||||
while (table)
|
||||
{
|
||||
i = 0;
|
||||
while (i < PTR_LENS)
|
||||
{
|
||||
if (table->table[i].ptr != NULL)
|
||||
{
|
||||
__libc_free(table->table[i].ptr);
|
||||
unfree_count++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
table_next = table->next;
|
||||
__libc_free(table);
|
||||
table = table_next;
|
||||
}
|
||||
if (unfree_count != 0)
|
||||
{
|
||||
me_putstr_fd("A total of ", 2);
|
||||
me_putnbr_fd(unfree_count, 2);
|
||||
me_putendl_fd(" blocks weren't freed !", 2);
|
||||
}
|
||||
}
|
||||
|
||||
void me_exit(t_i32 exit_code)
|
||||
{
|
||||
uninit_allocator();
|
||||
uninit_global_allocator();
|
||||
exit(exit_code);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/03 16:22:41 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/09 16:55:16 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:42:59 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
#include "me/os/process.h"
|
||||
#include "me/string/str_find_chr.h"
|
||||
#include "me/string/str_n_compare.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/string/str_split.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
|
|
@ -73,8 +74,8 @@ t_error in_path(t_spawn_info *info, t_process *process, t_const_str path,
|
|||
}
|
||||
sp_index = 0;
|
||||
while (splitted_path[sp_index])
|
||||
me_free(splitted_path[sp_index++]);
|
||||
me_free(splitted_path);
|
||||
mem_free(splitted_path[sp_index++]);
|
||||
mem_free(splitted_path);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
|
|
@ -99,7 +100,7 @@ t_error find_binary(t_spawn_info *info, t_process *process)
|
|||
}
|
||||
if (access(s.buf, X_OK | R_OK) == 0)
|
||||
{
|
||||
me_free(info->binary_path);
|
||||
mem_free(info->binary_path);
|
||||
info->binary_path = s.buf;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
@ -119,7 +120,7 @@ static void cleanup(t_spawn_info info, t_process *process, bool cleanup_process)
|
|||
close(info.stderr.vals.fd.value);
|
||||
vec_str_free(info.arguments);
|
||||
vec_str_free(info.environement);
|
||||
me_free(info.binary_path);
|
||||
mem_free(info.binary_path);
|
||||
}
|
||||
|
||||
t_error spawn_process(t_spawn_info info, t_process *process)
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/18 18:12:11 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/11 19:18:48 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:43:13 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_set.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/printf/formatter/utils.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include "me/string/str_len.h"
|
||||
|
|
@ -66,5 +66,5 @@ void printf_s(t_printf_arg data, t_printf_func f)
|
|||
.fill_zero = 0, .fill = 0, .len = len, .pretty = "", .pretty_len = 0, \
|
||||
.str = start_num, .allow_zero_fill = false, .sign = NULL, \
|
||||
.sign_len = 0, }, data, f);
|
||||
me_free(start_num);
|
||||
mem_free(start_num);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@
|
|||
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/18 01:44:35 by maix #+# #+# */
|
||||
/* Updated: 2023/12/11 19:19:27 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:43:24 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem_set.h"
|
||||
#include "me/printf/formatter/utils.h"
|
||||
#include "me/printf/printf.h"
|
||||
|
|
@ -85,5 +85,5 @@ void printf_d(t_printf_arg data, t_printf_func f)
|
|||
.fill_zero = 0, .fill = 0, .sign = sign, .pretty = NULL, .len = \
|
||||
str_len(start_num), .pretty_len = 0, .str = start_num, .allow_zero_fill \
|
||||
= true, .sign_len = str_len(sign), }, data, f);
|
||||
me_free(start_num);
|
||||
mem_free(start_num);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@
|
|||
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/18 01:44:35 by maix #+# #+# */
|
||||
/* Updated: 2023/12/11 19:19:59 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:43:39 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/mem/mem_set.h"
|
||||
#include "me/printf/formatter/utils.h"
|
||||
#include "me/printf/printf.h"
|
||||
|
|
@ -72,5 +72,5 @@ void printf_u(t_printf_arg data, t_printf_func f)
|
|||
.fill_zero = 0, .fill = 0, .len = str_len(start_num), \
|
||||
.pretty = NULL, .pretty_len = 0, .str = start_num, \
|
||||
.allow_zero_fill = true, .sign = NULL, .sign_len = 0, }, data, f);
|
||||
me_free(start_num);
|
||||
mem_free(start_num);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/16 17:57:04 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/01 21:20:07 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:43:44 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/buffered_str/buf_str.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/convert/atoi.h"
|
||||
#include "me/printf/formatter/utils.h"
|
||||
#include "me/printf/matchers/matchers.h"
|
||||
|
|
@ -99,7 +100,7 @@ t_printf_arg print_substr(t_usize *c_idx, t_usize *nxt, t_const_str fmt,
|
|||
|
||||
truc = str_substring(fmt, *c_idx, *nxt - *c_idx);
|
||||
extra.f(truc, *nxt - *c_idx, extra.p_args);
|
||||
me_free(truc);
|
||||
mem_free(truc);
|
||||
*c_idx = *nxt + 1;
|
||||
return ((t_printf_arg){
|
||||
.p_args = extra.p_args,
|
||||
|
|
|
|||
|
|
@ -6,14 +6,13 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/01 21:05:47 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/01 21:49:51 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:43:56 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/printf/formatter/utils.h"
|
||||
#include "me/printf/printf.h"
|
||||
#include <stdlib.h>
|
||||
#include "me/mem/mem.h"
|
||||
|
||||
void handle_weird_precision_stuff(t_printf_arg *data, t_prec_strs strs,
|
||||
t_usize value)
|
||||
|
|
@ -23,7 +22,7 @@ void handle_weird_precision_stuff(t_printf_arg *data, t_prec_strs strs,
|
|||
data->flags &= (~ZERO_ALIGN);
|
||||
data->flags |= ALIGN;
|
||||
if (strs.free_out)
|
||||
*strs.out = (me_free(*strs.out), (t_str)mem_alloc_array(1, 1));
|
||||
*strs.out = (mem_free(*strs.out), (t_str)mem_alloc_array(1, 1));
|
||||
else
|
||||
*strs.out = "";
|
||||
*strs.pretty = "";
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ t_usize me_printf(t_const_str fmt, ...)
|
|||
va_end(args);
|
||||
len = str_len(str);
|
||||
write(1, str, len);
|
||||
me_free(str);
|
||||
mem_free(str);
|
||||
return (len);
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ t_usize me_eprintf(t_const_str fmt, ...)
|
|||
va_end(args);
|
||||
len = str_len(str);
|
||||
write(2, str, len);
|
||||
me_free(str);
|
||||
mem_free(str);
|
||||
return (len);
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -101,8 +101,8 @@ int main(void) {
|
|||
printf("\n");
|
||||
printf("\n");
|
||||
}
|
||||
me_free(dest_libc);
|
||||
me_free(dest_ft);
|
||||
mem_free(dest_libc);
|
||||
mem_free(dest_ft);
|
||||
}
|
||||
}
|
||||
R*/
|
||||
|
|
|
|||
|
|
@ -97,8 +97,8 @@ int main(void) {
|
|||
printf("\n");
|
||||
printf("\n");
|
||||
}
|
||||
me_free(dest_libc);
|
||||
me_free(dest_ft);
|
||||
mem_free(dest_libc);
|
||||
mem_free(dest_ft);
|
||||
}
|
||||
}
|
||||
R*/
|
||||
|
|
|
|||
|
|
@ -6,12 +6,11 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/17 15:56:59 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/12/09 16:52:08 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/14 18:44:18 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/mem/mem_alloc.h"
|
||||
#include "me/mem/mem_alloc_array.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/string/str_l_copy.h"
|
||||
#include "me/string/str_split.h"
|
||||
#include <stdlib.h>
|
||||
|
|
@ -43,7 +42,7 @@ static t_usize local_count_words(t_const_str str, char chr)
|
|||
static t_str *local_split_freeall(t_str **to_free)
|
||||
{
|
||||
while (*to_free)
|
||||
me_free(*(to_free++));
|
||||
mem_free(*(to_free++));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue