From 5bc866cf3e7a838825773dc7ebc0121609314af2 Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Mon, 21 Mar 2022 23:20:24 +0300 Subject: [PATCH] build_dll --- .gitignore | 21 +++++++++++++++++++ DtsodParser/DtsodV24.h | 7 ++++++- Makefile | 44 +++++++++++++++++++++++++--------------- base/types.h | 8 ++++---- tests/main.c | 13 ++++++++++-- tests/test_marshalling.h | 13 ++++++++++++ tests/tests.h | 2 +- 7 files changed, 84 insertions(+), 24 deletions(-) create mode 100644 .gitignore create mode 100644 tests/test_marshalling.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1e6cd00 --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +# Build results +[Bb]in/ +.bin/ +[Dd]ebug/ +[Rr]elease/ +[Rr]eleases/ +[Oo]bj/ +[Oo]ut/ +[Ll]og/ +[Ll]ogs/ + +# IDE files +.vs/ +.vscode/ +.vshistory/ +.idea/ +.editorconfig +*.user + +#backups +.old*/ \ No newline at end of file diff --git a/DtsodParser/DtsodV24.h b/DtsodParser/DtsodV24.h index 2b15f1a..7500c60 100644 --- a/DtsodParser/DtsodV24.h +++ b/DtsodParser/DtsodV24.h @@ -1,5 +1,5 @@ #if __cplusplus -extern "c" { +extern "C" { #endif #pragma once @@ -8,14 +8,19 @@ extern "c" { //parses text to binary values Hashtable* DtsodV24_deserialize(char* text); + //creates text representation of dtsod char* DtsodV24_serialize(Hashtable* dtsod); + //returns value or UniNull if key not found Unitype DtsodV24_get(Hashtable* dtsod, char* key); + //adds or sets value void DtsodV24_addOrSet(Hashtable* dtsod, char* key, Unitype value); + //checks for dtsod contains value or dont bool DtsodV24_contains(Hashtable* dtsod, char* key); + //replaces value with UniNull if key exists in dtsod bool DtsodV24_remove(Hashtable* dtsod, char* key); diff --git a/Makefile b/Makefile index d6bea83..d60a0f2 100644 --- a/Makefile +++ b/Makefile @@ -1,33 +1,45 @@ SRC=$(wildcard [^tests]**/*.c) TESTS=$(wildcard tests/*c) $(wildcard tests/**/*.c) OUTDIR=.bin -OUTFILE=$(OUTDIR)/kerep_test.com CMP=gcc -all: clear_c build test + +all: clear_c clear_bin build_test build_dll clear_c: clear + clear_bin: @echo -e '\e[96m--------------[clear_bin]--------------\e[0m' - touch $(OUTDIR)/_.com - rm $(OUTDIR)/*.com + rm -rf $(OUTDIR) + mkdir $(OUTDIR) clang: CMP=clang clang: all -CMPARGS= -Wall -Wno-discarded-qualifiers $(SRC) $(TESTS) -o $(OUTFILE) -build: - @echo -e '\n\e[96m----------------[build]----------------\e[0m' - @mkdir -p $(OUTDIR) - $(CMP) -O1 -flto $(CMPARGS) -build_dbg: - @echo -e '\n\e[96m--------------[build_dbg]--------------\e[0m' - @mkdir -p $(OUTDIR) - $(CMP) -O0 -g $(CMPARGS).dbg +TEST_FILE=$(OUTDIR)/kerep_test.com +TEST_ARGS= -Wall -Wno-discarded-qualifiers $(SRC) $(TESTS) -o $(TEST_FILE) +OPT_ARGS= -O1 -flto +build_test: + @echo -e '\n\e[96m----------------[build_test]----------------\e[0m' + $(CMP) $(OPT_ARGS) $(TEST_ARGS) + +build_test_dbg: + @echo -e '\n\e[96m--------------[build_test_dbg]--------------\e[0m' + $(CMP) -O0 -g $(TEST_ARGS).dbg + test: @echo -e '\n\e[96m----------------[test]-----------------\e[0m' - $(OUTFILE) -valgrind: clear_c build_dbg + $(TEST_FILE) + +valgrind: clear_c build_test_dbg @echo -e '\n\e[96m--------------[valgrind]---------------\e[0m' valgrind -s --read-var-info=yes --track-origins=yes --fullpath-after=kerep/ \ - --leak-check=full --show-leak-kinds=all $(OUTFILE).dbg + --leak-check=full --show-leak-kinds=all $(TEST_FILE).dbg + +DLL_FILE=$(OUTDIR)/kerep.dll +DLL_ARGS= -Wall -Wno-discarded-qualifiers \ + -fPIC -shared -Wl,-soname,kerep.dll \ + $(SRC) $(TESTS) -o $(DLL_FILE) +build_dll: + @echo -e '\n\e[96m-------------[build_dll]---------------\e[0m' + $(CMP) $(OPT_ARGS) $(DLL_ARGS) diff --git a/base/types.h b/base/types.h index 3bc5728..3405a07 100644 --- a/base/types.h +++ b/base/types.h @@ -29,7 +29,6 @@ int8 typesize(my_type type); // can store any base type typedef struct Unitype{ - my_type type; union { int64 Int64; uint64 UInt64; @@ -38,11 +37,12 @@ typedef struct Unitype{ bool Bool; void* VoidPtr; }; + my_type type; } Unitype; -static const Unitype UniNull={Null,.VoidPtr=NULL}; -static const Unitype UniTrue={Bool,.Bool=true}; -static const Unitype UniFalse={Bool,.Bool=false}; +static const Unitype UniNull={.VoidPtr=NULL,.type=Null}; +static const Unitype UniTrue={.Bool=true,.type=Bool}; +static const Unitype UniFalse={.Bool=false,.type=Bool}; #define Uni(TYPE,VAL) (Unitype){.type=TYPE,.TYPE=VAL} #define UniPtr(TYPE,VAL) (Unitype){.type=TYPE,.VoidPtr=VAL} diff --git a/tests/main.c b/tests/main.c index e9ffe28..d120d77 100644 --- a/tests/main.c +++ b/tests/main.c @@ -1,11 +1,20 @@ #include "../base/base.h" #include "tests.h" +#include "../Hashtable/KeyValuePair.h" + +KeyValuePair test_marshalling(char* text){ + //printf("<%s>\n", text); + Unitype u={.VoidPtr=text,.type=CharPtr}; + KeyValuePair msg={"message",u}; + return msg; +} + void test_all(){ - /* test_searchtree(); + test_searchtree(); test_autoarr(); test_hashtable(); - test_string(); */ + test_string(); test_dtsod(); printf("\e[96m---------------------------------------\e[0m\n"); } diff --git a/tests/test_marshalling.h b/tests/test_marshalling.h new file mode 100644 index 0000000..f1b3582 --- /dev/null +++ b/tests/test_marshalling.h @@ -0,0 +1,13 @@ +#pragma once + +#if __cplusplus +extern "C" { +#endif + +#include "../Hashtable/KeyValuePair.h" + +KeyValuePair test_marshalling(char* text); + +#if __cplusplus +} +#endif \ No newline at end of file diff --git a/tests/tests.h b/tests/tests.h index a357fd2..220ac56 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -8,4 +8,4 @@ void test_searchtree(); void test_autoarr(); void test_hashtable(); void test_string(); -void test_dtsod(); +void test_dtsod(); \ No newline at end of file