Implemented clearing realloc() on the OS X backend.
This commit is contained in:
parent
ed9539de94
commit
cc56e2cece
|
@ -1,38 +1,54 @@
|
|||
// 4 december 2014
|
||||
#import <stdio.h>
|
||||
#import <stdlib.h>
|
||||
#import "uipriv_darwin.h"
|
||||
|
||||
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 SIZE(p) ((size_t *) (p))
|
||||
|
||||
void *uiAlloc(size_t size)
|
||||
{
|
||||
void *out;
|
||||
|
||||
out = malloc(size);
|
||||
out = malloc(sizeof (size_t) + size);
|
||||
if (out == NULL) {
|
||||
fprintf(stderr, "memory exhausted in uiAlloc()\n");
|
||||
abort();
|
||||
}
|
||||
memset(out, 0, size);
|
||||
return out;
|
||||
memset(DATA(out), 0, size);
|
||||
*SIZE(out) = size;
|
||||
return DATA(out);
|
||||
}
|
||||
|
||||
void *uiRealloc(void *p, size_t size)
|
||||
void *uiRealloc(void *p, size_t new)
|
||||
{
|
||||
void *out;
|
||||
size_t *s;
|
||||
|
||||
if (p == NULL)
|
||||
return uiAlloc(size);
|
||||
out = realloc(p, size);
|
||||
return uiAlloc(new);
|
||||
p = BASE(p);
|
||||
out = realloc(p, sizeof (size_t) + new);
|
||||
if (out == NULL) {
|
||||
fprintf(stderr, "memory exhausted in uiRealloc()\n");
|
||||
abort();
|
||||
}
|
||||
// TODO zero the extra memory
|
||||
return out;
|
||||
s = SIZE(out);
|
||||
if (new <= *s)
|
||||
memset(((uint8_t *) DATA(out)) + *s, 0, new - *s);
|
||||
*s = new;
|
||||
return DATA(out);
|
||||
}
|
||||
|
||||
void uiFree(void *p)
|
||||
{
|
||||
if (p == NULL)
|
||||
return;
|
||||
free(p);
|
||||
free(BASE(p));
|
||||
}
|
||||
|
|
|
@ -53,6 +53,8 @@ const char *uiInit(uiInitOptions *o)
|
|||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||
[NSApp setDelegate:[appDelegate new]];
|
||||
|
||||
initAlloc();
|
||||
|
||||
// always do this so we always have an application menu
|
||||
appDelegate().menuManager = [menuManager new];
|
||||
[NSApp setMainMenu:[appDelegate().menuManager makeMenubar]];
|
||||
|
|
|
@ -46,3 +46,6 @@ extern void finishNewTextField(NSTextField *, BOOL);
|
|||
|
||||
// window.m
|
||||
extern uiWindow *windowFromNSWindow(NSWindow *);
|
||||
|
||||
// alloc.m
|
||||
extern void initAlloc(void);
|
||||
|
|
Loading…
Reference in New Issue