Eliminated direct use of strdup(); introduced uiDarwinNSStringToText() to do that work for us (and abort on failure).
This commit is contained in:
parent
5bbaaeefe8
commit
a38024c781
|
@ -7,7 +7,7 @@ void *uiAlloc(size_t size, const char *type)
|
||||||
void *out;
|
void *out;
|
||||||
|
|
||||||
out = malloc(size);
|
out = malloc(size);
|
||||||
if (out != NULL) {
|
if (out == NULL) {
|
||||||
fprintf(stderr, "memory exhausted in uiAlloc() allocating %s\n", type);
|
fprintf(stderr, "memory exhausted in uiAlloc() allocating %s\n", type);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ void *uiRealloc(void *p, size_t size, const char *type)
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return uiAlloc(size, type);
|
return uiAlloc(size, type);
|
||||||
out = realloc(p, size);
|
out = realloc(p, size);
|
||||||
if (out != NULL) {
|
if (out == NULL) {
|
||||||
fprintf(stderr, "memory exhausted in uiRealloc() reallocating %s\n", type);
|
fprintf(stderr, "memory exhausted in uiRealloc() reallocating %s\n", type);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ char *uiButtonText(uiControl *c)
|
||||||
uiNSButton *b;
|
uiNSButton *b;
|
||||||
|
|
||||||
b = (uiNSButton *) uiControlHandle(c);
|
b = (uiNSButton *) uiControlHandle(c);
|
||||||
return strdup(fromNSString([b title]));
|
return uiDarwinNSStringToText([b title]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiButtonSetText(uiControl *c, const char *text)
|
void uiButtonSetText(uiControl *c, const char *text)
|
||||||
|
|
|
@ -57,7 +57,7 @@ char *uiCheckboxText(uiControl *c)
|
||||||
uiCheckboxNSButton *cc;
|
uiCheckboxNSButton *cc;
|
||||||
|
|
||||||
cc = (uiCheckboxNSButton *) uiControlHandle(c);
|
cc = (uiCheckboxNSButton *) uiControlHandle(c);
|
||||||
return strdup(fromNSString([cc title]));
|
return uiDarwinNSStringToText([cc title]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiCheckboxSetText(uiControl *c, const char *text)
|
void uiCheckboxSetText(uiControl *c, const char *text)
|
||||||
|
|
|
@ -55,8 +55,7 @@ char *uiEntryText(uiControl *c)
|
||||||
uiNSTextField *t;
|
uiNSTextField *t;
|
||||||
|
|
||||||
t = (uiNSTextField *) uiControlHandle(c);
|
t = (uiNSTextField *) uiControlHandle(c);
|
||||||
// TODO wrap all strdup calls
|
return uiDarwinNSStringToText([t stringValue]);
|
||||||
return strdup(fromNSString([t stringValue]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiEntrySetText(uiControl *c, const char *text)
|
void uiEntrySetText(uiControl *c, const char *text)
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// 10 april 2015
|
||||||
|
#import "uipriv_darwin.h"
|
||||||
|
|
||||||
|
char *uiDarwinNSStringToText(NSString *s)
|
||||||
|
{
|
||||||
|
char *out;
|
||||||
|
|
||||||
|
out = strdup([s UTF8String]);
|
||||||
|
if (out == NULL) {
|
||||||
|
fprintf(stderr, "memory exhausted in uiDarwinNSStringToText()\n");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
|
@ -15,6 +15,9 @@ This file assumes that you have imported <Cocoa/Cocoa.h> and "ui.h" beforehand.
|
||||||
extern uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHasBorder);
|
extern uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHasBorder);
|
||||||
extern BOOL uiDarwinControlFreeWhenAppropriate(uiControl *c, NSView *newSuperview);
|
extern BOOL uiDarwinControlFreeWhenAppropriate(uiControl *c, NSView *newSuperview);
|
||||||
|
|
||||||
|
// You can use this function from within your control implementations to return text strings that can be freed with uiTextFree().
|
||||||
|
extern char *uiDarwinNSStringToText(NSString *);
|
||||||
|
|
||||||
struct uiSizingSys {
|
struct uiSizingSys {
|
||||||
// this structure currently left blank
|
// this structure currently left blank
|
||||||
};
|
};
|
||||||
|
|
|
@ -81,7 +81,7 @@ uintptr_t uiWindowHandle(uiWindow *w)
|
||||||
|
|
||||||
char *uiWindowTitle(uiWindow *w)
|
char *uiWindowTitle(uiWindow *w)
|
||||||
{
|
{
|
||||||
return strdup(fromNSString([D.w title]));
|
return uiDarwinNSStringToText([D.w title]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiWindowSetTitle(uiWindow *w, const char *title)
|
void uiWindowSetTitle(uiWindow *w, const char *title)
|
||||||
|
|
Loading…
Reference in New Issue