Skip to content

Commit

Permalink
[WIP] Load Predefined Macros, Address Memory Leaks (#384)
Browse files Browse the repository at this point in the history
* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update shared_header.h

Signed-off-by: Ian Hunter <[email protected]>

* Create tinydir.h

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update parser.py

Signed-off-by: Ian Hunter <[email protected]>

* Format code with black, gofmt, yapf, autopep8, isort and gofumpt

* Update util.py

Signed-off-by: Ian Hunter <[email protected]>

* Format code with black, gofmt, yapf, autopep8, isort and gofumpt

* Update test_macros.py

Signed-off-by: Ian Hunter <[email protected]>

* Format code with black, gofmt, yapf, autopep8, isort and gofumpt

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Format code with gofumpt, yapf, black, gofmt, isort and autopep8

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update main.cpp

Signed-off-by: Ian Hunter <[email protected]>

* Update test_macros.py

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Delete lint_SuperLinter.yml

Signed-off-by: Ian Hunter <[email protected]>

* works locally

* Format code with gofumpt, yapf, black, gofmt, isort and autopep8

* Update test_macros.py

Signed-off-by: Ian Hunter <[email protected]>

* Update main.cpp

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update test_binding_cpp.yml

Signed-off-by: Ian Hunter <[email protected]>

* Update test_binding_cpp.yml

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Update main.cpp

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update macro_logic.c

Signed-off-by: Ian Hunter <[email protected]>

* Update macro_logic.c

Signed-off-by: Ian Hunter <[email protected]>

* Update macro_logic.c

Signed-off-by: Ian Hunter <[email protected]>

* Update macro_logic.c

Signed-off-by: Ian Hunter <[email protected]>

* Update macro_logic.c

Signed-off-by: Ian Hunter <[email protected]>

* Update macro_logic.c

Signed-off-by: Ian Hunter <[email protected]>

* Update macro_logic.c

Signed-off-by: Ian Hunter <[email protected]>

* Update macro_logic.c

Signed-off-by: Ian Hunter <[email protected]>

* Update macro_logic.c

Signed-off-by: Ian Hunter <[email protected]>

* Update macro_logic.c

Signed-off-by: Ian Hunter <[email protected]>

* Update macro_logic.c

Signed-off-by: Ian Hunter <[email protected]>

* Update macro_logic.c

Signed-off-by: Ian Hunter <[email protected]>

* Update macro_logic.c

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update safe_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* working clang locally

* Update test_binding_cpp.yml

Signed-off-by: Ian Hunter <[email protected]>

* WIP changes.. memory leak  exist

* Format code with black, gofmt, gofumpt, yapf, autopep8 and isort

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* Format code with yapf, black, gofmt, gofumpt, autopep8 and isort

* remove lots of memory leaks + some smaller bugs

* Rearrange and cleanup

* Update array_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update array_functions.h

Signed-off-by: Ian Hunter <[email protected]>

* Update string_functions.h

Signed-off-by: Ian Hunter <[email protected]>

* Update string_functions.c

Signed-off-by: Ian Hunter <[email protected]>

* Update string_functions.h

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update and rename manual_valgrind.yml to manual_leakcheck.yml

Signed-off-by: Ian Hunter <[email protected]>

* Update Makefile

Signed-off-by: Ian Hunter <[email protected]>

* fix a leak

* has_source defaulted to 0 (undefined), which is true. mistakenly freeing

* fix clang

* emcc errs

* dunno why the test was passing before!

* free for math

* unfree type

* add a step to cleanup final symbols in bison/yacc

* Format code with yapf, black, gofmt, gofumpt, autopep8 and isort

* fix minor leak

* safe_strdup to have consistent length

* remove more memory leaks

* Format code with yapf, black, gofmt, gofumpt, autopep8 and isort

* fix another leak

* saf

* boop

* fix delete_all leak

* fix a big mem leak

* fix another

* fix most??

* !

* remove print

* more

* a

* fix for df.2

* more more more!

* even more leaks

* It never ends

Signed-off-by: Ian Hunter <[email protected]>

* Update requirements.txt

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* Update dice.yacc

Signed-off-by: Ian Hunter <[email protected]>

* fix doublefree

* fix re-registration

* builtins

* fix delete of macros

* fix delete of macros

Signed-off-by: Ian Hunter <[email protected]>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
  • Loading branch information
ianfhunter and deepsource-autofix[bot] authored Nov 28, 2022
1 parent ecc810f commit 95fb3f6
Show file tree
Hide file tree
Showing 33 changed files with 2,427 additions and 911 deletions.
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
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
Loading

0 comments on commit 95fb3f6

Please sign in to comment.