diff --git a/Makefile b/Makefile index c5b6c64..0c16c3e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -###### Build tasks ####### +###### Building tasks ####### build_test: @build_scripts/build_test.sh @@ -12,4 +12,4 @@ test: test_valgrind: @build_scripts/test_valgrind.sh -all: build_test test +all: build_test diff --git a/build_scripts/build_lib.sh b/build_scripts/build_lib.sh index 20604be..45bb44b 100644 --- a/build_scripts/build_lib.sh +++ b/build_scripts/build_lib.sh @@ -6,6 +6,5 @@ print "${CYAN}=============[build_lib]==============\n" clear_dir bin clear_dir obj compile_c "-O2 -fpic -shared" "$SRC_C tests/test_marshalling.c" -compile_cpp "-flto -Wl,-soname,$LIB_FILE" "$SRC_CPP" -link " " $LIB_FILE -rm -rf $OBJDIR +compile_cpp "-O2 -fpic -shared" "$SRC_CPP" +link "-shared -O2 -fpic -flto -Wl,-soname,$LIB_FILE" "$LIB_FILE" diff --git a/build_scripts/build_test.sh b/build_scripts/build_test.sh index 18bee46..26bc10f 100644 --- a/build_scripts/build_test.sh +++ b/build_scripts/build_test.sh @@ -8,4 +8,3 @@ clear_dir obj compile_c "-O0 -g" "$SRC_C $TESTS_C" compile_cpp "-O0 -g" "$SRC_CPP $TESTS_CPP" link " " $TEST_FILE -rm -rf $OBJDIR diff --git a/build_scripts/functions.sh b/build_scripts/functions.sh index 3aacfd1..ff45314 100644 --- a/build_scripts/functions.sh +++ b/build_scripts/functions.sh @@ -48,6 +48,12 @@ function link { print "${BLUE}outfile: ${GRAY}$outfile\n" local objects="$(find $OBJDIR -name *.o)" print "${BLUE}objects: ${GRAY}$objects\n" - $CMP_C $args -o $outfile $(echo $objects | tr '\n' ' ') - print "${GREEN}file $CYAN$outfile ${GREEN}created\n" + if $CMP_C $args -o $outfile $(echo $objects | tr '\n' ' ') + then + print "${GREEN}file $CYAN$outfile ${GREEN}created\n" + rm -rf $OBJDIR + else + print "${RED}some error happened\n" + exit + fi } diff --git a/src/Autoarr/Autoarr2.cpp b/src/Autoarr/Autoarr2.cpp index acbf1be..2402c13 100644 --- a/src/Autoarr/Autoarr2.cpp +++ b/src/Autoarr/Autoarr2.cpp @@ -1,10 +1,10 @@ -#include "Autoarr2.hpp" // // // +#include "Autoarr2.hpp" + #define MAX_BLOCK_LENGTH_DEFAULT 64 -#define ALLOC_N_BLOCKS 1 template Autoarr2::Autoarr2() { @@ -21,7 +21,7 @@ Autoarr2::Autoarr2(uint16 _max_block_length) : Autoarr2() { template T *Autoarr2::GetPtr(uint32 index) { - if(index>=Length) throwcpp(ERR_WRONGINDEX); + if(index>=Length) throwcpp_id(ERR_WRONGINDEX); return values[index/max_block_length]+index%max_block_length; } @@ -38,15 +38,15 @@ void Autoarr2::Set(uint32 index, T value) { template void Autoarr2::Add(T value) { if(!values){ - values=malloc(ALLOC_N_BLOCKS*sizeof(T*)); + values=malloc(sizeof(T*)); goto create_block; } else if(block_length==max_block_length){ block_length=0; create_block: - values=realloc((blocks_count+ALLOC_N_BLOCKS)*sizeof(T*)); - blocks_count+=ALLOC_N_BLOCKS; + values=realloc(values,(blocks_count+1)*sizeof(T*)); values[blocks_count]=malloc(max_block_length*sizeof(T)); + blocks_count++; } values[blocks_count-1][block_length]=value; diff --git a/src/base/errors.c b/src/base/errors.c index f5c317c..a2a2864 100644 --- a/src/base/errors.c +++ b/src/base/errors.c @@ -2,7 +2,7 @@ #include "errors.h" #include "cptr.h" -char* errname(err_t err){ +char* errname(ErrorId err){ switch(err){ case SUCCESS: return "SUCCESS"; case ERR_MAXLENGTH: return "ERR_MAXLENGTH"; diff --git a/src/base/errors.cpp b/src/base/errors.cpp index ec1e963..7614c5f 100644 --- a/src/base/errors.cpp +++ b/src/base/errors.cpp @@ -1,9 +1,9 @@ #include "errors.hpp" -void throwcpp(err_t eid){ - throwcpp(errname(eid)); +void throwcpp_id(ErrorId eid){ + throwcpp_msg(errname(eid)); } -void throwcpp(char* emsg){ +void throwcpp_msg(char* emsg){ __EXIT(emsg); } \ No newline at end of file diff --git a/src/base/errors.h b/src/base/errors.h index 19da077..b536038 100644 --- a/src/base/errors.h +++ b/src/base/errors.h @@ -7,12 +7,12 @@ extern "C" { #include "std.h" #include "types.h" -typedef enum err_t { +typedef enum ErrorId { SUCCESS, // not an error ERR_MAXLENGTH, ERR_WRONGTYPE, ERR_WRONGINDEX, ERR_NOTIMPLEMENTED, ERR_NULLPTR, ERR_ENDOFSTR -} err_t; +} ErrorId; -char* errname(err_t err); +char* errname(ErrorId err); char* __genErrMsg(const char* errmsg, const char* srcfile, int line, const char* funcname); char* __extendErrMsg(const char* errmsg, const char* srcfile, int line, const char* funcname); @@ -21,8 +21,10 @@ typedef struct Maybe{ Unitype value; char* errmsg; } Maybe; + // return it if func doesn't return anything -static const Maybe MaybeNull={.value.type=Null, .value.VoidPtr=NULL,.errmsg=NULL}; +// .value .errmsg +static const Maybe MaybeNull={UniNull, NULL}; void Maybe_free(Maybe e); void printMaybe(Maybe e); diff --git a/src/base/errors.hpp b/src/base/errors.hpp index 93cdb3c..ad19bd7 100644 --- a/src/base/errors.hpp +++ b/src/base/errors.hpp @@ -3,6 +3,6 @@ #ifdef __cplusplus #include "errors.h" -void throwcpp(err_t eid); -void throwcpp(char* emsg); +void throwcpp_id(ErrorId eid); +void throwcpp_msg(char* emsg); #endif \ No newline at end of file