diff --git a/src/magic_memory.c b/src/magic_memory.c index 8f25b3d..bb498ea 100644 --- a/src/magic_memory.c +++ b/src/magic_memory.c @@ -6,8 +6,8 @@ #include "magic_memory.h" -magic_memory_t *magic_memory_begin(void) { - magic_memory_t *new_mm = (magic_memory_t *) malloc(sizeof(magic_memory_t)); +magic_memory_context_t *magic_memory_begin(void) { + magic_memory_context_t *new_mm = (magic_memory_context_t *) malloc(sizeof(magic_memory_context_t)); if (new_mm == NULL) { return NULL; @@ -19,9 +19,9 @@ magic_memory_t *magic_memory_begin(void) { return new_mm; } -void *magic_malloc(magic_memory_t *magic_memory, size_t size) { +void *magic_malloc(magic_memory_context_t *magic_memory, size_t size) { - magic_memory_t *mm = (magic_memory_t *) malloc(sizeof(magic_memory_t)); + magic_memory_context_t *mm = (magic_memory_context_t *) malloc(sizeof(magic_memory_context_t)); if (mm == NULL) { return NULL; @@ -37,7 +37,7 @@ void *magic_malloc(magic_memory_t *magic_memory, size_t size) { mm->ptr = new_ptr; mm->next = NULL; - magic_memory_t *p = magic_memory; + magic_memory_context_t *p = magic_memory; while (p->next != NULL) { p = p->next; } @@ -46,9 +46,9 @@ void *magic_malloc(magic_memory_t *magic_memory, size_t size) { return new_ptr; } -void magic_free(magic_memory_t *magic_memory, void *ptr) { +void magic_free(magic_memory_context_t *magic_memory, void *ptr) { - magic_memory_t *p = magic_memory; + magic_memory_context_t *p = magic_memory; while (p != NULL) { if (p->ptr == ptr) { free(p->ptr); @@ -60,15 +60,15 @@ void magic_free(magic_memory_t *magic_memory, void *ptr) { } -void magic_cleanup(magic_memory_t *magic_memory) { +void magic_cleanup(magic_memory_context_t *magic_memory) { - magic_memory_t *p = magic_memory; + magic_memory_context_t *p = magic_memory; while (p != NULL) { if (p->ptr != NULL) { free(p->ptr); // Free up the block this chain element points to } - magic_memory_t* p_old = p; + magic_memory_context_t* p_old = p; p = p->next; free(p_old); // Free up the chain piece itself } diff --git a/src/magic_memory.h b/src/magic_memory.h index d543ee8..1a8684f 100644 --- a/src/magic_memory.h +++ b/src/magic_memory.h @@ -5,14 +5,15 @@ #ifndef CAFF_PREVIEWER_MAGIC_MEMORY_H #define CAFF_PREVIEWER_MAGIC_MEMORY_H -typedef struct magic_memory_t { +typedef struct magic_memory_context_t { void* next; void *ptr; -} magic_memory_t; +} magic_memory_context_t; -magic_memory_t* magic_memory_begin(void); -void* magic_malloc(magic_memory_t* magic_memory, size_t size); -void magic_free(magic_memory_t* magic_memory, void* ptr); -void magic_cleanup(magic_memory_t* magic_memory); +magic_memory_context_t* magic_memory_begin(void); +void* magic_malloc(magic_memory_context_t* magic_memory, size_t size); + +void magic_free(magic_memory_context_t* magic_memory, void* ptr); +void magic_cleanup(magic_memory_context_t* magic_memory); #endif //CAFF_PREVIEWER_MAGIC_MEMORY_H