Skip to content

Commit

Permalink
remove HLL_MEM_CHECK
Browse files Browse the repository at this point in the history
  • Loading branch information
Holodome committed Oct 16, 2023
1 parent 4f3dcbe commit 449ca48
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 28 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ifneq (,$(STRESS_GC))
endif

ifneq (,$(DEBUG))
CFLAGS += -O0 -g -DHLL_DEBUG -DHLL_MEM_CHECK
CFLAGS += -O0 -g -DHLL_DEBUG
else
CFLAGS += -DNDEBUG
endif
Expand Down
11 changes: 0 additions & 11 deletions hololisp/hll_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,8 @@ void *hll_sb_grow_impl(void *arr, size_t inc, size_t stride) {
return header + 1;
}

#ifdef HLL_MEM_CHECK
static size_t global_allocated_size;
size_t hll_mem_check(void) { return global_allocated_size; }
#endif

void *hll_realloc(void *ptr, size_t old_size, size_t new_size) {
#ifdef HLL_MEM_CHECK
assert(global_allocated_size >= old_size);
global_allocated_size -= old_size;
global_allocated_size += new_size;
#else
(void)old_size;
#endif
if (old_size == 0) {
assert(ptr == NULL);
void *result = calloc(1, new_size);
Expand Down
4 changes: 0 additions & 4 deletions hololisp/hll_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,5 @@ void *hll_sb_grow_impl(void *arr, size_t inc, size_t stride);
void *hll_realloc(void *ptr, size_t old_size, size_t new_size)
__attribute__((alloc_size(3)));

#ifdef HLL_MEM_CHECK
// Retturns number of bytes allocated but not freed.
size_t hll_mem_check(void);
#endif

#endif
12 changes: 0 additions & 12 deletions hololisp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
#include "hll_compiler.h"
#include "hll_hololisp.h"

#ifdef HLL_MEM_CHECK
#include "hll_mem.h"
#endif

typedef enum {
HLL_MODE_EREPL,
HLL_MODE_EREPL_NO_TTY,
Expand Down Expand Up @@ -273,13 +269,5 @@ int main(int argc, const char **argv) {
}

out:
(void)0;
#if HLL_MEM_CHECK
size_t not_freed = hll_mem_check();
if (not_freed) {
fprintf(stderr, "Memory check failed: %zu not freed!\n", not_freed);
result = EXIT_FAILURE;
}
#endif
return result;
}

0 comments on commit 449ca48

Please sign in to comment.