small changes
This commit is contained in:
parent
e9b740183d
commit
b48405eae2
4
Makefile
4
Makefile
@ -1,4 +1,4 @@
|
|||||||
###### Build tasks #######
|
###### Building tasks #######
|
||||||
build_test:
|
build_test:
|
||||||
@build_scripts/build_test.sh
|
@build_scripts/build_test.sh
|
||||||
|
|
||||||
@ -12,4 +12,4 @@ test:
|
|||||||
test_valgrind:
|
test_valgrind:
|
||||||
@build_scripts/test_valgrind.sh
|
@build_scripts/test_valgrind.sh
|
||||||
|
|
||||||
all: build_test test
|
all: build_test
|
||||||
|
|||||||
@ -6,6 +6,5 @@ print "${CYAN}=============[build_lib]==============\n"
|
|||||||
clear_dir bin
|
clear_dir bin
|
||||||
clear_dir obj
|
clear_dir obj
|
||||||
compile_c "-O2 -fpic -shared" "$SRC_C tests/test_marshalling.c"
|
compile_c "-O2 -fpic -shared" "$SRC_C tests/test_marshalling.c"
|
||||||
compile_cpp "-flto -Wl,-soname,$LIB_FILE" "$SRC_CPP"
|
compile_cpp "-O2 -fpic -shared" "$SRC_CPP"
|
||||||
link " " $LIB_FILE
|
link "-shared -O2 -fpic -flto -Wl,-soname,$LIB_FILE" "$LIB_FILE"
|
||||||
rm -rf $OBJDIR
|
|
||||||
|
|||||||
@ -8,4 +8,3 @@ clear_dir obj
|
|||||||
compile_c "-O0 -g" "$SRC_C $TESTS_C"
|
compile_c "-O0 -g" "$SRC_C $TESTS_C"
|
||||||
compile_cpp "-O0 -g" "$SRC_CPP $TESTS_CPP"
|
compile_cpp "-O0 -g" "$SRC_CPP $TESTS_CPP"
|
||||||
link " " $TEST_FILE
|
link " " $TEST_FILE
|
||||||
rm -rf $OBJDIR
|
|
||||||
|
|||||||
@ -48,6 +48,12 @@ function link {
|
|||||||
print "${BLUE}outfile: ${GRAY}$outfile\n"
|
print "${BLUE}outfile: ${GRAY}$outfile\n"
|
||||||
local objects="$(find $OBJDIR -name *.o)"
|
local objects="$(find $OBJDIR -name *.o)"
|
||||||
print "${BLUE}objects: ${GRAY}$objects\n"
|
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' ' ')
|
||||||
print "${GREEN}file $CYAN$outfile ${GREEN}created\n"
|
then
|
||||||
|
print "${GREEN}file $CYAN$outfile ${GREEN}created\n"
|
||||||
|
rm -rf $OBJDIR
|
||||||
|
else
|
||||||
|
print "${RED}some error happened\n"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
#include "Autoarr2.hpp"
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include "Autoarr2.hpp"
|
||||||
|
|
||||||
#define MAX_BLOCK_LENGTH_DEFAULT 64
|
#define MAX_BLOCK_LENGTH_DEFAULT 64
|
||||||
#define ALLOC_N_BLOCKS 1
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Autoarr2<T>::Autoarr2() {
|
Autoarr2<T>::Autoarr2() {
|
||||||
@ -21,7 +21,7 @@ Autoarr2<T>::Autoarr2(uint16 _max_block_length) : Autoarr2() {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T *Autoarr2<T>::GetPtr(uint32 index) {
|
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;
|
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>
|
template<typename T>
|
||||||
void Autoarr2<T>::Add(T value) {
|
void Autoarr2<T>::Add(T value) {
|
||||||
if(!values){
|
if(!values){
|
||||||
values=malloc(ALLOC_N_BLOCKS*sizeof(T*));
|
values=malloc(sizeof(T*));
|
||||||
goto create_block;
|
goto create_block;
|
||||||
}
|
}
|
||||||
else if(block_length==max_block_length){
|
else if(block_length==max_block_length){
|
||||||
block_length=0;
|
block_length=0;
|
||||||
create_block:
|
create_block:
|
||||||
values=realloc((blocks_count+ALLOC_N_BLOCKS)*sizeof(T*));
|
values=realloc(values,(blocks_count+1)*sizeof(T*));
|
||||||
blocks_count+=ALLOC_N_BLOCKS;
|
|
||||||
values[blocks_count]=malloc(max_block_length*sizeof(T));
|
values[blocks_count]=malloc(max_block_length*sizeof(T));
|
||||||
|
blocks_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
values[blocks_count-1][block_length]=value;
|
values[blocks_count-1][block_length]=value;
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
#include "cptr.h"
|
#include "cptr.h"
|
||||||
|
|
||||||
char* errname(err_t err){
|
char* errname(ErrorId err){
|
||||||
switch(err){
|
switch(err){
|
||||||
case SUCCESS: return "SUCCESS";
|
case SUCCESS: return "SUCCESS";
|
||||||
case ERR_MAXLENGTH: return "ERR_MAXLENGTH";
|
case ERR_MAXLENGTH: return "ERR_MAXLENGTH";
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
#include "errors.hpp"
|
#include "errors.hpp"
|
||||||
|
|
||||||
void throwcpp(err_t eid){
|
void throwcpp_id(ErrorId eid){
|
||||||
throwcpp(errname(eid));
|
throwcpp_msg(errname(eid));
|
||||||
}
|
}
|
||||||
|
|
||||||
void throwcpp(char* emsg){
|
void throwcpp_msg(char* emsg){
|
||||||
__EXIT(emsg);
|
__EXIT(emsg);
|
||||||
}
|
}
|
||||||
@ -7,12 +7,12 @@ extern "C" {
|
|||||||
#include "std.h"
|
#include "std.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
typedef enum err_t {
|
typedef enum ErrorId {
|
||||||
SUCCESS, // not an error
|
SUCCESS, // not an error
|
||||||
ERR_MAXLENGTH, ERR_WRONGTYPE, ERR_WRONGINDEX, ERR_NOTIMPLEMENTED, ERR_NULLPTR, ERR_ENDOFSTR
|
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* __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);
|
char* __extendErrMsg(const char* errmsg, const char* srcfile, int line, const char* funcname);
|
||||||
@ -21,8 +21,10 @@ typedef struct Maybe{
|
|||||||
Unitype value;
|
Unitype value;
|
||||||
char* errmsg;
|
char* errmsg;
|
||||||
} Maybe;
|
} Maybe;
|
||||||
|
|
||||||
// return it if func doesn't return anything
|
// 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 Maybe_free(Maybe e);
|
||||||
void printMaybe(Maybe e);
|
void printMaybe(Maybe e);
|
||||||
|
|||||||
@ -3,6 +3,6 @@
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
|
||||||
void throwcpp(err_t eid);
|
void throwcpp_id(ErrorId eid);
|
||||||
void throwcpp(char* emsg);
|
void throwcpp_msg(char* emsg);
|
||||||
#endif
|
#endif
|
||||||
Loading…
Reference in New Issue
Block a user