This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec_stack_ressources.c
69 lines (60 loc) · 2.15 KB
/
exec_stack_ressources.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec_stack_ressources.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mgautier <mgautier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/24 10:47:24 by mgautier #+# #+# */
/* Updated: 2018/01/24 10:47:25 by mgautier ### ########.fr */
/* */
/* ************************************************************************** */
#include "exec_construct_defs.h"
#include "sym_interface.h"
#include <assert.h>
#include <stdlib.h>
void destroy_construct(t_exec_construct **to_destroy)
{
t_exec_construct *construct;
assert(to_destroy != NULL);
construct = *to_destroy;
if (construct != NULL)
{
construct->functions = NULL;
construct->remaining_symbols = 0;
construct->real = NULL;
free(construct);
*to_destroy = NULL;
}
}
t_exec_construct *create_construct(t_exec const *exec_functions)
{
t_exec_construct *new_construct;
assert(exec_functions != NULL);
new_construct = malloc(sizeof(*new_construct));
if (new_construct != NULL)
{
new_construct->functions = exec_functions;
new_construct->remaining_symbols = 0;
new_construct->real = NULL;
}
return (new_construct);
}
/*
** Intented to destroy symbols in the exec stack that have not be given to their
** parent, except the meta construct, which does not belong to the exec_stack.
*/
static void destroy_construct_in_stack(t_exec_construct **to_destroy)
{
t_exec_construct *construct;
construct = *to_destroy;
if (construct != construct->real)
{
construct->functions->destroy(&construct->real);
destroy_construct(to_destroy);
}
}
void clean_exec_struct(void **exec_struct)
{
destroy_construct_in_stack((t_exec_construct**)exec_struct);
}