From 919bc6fcbdf9f46cb82f4d675a67c01625fab909 Mon Sep 17 00:00:00 2001 From: cozis Date: Tue, 16 Aug 2022 22:45:46 +0200 Subject: [PATCH] fixed compiler warnings for release builds --- src/lib/builtins/basic.c | 81 ++++++----- src/lib/builtins/math.c | 112 +++++++-------- src/lib/common/executable.c | 47 +++---- src/lib/compiler/codegenctx.c | 4 +- src/lib/objects/o_bool.c | 29 ++-- src/lib/objects/o_buffer.c | 65 ++++----- src/lib/objects/o_list.c | 40 +++--- src/lib/objects/o_map.c | 32 ++--- src/lib/objects/o_none.c | 26 ++-- src/lib/objects/o_string.c | 53 +++---- src/lib/objects/objects.c | 136 +++++++++--------- src/lib/runtime/o_nfunc.c | 5 +- src/lib/runtime/o_staticmap.c | 2 +- src/lib/runtime/runtime.c | 256 +++++++++++++++++----------------- src/lib/utils/bpalloc.c | 23 +-- src/lib/utils/defs.h | 24 +++- src/lib/utils/stack.c | 12 +- src/lib/utils/utf8.c | 26 ++-- 18 files changed, 507 insertions(+), 466 deletions(-) diff --git a/src/lib/builtins/basic.c b/src/lib/builtins/basic.c index 8a6e8fd..b6b3a15 100644 --- a/src/lib/builtins/basic.c +++ b/src/lib/builtins/basic.c @@ -28,7 +28,6 @@ ** +--------------------------------------------------------------------------+ */ -#include #include #include #include @@ -37,15 +36,17 @@ #include "basic.h" #include "files.h" #include "../utils/utf8.h" +#include "../utils/defs.h" #include "../objects/objects.h" #include "../compiler/compile.h" #include "../runtime/runtime.h" + static int bin_print(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) { - (void) runtime; - (void) rets; - (void) maxretc; - (void) error; + UNUSED(runtime); + UNUSED(rets); + UNUSED(maxretc); + UNUSED(error); for(int i = 0; i < (int) argc; i += 1) Object_Print(argv[i], stdout); @@ -54,9 +55,11 @@ static int bin_print(Runtime *runtime, Object **argv, unsigned int argc, Object static int bin_import(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) { - assert(argc == 1); + UNUSED(argc); + ASSERT(argc == 1); + Heap *heap = Runtime_GetHeap(runtime); - assert(heap != NULL); + ASSERT(heap != NULL); Object *o_path = argv[0]; const char *path; @@ -73,7 +76,7 @@ static int bin_import(Runtime *runtime, Object **argv, unsigned int argc, Object if (path == NULL) return -1; - assert(n >= 0); + ASSERT(n >= 0); path_len = (size_t) n; } @@ -137,7 +140,7 @@ static int bin_import(Runtime *runtime, Object **argv, unsigned int argc, Object case CompilationErrorType_SYNTAX: errname = "Syntax"; break; case CompilationErrorType_SEMANTIC: errname = "Semantic"; break; } - (void) errname; + UNUSED(errname); { if(maxretc == 0) @@ -170,7 +173,7 @@ static int bin_import(Runtime *runtime, Object **argv, unsigned int argc, Object { const char *errname = "Runtime"; // Snapshot? - (void) errname; + UNUSED(errname); { if(maxretc == 0) return 0; @@ -194,7 +197,7 @@ static int bin_import(Runtime *runtime, Object **argv, unsigned int argc, Object return 2; } } - assert(retc == 1); + ASSERT(retc == 1); if(maxretc == 0) return 0; @@ -206,9 +209,10 @@ static int bin_import(Runtime *runtime, Object **argv, unsigned int argc, Object static int bin_type(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) { - assert(argc == 1); - (void) runtime; - (void) error; + ASSERT(argc == 1); + UNUSED(runtime); + UNUSED(error); + UNUSED(argc); if(maxretc == 0) return 0; @@ -218,10 +222,10 @@ static int bin_type(Runtime *runtime, Object **argv, unsigned int argc, Object * static int bin_unicode(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) { - (void) runtime; - (void) error; - - assert(argc == 1); + UNUSED(runtime); + UNUSED(error); + UNUSED(argc); + ASSERT(argc == 1); uint32_t ret = 0; @@ -245,7 +249,8 @@ static int bin_unicode(Runtime *runtime, Object **argv, unsigned int argc, Objec int k = utf8_sequence_to_utf32_codepoint(string,n,&ret); - assert(k >= 0); + UNUSED(k); + ASSERT(k >= 0); Object *temp = Object_FromInt(ret,Runtime_GetHeap(runtime),error); @@ -260,17 +265,15 @@ static int bin_unicode(Runtime *runtime, Object **argv, unsigned int argc, Objec static int bin_chr(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) { + UNUSED(argc); + ASSERT(argc == 1); - assert(argc == 1); - - if(!Object_IsInt(argv[0])) { Error_Report(error, 0, "Argument #%d is not an integer", 1); return -1; } - char buff[32]; int value = Object_ToInt(argv[0],error); @@ -300,7 +303,8 @@ static int bin_chr(Runtime *runtime, Object **argv, unsigned int argc, Object ** static int bin_count(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) { - assert(argc == 1); + UNUSED(argc); + ASSERT(argc == 1); int n = Object_Count(argv[0], error); @@ -320,9 +324,9 @@ static int bin_count(Runtime *runtime, Object **argv, unsigned int argc, Object static int bin_input(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) { - (void) argv; - - assert(argc == 0); + UNUSED(argv); + UNUSED(argc); + ASSERT(argc == 0); char maybe[256]; char *str = maybe; @@ -372,9 +376,9 @@ static int bin_input(Runtime *runtime, Object **argv, unsigned int argc, Object static int bin_assert(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) { - (void) runtime; - (void) rets; - (void) maxretc; + UNUSED(runtime); + UNUSED(rets); + UNUSED(maxretc); for(unsigned int i = 0; i < argc; i += 1) if(!Object_ToBool(argv[i], error)) @@ -388,10 +392,10 @@ static int bin_assert(Runtime *runtime, Object **argv, unsigned int argc, Object static int bin_error(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) { - (void) rets; - (void) maxretc; - - assert(argc == 1); + UNUSED(argc); + UNUSED(rets); + UNUSED(maxretc); + ASSERT(argc == 1); int length; const char *string; @@ -471,7 +475,8 @@ done: static int bin_newBuffer(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) { - assert(argc == 1); + UNUSED(argc); + ASSERT(argc == 1); long long int size = Object_ToInt(argv[0], error); @@ -491,7 +496,8 @@ static int bin_newBuffer(Runtime *runtime, Object **argv, unsigned int argc, Obj static int bin_sliceBuffer(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) { - assert(argc == 3); + UNUSED(argc); + ASSERT(argc == 3); long long int offset = Object_ToInt(argv[1], error); if(error->occurred == 1) return -1; @@ -512,7 +518,8 @@ static int bin_sliceBuffer(Runtime *runtime, Object **argv, unsigned int argc, O static int bin_bufferToString(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) { - assert(argc == 1); + UNUSED(argc); + ASSERT(argc == 1); void *buffaddr; int buffsize; diff --git a/src/lib/builtins/math.c b/src/lib/builtins/math.c index 01d66e3..cc10ed9 100644 --- a/src/lib/builtins/math.c +++ b/src/lib/builtins/math.c @@ -28,70 +28,72 @@ ** +--------------------------------------------------------------------------+ */ -#include #include #include "math.h" +#include "../utils/defs.h" #define WRAP_FUNC(name) \ static int bin_ ## name(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) \ - { \ - assert(argc == 1); \ - \ - if(Object_IsFloat(argv[0])) \ - { \ - double v = Object_ToFloat(argv[0], error); \ - \ - if(error->occurred) \ - return -1; \ - \ - if(maxretc > 0) \ - { \ - rets[0] = Object_FromFloat(name(v), Runtime_GetHeap(runtime), error); \ - if(rets[0] == NULL) \ - return -1; \ - return 1; \ - } \ - return 0; \ - } \ - else \ - { \ - Error_Report(error, 0, "Expected first argument to be a float, but it's a %s", Object_GetName(argv[0]));\ - return -1; \ - } \ + { \ + UNUSED(argc); \ + ASSERT(argc == 1); \ + \ + if(Object_IsFloat(argv[0])) \ + { \ + double v = Object_ToFloat(argv[0], error); \ + \ + if(error->occurred) \ + return -1; \ + \ + if(maxretc > 0) \ + { \ + rets[0] = Object_FromFloat(name(v), Runtime_GetHeap(runtime), error); \ + if(rets[0] == NULL) \ + return -1; \ + return 1; \ + } \ + return 0; \ + } \ + else \ + { \ + Error_Report(error, 0, "Expected first argument to be a float, but it's a %s", Object_GetName(argv[0])); \ + return -1; \ + } \ } #define WRAP_FUNC_2(name) \ static int bin_ ## name(Runtime *runtime, Object **argv, unsigned int argc, Object **rets, unsigned int maxretc, Error *error) \ - { \ - assert(argc == 2); \ - \ - if(!Object_IsFloat(argv[0])) \ - { \ - Error_Report(error, 0, "Expected first argument to be a float, but it's a %s", Object_GetName(argv[0]));\ - return -1; \ - } \ - \ - if(!Object_IsFloat(argv[1])) \ - { \ - Error_Report(error, 0, "Expected second argument to be a float, but it's a %s", Object_GetName(argv[1]));\ - return -1; \ - } \ - \ - double v1 = Object_ToFloat(argv[0], error); \ - \ - if(error->occurred) \ - return -1; \ - \ - double v2 = Object_ToFloat(argv[1], error); \ - \ - if(error->occurred) \ - return -1; \ - \ - Object *res = Object_FromFloat(name(v1, v2), Runtime_GetHeap(runtime), error); \ - if(res == NULL) return -1; \ - if(maxretc == 0) return 0; \ - rets[0] = res; \ - return 1; \ + { \ + UNUSED(argc); \ + ASSERT(argc == 2); \ + \ + if(!Object_IsFloat(argv[0])) \ + { \ + Error_Report(error, 0, "Expected first argument to be a float, but it's a %s", Object_GetName(argv[0])); \ + return -1; \ + } \ + \ + if(!Object_IsFloat(argv[1])) \ + { \ + Error_Report(error, 0, "Expected second argument to be a float, but it's a %s", Object_GetName(argv[1])); \ + return -1; \ + } \ + \ + double v1 = Object_ToFloat(argv[0], error); \ + \ + if(error->occurred) \ + return -1; \ + \ + double v2 = Object_ToFloat(argv[1], error); \ + \ + if(error->occurred) \ + return -1; \ + \ + Object *res = Object_FromFloat(name(v1, v2), Runtime_GetHeap(runtime), error); \ + if(res == NULL) return -1; \ + if(maxretc == 0) return 0; \ + rets[0] = res; \ + return 1; \ } WRAP_FUNC(ceil) diff --git a/src/lib/common/executable.c b/src/lib/common/executable.c index 2586a0e..ec29f58 100644 --- a/src/lib/common/executable.c +++ b/src/lib/common/executable.c @@ -117,7 +117,7 @@ _Bool Executable_GetOpcodeBinaryFromName(const char *name, size_t name_len, Opco // so to simplify things we duplicate it to add // an extra null byte. char buff[128]; // No opcode should have a name this big. - assert(name_len < sizeof(buff)); // If this is triggered, [buff] should be made bigger. + ASSERT(name_len < sizeof(buff)); // If this is triggered, [buff] should be made bigger. memcpy(buff, name, name_len); buff[name_len] = '\0'; @@ -125,7 +125,7 @@ _Bool Executable_GetOpcodeBinaryFromName(const char *name, size_t name_len, Opco name = buff; // Now name is zero terminated. - assert(name[name_len] == '\0'); + ASSERT(name[name_len] == '\0'); for(size_t i = 0; i < sizeof(instr_table)/sizeof(instr_table[0]); i += 1) { if(!strcmp(name, instr_table[i].name)) { @@ -143,7 +143,7 @@ const char *Executable_GetOpcodeName(Opcode opcode) Executable *Executable_Copy(Executable *exe) { - assert(exe != NULL); + ASSERT(exe != NULL); exe->refs += 1; return exe; @@ -152,7 +152,7 @@ Executable *Executable_Copy(Executable *exe) void Executable_Free(Executable *exe) { exe->refs -= 1; - assert(exe->refs >= 0); + ASSERT(exe->refs >= 0); if(exe->refs == 0) { @@ -243,7 +243,7 @@ int Executable_GetInstrLength(Executable *exe, int index) _Bool Executable_Fetch(Executable *exe, int index, Opcode *opcode, Operand *ops, int *opc) { - assert(index >= 0); + ASSERT(index >= 0); if(index >= exe->bodyl) return 0; @@ -263,7 +263,7 @@ _Bool Executable_Fetch(Executable *exe, int index, Opcode *opcode, Operand *ops, for(i = 0; i < k; i += 1) { OperandType type = info->optypes[i]; - assert(type != OPTP_PROMISE); + ASSERT(type != OPTP_PROMISE); switch(type) { @@ -271,7 +271,7 @@ _Bool Executable_Fetch(Executable *exe, int index, Opcode *opcode, Operand *ops, { int data_offset = instr->operands[i].as_int; - assert(data_offset < exe->headl); + ASSERT(data_offset < exe->headl); ops[i].type = OPTP_STRING; ops[i].as_string = exe->head + data_offset; @@ -337,16 +337,16 @@ _Bool Executable_Equiv(Executable *exe1, Executable *exe2, FILE *log, const char // same, the number of operands must be // the same too. (Their type must be // the same too.) - assert(exe1_opc == exe2_opc); + ASSERT(exe1_opc == exe2_opc); for(int opno = 0; opno < exe1_opc; opno += 1) { - assert(exe1_opv[opno].type == exe2_opv[opno].type); + ASSERT(exe1_opv[opno].type == exe2_opv[opno].type); // Also, an executable can never have // a promise operand. That's only used // when building the executable. - assert(exe1_opv[opno].type != OPTP_PROMISE); + ASSERT(exe1_opv[opno].type != OPTP_PROMISE); switch(exe1_opv[opno].type) { @@ -392,8 +392,7 @@ _Bool Executable_Equiv(Executable *exe1, Executable *exe2, FILE *log, const char break; case OPTP_PROMISE: - /* Unreachable */ - assert(0); + UNREACHABLE; break; } } @@ -405,7 +404,7 @@ _Bool Executable_Equiv(Executable *exe1, Executable *exe2, FILE *log, const char ExeBuilder *ExeBuilder_New(BPAlloc *alloc) { - assert(alloc != NULL); + ASSERT(alloc != NULL); ExeBuilder *exeb = BPAlloc_Malloc(alloc, sizeof(ExeBuilder)); @@ -423,7 +422,7 @@ ExeBuilder *ExeBuilder_New(BPAlloc *alloc) Executable *ExeBuilder_Finalize(ExeBuilder *exeb, Error *error) { - assert(exeb != NULL); + ASSERT(exeb != NULL); if(exeb->promc > 0) { @@ -436,7 +435,7 @@ Executable *ExeBuilder_Finalize(ExeBuilder *exeb, Error *error) int data_size = BucketList_Size(exeb->data); int code_size = BucketList_Size(exeb->code); - assert(code_size % sizeof(Instruction) == 0); + ASSERT(code_size % sizeof(Instruction) == 0); void *temp = malloc(sizeof(Executable) + data_size + code_size); @@ -463,18 +462,18 @@ Executable *ExeBuilder_Finalize(ExeBuilder *exeb, Error *error) static void promise_callback(void *userp) { - assert(userp != NULL); + ASSERT(userp != NULL); ExeBuilder *exeb = userp; exeb->promc -= 1; - assert(exeb->promc >= 0); + ASSERT(exeb->promc >= 0); } _Bool ExeBuilder_Append(ExeBuilder *exeb, Error *error, Opcode opcode, Operand *opv, int opc, int off, int len) { - assert(exeb != NULL); - assert(opc >= 0); + ASSERT(exeb != NULL); + ASSERT(opc >= 0); static const char *operand_type_names[] = { [OPTP_IDX] = "index", @@ -508,7 +507,7 @@ _Bool ExeBuilder_Append(ExeBuilder *exeb, Error *error, Opcode opcode, Operand * return 0; } - assert(opc <= MAX_OPS); + ASSERT(opc <= MAX_OPS); { Instruction *instr = BucketList_Append2(exeb->code, NULL, sizeof(Instruction)); @@ -532,11 +531,11 @@ _Bool ExeBuilder_Append(ExeBuilder *exeb, Error *error, Opcode opcode, Operand * OperandType expected_type = info->optypes[i]; OperandType provided_type = opv[i].type; - assert(expected_type != OPTP_PROMISE); + ASSERT(expected_type != OPTP_PROMISE); if(provided_type == OPTP_PROMISE) { - assert(opv[i].as_promise != NULL); + ASSERT(opv[i].as_promise != NULL); if(expected_type == OPTP_STRING) { @@ -588,7 +587,7 @@ _Bool ExeBuilder_Append(ExeBuilder *exeb, Error *error, Opcode opcode, Operand * break; case OPTP_PROMISE: - assert(info->optypes[i] != OPTP_STRING); + ASSERT(info->optypes[i] != OPTP_STRING); // This must be incremented before subscribing // since the counter-decrementing callback may @@ -630,7 +629,7 @@ int ExeBuilder_InstrCount(ExeBuilder *exeb) { int raw_size = BucketList_Size(exeb->code); - assert(raw_size % sizeof(Instruction) == 0); + ASSERT(raw_size % sizeof(Instruction) == 0); return raw_size / sizeof(Instruction); } diff --git a/src/lib/compiler/codegenctx.c b/src/lib/compiler/codegenctx.c index ff5758d..7be4527 100644 --- a/src/lib/compiler/codegenctx.c +++ b/src/lib/compiler/codegenctx.c @@ -48,7 +48,7 @@ Promise *Label_ToPromise(Label *label) static void okNowJump(CodegenContext *ctx) { - assert(ctx->env_set == true); + ASSERT(ctx->env_set == true); longjmp(*ctx->env, 1); UNREACHABLE; } @@ -68,7 +68,7 @@ void CodegenContext_ReportErrorAndJump_(CodegenContext *ctx, const char *file, void CodegenContext_SetJumpDest(CodegenContext *ctx, jmp_buf *env) { - assert(ctx->env_set == false); + ASSERT(ctx->env_set == false); ctx->env = env; ctx->env_set = true; } diff --git a/src/lib/objects/o_bool.c b/src/lib/objects/o_bool.c index 1eae4a4..21282bc 100644 --- a/src/lib/objects/o_bool.c +++ b/src/lib/objects/o_bool.c @@ -28,9 +28,9 @@ ** +--------------------------------------------------------------------------+ */ -#include #include #include "objects.h" +#include "../utils/defs.h" static _Bool to_bool(Object *obj, Error *err); static void print(Object *obj, FILE *fp); @@ -62,13 +62,13 @@ static Object the_false_object = { static int hash(Object *self) { - assert(self != NULL); - assert(self->type == &t_bool); + ASSERT(self != NULL); + ASSERT(self->type == &t_bool); if(self == &the_true_object) return 1; - assert(self == &the_false_object); + ASSERT(self == &the_false_object); return 0; } @@ -81,19 +81,20 @@ static Object *copy(Object *self, Heap *heap, Error *err) static _Bool op_eql(Object *self, Object *other) { - assert(self != NULL); - assert(self->type == &t_bool); - assert(other != NULL); - assert(other->type == &t_bool); + ASSERT(self != NULL); + ASSERT(self->type == &t_bool); + ASSERT(other != NULL); + ASSERT(other->type == &t_bool); return self == other; } static _Bool to_bool(Object *obj, Error *err) { - assert(obj); - assert(err); - assert(Object_GetType(obj) == &t_bool); + UNUSED(err); + ASSERT(obj); + ASSERT(err); + ASSERT(Object_GetType(obj) == &t_bool); return obj == &the_true_object; } @@ -111,9 +112,9 @@ Object *Object_FromBool(_Bool val, Heap *heap, Error *error) static void print(Object *obj, FILE *fp) { - assert(fp != NULL); - assert(obj != NULL); - assert(obj->type == &t_bool); + ASSERT(fp != NULL); + ASSERT(obj != NULL); + ASSERT(obj->type == &t_bool); fprintf(fp, obj == &the_true_object ? "true" : "false"); } \ No newline at end of file diff --git a/src/lib/objects/o_buffer.c b/src/lib/objects/o_buffer.c index 5df5781..9518d8f 100644 --- a/src/lib/objects/o_buffer.c +++ b/src/lib/objects/o_buffer.c @@ -29,7 +29,6 @@ */ #include -#include #include #include "../utils/defs.h" #include "objects.h" @@ -94,7 +93,7 @@ _Bool Object_IsBuffer(Object *obj) Object *Object_NewBuffer(int size, Heap *heap, Error *error) { - assert(size >= 0); + ASSERT(size >= 0); // Make the thing. BufferObject *obj; @@ -189,7 +188,7 @@ Object *Object_SliceBuffer(Object *buffer, int offset, int length, Heap *heap, E } else { - assert(buffer->type == &t_buffer_slice); + ASSERT(buffer->type == &t_buffer_slice); slice = (BufferSliceObject*) Heap_Malloc(heap, &t_buffer_slice, error); @@ -243,7 +242,7 @@ void *Object_GetBufferAddrAndSize(Object *obj, int *size, Error *error) } else { - assert(obj->type == &t_buffer_slice); + ASSERT(obj->type == &t_buffer_slice); BufferSliceObject *slice = (BufferSliceObject*) obj; @@ -256,11 +255,11 @@ void *Object_GetBufferAddrAndSize(Object *obj, int *size, Error *error) static Object *buffer_select(Object *self, Object *key, Heap *heap, Error *error) { - assert(self != NULL); - assert(self->type == &t_buffer); - assert(key != NULL); - assert(heap != NULL); - assert(error != NULL); + ASSERT(self != NULL); + ASSERT(self->type == &t_buffer); + ASSERT(key != NULL); + ASSERT(heap != NULL); + ASSERT(error != NULL); if(!Object_IsInt(key)) { @@ -269,7 +268,7 @@ static Object *buffer_select(Object *self, Object *key, Heap *heap, Error *error } int idx = Object_ToInt(key, error); - assert(error->occurred == 0); + ASSERT(error->occurred == 0); BufferObject *buffer = (BufferObject*) self; @@ -286,11 +285,11 @@ static Object *buffer_select(Object *self, Object *key, Heap *heap, Error *error static Object *slice_select(Object *self, Object *key, Heap *heap, Error *error) { - assert(self != NULL); - assert(self->type == &t_buffer_slice); - assert(key != NULL); - assert(heap != NULL); - assert(error != NULL); + ASSERT(self != NULL); + ASSERT(self->type == &t_buffer_slice); + ASSERT(key != NULL); + ASSERT(heap != NULL); + ASSERT(error != NULL); if(!Object_IsInt(key)) { @@ -299,7 +298,7 @@ static Object *slice_select(Object *self, Object *key, Heap *heap, Error *error) } int idx = Object_ToInt(key, error); - assert(error->occurred == 0); + ASSERT(error->occurred == 0); BufferSliceObject *slice = (BufferSliceObject*) self; @@ -316,12 +315,13 @@ static Object *slice_select(Object *self, Object *key, Heap *heap, Error *error) static _Bool buffer_insert(Object *self, Object *key, Object *val, Heap *heap, Error *error) { - assert(error != NULL); - assert(key != NULL); - assert(val != NULL); - assert(heap != NULL); - assert(self != NULL); - assert(self->type == &t_buffer); + UNUSED(heap); + ASSERT(error != NULL); + ASSERT(key != NULL); + ASSERT(val != NULL); + ASSERT(heap != NULL); + ASSERT(self != NULL); + ASSERT(self->type == &t_buffer); BufferObject *buffer = (BufferObject*) self; @@ -332,7 +332,7 @@ static _Bool buffer_insert(Object *self, Object *key, Object *val, Heap *heap, E } int idx = Object_ToInt(key, error); - assert(error->occurred == 0); + ASSERT(error->occurred == 0); if(idx < 0 || idx >= buffer->size) { @@ -359,12 +359,13 @@ static _Bool buffer_insert(Object *self, Object *key, Object *val, Heap *heap, E static _Bool slice_insert(Object *self, Object *key, Object *val, Heap *heap, Error *error) { - assert(error != NULL); - assert(key != NULL); - assert(val != NULL); - assert(heap != NULL); - assert(self != NULL); - assert(self->type == &t_buffer_slice); + UNUSED(heap); + ASSERT(error != NULL); + ASSERT(key != NULL); + ASSERT(val != NULL); + ASSERT(heap != NULL); + ASSERT(self != NULL); + ASSERT(self->type == &t_buffer_slice); BufferSliceObject *slice = (BufferSliceObject*) self; @@ -375,7 +376,7 @@ static _Bool slice_insert(Object *self, Object *key, Object *val, Heap *heap, Er } int idx = Object_ToInt(key, error); - assert(error->occurred == 0); + ASSERT(error->occurred == 0); if(idx < 0 || idx >= slice->length) { @@ -426,8 +427,8 @@ static void print_bytes(FILE *fp, unsigned char *addr, int size) low = byte & 0xf; high = byte >> 4; - assert(low < 16); - assert(high < 16); + ASSERT(low < 16); + ASSERT(high < 16); char c1, c2; diff --git a/src/lib/objects/o_list.c b/src/lib/objects/o_list.c index 53bbe6f..3dc1943 100644 --- a/src/lib/objects/o_list.c +++ b/src/lib/objects/o_list.c @@ -28,7 +28,6 @@ ** +--------------------------------------------------------------------------+ */ -#include #include #include "../utils/defs.h" #include "objects.h" @@ -64,8 +63,8 @@ static TypeObject t_list = { static int hash(Object *self) { - assert(self != NULL); - assert(self->type == &t_list); + ASSERT(self != NULL); + ASSERT(self->type == &t_list); ListObject *ls = (ListObject*) self; @@ -81,8 +80,8 @@ static int hash(Object *self) static Object *copy(Object *self, Heap *heap, Error *err) { - (void) heap; - (void) err; + UNUSED(heap); + UNUSED(err); ListObject *ls = (ListObject*) self; ListObject *ls2 = (ListObject*) Object_NewList(ls->count, heap, err); @@ -131,7 +130,7 @@ Object *Object_NewList(int capacity, Heap *heap, Error *error) Object *Object_NewList2(int num, Object **items, Heap *heap, Error *error) { - assert(num > -1); + ASSERT(num > -1); ListObject *list = (ListObject*) Object_NewList(num, heap, error); @@ -161,11 +160,12 @@ static void walkexts(Object *self, void (*callback)(void **referer, unsigned int static Object *select(Object *self, Object *key, Heap *heap, Error *error) { - assert(self != NULL); - assert(self->type == &t_list); - assert(key != NULL); - assert(heap != NULL); - assert(error != NULL); + UNUSED(heap); + ASSERT(self != NULL); + ASSERT(self->type == &t_list); + ASSERT(key != NULL); + ASSERT(heap != NULL); + ASSERT(error != NULL); if(!Object_IsInt(key)) { @@ -174,7 +174,7 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error) } int idx = Object_ToInt(key, error); - assert(error->occurred == 0); + ASSERT(error->occurred == 0); ListObject *list = (ListObject*) self; @@ -194,7 +194,7 @@ static unsigned int calc_new_capacity(unsigned int old_capacity) static _Bool grow(ListObject *list, Heap *heap, Error *error) { - assert(list != NULL); + ASSERT(list != NULL); int new_capacity = calc_new_capacity(list->capacity); @@ -213,12 +213,12 @@ static _Bool grow(ListObject *list, Heap *heap, Error *error) static _Bool insert(Object *self, Object *key, Object *val, Heap *heap, Error *error) { - assert(error != NULL); - assert(key != NULL); - assert(val != NULL); - assert(heap != NULL); - assert(self != NULL); - assert(self->type == &t_list); + ASSERT(error != NULL); + ASSERT(key != NULL); + ASSERT(val != NULL); + ASSERT(heap != NULL); + ASSERT(self != NULL); + ASSERT(self->type == &t_list); ListObject *list = (ListObject*) self; @@ -229,7 +229,7 @@ static _Bool insert(Object *self, Object *key, Object *val, Heap *heap, Error *e } int idx = Object_ToInt(key, error); - assert(error->occurred == 0); + ASSERT(error->occurred == 0); if(idx < 0 || idx > list->count) { diff --git a/src/lib/objects/o_map.c b/src/lib/objects/o_map.c index a4ae59b..c369777 100644 --- a/src/lib/objects/o_map.c +++ b/src/lib/objects/o_map.c @@ -28,7 +28,6 @@ ** +--------------------------------------------------------------------------+ */ -#include #include "../utils/defs.h" #include "objects.h" @@ -164,7 +163,7 @@ static void walk(Object *self, void (*callback)(Object **referer, void *userp), static void walkexts(Object *self, void (*callback)(void **referer, unsigned int size, void *userp), void *userp) { - assert(self->type == &t_map); + ASSERT(self->type == &t_map); MapObject *map = (MapObject*) self; @@ -177,11 +176,12 @@ static void walkexts(Object *self, void (*callback)(void **referer, unsigned int static Object *select(Object *self, Object *key, Heap *heap, Error *error) { - assert(self != NULL); - assert(self->type == &t_map); - assert(key != NULL); - assert(heap != NULL); - assert(error != NULL); + UNUSED(heap); + ASSERT(self != NULL); + ASSERT(self->type == &t_map); + ASSERT(key != NULL); + ASSERT(heap != NULL); + ASSERT(error != NULL); MapObject *map = (MapObject*) self; @@ -206,7 +206,7 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error) // Found an item. // Is it the right one? - assert(k >= 0); + ASSERT(k >= 0); if(Object_Compare(key, map->keys[k], error)) // Found it! @@ -229,7 +229,7 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error) static _Bool grow(MapObject *map, Heap *heap, Error *error) { - assert(map != NULL); + ASSERT(map != NULL); int new_mapper_size = map->mapper_size << 1; int new_capacity = calc_capacity(new_mapper_size); @@ -289,12 +289,12 @@ static _Bool grow(MapObject *map, Heap *heap, Error *error) static _Bool insert(Object *self, Object *key, Object *val, Heap *heap, Error *error) { - assert(error != NULL); - assert(key != NULL); - assert(val != NULL); - assert(heap != NULL); - assert(self != NULL); - assert(self->type == &t_map); + ASSERT(error != NULL); + ASSERT(key != NULL); + ASSERT(val != NULL); + ASSERT(heap != NULL); + ASSERT(self != NULL); + ASSERT(self->type == &t_map); MapObject *map = (MapObject*) self; @@ -328,7 +328,7 @@ static _Bool insert(Object *self, Object *key, Object *val, Heap *heap, Error *e } else { - assert(k >= 0); + ASSERT(k >= 0); if(Object_Compare(key, map->keys[k], error)) { diff --git a/src/lib/objects/o_none.c b/src/lib/objects/o_none.c index 5bbe450..7881c45 100644 --- a/src/lib/objects/o_none.c +++ b/src/lib/objects/o_none.c @@ -28,9 +28,9 @@ ** +--------------------------------------------------------------------------+ */ -#include #include #include "objects.h" +#include "../utils/defs.h" static _Bool op_eql(Object *self, Object *other); static void print(Object *obj, FILE *fp); @@ -64,37 +64,39 @@ _Bool Object_IsNone(Object *obj) static int hash(Object *self) { - assert(self == &the_none_object); + UNUSED(self); + ASSERT(self == &the_none_object); return 0; } static Object *copy(Object *self, Heap *heap, Error *err) { - (void) heap; - (void) err; + UNUSED(heap); + UNUSED(err); return self; } Object *Object_NewNone(Heap *heap, Error *error) { - (void) heap; - (void) error; + UNUSED(heap); + UNUSED(error); return &the_none_object; } static void print(Object *obj, FILE *fp) { - assert(fp != NULL); - assert(obj != NULL); - assert(obj->type == &t_none); + UNUSED(obj); + ASSERT(fp != NULL); + ASSERT(obj != NULL); + ASSERT(obj->type == &t_none); fprintf(fp, "none"); } static _Bool op_eql(Object *self, Object *other) { - (void) self; - - assert(other->type == &t_none); + UNUSED(self); + UNUSED(other); + ASSERT(other->type == &t_none); return 1; } \ No newline at end of file diff --git a/src/lib/objects/o_string.c b/src/lib/objects/o_string.c index 2936c77..27c3327 100644 --- a/src/lib/objects/o_string.c +++ b/src/lib/objects/o_string.c @@ -29,7 +29,6 @@ */ #include -#include #include "../utils/defs.h" #include "../utils/hash.h" #include "../utils/utf8.h" @@ -83,17 +82,17 @@ static int char_index_to_offset(StringObject *str, int idx) scanned_bytes += last_code_len; idx -= 1; - assert(scanned_bytes <= str->bytes); + ASSERT(scanned_bytes <= str->bytes); } - assert(idx == 0); + ASSERT(idx == 0); return scanned_bytes; } static Object *select(Object *self, Object *key, Heap *heap, Error *error) { - assert(self != NULL && self->type == &t_string); - assert(key != NULL && heap != NULL && error != NULL); + ASSERT(self != NULL && self->type == &t_string); + ASSERT(key != NULL && heap != NULL && error != NULL); if(!Object_IsInt(key)) { @@ -102,7 +101,7 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error) } int idx = Object_ToInt(key, error); - assert(error->occurred == 0); + ASSERT(error->occurred == 0); StringObject *str = (StringObject*) self; @@ -120,8 +119,8 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error) static char *to_string(Object *self, int *size, Heap *heap, Error *err) { - assert(self != NULL); - assert(self->type == &t_string); + ASSERT(self != NULL); + ASSERT(self->type == &t_string); (void) heap; (void) err; @@ -141,9 +140,9 @@ TypeObject *Object_GetStringType() Object *Object_FromString(const char *str, int len, Heap *heap, Error *error) { - assert(str != NULL); - assert(heap != NULL); - assert(error != NULL); + ASSERT(str != NULL); + ASSERT(heap != NULL); + ASSERT(error != NULL); if(len < 0) len = strlen(str); @@ -177,8 +176,8 @@ Object *Object_FromString(const char *str, int len, Heap *heap, Error *error) static int count(Object *self) { - assert(self != NULL); - assert(self->type == &t_string); + ASSERT(self != NULL); + ASSERT(self->type == &t_string); StringObject *strobj = (StringObject*) self; @@ -187,8 +186,8 @@ static int count(Object *self) static int hash(Object *self) { - assert(self != NULL); - assert(self->type == &t_string); + ASSERT(self != NULL); + ASSERT(self->type == &t_string); StringObject *strobj = (StringObject*) self; @@ -197,20 +196,22 @@ static int hash(Object *self) static Object *copy(Object *self, Heap *heap, Error *err) { - assert(self != NULL); - assert(self->type == &t_string); - assert(heap != NULL); - assert(err != NULL); + UNUSED(heap); + UNUSED(err); + ASSERT(self != NULL); + ASSERT(self->type == &t_string); + ASSERT(heap != NULL); + ASSERT(err != NULL); return self; } static _Bool op_eql(Object *self, Object *other) { - assert(self != NULL); - assert(self->type == &t_string); - assert(other != NULL); - assert(other->type == &t_string); + ASSERT(self != NULL); + ASSERT(self->type == &t_string); + ASSERT(other != NULL); + ASSERT(other->type == &t_string); StringObject *s1 = (StringObject*) self; StringObject *s2 = (StringObject*) other; @@ -222,9 +223,9 @@ static _Bool op_eql(Object *self, Object *other) static void print(Object *obj, FILE *fp) { - assert(fp != NULL); - assert(obj != NULL); - assert(obj->type == &t_string); + ASSERT(fp != NULL); + ASSERT(obj != NULL); + ASSERT(obj->type == &t_string); StringObject *str = (StringObject*) obj; diff --git a/src/lib/objects/objects.c b/src/lib/objects/objects.c index 57d32a9..28cc7d2 100644 --- a/src/lib/objects/objects.c +++ b/src/lib/objects/objects.c @@ -28,7 +28,6 @@ ** +--------------------------------------------------------------------------+ */ -#include #include "../utils/defs.h" #include "objects.h" @@ -53,42 +52,43 @@ static _Bool op_eql(Object *self, Object *other) const char *Object_GetName(const Object *obj) { - assert(obj != NULL); + ASSERT(obj != NULL); const TypeObject *type = Object_GetType(obj); - assert(type); + ASSERT(type); const char *name = type->name; - assert(name); + ASSERT(name); return name; } const TypeObject *Object_GetType(const Object *obj) { - assert(obj != NULL); - assert(obj->type != NULL); + ASSERT(obj != NULL); + ASSERT(obj->type != NULL); return obj->type; } unsigned int Object_GetSize(const Object *obj, Error *err) { - assert(err != NULL); - assert(obj != NULL); + UNUSED(err); + ASSERT(err != NULL); + ASSERT(obj != NULL); const TypeObject *type = Object_GetType(obj); - assert(type); + ASSERT(type); return type->size; } unsigned int Object_GetDeepSize(const Object *obj, Error *err) { - assert(err != NULL); - assert(obj != NULL); + ASSERT(err != NULL); + ASSERT(obj != NULL); const TypeObject *type = Object_GetType(obj); - assert(type); + ASSERT(type); if(type->deepsize == NULL) { @@ -101,20 +101,20 @@ unsigned int Object_GetDeepSize(const Object *obj, Error *err) int Object_Hash(Object *obj) { - assert(obj != NULL); + ASSERT(obj != NULL); const TypeObject *type = Object_GetType(obj); - assert(type != NULL); - assert(type->hash != NULL); + ASSERT(type != NULL); + ASSERT(type->hash != NULL); return type->hash(obj); } Object *Object_Copy(Object *obj, Heap *heap, Error *err) { - assert(err != NULL); - assert(obj != NULL); + ASSERT(err != NULL); + ASSERT(obj != NULL); const TypeObject *type = Object_GetType(obj); - assert(type != NULL); + ASSERT(type != NULL); if(type->copy == NULL) { @@ -127,10 +127,10 @@ Object *Object_Copy(Object *obj, Heap *heap, Error *err) int Object_Call(Object *obj, Object **argv, unsigned int argc, Object **rets, unsigned int maxrets, Heap *heap, Error *err) { - assert(err != NULL && obj != NULL); + ASSERT(err != NULL && obj != NULL); const TypeObject *type = Object_GetType(obj); - assert(type); + ASSERT(type); if(type->call == NULL) { @@ -143,10 +143,10 @@ int Object_Call(Object *obj, Object **argv, unsigned int argc, Object **rets, un void Object_Print(Object *obj, FILE *fp) { - assert(obj != NULL); + ASSERT(obj != NULL); const TypeObject *type = Object_GetType(obj); - assert(type); + ASSERT(type); if(type->print == NULL) fprintf(fp, "<%s is unprintable>", Object_GetName(obj)); @@ -156,12 +156,12 @@ void Object_Print(Object *obj, FILE *fp) Object *Object_Select(Object *coll, Object *key, Heap *heap, Error *err) { - assert(err); - assert(key); - assert(coll); + ASSERT(err); + ASSERT(key); + ASSERT(coll); const TypeObject *type = Object_GetType(coll); - assert(type); + ASSERT(type); if(type->select == NULL) { @@ -174,12 +174,12 @@ Object *Object_Select(Object *coll, Object *key, Heap *heap, Error *err) Object *Object_Delete(Object *coll, Object *key, Heap *heap, Error *err) { - assert(err); - assert(key); - assert(coll); + ASSERT(err); + ASSERT(key); + ASSERT(coll); const TypeObject *type = Object_GetType(coll); - assert(type); + ASSERT(type); if(type->delete == NULL) { @@ -192,12 +192,12 @@ Object *Object_Delete(Object *coll, Object *key, Heap *heap, Error *err) _Bool Object_Insert(Object *coll, Object *key, Object *val, Heap *heap, Error *err) { - assert(err); - assert(key); - assert(coll); + ASSERT(err); + ASSERT(key); + ASSERT(coll); const TypeObject *type = Object_GetType(coll); - assert(type); + ASSERT(type); if(type->insert == NULL) { @@ -210,11 +210,11 @@ _Bool Object_Insert(Object *coll, Object *key, Object *val, Heap *heap, Error *e int Object_Count(Object *coll, Error *err) { - assert(err); - assert(coll); + ASSERT(err); + ASSERT(coll); const TypeObject *type = Object_GetType(coll); - assert(type); + ASSERT(type); if(type->count == NULL) { @@ -227,11 +227,11 @@ int Object_Count(Object *coll, Error *err) Object *Object_Next(Object *iter, Heap *heap, Error *err) { - assert(err); - assert(iter); + ASSERT(err); + ASSERT(iter); const TypeObject *type = Object_GetType(iter); - assert(type); + ASSERT(type); if(type->next == NULL) { @@ -244,11 +244,11 @@ Object *Object_Next(Object *iter, Heap *heap, Error *err) Object *Object_Prev(Object *iter, Heap *heap, Error *err) { - assert(err); - assert(iter); + ASSERT(err); + ASSERT(iter); const TypeObject *type = Object_GetType(iter); - assert(type); + ASSERT(type); if(type->prev == NULL) { @@ -261,36 +261,36 @@ Object *Object_Prev(Object *iter, Heap *heap, Error *err) _Bool Object_IsInt(Object *obj) { - assert(obj != NULL); - assert(obj->type != NULL); + ASSERT(obj != NULL); + ASSERT(obj->type != NULL); return obj->type->atomic == ATMTP_INT; } _Bool Object_IsBool(Object *obj) { - assert(obj != NULL); - assert(obj->type != NULL); + ASSERT(obj != NULL); + ASSERT(obj->type != NULL); return obj->type->atomic == ATMTP_BOOL; } _Bool Object_IsFloat(Object *obj) { - assert(obj != NULL); - assert(obj->type != NULL); + ASSERT(obj != NULL); + ASSERT(obj->type != NULL); return obj->type->atomic == ATMTP_FLOAT; } _Bool Object_IsString(Object *obj) { - assert(obj != NULL); - assert(obj->type != NULL); + ASSERT(obj != NULL); + ASSERT(obj->type != NULL); return obj->type->atomic == ATMTP_STRING; } long long int Object_ToInt(Object *obj, Error *err) { - assert(err); - assert(obj); + ASSERT(err); + ASSERT(obj); if(!Object_IsInt(obj)) { @@ -299,7 +299,7 @@ long long int Object_ToInt(Object *obj, Error *err) } const TypeObject *type = Object_GetType(obj); - assert(type); + ASSERT(type); if(type->to_int == NULL) { @@ -312,8 +312,8 @@ long long int Object_ToInt(Object *obj, Error *err) _Bool Object_ToBool(Object *obj, Error *err) { - assert(err); - assert(obj); + ASSERT(err); + ASSERT(obj); if(!Object_IsBool(obj)) { @@ -322,7 +322,7 @@ _Bool Object_ToBool(Object *obj, Error *err) } const TypeObject *type = Object_GetType(obj); - assert(type); + ASSERT(type); if(type->to_bool == NULL) { @@ -335,8 +335,8 @@ _Bool Object_ToBool(Object *obj, Error *err) double Object_ToFloat(Object *obj, Error *err) { - assert(err); - assert(obj); + ASSERT(err); + ASSERT(obj); if(!Object_IsFloat(obj)) { @@ -345,7 +345,7 @@ double Object_ToFloat(Object *obj, Error *err) } const TypeObject *type = Object_GetType(obj); - assert(type); + ASSERT(type); if(type->to_float == NULL) { @@ -358,8 +358,8 @@ double Object_ToFloat(Object *obj, Error *err) const char *Object_ToString(Object *obj, int *size, Heap *heap, Error *err) { - assert(err != NULL); - assert(obj != NULL); + ASSERT(err != NULL); + ASSERT(obj != NULL); if(!Object_IsString(obj)) { @@ -368,7 +368,7 @@ const char *Object_ToString(Object *obj, int *size, Heap *heap, Error *err) } const TypeObject *type = Object_GetType(obj); - assert(type); + ASSERT(type); if(type->to_string == NULL) { @@ -381,9 +381,9 @@ const char *Object_ToString(Object *obj, int *size, Heap *heap, Error *err) _Bool Object_Compare(Object *obj1, Object *obj2, Error *error) { - assert(obj1 != NULL); - assert(obj2 != NULL); - assert(error != NULL); + ASSERT(obj1 != NULL); + ASSERT(obj2 != NULL); + ASSERT(error != NULL); if(obj1->type != obj2->type) return 0; @@ -399,14 +399,14 @@ _Bool Object_Compare(Object *obj1, Object *obj2, Error *error) void Object_WalkReferences(Object *parent, void (*callback)(Object **referer, void *userp), void *userp) { - assert(parent != NULL); + ASSERT(parent != NULL); if(parent->type->walk != NULL) parent->type->walk(parent, callback, userp); } void Object_WalkExtensions(Object *parent, void (*callback)(void **referer, unsigned int size, void *userp), void *userp) { - assert(parent != NULL); + ASSERT(parent != NULL); if(parent->type->walkexts != NULL) parent->type->walkexts(parent, callback, userp); } \ No newline at end of file diff --git a/src/lib/runtime/o_nfunc.c b/src/lib/runtime/o_nfunc.c index 540f245..9780ded 100644 --- a/src/lib/runtime/o_nfunc.c +++ b/src/lib/runtime/o_nfunc.c @@ -105,8 +105,11 @@ static int call(Object *self, Object **argv, unsigned int argc, Object **rets, u return -1; } } + } else { + UNREACHABLE; + argv2 = NULL; + argc2 = -1; } - else UNREACHABLE; assert(func->callback != NULL); int retc = func->callback(func->runtime, argv2, argc2, rets, maxretc, error); diff --git a/src/lib/runtime/o_staticmap.c b/src/lib/runtime/o_staticmap.c index c2a7008..f359209 100644 --- a/src/lib/runtime/o_staticmap.c +++ b/src/lib/runtime/o_staticmap.c @@ -125,7 +125,7 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error) if(!strcmp(name, map->slots[i].name)) { StaticMapSlot slot = map->slots[i]; - Object *obj; + Object *obj = NULL; switch(slot.kind) { case SM_BOOL: return Object_FromBool(slot.as_bool, heap, error); diff --git a/src/lib/runtime/runtime.c b/src/lib/runtime/runtime.c index 4831116..ca2a96c 100644 --- a/src/lib/runtime/runtime.c +++ b/src/lib/runtime/runtime.c @@ -78,20 +78,20 @@ size_t Runtime_GetCurrentScriptFolder(Runtime *runtime, char *buff, size_t buffs { // This is buggy code!! size_t path_len = strlen(path); - assert(path_len > 0); // Not empty - assert(Path_IsAbsolute(path)); // Is absolute - assert(path[path_len-1] != '/'); // Doesn't end with a slash. + ASSERT(path_len > 0); // Not empty + ASSERT(Path_IsAbsolute(path)); // Is absolute + ASSERT(path[path_len-1] != '/'); // Doesn't end with a slash. size_t popped = 0; while(path[path_len-1-popped] != '/') popped += 1; - assert(path_len > popped); + ASSERT(path_len > popped); dir_len = path_len - popped; - assert(dir_len < path_len); - assert(path[dir_len-1] == '/'); + ASSERT(dir_len < path_len); + ASSERT(path[dir_len-1] == '/'); } if(dir_len >= buffsize) @@ -105,7 +105,7 @@ size_t Runtime_GetCurrentScriptFolder(Runtime *runtime, char *buff, size_t buffs const char *Runtime_GetCurrentScriptAbsolutePath(Runtime *runtime) { Executable *exe = Runtime_GetCurrentExecutable(runtime); - assert(exe != NULL); + ASSERT(exe != NULL); Source *src = Executable_GetSource(exe); if(src == NULL) @@ -115,7 +115,7 @@ const char *Runtime_GetCurrentScriptAbsolutePath(Runtime *runtime) if(path == NULL) return NULL; - assert(path[0] != '\0'); + ASSERT(path[0] != '\0'); return path; } @@ -207,9 +207,9 @@ void Runtime_SetBuiltins(Runtime *runtime, Object *builtins) _Bool Runtime_Push(Runtime *runtime, Error *error, Object *obj) { - assert(runtime != NULL); - assert(error != NULL); - assert(obj != NULL); + ASSERT(runtime != NULL); + ASSERT(error != NULL); + ASSERT(obj != NULL); if(runtime->depth == 0) { @@ -217,7 +217,7 @@ _Bool Runtime_Push(Runtime *runtime, Error *error, Object *obj) return 0; } - assert(runtime->frame->used <= MAX_FRAME_STACK); + ASSERT(runtime->frame->used <= MAX_FRAME_STACK); if(runtime->frame->used == MAX_FRAME_STACK) { @@ -237,8 +237,8 @@ _Bool Runtime_Push(Runtime *runtime, Error *error, Object *obj) _Bool Runtime_Pop(Runtime *runtime, Error *error, unsigned int n) { - assert(runtime != NULL); - assert(error != NULL); + ASSERT(runtime != NULL); + ASSERT(error != NULL); if(runtime->depth == 0) { @@ -246,7 +246,7 @@ _Bool Runtime_Pop(Runtime *runtime, Error *error, unsigned int n) return 0; } - assert(runtime->frame->used >= 0); + ASSERT(runtime->frame->used >= 0); if((unsigned int) runtime->frame->used < n) { @@ -261,7 +261,7 @@ _Bool Runtime_Pop(Runtime *runtime, Error *error, unsigned int n) runtime->frame->used -= n; - assert(runtime->frame->used >= 0); + ASSERT(runtime->frame->used >= 0); return 1; } @@ -278,7 +278,7 @@ struct xSnapshot { Snapshot *Snapshot_New(Runtime *runtime) { - assert(runtime->depth >= 0); + ASSERT(runtime->depth >= 0); Snapshot *snapshot = malloc(sizeof(Snapshot) + sizeof(SnapshotNode) * runtime->depth); @@ -292,7 +292,7 @@ Snapshot *Snapshot_New(Runtime *runtime) while(snapshot->depth < runtime->depth) { - assert(f != NULL); + ASSERT(f != NULL); SnapshotNode *node = snapshot->nodes + snapshot->depth; @@ -306,7 +306,7 @@ Snapshot *Snapshot_New(Runtime *runtime) snapshot->depth += 1; } - assert(f == NULL); + ASSERT(f == NULL); } return snapshot; @@ -328,8 +328,8 @@ void Snapshot_Free(Snapshot *snapshot) void Snapshot_Print(Snapshot *snapshot, FILE *fp) { - assert(snapshot != NULL); - assert(fp != NULL); + ASSERT(snapshot != NULL); + ASSERT(fp != NULL); fprintf(fp, "Stack trace:\n"); @@ -385,8 +385,8 @@ void Snapshot_Print(Snapshot *snapshot, FILE *fp) static Object *do_math_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, Error *error) { - assert(lop != NULL); - assert(rop != NULL); + ASSERT(lop != NULL); + ASSERT(rop != NULL); #define APPLY(x, y, z, id) \ switch(opcode) \ @@ -402,7 +402,7 @@ static Object *do_math_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, E } \ (z) = (x) / (y); \ break; \ - default: assert(0); break; \ + default: UNREACHABLE; break; \ } Object *res; @@ -422,7 +422,7 @@ static Object *do_math_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, E if(error->occurred) return NULL; - long long int raw_res; + long long int raw_res = 0; APPLY(raw_lop, raw_rop, raw_res, id) @@ -436,7 +436,7 @@ static Object *do_math_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, E if(error->occurred) return NULL; - double raw_res; + double raw_res = 0; APPLY((double) raw_lop, raw_rop, raw_res, id) @@ -463,7 +463,7 @@ static Object *do_math_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, E if(error->occurred) return NULL; - double raw_res; + double raw_res = 0; APPLY(raw_lop, (double) raw_rop, raw_res, id) @@ -477,7 +477,7 @@ static Object *do_math_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, E if(error->occurred) return NULL; - double raw_res; + double raw_res = 0; APPLY(raw_lop, raw_rop, raw_res, id) @@ -502,20 +502,20 @@ static Object *do_math_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, E static Object *do_relational_op(Object *lop, Object *rop, Opcode opcode, Heap *heap, Error *error) { - assert(lop != NULL); - assert(rop != NULL); + ASSERT(lop != NULL); + ASSERT(rop != NULL); - #define APPLY(x, y, z, id) \ - switch(opcode) \ + #define APPLY(x, y, z, id) \ + switch(opcode) \ { \ case OPCODE_LSS: (z) = (x) < (y); break; \ case OPCODE_GRT: (z) = (x) > (y); break; \ case OPCODE_LEQ: (z) = (x) <= (y); break; \ case OPCODE_GEQ: (z) = (x) >= (y); break; \ - default: assert(0); break; \ + default: UNREACHABLE; break; \ } - _Bool res; + _Bool res = 0; if(Object_IsInt(lop)) { @@ -596,8 +596,8 @@ static Object *do_relational_op(Object *lop, Object *rop, Opcode opcode, Heap *h static _Bool step(Runtime *runtime, Error *error) { - assert(runtime != NULL); - assert(error->occurred == 0); + ASSERT(runtime != NULL); + ASSERT(error->occurred == 0); Opcode opcode; Operand ops[3]; int opc = sizeof(ops) / sizeof(ops[0]); @@ -618,7 +618,7 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_POS: { - assert(opc == 0); + ASSERT(opc == 0); if(runtime->frame->used == 0) { @@ -632,7 +632,7 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_NEG: { - assert(opc == 0); + ASSERT(opc == 0); if(runtime->frame->used == 0) { @@ -641,13 +641,13 @@ static _Bool step(Runtime *runtime, Error *error) } Object *top = Stack_Top(runtime->stack, 0); - assert(top != NULL); + ASSERT(top != NULL); if(!Runtime_Pop(runtime, error, 1)) return 0; Heap *heap = Runtime_GetHeap(runtime); - assert(heap != NULL); + ASSERT(heap != NULL); if(Object_IsInt(top)) { @@ -683,7 +683,7 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_NOT: { - assert(opc == 0); + ASSERT(opc == 0); if(runtime->frame->used == 0) { @@ -696,7 +696,7 @@ static _Bool step(Runtime *runtime, Error *error) if(!Runtime_Pop(runtime, error, 1)) return 0; - assert(top != NULL); + ASSERT(top != NULL); _Bool v = Object_ToBool(top, error); @@ -718,7 +718,7 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_MUL: case OPCODE_DIV: { - assert(opc == 0); + ASSERT(opc == 0); Object *rop = Stack_Top(runtime->stack, 0); Object *lop = Stack_Top(runtime->stack, -1); @@ -728,8 +728,8 @@ static _Bool step(Runtime *runtime, Error *error) // We managed to pop rop and lop, // so we know they're not NULL. - assert(rop != NULL); - assert(lop != NULL); + ASSERT(rop != NULL); + ASSERT(lop != NULL); Object *res = do_math_op(lop, rop, opcode, runtime->heap, error); @@ -744,7 +744,7 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_EQL: case OPCODE_NQL: { - assert(opc == 0); + ASSERT(opc == 0); Object *rop = Stack_Top(runtime->stack, 0); Object *lop = Stack_Top(runtime->stack, -1); @@ -754,8 +754,8 @@ static _Bool step(Runtime *runtime, Error *error) // We managed to pop rop and lop, // so we know they're not NULL. - assert(rop != NULL); - assert(lop != NULL); + ASSERT(rop != NULL); + ASSERT(lop != NULL); _Bool rawres = Object_Compare(lop, rop, error); @@ -780,7 +780,7 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_LEQ: case OPCODE_GEQ: { - assert(opc == 0); + ASSERT(opc == 0); Object *rop = Stack_Top(runtime->stack, 0); Object *lop = Stack_Top(runtime->stack, -1); @@ -790,8 +790,8 @@ static _Bool step(Runtime *runtime, Error *error) // We managed to pop rop and lop, // so we know they're not NULL. - assert(rop != NULL); - assert(lop != NULL); + ASSERT(rop != NULL); + ASSERT(lop != NULL); Object *res = do_relational_op(lop, rop, opcode, runtime->heap, error); @@ -806,7 +806,7 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_AND: case OPCODE_OR: { - assert(opc == 0); + ASSERT(opc == 0); Object *rop = Stack_Top(runtime->stack, 0); Object *lop = Stack_Top(runtime->stack, -1); @@ -816,8 +816,8 @@ static _Bool step(Runtime *runtime, Error *error) // We managed to pop rop and lop, // so we know they're not NULL. - assert(rop != NULL); - assert(lop != NULL); + ASSERT(rop != NULL); + ASSERT(lop != NULL); _Bool raw_rop, raw_lop, raw_res; raw_lop = Object_ToBool(lop, error); @@ -828,7 +828,10 @@ static _Bool step(Runtime *runtime, Error *error) { case OPCODE_AND: raw_res = raw_lop && raw_rop; break; case OPCODE_OR: raw_res = raw_lop || raw_rop; break; - default: assert(0); break; + default: + UNREACHABLE; + raw_res = 0; + break; } Object *res = Object_FromBool(raw_res, runtime->heap, error); @@ -843,8 +846,8 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_ASS: { - assert(opc == 1); - assert(ops[0].type == OPTP_STRING); + ASSERT(opc == 1); + ASSERT(ops[0].type == OPTP_STRING); if(runtime->frame->used == 0) { @@ -853,7 +856,7 @@ static _Bool step(Runtime *runtime, Error *error) } Object *val = Stack_Top(runtime->stack, 0); - assert(val != NULL); + ASSERT(val != NULL); Object *key = Object_FromString(ops[0].as_string, -1, runtime->heap, error); @@ -867,7 +870,7 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_POP: { - assert(opc == 1); + ASSERT(opc == 1); if(!Runtime_Pop(runtime, error, ops[0].as_int)) return 0; @@ -876,13 +879,13 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_CALL: { - assert(opc == 2); - assert(ops[0].type == OPTP_INT); - assert(ops[1].type == OPTP_INT); + ASSERT(opc == 2); + ASSERT(ops[0].type == OPTP_INT); + ASSERT(ops[1].type == OPTP_INT); int argc = ops[0].as_int; int retc = ops[1].as_int; - assert(argc >= 0 && retc > 0); + ASSERT(argc >= 0 && retc > 0); if(runtime->frame->used < argc + 1) { @@ -891,7 +894,7 @@ static _Bool step(Runtime *runtime, Error *error) } Object *callable = Stack_Top(runtime->stack, 0); - assert(callable != NULL); + ASSERT(callable != NULL); Object *argv[8]; @@ -905,12 +908,12 @@ static _Bool step(Runtime *runtime, Error *error) for(int i = 0; i < argc; i += 1) { argv[i] = Stack_Top(runtime->stack, -(i+1)); - assert(argv[i] != NULL); + ASSERT(argv[i] != NULL); } - assert(error->occurred == 0); + ASSERT(error->occurred == 0); (void) Runtime_Pop(runtime, error, argc+1); - assert(error->occurred == 0); + ASSERT(error->occurred == 0); Object *rets[8]; unsigned int maxrets = sizeof(rets)/sizeof(rets[0]); @@ -922,7 +925,7 @@ static _Bool step(Runtime *runtime, Error *error) // NOTE: Every local object reference is invalidated from here. - assert(error->occurred == 0); + ASSERT(error->occurred == 0); for(int g = 0; g < MIN(num_rets, retc); g += 1) if(!Runtime_Push(runtime, error, rets[g])) @@ -943,7 +946,7 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_SELECT: { - assert(opc == 0); + ASSERT(opc == 0); if(runtime->frame->used < 2) { @@ -954,12 +957,12 @@ static _Bool step(Runtime *runtime, Error *error) Object *col = Stack_Top(runtime->stack, -1); Object *key = Stack_Top(runtime->stack, 0); - assert(col != NULL && key != NULL); + ASSERT(col != NULL && key != NULL); if(!Runtime_Pop(runtime, error, 2)) return 0; - assert(error->occurred == 0); + ASSERT(error->occurred == 0); Error dummy; Error_Init(&dummy); // We want to catch the error reported by this Object_Select. @@ -976,18 +979,18 @@ static _Bool step(Runtime *runtime, Error *error) return 0; } - assert(error->occurred == 0); + ASSERT(error->occurred == 0); if(!Runtime_Push(runtime, error, val)) return 0; - assert(error->occurred == 0); + ASSERT(error->occurred == 0); return 1; } case OPCODE_INSERT: { - assert(opc == 0); + ASSERT(opc == 0); if(runtime->frame->used < 3) { @@ -999,7 +1002,7 @@ static _Bool step(Runtime *runtime, Error *error) Object *key = Stack_Top(runtime->stack, -1); Object *val = Stack_Top(runtime->stack, 0); - assert(col != NULL && key != NULL && val != NULL); + ASSERT(col != NULL && key != NULL && val != NULL); if(!Runtime_Pop(runtime, error, 2)) return 0; @@ -1011,7 +1014,7 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_INSERT2: { - assert(opc == 0); + ASSERT(opc == 0); if(runtime->frame->used < 3) { @@ -1023,7 +1026,7 @@ static _Bool step(Runtime *runtime, Error *error) Object *col = Stack_Top(runtime->stack, -1); Object *key = Stack_Top(runtime->stack, 0); - assert(col != NULL && key != NULL && val != NULL); + ASSERT(col != NULL && key != NULL && val != NULL); if(!Runtime_Pop(runtime, error, 2)) return 0; @@ -1035,8 +1038,8 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_PUSHINT: { - assert(opc == 1); - assert(ops[0].type == OPTP_INT); + ASSERT(opc == 1); + ASSERT(ops[0].type == OPTP_INT); Object *obj = Object_FromInt(ops[0].as_int, runtime->heap, error); @@ -1050,8 +1053,8 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_PUSHFLT: { - assert(opc == 1); - assert(ops[0].type == OPTP_FLOAT); + ASSERT(opc == 1); + ASSERT(ops[0].type == OPTP_FLOAT); Object *obj = Object_FromFloat(ops[0].as_float, runtime->heap, error); @@ -1065,8 +1068,8 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_PUSHSTR: { - assert(opc == 1); - assert(ops[0].type == OPTP_STRING); + ASSERT(opc == 1); + ASSERT(ops[0].type == OPTP_STRING); Object *obj = Object_FromString(ops[0].as_string, -1, runtime->heap, error); @@ -1080,8 +1083,8 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_PUSHVAR: { - assert(opc == 1); - assert(ops[0].type == OPTP_STRING); + ASSERT(opc == 1); + ASSERT(ops[0].type == OPTP_STRING); Object *key = Object_FromString(ops[0].as_string, -1, runtime->heap, error); @@ -1120,7 +1123,7 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_PUSHNNE: { - assert(opc == 0); + ASSERT(opc == 0); Object *obj = Object_NewNone(runtime->heap, error); @@ -1134,7 +1137,7 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_PUSHTRU: { - assert(opc == 0); + ASSERT(opc == 0); Object *obj = Object_FromBool(1, runtime->heap, error); @@ -1148,7 +1151,7 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_PUSHFLS: { - assert(opc == 0); + ASSERT(opc == 0); Object *obj = Object_FromBool(0, runtime->heap, error); @@ -1162,9 +1165,9 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_PUSHFUN: { - assert(opc == 2); - assert(ops[0].type == OPTP_IDX); - assert(ops[1].type == OPTP_INT); + ASSERT(opc == 2); + ASSERT(ops[0].type == OPTP_IDX); + ASSERT(ops[1].type == OPTP_INT); Object *closure = Object_NewClosure(runtime->frame->closure, runtime->frame->locals, Runtime_GetHeap(runtime), error); @@ -1183,8 +1186,8 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_PUSHLST: { - assert(opc == 1); - assert(ops[0].type == OPTP_INT); + ASSERT(opc == 1); + ASSERT(ops[0].type == OPTP_INT); Object *obj = Object_NewList(ops[0].as_int, runtime->heap, error); @@ -1198,8 +1201,8 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_PUSHMAP: { - assert(opc == 1); - assert(ops[0].type == OPTP_INT); + ASSERT(opc == 1); + ASSERT(ops[0].type == OPTP_INT); Object *obj = Object_NewMap(ops[0].as_int, runtime->heap, error); @@ -1213,10 +1216,10 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_PUSHTYPTYP: { - assert(opc == 0); + ASSERT(opc == 0); Object *obj = (Object*) Object_GetTypeType(); - assert(obj != NULL); + ASSERT(obj != NULL); if(!Runtime_Push(runtime, error, obj)) return 0; @@ -1225,10 +1228,10 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_PUSHNNETYP: { - assert(opc == 0); + ASSERT(opc == 0); Object *obj = (Object*) Object_GetNoneType(); - assert(obj != NULL); + ASSERT(obj != NULL); if(!Runtime_Push(runtime, error, obj)) return 0; @@ -1237,7 +1240,7 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_PUSHTYP: { - assert(opc == 0); + ASSERT(opc == 0); if(runtime->frame->used < 1) { @@ -1246,10 +1249,10 @@ static _Bool step(Runtime *runtime, Error *error) } Object *top = Stack_Top(runtime->stack, 0); - assert(top != NULL); + ASSERT(top != NULL); Object *typ = (Object*) Object_GetType(top); - assert(typ != NULL); + ASSERT(typ != NULL); if(!Runtime_Push(runtime, error, typ)) return 0; @@ -1258,10 +1261,10 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_EXIT: { - assert(opc == 0); + ASSERT(opc == 0); Object *vars = runtime->frame->locals; - assert(vars != NULL); + ASSERT(vars != NULL); if(!Runtime_Push(runtime, error, vars)) return 0; @@ -1270,33 +1273,34 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_RETURN: { - assert(opc == 1); - assert(ops[0].type == OPTP_INT); + ASSERT(opc == 1); + ASSERT(ops[0].type == OPTP_INT); int retc = ops[0].as_int; - assert(retc >= 0); - assert(retc == runtime->frame->used); + UNUSED(retc); + ASSERT(retc >= 0); + ASSERT(retc == runtime->frame->used); return 0; } case OPCODE_ERROR: { - assert(opc == 1); - assert(ops[0].type == OPTP_STRING); + ASSERT(opc == 1); + ASSERT(ops[0].type == OPTP_STRING); const char *msg = ops[0].as_string; Error_Report(error, 0, "%s", msg); return 0; } case OPCODE_JUMP: - assert(opc == 1); - assert(ops[0].type == OPTP_IDX); + ASSERT(opc == 1); + ASSERT(ops[0].type == OPTP_IDX); runtime->frame->index = ops[0].as_int; return 1; case OPCODE_JUMPIFANDPOP: { - assert(opc == 1); - assert(ops[0].type == OPTP_IDX); + ASSERT(opc == 1); + ASSERT(ops[0].type == OPTP_IDX); long long int target = ops[0].as_int; @@ -1311,7 +1315,7 @@ static _Bool step(Runtime *runtime, Error *error) if(!Runtime_Pop(runtime, error, 1)) return 0; - assert(top != NULL); + ASSERT(top != NULL); if(!Object_IsBool(top)) { @@ -1327,8 +1331,8 @@ static _Bool step(Runtime *runtime, Error *error) case OPCODE_JUMPIFNOTANDPOP: { - assert(opc == 1); - assert(ops[0].type == OPTP_IDX); + ASSERT(opc == 1); + ASSERT(ops[0].type == OPTP_IDX); long long int target = ops[0].as_int; @@ -1343,7 +1347,7 @@ static _Bool step(Runtime *runtime, Error *error) if(!Runtime_Pop(runtime, error, 1)) return 0; - assert(top != NULL); + ASSERT(top != NULL); if(!Object_IsBool(top)) { @@ -1384,7 +1388,7 @@ static _Bool collect(Runtime *runtime, Error *error) for(unsigned int i = 0; i < Stack_Size(runtime->stack); i += 1) { Object **ref = (Object**) Stack_TopRef(runtime->stack, -i); - assert(ref != NULL); + ASSERT(ref != NULL); Heap_CollectReference(ref, runtime->heap); } @@ -1398,11 +1402,11 @@ int run(Runtime *runtime, Error *error, Object **argv, int argc, Object **rets, int maxretc) { - assert(runtime != NULL); - assert(error != NULL); - assert(exe != NULL); - assert(index >= 0); - assert(argc >= 0); + ASSERT(runtime != NULL); + ASSERT(error != NULL); + ASSERT(exe != NULL); + ASSERT(index >= 0); + ASSERT(argc >= 0); if(runtime->depth == MAX_FRAMES) { @@ -1410,7 +1414,7 @@ int run(Runtime *runtime, Error *error, return -1; } - assert(runtime->depth < MAX_FRAMES); + ASSERT(runtime->depth < MAX_FRAMES); // Initialize the frame. Frame frame; @@ -1485,7 +1489,7 @@ int run(Runtime *runtime, Error *error, for(int i = 0; i < retc; i += 1) { rets[i] = Stack_Top(runtime->stack, i - retc + 1); - assert(rets[i] != NULL); + ASSERT(rets[i] != NULL); } } diff --git a/src/lib/utils/bpalloc.c b/src/lib/utils/bpalloc.c index 5108afd..4d9956c 100644 --- a/src/lib/utils/bpalloc.c +++ b/src/lib/utils/bpalloc.c @@ -29,7 +29,6 @@ */ #include -#include #include #include "defs.h" #include "bpalloc.h" @@ -117,8 +116,8 @@ BPAlloc *BPAlloc_Init3(void *mem, int mem_size, int chunk_size, void *(*fn_malloc)(void *userp, int size), void (*fn_free )(void *userp, void *addr)) { - assert(mem != NULL); - assert(mem_size >= 0); + ASSERT(mem != NULL); + ASSERT(mem_size >= 0); if(chunk_size < 0) chunk_size = CHUNK_SIZE; @@ -161,7 +160,7 @@ BPAlloc *BPAlloc_Init3(void *mem, int mem_size, int chunk_size, void BPAlloc_Free(BPAlloc *alloc) { - assert(alloc != NULL); + ASSERT(alloc != NULL); #if USING_VALGRIND VALGRIND_DESTROY_MEMPOOL(alloc); @@ -186,8 +185,8 @@ void BPAlloc_Free(BPAlloc *alloc) void *BPAlloc_Malloc(BPAlloc *alloc, int req_size) { - assert(alloc != NULL); - assert(req_size >= 0); + ASSERT(alloc != NULL); + ASSERT(req_size >= 0); alloc->used += PADDING; @@ -201,7 +200,7 @@ void *BPAlloc_Malloc(BPAlloc *alloc, int req_size) // size to the requested size. int chunk_size = MAX(alloc->minsize, req_size + PADDING); - assert(alloc->fn_malloc != NULL); + ASSERT(alloc->fn_malloc != NULL); BPAllocChunk *chunk = alloc->fn_malloc(alloc->userp, sizeof(BPAllocChunk) + chunk_size); if(chunk == NULL) @@ -218,7 +217,7 @@ void *BPAlloc_Malloc(BPAlloc *alloc, int req_size) void *addr = alloc->tail->body + alloc->used; - assert(((intptr_t) addr) % 8 == 0); + ASSERT(((intptr_t) addr) % 8 == 0); alloc->used += req_size; @@ -233,15 +232,17 @@ void *BPAlloc_Malloc(BPAlloc *alloc, int req_size) static void *default_fn_malloc(void *userp, int size) { - assert(userp == NULL); - assert(size >= 0); + UNUSED(userp); + ASSERT(userp == NULL); + ASSERT(size >= 0); return malloc(size); } static void default_fn_free(void *userp, void *addr) { - assert(userp == NULL); + UNUSED(userp); + ASSERT(userp == NULL); free(addr); } diff --git a/src/lib/utils/defs.h b/src/lib/utils/defs.h index b40c803..4901898 100644 --- a/src/lib/utils/defs.h +++ b/src/lib/utils/defs.h @@ -28,8 +28,6 @@ ** +--------------------------------------------------------------------------+ */ -#include - #ifndef MAX #define MAX(x, y) ((x) > (y) ? (x) : (y)) #endif @@ -42,6 +40,26 @@ #define NULL ((void*) 0) #endif -#define UNREACHABLE assert(0); +#define UNUSED(x) ((void) (x)) + +#ifdef DEBUG +#define ASSERT(X) \ + do { \ + if(!(X)) { \ + fprintf(stderr, "Assertion failure %s:%d (in %s): [" #X "] is false\n", __FILE__, __LINE__, __func__); \ + abort(); \ + } \ + } while(0); +#define UNREACHABLE \ + do { \ + if(!(x)) { \ + fprintf(stderr, "ABORT at %s:%d (in %s): Reached code assumed to be unreachable\n", __FILE__, __LINE__, __func__); \ + abort(); \ + } \ + } while(0); +#else +#define ASSERT(x) +#define UNREACHABLE +#endif #define membersizeof(type, member) (sizeof(((type*) 0)->member)) \ No newline at end of file diff --git a/src/lib/utils/stack.c b/src/lib/utils/stack.c index bfce68b..27fbec7 100644 --- a/src/lib/utils/stack.c +++ b/src/lib/utils/stack.c @@ -55,7 +55,7 @@ void *Stack_New(int size) if(s == NULL) return NULL; - assert((intptr_t) s % 8 == 0); + ASSERT((intptr_t) s % 8 == 0); s->size = size; s->used = 0; @@ -70,7 +70,7 @@ static Stack *unmark(Stack *s) void *Stack_Top(Stack *s, int n) { - assert(n <= 0); + ASSERT(n <= 0); // Remove readonly bit. s = unmark(s); @@ -86,7 +86,7 @@ void *Stack_Top(Stack *s, int n) void **Stack_TopRef(Stack *s, int n) { - assert(n <= 0); + ASSERT(n <= 0); if(Stack_IsReadOnlyCopy(s)) return NULL; @@ -118,8 +118,8 @@ _Bool Stack_Pop(Stack *s, unsigned int n) _Bool Stack_Push(Stack *s, void *item) { - assert(s != NULL); - assert(item != NULL); + ASSERT(s != NULL); + ASSERT(item != NULL); if(Stack_IsReadOnlyCopy(s)) return 0; @@ -159,7 +159,7 @@ void Stack_Free(Stack *s) s = unmark(s); s->refs -= 1; - assert(s->refs >= 0); + ASSERT(s->refs >= 0); if(s->refs == 0) free(s); diff --git a/src/lib/utils/utf8.c b/src/lib/utils/utf8.c index a7ca9fd..f1ea34f 100644 --- a/src/lib/utils/utf8.c +++ b/src/lib/utils/utf8.c @@ -28,8 +28,8 @@ ** +--------------------------------------------------------------------------+ */ -#include #include // NULL +#include "defs.h" #include "utf8.h" // If this is turned on, these functions will assume @@ -137,8 +137,8 @@ int utf8_sequence_from_utf32_codepoint(char *utf8_data, int nbytes, uint32_t utf */ int utf8_sequence_to_utf32_codepoint(const char *utf8_data, int nbytes, uint32_t *utf32_code) { - assert(utf8_data != NULL); - assert(nbytes >= 0); + ASSERT(utf8_data != NULL); + ASSERT(nbytes >= 0); uint32_t dummy; if(utf32_code == NULL) @@ -204,7 +204,7 @@ int utf8_sequence_to_utf32_codepoint(const char *utf8_data, int nbytes, uint32_t = (((uint32_t) utf8_data[0] & 0x1f) << 6) | (((uint32_t) utf8_data[1] & 0x3f)); - assert(*utf32_code <= 0x10ffff); + ASSERT(*utf32_code <= 0x10ffff); return 2; } @@ -248,8 +248,8 @@ int utf8_sequence_to_utf32_codepoint(const char *utf8_data, int nbytes, uint32_t */ int utf8_strlen(const char *utf8_data, int nbytes) { - assert(utf8_data != NULL); - assert(nbytes >= 0); + ASSERT(utf8_data != NULL); + ASSERT(nbytes >= 0); int len = 0; @@ -324,8 +324,10 @@ int utf8_strlen(const char *utf8_data, int nbytes) */ int utf8_prev(const char *utf8_data, int nbytes, int idx, uint32_t *utf32_code) { - assert(idx >= 0); - assert(idx <= nbytes); + UNUSED(nbytes); + ASSERT(idx >= 0); + ASSERT(idx <= nbytes); + // [idx] currently refers to the head byte // of a UTF-8 sequence. We need to first @@ -384,13 +386,13 @@ int utf8_prev(const char *utf8_data, int nbytes, int idx, uint32_t *utf32_code) // The sequence wasn't valid UTF-8. return -1; - assert(n > 0); + ASSERT(n > 0); if(n < aux + 1) // Not all of the auxiliary bytes were considered while parsing. return -1; - assert(n == aux + 1); + ASSERT(n == aux + 1); return head; } @@ -444,8 +446,8 @@ int utf8_next(const char *utf8_data, int nbytes, int idx, uint32_t *utf32_code) int utf8_curr(const char *utf8_data, int nbytes, int idx, uint32_t *utf32_code) { - assert(idx >= 0); - assert(idx < nbytes); + ASSERT(idx >= 0); + ASSERT(idx < nbytes); int n = utf8_sequence_to_utf32_codepoint(utf8_data + idx, nbytes - idx, utf32_code);