diff --git a/allocator.h b/allocator.h index cfa84ad..f70e243 100644 --- a/allocator.h +++ b/allocator.h @@ -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); diff --git a/makefile b/makefile index 49326d7..691a36d 100644 --- a/makefile +++ b/makefile @@ -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 diff --git a/std_allocator.c b/std_allocator.c index 23398d7..10f098d 100644 --- a/std_allocator.c +++ b/std_allocator.c @@ -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, + }; +} diff --git a/test_std_allocator.c b/test_std_allocator.c index a764e4c..98a22d1 100644 --- a/test_std_allocator.c +++ b/test_std_allocator.c @@ -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);