Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load Predefined Macros, Address many many Memory Leaks #384

Merged
merged 141 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 111 commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
efb9f26
Update dice.yacc
ianfhunter Nov 13, 2022
eb8be03
Update shared_header.h
ianfhunter Nov 13, 2022
97a948b
Create tinydir.h
ianfhunter Nov 13, 2022
1aaa19e
Update dice.yacc
ianfhunter Nov 13, 2022
efa0d90
Update parser.py
ianfhunter Nov 13, 2022
d60f94f
Format code with black, gofmt, yapf, autopep8, isort and gofumpt
deepsource-autofix[bot] Nov 13, 2022
2253878
Update util.py
ianfhunter Nov 13, 2022
b3235c6
Format code with black, gofmt, yapf, autopep8, isort and gofumpt
deepsource-autofix[bot] Nov 13, 2022
319a0ec
Update test_macros.py
ianfhunter Nov 13, 2022
b4a129b
Format code with black, gofmt, yapf, autopep8, isort and gofumpt
deepsource-autofix[bot] Nov 13, 2022
bd1cec4
Update dice.yacc
ianfhunter Nov 13, 2022
8344e5f
Update dice.yacc
ianfhunter Nov 13, 2022
59e72a8
Update dice.yacc
ianfhunter Nov 13, 2022
7efdcc2
Update dice.yacc
ianfhunter Nov 13, 2022
e817ed8
Update dice.yacc
ianfhunter Nov 13, 2022
a44b37b
Update dice.yacc
ianfhunter Nov 13, 2022
3364ac9
Format code with gofumpt, yapf, black, gofmt, isort and autopep8
deepsource-autofix[bot] Nov 13, 2022
59c0808
Update dice.yacc
ianfhunter Nov 13, 2022
bec67f5
Update dice.yacc
ianfhunter Nov 13, 2022
698f840
Update dice.yacc
ianfhunter Nov 13, 2022
32a9303
Update main.cpp
ianfhunter Nov 13, 2022
c9c6510
Update test_macros.py
ianfhunter Nov 13, 2022
e1b2366
Update dice.yacc
ianfhunter Nov 13, 2022
cf5c324
Update dice.yacc
ianfhunter Nov 13, 2022
9e5ed36
Update dice.yacc
ianfhunter Nov 14, 2022
a5ef665
Delete lint_SuperLinter.yml
ianfhunter Nov 14, 2022
17681a2
works locally
ianfhunter Nov 14, 2022
5f6b30e
Format code with gofumpt, yapf, black, gofmt, isort and autopep8
deepsource-autofix[bot] Nov 14, 2022
585f886
Update test_macros.py
ianfhunter Nov 14, 2022
7d4142b
Update main.cpp
ianfhunter Nov 14, 2022
fb49c8b
Update dice.yacc
ianfhunter Nov 14, 2022
992d437
Update dice.yacc
ianfhunter Nov 14, 2022
21feef0
Update dice.yacc
ianfhunter Nov 14, 2022
7b7a8e2
Update dice.yacc
ianfhunter Nov 14, 2022
89a4c27
Update dice.yacc
ianfhunter Nov 14, 2022
414a0d7
Update dice.yacc
ianfhunter Nov 14, 2022
3e5cb4d
Update dice.yacc
ianfhunter Nov 14, 2022
10fa5ec
Update test_binding_cpp.yml
ianfhunter Nov 14, 2022
9a72e9a
Update test_binding_cpp.yml
ianfhunter Nov 14, 2022
ad99cb2
Update Makefile
ianfhunter Nov 14, 2022
6e54646
Update Makefile
ianfhunter Nov 14, 2022
be3ba59
Update Makefile
ianfhunter Nov 14, 2022
ba9a337
Update Makefile
ianfhunter Nov 14, 2022
3adca55
Update main.cpp
ianfhunter Nov 14, 2022
90f15be
Update dice.yacc
ianfhunter Nov 14, 2022
1e84de9
Update dice.yacc
ianfhunter Nov 14, 2022
8665750
Update dice.yacc
ianfhunter Nov 14, 2022
7c6cd22
Update dice.yacc
ianfhunter Nov 14, 2022
72df248
Update dice.yacc
ianfhunter Nov 14, 2022
f475879
Update dice.yacc
ianfhunter Nov 14, 2022
cd24f91
Update dice.yacc
ianfhunter Nov 14, 2022
f72e5c9
Update macro_logic.c
ianfhunter Nov 14, 2022
5fa3bc8
Update macro_logic.c
ianfhunter Nov 14, 2022
b755239
Update macro_logic.c
ianfhunter Nov 14, 2022
97ce3c6
Update macro_logic.c
ianfhunter Nov 14, 2022
ed9478e
Update macro_logic.c
ianfhunter Nov 14, 2022
dbaa363
Update macro_logic.c
ianfhunter Nov 14, 2022
bcd2f84
Update macro_logic.c
ianfhunter Nov 15, 2022
32608db
Update macro_logic.c
ianfhunter Nov 15, 2022
49b8252
Update macro_logic.c
ianfhunter Nov 15, 2022
ea0957b
Update macro_logic.c
ianfhunter Nov 15, 2022
be4e138
Update macro_logic.c
ianfhunter Nov 15, 2022
89cc6c9
Update macro_logic.c
ianfhunter Nov 15, 2022
9897676
Update macro_logic.c
ianfhunter Nov 15, 2022
d4ea17c
Update safe_functions.c
ianfhunter Nov 15, 2022
ee51678
Update safe_functions.c
ianfhunter Nov 15, 2022
21259b4
Update safe_functions.c
ianfhunter Nov 15, 2022
4e11f72
Update safe_functions.c
ianfhunter Nov 15, 2022
b304c39
Update dice.yacc
ianfhunter Nov 15, 2022
97b40e5
Update dice.yacc
ianfhunter Nov 15, 2022
5e9db44
Update safe_functions.c
ianfhunter Nov 15, 2022
b8e5b3f
Update dice.yacc
ianfhunter Nov 15, 2022
29bc77b
Update dice.yacc
ianfhunter Nov 15, 2022
1609a70
Update dice.yacc
ianfhunter Nov 15, 2022
066a88b
Update dice.yacc
ianfhunter Nov 15, 2022
09d4a8b
Update dice.yacc
ianfhunter Nov 15, 2022
69414cf
Update dice.yacc
ianfhunter Nov 15, 2022
815275f
Update dice.yacc
ianfhunter Nov 15, 2022
9189824
working clang locally
ianfhunter Nov 15, 2022
23cd66e
Update test_binding_cpp.yml
ianfhunter Nov 15, 2022
d40bd9d
WIP changes.. memory leak exist
ianfhunter Nov 19, 2022
cf35df9
Format code with black, gofmt, gofumpt, yapf, autopep8 and isort
deepsource-autofix[bot] Nov 19, 2022
125a2da
Update dice.yacc
ianfhunter Nov 20, 2022
b13da53
Update dice.yacc
ianfhunter Nov 20, 2022
1f3830a
Merge branch 'main' into load_builtins
ianfhunter Nov 21, 2022
e56dd2d
Update Makefile
ianfhunter Nov 23, 2022
cfde366
Format code with yapf, black, gofmt, gofumpt, autopep8 and isort
deepsource-autofix[bot] Nov 23, 2022
b9c9b95
remove lots of memory leaks + some smaller bugs
ianfhunter Nov 26, 2022
96042a2
Rearrange and cleanup
ianfhunter Nov 26, 2022
7f59554
Update array_functions.c
ianfhunter Nov 26, 2022
651f875
Update array_functions.h
ianfhunter Nov 26, 2022
a4622a2
Update string_functions.h
ianfhunter Nov 26, 2022
f52caf3
Update string_functions.c
ianfhunter Nov 26, 2022
8b06944
Merge branch 'main' into load_builtins
ianfhunter Nov 26, 2022
41a1516
Update string_functions.h
ianfhunter Nov 26, 2022
1691291
Update dice.yacc
ianfhunter Nov 26, 2022
a25b3f1
Update dice.yacc
ianfhunter Nov 26, 2022
e5fec7e
Update dice.yacc
ianfhunter Nov 26, 2022
dfd6920
Update dice.yacc
ianfhunter Nov 26, 2022
e02cc0e
Update dice.yacc
ianfhunter Nov 26, 2022
999985f
Update dice.yacc
ianfhunter Nov 26, 2022
2f0d3ad
Update and rename manual_valgrind.yml to manual_leakcheck.yml
ianfhunter Nov 26, 2022
7fbb20d
Update Makefile
ianfhunter Nov 26, 2022
ce7989e
fix a leak
ianfhunter Nov 26, 2022
50fea77
has_source defaulted to 0 (undefined), which is true. mistakenly freeing
ianfhunter Nov 26, 2022
db8f7a1
fix clang
ianfhunter Nov 26, 2022
6382196
emcc errs
ianfhunter Nov 26, 2022
60ece23
dunno why the test was passing before!
ianfhunter Nov 26, 2022
b60ac5a
free for math
ianfhunter Nov 26, 2022
5678214
unfree type
ianfhunter Nov 26, 2022
edeff30
add a step to cleanup final symbols in bison/yacc
ianfhunter Nov 26, 2022
3166e0f
Format code with yapf, black, gofmt, gofumpt, autopep8 and isort
deepsource-autofix[bot] Nov 26, 2022
b963160
fix minor leak
ianfhunter Nov 26, 2022
39bcffd
Merge branch 'load_builtins' of github.com:ianfhunter/GNOLL into load…
ianfhunter Nov 26, 2022
53181be
safe_strdup to have consistent length
ianfhunter Nov 27, 2022
224730d
remove more memory leaks
ianfhunter Nov 27, 2022
70964ba
Format code with yapf, black, gofmt, gofumpt, autopep8 and isort
deepsource-autofix[bot] Nov 27, 2022
31f5afd
fix another leak
ianfhunter Nov 27, 2022
8e8f38b
saf
ianfhunter Nov 27, 2022
3f43884
boop
ianfhunter Nov 27, 2022
76e7e8f
fix delete_all leak
ianfhunter Nov 27, 2022
0f3c749
fix a big mem leak
ianfhunter Nov 27, 2022
9b15682
fix another
ianfhunter Nov 27, 2022
c29975f
fix most??
ianfhunter Nov 27, 2022
6d90576
!
ianfhunter Nov 27, 2022
5f20ffc
remove print
ianfhunter Nov 27, 2022
a18b2a1
more
ianfhunter Nov 27, 2022
fcc05c2
a
ianfhunter Nov 27, 2022
1f1073f
fix for df.2
ianfhunter Nov 27, 2022
e0ad921
more more more!
ianfhunter Nov 27, 2022
b361b59
even more leaks
ianfhunter Nov 27, 2022
a82dd7c
It never ends
ianfhunter Nov 27, 2022
ef12ceb
Update requirements.txt
ianfhunter Nov 27, 2022
240a711
Update dice.yacc
ianfhunter Nov 28, 2022
b4c27e0
Update dice.yacc
ianfhunter Nov 28, 2022
7fcbf60
Update dice.yacc
ianfhunter Nov 28, 2022
fc4a82f
fix doublefree
ianfhunter Nov 28, 2022
c19b7da
fix re-registration
ianfhunter Nov 28, 2022
c0d06f0
builtins
ianfhunter Nov 28, 2022
0cd6a9f
fix delete of macros
ianfhunter Nov 28, 2022
a66da46
fix delete of macros
ianfhunter Nov 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ jobs:
- name: Lib Install
run: |
sudo apt-get install valgrind
make all DEBUG=1

