normm
This commit is contained in:
parent
71d3fde169
commit
80fedbeb03
5 changed files with 16 additions and 27 deletions
|
@ -6,7 +6,7 @@
|
|||
/* By: gtertysh <gtertysh@student.unit.ua> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/05/06 22:37:07 by foton #+# #+# */
|
||||
/* Updated: 2019/05/06 22:40:18 by gtertysh ### ########.fr */
|
||||
/* Updated: 2019/05/08 19:45:18 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -47,4 +47,4 @@ typedef struct s_arena
|
|||
|
||||
extern t_arena g_base;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
10
src/malloc.c
10
src/malloc.c
|
@ -6,7 +6,7 @@
|
|||
/* By: gtertysh <gtertysh@student.unit.ua> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/05/06 22:35:57 by foton #+# #+# */
|
||||
/* Updated: 2019/05/07 22:06:49 by gtertysh ### ########.fr */
|
||||
/* Updated: 2019/05/08 19:44:07 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -96,10 +96,10 @@ void *malloc(size_t size)
|
|||
size = CHUNK_SIZE(size);
|
||||
arena = g_base.next;
|
||||
arena_type = get_arena_type(size);
|
||||
while(!space)
|
||||
while (!space)
|
||||
{
|
||||
if(arena->type == arena_type && (heap = arena->heap))
|
||||
while(!space && heap)
|
||||
if (arena->type == arena_type && (heap = arena->heap))
|
||||
while (!space && heap)
|
||||
{
|
||||
if (heap->size >= size && heap->is_free)
|
||||
space = chunk_heap(heap, size);
|
||||
|
@ -111,4 +111,4 @@ void *malloc(size_t size)
|
|||
return (NULL);
|
||||
}
|
||||
return (space + 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gtertysh <gtertysh@student.unit.ua> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/05/06 22:35:48 by foton #+# #+# */
|
||||
/* Updated: 2019/05/07 00:25:13 by gtertysh ### ########.fr */
|
||||
/* Updated: 2019/05/08 19:44:41 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -30,4 +30,4 @@ void *realloc(void *ptr, size_t size)
|
|||
ft_memmove(new_chunk, ptr, chunk->size - CHUNK_SIZE(0));
|
||||
free(ptr);
|
||||
return (new_chunk);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 15:17:18 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:24:55 by gtertysh ### ########.fr */
|
||||
/* Updated: 2019/05/08 19:48:54 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -16,8 +16,8 @@ void ft_putendl_fd(char const *s, int fd)
|
|||
{
|
||||
if (s)
|
||||
while (*s)
|
||||
if(write(fd, s++, 1) == -1)
|
||||
if (write(fd, s++, 1) == -1)
|
||||
return ;
|
||||
if(write(fd, "\n", 1) == -1)
|
||||
if (write(fd, "\n", 1) == -1)
|
||||
return ;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gtertysh <gtertysh@student.unit.ua> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/05/06 22:35:37 by foton #+# #+# */
|
||||
/* Updated: 2019/05/07 22:44:42 by gtertysh ### ########.fr */
|
||||
/* Updated: 2019/05/08 19:47:45 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -28,10 +28,9 @@ int returns_not_null_pointer(void)
|
|||
g_base.next = &g_base;
|
||||
ptr = malloc(10);
|
||||
_IS(ptr != NULL);
|
||||
|
||||
ptr = ptr - 1;
|
||||
_IS(ptr->is_free == 0);
|
||||
_IS(ptr->size == 10 + sizeof(t_chunk));
|
||||
_IS(ptr->size == 10 + sizeof(t_chunk));
|
||||
_IS(ptr->magic == MAGIC);
|
||||
_IS(ptr->next == NULL);
|
||||
_IS(ptr->prev != NULL);
|
||||
|
@ -48,25 +47,19 @@ int free_concatenates_adjacent_blocks(void)
|
|||
g_base.next = &g_base;
|
||||
ptr = malloc(10);
|
||||
next_malloc = malloc(10);
|
||||
|
||||
ptr -= 1;
|
||||
next_malloc -= 1;
|
||||
|
||||
free(ptr + 1);
|
||||
|
||||
_IS(ptr->is_free == 1);
|
||||
_IS(ptr->prev == next_malloc);
|
||||
_IS(next_malloc->is_free == 0);
|
||||
_IS(next_malloc->next == ptr);
|
||||
_IS(next_malloc->prev->prev == NULL);
|
||||
|
||||
heap = next_malloc->prev;
|
||||
free(next_malloc + 1);
|
||||
|
||||
_IS(heap->is_free == 1);
|
||||
_IS(heap->prev == NULL);
|
||||
_IS(heap->next == NULL);
|
||||
|
||||
_END("free_concatenates_adjacent_blocks");
|
||||
}
|
||||
|
||||
|
@ -88,12 +81,9 @@ int malloc_creates_new_arena(void)
|
|||
second_arena_chunk = malloc(TINY);
|
||||
i++;
|
||||
}
|
||||
|
||||
_IS(g_base.next->next == &g_base);
|
||||
_IS(g_base.next->type == TINY);
|
||||
|
||||
second_arena_chunk = malloc(TINY);
|
||||
|
||||
_IS(g_base.next->next != &g_base);
|
||||
_IS(g_base.next->type == TINY);
|
||||
_IS(g_base.next->heap->next == second_arena_chunk - 1);
|
||||
|
@ -108,7 +98,6 @@ int realloc_return_same_pointer(void)
|
|||
g_base.next = &g_base;
|
||||
ptr = malloc(20);
|
||||
new_ptr = realloc(ptr, 10);
|
||||
|
||||
_IS(ptr == new_ptr);
|
||||
_END("realloc_return_same_pointer");
|
||||
}
|
||||
|
@ -120,5 +109,5 @@ int main(void)
|
|||
_SHOULD(free_concatenates_adjacent_blocks);
|
||||
_SHOULD(malloc_creates_new_arena);
|
||||
_SHOULD(realloc_return_same_pointer);
|
||||
return 0;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue