From 33f41d6c3797eb0d4c048f28e51315cb28862723 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 8 May 2015 17:29:36 -0400 Subject: [PATCH] Implemented the allocation type stuff on OS X. --- darwin/alloc.m | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/darwin/alloc.m b/darwin/alloc.m index 611ed440..07f5d99c 100644 --- a/darwin/alloc.m +++ b/darwin/alloc.m @@ -8,33 +8,41 @@ void initAlloc(void) #define UINT8(p) ((uint8_t *) (p)) #define PVOID(p) ((void *) (p)) -#define DATA(p) PVOID(UINT8(p) + sizeof (size_t)) -#define BASE(p) PVOID(UINT8(p) - sizeof (size_t)) +#define EXTRA (sizeof (size_t) + sizeof (const char **)) +#define DATA(p) PVOID(UINT8(p) + EXTRA) +#define BASE(p) PVOID(UINT8(p) - EXTRA) #define SIZE(p) ((size_t *) (p)) +#define CCHAR(p) ((const char **) (p)) +#define TYPE(p) CCHAR(UINT8(p) + sizeof (size_t)) -void *uiAlloc(size_t size) +void uninitAlloc(void) +{ +} + +void *uiAlloc(size_t size, const char *type) { void *out; - out = malloc(sizeof (size_t) + size); + out = malloc(EXTRA + size); if (out == NULL) { fprintf(stderr, "memory exhausted in uiAlloc()\n"); abort(); } memset(DATA(out), 0, size); *SIZE(out) = size; + *TYPE(out) = type; return DATA(out); } -void *uiRealloc(void *p, size_t new) +void *uiRealloc(void *p, size_t new, const char *type) { void *out; size_t *s; if (p == NULL) - return uiAlloc(new); + return uiAlloc(new, type); p = BASE(p); - out = realloc(p, sizeof (size_t) + new); + out = realloc(p, EXTRA + new); if (out == NULL) { fprintf(stderr, "memory exhausted in uiRealloc()\n"); abort();