- name: Run Asan
run: |
make all DEBUG=2
./build/dice d20
- name: Run Valgrind
run: valgrind --leak-check=full ./build/dice d20
run: |
make all DEBUG=1
valgrind --leak-check=full ./build/dice d20
3 changes: 2 additions & 1 deletion .github/workflows/test_binding_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ jobs:
- uses: actions/checkout@v3
- name: make
run: |
make CC=clang all
clang --version
make CC=clang DEBUG=0 all
./build/dice d20

build_cpp:
Expand Down
34 changes: 30 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ else
STANDARD= -std=c99
endif

OPT=-O3 $(STANDARD) -Wall -Wextra -Werror -pedantic -Wcast-align \


OPT=-O3 \
$(STANDARD) -Wall -Wextra -Werror -pedantic -Wcast-align \
-Wcast-qual -Wdisabled-optimization -Winit-self \
-Wmissing-declarations -Wmissing-include-dirs \
-Wredundant-decls -Wshadow -Wsign-conversion \
-Wundef -Wno-unused -Wformat=2
-Wundef -Wno-unused -Wformat=2


# -ffast-math # Problematic for Python

Expand All @@ -26,13 +30,35 @@ OPT=-O3 $(STANDARD) -Wall -Wextra -Werror -pedantic -Wcast-align \
# -Wlogical-op

