Skip to content

Commit

Permalink
Hide old alloc functions behind macro
Browse files Browse the repository at this point in the history
  • Loading branch information
knot126 committed Jun 13, 2024
1 parent 6359942 commit 7f104b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "memory.h"

#if DG_MELON_OLD_MEMORY_FUNCTIONS
void *DgAlloc(size_t size) {
/**
* Allocate some memory, or return NULL on failure.
Expand Down Expand Up @@ -53,6 +54,7 @@ void *DgRealloc(void* block, size_t size) {

return realloc(block, size);
}
#endif

void *DgMemoryAllocate(size_t size) {
/**
Expand All @@ -62,7 +64,7 @@ void *DgMemoryAllocate(size_t size) {
* @return Pointer to the allocated memory, or NULL if failed
*/

return DgAlloc(size);
return malloc(size);
}

DgError DgMemoryFree(void *block) {
Expand All @@ -78,7 +80,7 @@ DgError DgMemoryFree(void *block) {
return DG_ERROR_NOT_SAFE;
}

DgFree(block);
free(block);

return DG_ERROR_SUCCESS;
}
Expand All @@ -104,7 +106,7 @@ void *DgMemoryReallocate(void* block, size_t size) {
return DgMemoryAllocate(size);
}
else {
return DgRealloc(block, size);
return realloc(block, size);
}
}

Expand Down
2 changes: 2 additions & 0 deletions source/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
#include <stdlib.h>
#include "error.h"

#if DG_MELON_OLD_MEMORY_FUNCTIONS
void *DgAlloc(size_t size);
void DgFree(void *block);
void *DgRealloc(void *block, size_t size);
#endif

void *DgMemoryAllocate(size_t size);
DgError DgMemoryFree(void *block);
Expand Down

0 comments on commit 7f104b4

Please sign in to comment.