Minishell
 
Loading...
Searching...
No Matches
garbage.h
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* garbage.h :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: ppontet <ppontet@student.42lyon.fr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/03/18 17:09:50 by ppontet #+# #+# */
9/* Updated: 2025/05/30 11:22:17 by ppontet ### ########lyon.fr */
10/* */
11/* ************************************************************************** */
12
13#ifndef GARBAGE_H
14# define GARBAGE_H
15
16# include <stdlib.h>
17
18typedef struct s_element t_element;
19typedef struct s_garbage t_garbage;
20
26{
27 void *ptr;
28 void *next;
29};
30
36{
37 size_t n_elements;
39};
40
46// Function to replace all the malloc by this to use the garbage
47void *malloc_gb(t_garbage *garbage, size_t size);
48void add_to_garbage(t_garbage *garbage, void *ptr);
49void free_element_gb(t_garbage *garbage, void *ptr);
50char *ft_strdup_gb(t_garbage *garbage,
51 const char *source);
52
53// Initialise the garbage and free it's content
54void garbage_init(t_garbage *garbage);
55void free_garbage(t_garbage *garbage);
56
57// Private functions for garbage management
58// t_garbage *get_garbage(void);
59void print_garbage(t_garbage *garbage);
60
61// Garbage stack management
62t_element *ft_garbagenew(void *ptr);
63void ft_garbageadd_front(t_garbage *garbage,
64 t_element *new);
66 t_element *new) __attribute__((deprecated));
67int ft_garbageclear(t_garbage *data);
69#endif
struct s_element t_element
Definition data_structure.h:25
struct s_garbage t_garbage
Definition data_structure.h:26
void free_element_gb(t_garbage *garbage, void *ptr)
Free an element in the garbage collector.
Definition garbage_utils.c:84
void print_garbage(t_garbage *garbage)
Print the garbage collector.
Definition garbage_utils.c:117
void ft_garbageadd_front(t_garbage *garbage, t_element *new)
Adds the 'new' element at the start of stack.
Definition garbage_stack.c:41
int ft_garbageclear(t_garbage *data)
Remove all elements from garbage.
Definition garbage_stack.c:85
void add_to_garbage(t_garbage *garbage, void *ptr)
Add a pointer to the garbage list.
Definition garbage.c:51
void ft_garbageadd_back(t_garbage *stack, t_element *new) __attribute__((deprecated))
Adds the 'new' element at the end of stack.
Definition garbage_stack.c:56
t_element * ft_garbagenew(void *ptr)
Allocates and returns the newly created element 'value' is initialised with content 'next' is set to ...
Definition garbage_stack.c:23
void free_garbage(t_garbage *garbage)
Free the garbage.
Definition garbage.c:72
void garbage_init(t_garbage *garbage)
Get the garbage object.
Definition garbage.c:38
void * malloc_gb(t_garbage *garbage, size_t size)
Replace the original malloc by storing the created adresses into a garbage to remove them afterwards.
Definition garbage.c:86
char * ft_strdup_gb(t_garbage *garbage, const char *source)
Create a copy of source into a new pointer NEEDS to be freed.
Definition garbage_utils.c:30
Basic node for an element of a linked list.
Definition garbage.h:26
void * ptr
Definition garbage.h:27
void * next
Definition garbage.h:28
Head of the linked list.
Definition garbage.h:36
t_element * head
Definition garbage.h:38
size_t n_elements
Definition garbage.h:37