# === DEBUG OPTIONS ====

ASAN_FLAGS= -fsanitize=address \
-fsanitize-recover=address \
-fsanitize-address-use-after-scope \
-fno-omit-frame-pointer -static-libasan -g
GDB_FLAGS= -g -gdwarf-5

DEBUG=0
ifeq ($(DEBUG), 1)
OPT=-O0 -g # Valgrind info
# Valgrind
OPT=-O0 $(GDB_FLAGS)
PARSER_DEBUG:=--debug --verbose
else
ifeq ($(DEBUG), 2)
# ASAN
OPT=-O0 $(ASAN_FLAGS)
PARSER_DEBUG:=
else
ifeq ($(DEBUG), 3)
# ASAN
OPT=-O0 $(GDB_FLAGS) -lefence
PARSER_DEBUG:=
else
# USUAL
PARSER_DEBUG:=
endif
endif
endif


USE_SECURE_RANDOM=0
ifeq ($(USE_SECURE_RANDOM), 1)
Expand Down Expand Up @@ -62,7 +88,7 @@ LEXER:=flex -f -Ca -Ce -Cr
endif

# add flags and the include paths
DEFS=-DUSE_SECURE_RANDOM=${USE_SECURE_RANDOM} -DJUST_YACC=${YACC_FALLBACK} -DBREAKDOWN
DEFS=-DUSE_SECURE_RANDOM=${USE_SECURE_RANDOM} -DJUST_YACC=${YACC_FALLBACK}

