small changes

This commit is contained in:
Timerix22 2022-05-31 19:15:28 +03:00
parent e9b740183d
commit b48405eae2
9 changed files with 30 additions and 24 deletions

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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' ' ')
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
}

View File

@ -1,10 +1,10 @@
#include "Autoarr2.hpp"
//
//
//
#include "Autoarr2.hpp"
#define MAX_BLOCK_LENGTH_DEFAULT 64
#define ALLOC_N_BLOCKS 1
template<typename T>
Autoarr2<T>::Autoarr2() {
@ -21,7 +21,7 @@ Autoarr2<T>::Autoarr2(uint16 _max_block_length) : Autoarr2() {
template<typename T>
T *Autoarr2<T>::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<T>::Set(uint32 index, T value) {
template<typename T>
void Autoarr2<T>::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;

View File

@ -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";

View File

@ -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);
}

View File

@ -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);

View File

@ -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