fix: use ifdef instead ifndef

This commit is contained in:
starnakin 2024-07-31 14:35:54 +02:00
parent 46f485dc27
commit 253d037344
3 changed files with 7 additions and 5 deletions

View File

@ -9,6 +9,7 @@
#include "align.h" #include "align.h"
#include "chunk.h" #include "chunk.h"
#include "chunk_manager.h" #include "chunk_manager.h"
#include "malloc.h"
int add_new_block(chunk_t* chunk, size_t size, void *prev, bool is_used) int add_new_block(chunk_t* chunk, size_t size, void *prev, bool is_used)
{ {
@ -19,7 +20,7 @@ int add_new_block(chunk_t* chunk, size_t size, void *prev, bool is_used)
// TODO check with getrlimit() // TODO check with getrlimit()
new_block = mmap(NULL, size + ALIGN_MARGING + HEADER_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); new_block = mmap(NULL, size + ALIGN_MARGING + HEADER_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
#ifndef DEBUG #ifdef DEBUG
if (new_block == NULL) if (new_block == NULL)
write(2, "mmap failed\n", 12); write(2, "mmap failed\n", 12);
#endif #endif

View File

@ -3,12 +3,13 @@
#include "raw_chunk_manager.h" #include "raw_chunk_manager.h"
#include "print.h" #include "print.h"
#include "block.h" #include "block.h"
#include "malloc.h"
#include <unistd.h> #include <unistd.h>
void chunk_merge(chunk_t *first, chunk_t *second) void chunk_merge(chunk_t *first, chunk_t *second)
{ {
#ifndef DEBUG #ifdef DEBUG
if (first->block_id != second->block_id) if (first->block_id != second->block_id)
write(2, "Attempt merge two chunk on different block\n", 43); write(2, "Attempt merge two chunk on different block\n", 43);
#endif #endif
@ -22,7 +23,7 @@ int chunk_split(chunk_t *chunk, size_t new_size)
{ {
chunk_t new_chunk; chunk_t new_chunk;
#ifndef DEBUG #ifdef DEBUG
if (chunk->size + 1 < new_size + HEADER_SIZE + get_align_increment(chunk->current + HEADER_SIZE)) if (chunk->size + 1 < new_size + HEADER_SIZE + get_align_increment(chunk->current + HEADER_SIZE))
write(2, "chunk too small to be splitted\n", 31); write(2, "chunk too small to be splitted\n", 31);
#endif #endif

View File

@ -57,7 +57,7 @@ void ft_free(void *ptr)
for (i = TINY; i <= LARGE + 1; i++) for (i = TINY; i <= LARGE + 1; i++)
{ {
#ifndef DEBUG #ifdef DEBUG
if (i > LARGE) if (i > LARGE)
write(2, "chunk not found\n", 16); write(2, "chunk not found\n", 16);
#endif #endif
@ -72,7 +72,7 @@ void ft_free(void *ptr)
chunk_read(raw_chunk, &chunk); chunk_read(raw_chunk, &chunk);
#ifndef DEBUG #ifdef DEBUG
if (chunk.is_used == false) if (chunk.is_used == false)
write(2, "double free\n", 12); write(2, "double free\n", 12);
#endif #endif