fix constant issue, and make running of test program dependent on successful build
This commit is contained in:
+2
-2
@@ -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__)
|
#define allocator_free(this, ptr) allocator_free_func(this, ptr, __FILE__, __LINE__)
|
||||||
|
|
||||||
// std_allocator ///////////////////////////////////////////////////////////////
|
// std_allocator ///////////////////////////////////////////////////////////////
|
||||||
extern const allocator_t allocator_stdlib;
|
allocator_t allocator_stdlib();
|
||||||
// buffer_allocator ////////////////////////////////////////////////////////////
|
// buffer_allocator ////////////////////////////////////////////////////////////
|
||||||
typedef struct buffer_allocator {
|
typedef struct buffer_allocator {
|
||||||
size_t size, capacity;
|
size_t size, capacity;
|
||||||
@@ -47,7 +47,7 @@ typedef struct buffer_allocator {
|
|||||||
|
|
||||||
#define buffer_allocator_create(CAPACITY) \
|
#define buffer_allocator_create(CAPACITY) \
|
||||||
((buffer_allocator_t){ \
|
((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);
|
allocator_t buffer_allocator_interface(buffer_allocator_t *this);
|
||||||
void *buffer_allocator_alloc(buffer_allocator_t *this, size_t bytes);
|
void *buffer_allocator_alloc(buffer_allocator_t *this, size_t bytes);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
CC := gcc
|
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
|
LDFLAGS := -lcriterion
|
||||||
|
|
||||||
TESTBIN := /tmp/all_tests
|
TESTBIN := /tmp/all_tests
|
||||||
@@ -14,7 +14,7 @@ test:
|
|||||||
echo "No test files found!"; \
|
echo "No test files found!"; \
|
||||||
else \
|
else \
|
||||||
echo "Compiling all test files into $(TESTBIN)..."; \
|
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..."; \
|
echo "Running tests..."; \
|
||||||
valgrind $(TESTBIN); \
|
valgrind $(TESTBIN); \
|
||||||
fi
|
fi
|
||||||
|
|||||||
+4
-2
@@ -25,8 +25,10 @@ static const allocator_vtbl_t stdlib_vtbl = {
|
|||||||
.free = stdlib_free,
|
.free = stdlib_free,
|
||||||
};
|
};
|
||||||
|
|
||||||
const allocator_t allocator_stdlib = (allocator_t) {
|
allocator_t allocator_stdlib() {
|
||||||
|
return (allocator_t) {
|
||||||
.this=NULL,
|
.this=NULL,
|
||||||
.vtbl=&stdlib_vtbl,
|
.vtbl=&stdlib_vtbl,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
Test(std_allocator, test) {
|
Test(std_allocator, test) {
|
||||||
allocator_t this = allocator_stdlib;
|
allocator_t this = allocator_stdlib();
|
||||||
void *ptr = allocator_alloc(this, 10);
|
void *ptr = allocator_alloc(this, 10);
|
||||||
cr_assert(ptr != ((void *)0), "non null from malloc");
|
cr_assert(ptr != ((void *)0), "non null from malloc");
|
||||||
void *new_ptr = allocator_resize(this, ptr, 1024*1024*500);
|
void *new_ptr = allocator_resize(this, ptr, 1024*1024*500);
|
||||||
|
|||||||
Reference in New Issue
Block a user