2015-04-22 16:54:05 -05:00
|
|
|
// 7 april 2015
|
2015-05-04 18:26:05 -05:00
|
|
|
#include <string.h>
|
2015-04-22 16:54:05 -05:00
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
2015-05-04 18:26:05 -05:00
|
|
|
void initAlloc(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-05-04 18:55:39 -05:00
|
|
|
#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 SIZE(p) ((size_t *) (p))
|
|
|
|
|
2015-05-03 18:52:24 -05:00
|
|
|
void *uiAlloc(size_t size)
|
2015-04-22 16:54:05 -05:00
|
|
|
{
|
|
|
|
void *out;
|
|
|
|
|
2015-05-04 18:55:39 -05:00
|
|
|
out = g_malloc0(sizeof (size_t) + size);
|
|
|
|
*SIZE(out) = size;
|
|
|
|
return DATA(out);
|
2015-04-22 16:54:05 -05:00
|
|
|
}
|
|
|
|
|
2015-05-04 18:26:05 -05:00
|
|
|
void *uiRealloc(void *p, size_t new)
|
2015-04-22 16:54:05 -05:00
|
|
|
{
|
|
|
|
void *out;
|
2015-05-04 18:26:05 -05:00
|
|
|
size_t *s;
|
2015-04-22 16:54:05 -05:00
|
|
|
|
|
|
|
if (p == NULL)
|
2015-05-04 18:26:05 -05:00
|
|
|
return uiAlloc(new);
|
2015-05-04 18:55:39 -05:00
|
|
|
p = BASE(p);
|
2015-05-04 19:02:00 -05:00
|
|
|
out = g_realloc(p, sizeof (size_t) + new);
|
2015-05-04 18:55:39 -05:00
|
|
|
s = SIZE(out);
|
2015-05-04 18:26:05 -05:00
|
|
|
if (new <= *s)
|
2015-05-04 18:55:39 -05:00
|
|
|
memset(((uint8_t *) DATA(out)) + *s, 0, new - *s);
|
2015-05-04 18:26:05 -05:00
|
|
|
*s = new;
|
2015-05-04 18:55:39 -05:00
|
|
|
return DATA(out);
|
2015-04-22 16:54:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiFree(void *p)
|
|
|
|
{
|
2015-05-07 16:45:34 -05:00
|
|
|
if (p == NULL)
|
|
|
|
complain("attempt to uiFree(NULL); there's a bug somewhere");
|
2015-05-04 18:55:39 -05:00
|
|
|
g_free(BASE(p));
|
2015-04-22 16:54:05 -05:00
|
|
|
}
|