fix compilation error on newer clang version, fix some norm errors and start doing show_alloc_mem_ex function
This commit is contained in:
@ -6,12 +6,11 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/06 19:16:40 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/10 18:18:03 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/02/14 17:24:10 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "includes/malloc.h"
|
||||
#include <stdio.h>
|
||||
|
||||
t_settings *get_settings(void)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/30 18:46:07 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/10 19:13:55 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/02/14 17:20:17 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -51,8 +51,8 @@ int get_prev_alloc(t_alloc **alloc, t_alloc **res, t_alloc *cur, char *fnc)
|
||||
*alloc = cur;
|
||||
*res = prev;
|
||||
}
|
||||
if(*res)
|
||||
return(1);
|
||||
if (*res)
|
||||
return (1);
|
||||
prev = cur;
|
||||
cur = cur->next;
|
||||
}
|
||||
|
45
srcs/hex_dump.c
Normal file
45
srcs/hex_dump.c
Normal file
@ -0,0 +1,45 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* hex_dump.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/14 18:03:26 by tomoron #+# #+# */
|
||||
/* Updated: 2025/02/14 19:38:12 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "includes/malloc.h"
|
||||
|
||||
static void hex_dump_show_address(long unsigned addr)
|
||||
{
|
||||
i
|
||||
}
|
||||
|
||||
static void hex_dump_show_line(char *addr, int len)
|
||||
{
|
||||
hex_dump_show_address((long unsigned)addr);
|
||||
}
|
||||
|
||||
void hex_dump(char *addr, size_t nb)
|
||||
{
|
||||
char buf[16];
|
||||
size_t cur;
|
||||
|
||||
cur = 0;
|
||||
while (cur < nb)
|
||||
{
|
||||
if(cur && !ft_memcmp(buf, addr + cur, 16))
|
||||
{
|
||||
cur += 16;
|
||||
continue;
|
||||
}
|
||||
ft_memcpy(buf, addr + cur, 16);
|
||||
if(nb - cur < 16)
|
||||
hex_dump_show_line(addr + cur, nb - cur);
|
||||
else
|
||||
hex_dump_show_line(addr + cur, 16);
|
||||
cur += 16;
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/26 16:38:01 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/10 18:19:55 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/02/14 18:16:06 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -66,6 +66,10 @@ extern t_allocations g_allocs;
|
||||
extern pthread_mutex_t g_mallock;
|
||||
|
||||
size_t align(size_t nb, size_t align_nb);
|
||||
size_t show_pre_allocated(char *type, t_mem_chunk *chunk, int dump);
|
||||
size_t show_large(int dump);
|
||||
void put_ulnbr_base(t_ul nbr, char *base);
|
||||
void hex_dump(char *addr, size_t nb);
|
||||
|
||||
void *malloc(size_t size);
|
||||
t_settings *get_settings(void);
|
||||
|
@ -6,12 +6,11 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/10 17:11:27 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/10 18:13:37 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/02/14 17:24:02 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "includes/malloc.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void __attribute__((destructor)) malloc_end(void)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/02 14:41:22 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/10 18:14:56 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/02/14 17:43:40 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -27,7 +27,7 @@ static void *realloc_recreate(t_alloc *alloc, size_t size)
|
||||
size = alloc->size;
|
||||
pthread_mutex_unlock(&g_mallock);
|
||||
ft_memcpy(new, alloc + 1, size);
|
||||
free(alloc + 1);
|
||||
free((void *)(alloc + 1));
|
||||
pthread_mutex_lock(&g_mallock);
|
||||
return (new);
|
||||
}
|
||||
|
@ -6,13 +6,13 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/30 12:19:34 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/05 17:05:48 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/02/14 18:18:48 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "includes/malloc.h"
|
||||
|
||||
static void put_ulnbr_base(t_ul nbr, char *base)
|
||||
void put_ulnbr_base(t_ul nbr, char *base)
|
||||
{
|
||||
t_ul base_len;
|
||||
|
||||
@ -26,7 +26,7 @@ static void put_ulnbr_base(t_ul nbr, char *base)
|
||||
write(1, base + nbr, 1);
|
||||
}
|
||||
|
||||
static size_t show_allocs(t_alloc *alloc)
|
||||
static size_t show_allocs(t_alloc *alloc, int dump)
|
||||
{
|
||||
size_t nb_bytes;
|
||||
|
||||
@ -42,12 +42,14 @@ static size_t show_allocs(t_alloc *alloc)
|
||||
write(1, " : ", 3);
|
||||
put_ulnbr_base(alloc->size, "0123456789");
|
||||
write(1, " bytes\n", 7);
|
||||
if(dump)
|
||||
hex_dump((void *)(alloc + 1), alloc->size);
|
||||
alloc = alloc->next;
|
||||
}
|
||||
return (nb_bytes);
|
||||
}
|
||||
|
||||
static size_t show_pre_allocated(char *type, t_mem_chunk *chunk)
|
||||
size_t show_pre_allocated(char *type, t_mem_chunk *chunk, int dump)
|
||||
{
|
||||
size_t nb_bytes;
|
||||
|
||||
@ -58,13 +60,13 @@ static size_t show_pre_allocated(char *type, t_mem_chunk *chunk)
|
||||
write(1, " : 0x", 5);
|
||||
put_ulnbr_base((t_ul)chunk, "0123456789ABCDEF");
|
||||
write(1, "\n", 1);
|
||||
nb_bytes += show_allocs(chunk->first);
|
||||
nb_bytes += show_allocs(chunk->first, dump);
|
||||
chunk = chunk->next;
|
||||
}
|
||||
return (nb_bytes);
|
||||
}
|
||||
|
||||
static size_t show_large(void)
|
||||
size_t show_large(int dump)
|
||||
{
|
||||
t_alloc *alloc;
|
||||
size_t total_size;
|
||||
@ -84,6 +86,8 @@ static size_t show_large(void)
|
||||
put_ulnbr_base(alloc->size, "0123456789");
|
||||
write(1, " bytes\n", 7);
|
||||
total_size += alloc->size;
|
||||
if(dump)
|
||||
hex_dump((void *)(alloc + 1), alloc->size);
|
||||
alloc = alloc->next;
|
||||
}
|
||||
return (total_size);
|
||||
@ -95,9 +99,9 @@ void show_alloc_mem(void)
|
||||
|
||||
total = 0;
|
||||
pthread_mutex_lock(&g_mallock);
|
||||
total += show_pre_allocated("TINY", g_allocs.tiny);
|
||||
total += show_pre_allocated("SMALL", g_allocs.small);
|
||||
total += show_large();
|
||||
total += show_pre_allocated("TINY", g_allocs.tiny, 0);
|
||||
total += show_pre_allocated("SMALL", g_allocs.small, 0);
|
||||
total += show_large(0);
|
||||
pthread_mutex_unlock(&g_mallock);
|
||||
write(1, "Total : ", 8);
|
||||
put_ulnbr_base(total, "0123456789");
|
||||
|
28
srcs/show_alloc_mem_ex.c
Normal file
28
srcs/show_alloc_mem_ex.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* show_alloc_mem_ex.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/14 17:26:41 by tomoron #+# #+# */
|
||||
/* Updated: 2025/02/14 17:48:53 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "includes/malloc.h"
|
||||
|
||||
void show_alloc_mem_ex(void)
|
||||
{
|
||||
size_t total;
|
||||
|
||||
total = 0;
|
||||
pthread_mutex_lock(&g_mallock);
|
||||
total += show_pre_allocated("TINY", g_allocs.tiny, 1);
|
||||
total += show_pre_allocated("SMALL", g_allocs.small, 1);
|
||||
total += show_large(1);
|
||||
pthread_mutex_unlock(&g_mallock);
|
||||
write(1, "Total : ", 8);
|
||||
put_ulnbr_base(total, "0123456789");
|
||||
write(1, " bytes\n", 7);
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/03 13:20:54 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/10 18:16:13 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/02/14 17:45:17 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -43,7 +43,7 @@ int log_fd(int closefd)
|
||||
if (fd == -1)
|
||||
{
|
||||
ft_putnbr_fd(errno, 1);
|
||||
write(2, "malloc(): can't open log file\n", 37);
|
||||
write(2, "malloc(): can't open log file\n", 30);
|
||||
}
|
||||
}
|
||||
return (fd);
|
||||
|
Reference in New Issue
Block a user