CFLAGS=$(foreach D,$(INCDIRS),-I$(D)) $(OPT) $(DEFS)

Expand Down
1 change: 1 addition & 0 deletions reqs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ cppyy
# tests
pytest
numpy>=1.22.2
wurlitzer

# distribution
build
Expand Down
11 changes: 1 addition & 10 deletions src/C++/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
#include <string.h>
#include "shared_header.h"

int roll_full_options(
char* roll_request,
char* log_file,
int enable_verbosity,
int enable_introspection,
int enable_mocking,
int mocking_type,
int mocking_seed
);

int main()
{
const char* fn = "out.dice";
Expand All @@ -27,6 +17,7 @@ int main()
0,
0,
0,
0,
0
);
assert(err_code == 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#ifndef __DICE_ENUMS_H__
#define __DICE_ENUMS_H__
typedef enum {
// 0 is invalid
SYMBOLIC = 1,
NUMERIC = 2
} DIE_TYPE;
typedef enum {
NO_EXPLOSION = 0,
STANDARD_EXPLOSION = 1,
ONLY_ONCE_EXPLOSION = 2,
PENETRATING_EXPLOSION = 3,
DIMINISHING_EXPLOSION = 4
} EXPLOSION_TYPE;
#endif
#ifndef __DICE_ENUMS_H__
#define __DICE_ENUMS_H__

typedef enum {
// 0 is invalid
SYMBOLIC = 1,
NUMERIC = 2
} DIE_TYPE;

typedef enum {
NO_EXPLOSION = 0,
STANDARD_EXPLOSION = 1,
ONLY_ONCE_EXPLOSION = 2,
PENETRATING_EXPLOSION = 3,
DIMINISHING_EXPLOSION = 4
} EXPLOSION_TYPE;

#endif
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#ifndef __DICE_ROLL_STRUCTS_H__
#define __DICE_ROLL_STRUCTS_H__
#include "dice_enums.h"
typedef struct roll_params {
unsigned int number_of_dice;
unsigned int die_sides;
EXPLOSION_TYPE explode;
char** symbol_pool;
int start_value;
DIE_TYPE dtype;
} roll_params;
#endif
#ifndef __DICE_ROLL_STRUCTS_H__
#define __DICE_ROLL_STRUCTS_H__

#include "constructs/dice_enums.h"

typedef struct roll_params {
unsigned int number_of_dice;
unsigned int die_sides;
EXPLOSION_TYPE explode;
char** symbol_pool;
int start_value;
DIE_TYPE dtype;
} roll_params;

#endif
36 changes: 19 additions & 17 deletions src/grammar/rolls/vec.h → src/grammar/constructs/vec.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#ifndef __VEC_H__
#define __VEC_H__

#include "dice_enums.h"
#include "dice_roll_structs.h"

typedef struct vec {
DIE_TYPE dtype;
int* content;
unsigned int length;
// TODO: Split length into content_length and symbol length
// maybe use union? If it exists in c
char** symbols;
roll_params source;
} vec;

#endif
#ifndef __VEC_H__
#define __VEC_H__

#include "constructs/dice_enums.h"
#include "constructs/roll_parameters.h"
#include <stdbool.h>

typedef struct vec {
DIE_TYPE dtype;
int* content;
unsigned int length;
// TODO: Split length into content_length and symbol length
// maybe use union? If it exists in c
char** symbols;
roll_params source;
bool has_source;
} vec;

#endif
16 changes: 15 additions & 1 deletion src/grammar/dice.lex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <stdio.h>
#include "shared_header.h"
#include "util/safe_functions.h"
#include "operations/condition_checking.h"
#include "operations/conditionals.h"
#include "y.tab.h"
#include <assert.h>

Expand All @@ -31,6 +31,7 @@

vector.dtype = SYMBOLIC;
vector.length = 1;
vector.has_source = false;

yylval.values = vector;
return CAPITAL_STRING;
Expand All @@ -43,6 +44,7 @@

vector.content[0] = fast_atoi(yytext);

vector.has_source = false;
vector.dtype = NUMERIC;
vector.length = 1;
yylval.values = vector;
Expand Down Expand Up @@ -80,6 +82,7 @@ d {
vector.symbols[4] = zero;
vector.symbols[5] = minus;
vector.length = 6;
vector.has_source = false;
yylval.values = vector;

return(FATE_DIE);
Expand All @@ -100,6 +103,7 @@ d {
vector.symbols[0] = plus;
vector.symbols[1] = minus;
vector.length = 2;
vector.has_source = false;
yylval.values = vector;

return(FATE_DIE);
Expand All @@ -123,6 +127,7 @@ d {
vector.symbols[0] = plus;
vector.symbols[1] = zero;
vector.symbols[2] = minus;
vector.has_source = false;
vector.length = 3;
yylval.values = vector;

Expand Down Expand Up @@ -197,6 +202,7 @@ u {
vector.content[0] = IS_UNIQUE;
vector.dtype = NUMERIC;
vector.length = 1;
vector.has_source = false;
yylval.values = vector;
return (UNIQUE);
}
Expand All @@ -223,6 +229,7 @@ o {
vector.content[0] = NOT_EQUAL;
vector.dtype = NUMERIC;
vector.length = 1;
vector.has_source = false;
yylval.values = vector;
return NE;
}
Expand All @@ -233,6 +240,7 @@ o {
vector.content[0] = EQUALS;
vector.dtype = NUMERIC;
vector.length = 1;
vector.has_source = false;
yylval.values = vector;
return EQ;
}
Expand All @@ -243,6 +251,7 @@ o {
vector.content[0] = LESS_THAN;
vector.dtype = NUMERIC;
vector.length = 1;
vector.has_source = false;
yylval.values = vector;
return LT;
}
Expand All @@ -252,6 +261,7 @@ o {
if(gnoll_errno){yyerror("Memory Err");}
vector.content[0] = GREATER_THAN;
vector.dtype = NUMERIC;
vector.has_source = false;
vector.length = 1;
yylval.values = vector;
return GT;
Expand All @@ -263,6 +273,7 @@ o {
vector.content[0] = LESS_OR_EQUALS;
vector.dtype = NUMERIC;
vector.length = 1;
vector.has_source = false;
yylval.values = vector;
return(LE);
}
Expand All @@ -273,6 +284,7 @@ o {
vector.content[0] = GREATER_OR_EQUALS;
vector.dtype = NUMERIC;
vector.length = 1;
vector.has_source = false;
yylval.values = vector;
return(GE);
}
Expand All @@ -283,6 +295,7 @@ is_even {
vector.content[0] = IF_EVEN;
vector.dtype = NUMERIC;
vector.length = 1;
vector.has_source = false;
yylval.values = vector;
return(IS_EVEN);
}
Expand All @@ -293,6 +306,7 @@ is_odd {
vector.content[0] = IF_ODD;
vector.dtype = NUMERIC;
vector.length = 1;
vector.has_source = false;
yylval.values = vector;
return(IS_ODD);
}
Expand Down
Loading