Skip to content

Commit

Permalink
fix: memory mgmt lib
Browse files Browse the repository at this point in the history
  • Loading branch information
araujo88 committed Jan 19, 2025
1 parent 2d51cdd commit e57b3c6
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 153 deletions.
26 changes: 13 additions & 13 deletions ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ extern TypeModifiers current_modifiers;
#define SET_DATA_FLOAT(node, value) ((node)->data.fvalue = (value))
#define SET_DATA_DOUBLE(node, value) ((node)->data.dvalue = (value))
#define SET_DATA_BOOL(node, value) ((node)->data.bvalue = (value) ? 1 : 0)
#define SET_DATA_NAME(node, n) ((node)->data.name = strdup(n), free(n))
#define SET_DATA_NAME(node, n) ((node)->data.name = safe_strdup(n), SAFE_FREE(n))
#define SET_SIZEOF(node, n) ((node)->data.sizeof_stmt.expr = (n))
#define SET_DATA_OP(node, l, r, opr) \
do \
Expand Down Expand Up @@ -357,28 +357,28 @@ extern TypeModifiers current_modifiers;
(node)->data.while_stmt.body = (b); \
} while (0)

#define SET_DATA_FUNC_CALL(node, func_name, args) \
do \
{ \
(node)->data.func_call.function_name = strdup(func_name); \
(node)->data.func_call.arguments = (args); \
#define SET_DATA_FUNC_CALL(node, func_name, args) \
do \
{ \
(node)->data.func_call.function_name = safe_strdup(func_name); \
(node)->data.func_call.arguments = (args); \
} while (0)

/* Macros for handling jump buffer */
#define PUSH_JUMP_BUFFER() \
do \
{ \
JumpBuffer *jb = malloc(sizeof(JumpBuffer)); \
jb->next = jump_buffer; \
jump_buffer = jb; \
#define PUSH_JUMP_BUFFER() \
do \
{ \
JumpBuffer *jb = SAFE_MALLOC(JumpBuffer); \
jb->next = jump_buffer; \
jump_buffer = jb; \
} while (0)

#define POP_JUMP_BUFFER() \
do \
{ \
JumpBuffer *jb = jump_buffer; \
jump_buffer = jump_buffer->next; \
free(jb); \
SAFE_FREE(jb); \
} while (0)

#define LONGJMP() \
Expand Down
Loading

0 comments on commit e57b3c6

Please sign in to comment.