I want to kill sheeps in minecraft with a sword

This commit is contained in:
Maieul BOYER 2024-05-12 17:14:25 +02:00
parent 4f1768b9e8
commit a779ccb768
No known key found for this signature in database
17 changed files with 488 additions and 268 deletions

View file

@ -6,45 +6,86 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 13:08:52 by maiboyer #+# #+# */
/* Updated: 2024/05/12 14:07:28 by maiboyer ### ########.fr */
/* Updated: 2024/05/12 17:05:27 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/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)
{
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));
uninit_allocator();
exit(exit_code);
}