renamed context to context

This commit is contained in:
Pünkösd Marcell 2020-11-03 18:25:18 +01:00
parent fba1b6487f
commit 267ec89571
2 changed files with 17 additions and 16 deletions

View File

@ -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
}

View File

@ -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