2015-04-06 18:04:13 -05:00
|
|
|
// 4 december 2014
|
2015-04-07 22:40:18 -05:00
|
|
|
#import <stdio.h>
|
2015-04-06 23:26:27 -05:00
|
|
|
#import "uipriv_darwin.h"
|
2015-04-06 18:04:13 -05:00
|
|
|
|
2015-04-07 22:40:18 -05:00
|
|
|
void *uiAlloc(size_t size, const char *type)
|
2015-04-06 18:04:13 -05:00
|
|
|
{
|
|
|
|
void *out;
|
|
|
|
|
|
|
|
out = malloc(size);
|
2015-04-10 12:24:34 -05:00
|
|
|
if (out == NULL) {
|
2015-04-10 12:06:29 -05:00
|
|
|
fprintf(stderr, "memory exhausted in uiAlloc() allocating %s\n", type);
|
|
|
|
abort();
|
|
|
|
}
|
2015-04-06 18:04:13 -05:00
|
|
|
memset(out, 0, size);
|
2015-04-09 21:38:11 -05:00
|
|
|
if (options.debugLogAllocations)
|
|
|
|
fprintf(stderr, "%p alloc %s\n", out, type);
|
2015-04-06 18:04:13 -05:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2015-04-07 22:40:18 -05:00
|
|
|
void *uiRealloc(void *p, size_t size, const char *type)
|
2015-04-06 18:04:13 -05:00
|
|
|
{
|
|
|
|
void *out;
|
|
|
|
|
|
|
|
if (p == NULL)
|
2015-04-07 22:40:18 -05:00
|
|
|
return uiAlloc(size, type);
|
2015-04-06 18:04:13 -05:00
|
|
|
out = realloc(p, size);
|
2015-04-10 12:24:34 -05:00
|
|
|
if (out == NULL) {
|
2015-04-10 12:06:29 -05:00
|
|
|
fprintf(stderr, "memory exhausted in uiRealloc() reallocating %s\n", type);
|
|
|
|
abort();
|
|
|
|
}
|
2015-04-06 18:04:13 -05:00
|
|
|
// TODO zero the extra memory
|
2015-04-09 21:38:11 -05:00
|
|
|
if (options.debugLogAllocations)
|
|
|
|
fprintf(stderr, "%p realloc %p\n", p, out);
|
2015-04-06 18:04:13 -05:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiFree(void *p)
|
|
|
|
{
|
|
|
|
if (p == NULL)
|
|
|
|
return;
|
|
|
|
free(p);
|
2015-04-09 21:38:11 -05:00
|
|
|
if (options.debugLogAllocations)
|
|
|
|
fprintf(stderr, "%p free\n", p);
|
2015-04-06 18:04:13 -05:00
|
|
|
}
|