fix constant issue, and make running of test program dependent on successful build

This commit is contained in:
2025-10-09 21:17:29 +02:00
parent 4942d959d5
commit 6e3211ab49
4 changed files with 11 additions and 9 deletions
+2 -2
View File
@@ -38,7 +38,7 @@ void allocator_free_func(allocator_t this, void *ptr, const char *file, int line
#define allocator_free(this, ptr) allocator_free_func(this, ptr, __FILE__, __LINE__)
// std_allocator ///////////////////////////////////////////////////////////////
extern const allocator_t allocator_stdlib;
allocator_t allocator_stdlib();
// buffer_allocator ////////////////////////////////////////////////////////////
typedef struct buffer_allocator {
size_t size, capacity;
@@ -47,7 +47,7 @@ typedef struct buffer_allocator {
#define buffer_allocator_create(CAPACITY) \
((buffer_allocator_t){ \
.size = 0, .capacity = CAPACITY, .data = (uint8_t[CAPACITY]){}})
.size = 0, .capacity = CAPACITY, .data = (uint8_t[CAPACITY]){0}})
allocator_t buffer_allocator_interface(buffer_allocator_t *this);
void *buffer_allocator_alloc(buffer_allocator_t *this, size_t bytes);
+2 -2
View File
@@ -1,6 +1,6 @@
CC := gcc
CFLAGS := -Wall -Wextra -Wno-override-init -O0 -g -fno-omit-frame-pointer -fno-inline
CFLAGS := -std=c99 -pedantic -Wall -Wextra -Wno-override-init -O0 -g -fno-omit-frame-pointer -fno-inline
LDFLAGS := -lcriterion
TESTBIN := /tmp/all_tests
@@ -14,7 +14,7 @@ test:
echo "No test files found!"; \
else \
echo "Compiling all test files into $(TESTBIN)..."; \
$(CC) $(CFLAGS) _allocator_impl.c $$files -o $(TESTBIN) $(LDFLAGS); \
$(CC) $(CFLAGS) _allocator_impl.c $$files -o $(TESTBIN) $(LDFLAGS) || exit 1; \
echo "Running tests..."; \
valgrind $(TESTBIN); \
fi
+6 -4
View File
@@ -25,8 +25,10 @@ static const allocator_vtbl_t stdlib_vtbl = {
.free = stdlib_free,
};
const allocator_t allocator_stdlib = (allocator_t) {
.this=NULL,
.vtbl=&stdlib_vtbl,
};
allocator_t allocator_stdlib() {
return (allocator_t) {
.this=NULL,
.vtbl=&stdlib_vtbl,
};
}
+1 -1
View File
@@ -3,7 +3,7 @@
Test(std_allocator, test) {
allocator_t this = allocator_stdlib;
allocator_t this = allocator_stdlib();
void *ptr = allocator_alloc(this, 10);
cr_assert(ptr != ((void *)0), "non null from malloc");
void *new_ptr = allocator_resize(this, ptr, 1024*1024*500);