fixed compiler warnings for release builds

This commit is contained in:
cozis
2022-08-16 22:45:46 +02:00
parent 7b9bf06630
commit 919bc6fcbd
18 changed files with 507 additions and 466 deletions
+12 -11
View File
@@ -29,7 +29,6 @@
*/
#include <stdint.h>
#include <assert.h>
#include <stdlib.h>
#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);
}
+21 -3
View File
@@ -28,8 +28,6 @@
** +--------------------------------------------------------------------------+
*/
#include <assert.h>
#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))
+6 -6
View File
@@ -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);
+14 -12
View File
@@ -28,8 +28,8 @@
** +--------------------------------------------------------------------------+
*/
#include <assert.h>
#include <stddef.h> // 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);