aboutsummaryrefslogtreecommitdiff
path: root/teensy/teensy_mem.c
diff options
context:
space:
mode:
Diffstat (limited to 'teensy/teensy_mem.c')
-rw-r--r--teensy/teensy_mem.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/teensy/teensy_mem.c b/teensy/teensy_mem.c
index 62088b8..7e8dd58 100644
--- a/teensy/teensy_mem.c
+++ b/teensy/teensy_mem.c
@@ -14,16 +14,16 @@ uint8_t *next_temp_alloc = temp_arena;
#define BACKTRACE_SIZE 16
-struct alloc {
+typedef struct {
void *ptr;
size_t size;
int backtrace_len;
char **backtrace;
-};
+} Alloc;
int allocations_cap;
int allocations_len;
-struct alloc *allocations;
+Alloc *allocations;
#endif // TODO TEENSY_DEBUG
@@ -32,7 +32,7 @@ void ty_init_mem(void)
#ifdef TEENSY_DEBUG
allocations_len = 0;
allocations_cap = 8;
- allocations = malloc(sizeof(struct alloc) * 8);
+ allocations = malloc(sizeof(Alloc) * 8);
if (!allocations)
ty_log_fatal(TY_ERR_MEM, "(%s) (track) ran out of memory", __func__);
#endif // TEENSY_DEBUG
@@ -43,7 +43,7 @@ void ty_deinit_mem(void)
#ifdef TEENSY_DEBUG
fprintf(stderr, "%d allocations leaked\n", allocations_len);
for (int i = 0; i < allocations_len; i++) {
- struct alloc *alloc = &allocations[i];
+ Alloc *alloc = &allocations[i];
fprintf(
stderr,
"leaked %zu bytes at %p\n",
@@ -87,7 +87,7 @@ void *ty_alloc(size_t size)
#ifdef TEENSY_DEBUG
// Log allocation
- struct alloc alloc;
+ Alloc alloc;
void *bt[BACKTRACE_SIZE];
int bt_len = backtrace(bt, BACKTRACE_SIZE);
char **symbols = backtrace_symbols(bt, bt_len);
@@ -130,7 +130,7 @@ void *ty_realloc(void *ptr, size_t new_size)
#ifdef TEENSY_DEBUG
for (int i = 0; i < allocations_len; i++) {
- struct alloc *alloc = &allocations[i];
+ Alloc *alloc = &allocations[i];
if (alloc->ptr == ptr) {
alloc->ptr = new_ptr;
alloc->size = new_size;
@@ -148,7 +148,7 @@ void ty_free(void *ptr)
bool double_free = true;
for (int i = 0; i < allocations_len; i++) {
- struct alloc *alloc = &allocations[i];
+ Alloc *alloc = &allocations[i];
if (alloc->ptr == ptr) {
free(alloc->backtrace);
*alloc = allocations[allocations_len - 1];