uiAlloc() et al -> uiprivAlloc() et al, Windows code.

This commit is contained in:
Pietro Gagliardi 2018-04-15 18:12:58 -04:00
parent 099c4ff631
commit c6bb463692
31 changed files with 106 additions and 106 deletions

View File

@ -27,7 +27,7 @@ void uninitAlloc(void)
#define rawBytes(pa) (&((*pa)[0]))
void *uiAlloc(size_t size, const char *type)
void *uiprivAlloc(size_t size, const char *type)
{
byteArray *out;
@ -37,13 +37,13 @@ void *uiAlloc(size_t size, const char *type)
return rawBytes(out);
}
void *uiRealloc(void *_p, size_t size, const char *type)
void *uiprivRealloc(void *_p, size_t size, const char *type)
{
uint8_t *p = (uint8_t *) _p;
byteArray *arr;
if (p == NULL)
return uiAlloc(size, type);
return uiprivAlloc(size, type);
arr = heap[p];
// TODO does this fill in?
arr->resize(size, 0);
@ -52,12 +52,12 @@ void *uiRealloc(void *_p, size_t size, const char *type)
return rawBytes(arr);
}
void uiFree(void *_p)
void uiprivFree(void *_p)
{
uint8_t *p = (uint8_t *) _p;
if (p == NULL)
implbug("attempt to uiFree(NULL)");
implbug("attempt to uiprivFree(NULL)");
types.erase(heap[p]);
delete heap[p];
heap.erase(p);

View File

@ -295,7 +295,7 @@ static uiForEach processAttribute(const uiAttributedString *s, const uiAttribute
hr = p->layout->SetFontFamilyName(wfamily, range);
if (hr != S_OK)
logHRESULT(L"error applying family name attribute", hr);
uiFree(wfamily);
uiprivFree(wfamily);
break;
case uiAttributeTypeSize:
hr = p->layout->SetFontSize(

View File

@ -95,7 +95,7 @@ uiButton *uiNewButton(const char *text)
BS_PUSHBUTTON | WS_TABSTOP,
hInstance, NULL,
TRUE);
uiFree(wtext);
uiprivFree(wtext);
uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b));
uiButtonOnClicked(b, defaultOnClicked, NULL);

View File

@ -108,7 +108,7 @@ uiCheckbox *uiNewCheckbox(const char *text)
BS_CHECKBOX | WS_TABSTOP,
hInstance, NULL,
TRUE);
uiFree(wtext);
uiprivFree(wtext);
uiWindowsRegisterWM_COMMANDHandler(c->hwnd, onWM_COMMAND, uiControl(c));
uiCheckboxOnToggled(c, defaultOnToggled, NULL);

View File

@ -228,7 +228,7 @@ static void updateDouble(HWND hwnd, double d, HWND whichChanged)
return;
str = ftoutf16(d);
setWindowText(hwnd, str);
uiFree(str);
uiprivFree(str);
}
static void updateDialog(struct colorDialog *c, HWND whichChanged)
@ -259,22 +259,22 @@ static void updateDialog(struct colorDialog *c, HWND whichChanged)
if (whichChanged != c->editRInt) {
str = itoutf16(rb);
setWindowText(c->editRInt, str);
uiFree(str);
uiprivFree(str);
}
if (whichChanged != c->editGInt) {
str = itoutf16(gb);
setWindowText(c->editGInt, str);
uiFree(str);
uiprivFree(str);
}
if (whichChanged != c->editBInt) {
str = itoutf16(bb);
setWindowText(c->editBInt, str);
uiFree(str);
uiprivFree(str);
}
if (whichChanged != c->editAInt) {
str = itoutf16(ab);
setWindowText(c->editAInt, str);
uiFree(str);
uiprivFree(str);
}
if (whichChanged != c->editHex) {
@ -956,7 +956,7 @@ static struct colorDialog *beginColorDialog(HWND hwnd, LPARAM lParam)
{
struct colorDialog *c;
c = uiNew(struct colorDialog);
c = uiprivNew(struct colorDialog);
c->hwnd = hwnd;
c->out = (struct colorDialogRGBA *) lParam;
// load initial values now
@ -995,7 +995,7 @@ static void endColorDialog(struct colorDialog *c, INT_PTR code)
{
if (EndDialog(c->hwnd, code) == 0)
logLastError(L"error ending color dialog");
uiFree(c);
uiprivFree(c);
}
// TODO make this void on the font dialog too
@ -1020,7 +1020,7 @@ static double editDouble(HWND hwnd)
s = windowText(hwnd);
d = _wtof(s);
uiFree(s);
uiprivFree(s);
return d;
}
@ -1111,7 +1111,7 @@ static int editInt(HWND hwnd)
s = windowText(hwnd);
i = _wtoi(s);
uiFree(s);
uiprivFree(s);
return i;
}
@ -1176,7 +1176,7 @@ static void hexChanged(struct colorDialog *c)
buf = windowText(c->editHex);
is = hex2RGBA(buf, &r, &g, &b, &a);
uiFree(buf);
uiprivFree(buf);
if (!is)
return;
rgb2HSV(r, g, b, &(c->h), &(c->s), &(c->v));

View File

@ -66,7 +66,7 @@ void uiComboboxAppend(uiCombobox *c, const char *text)
logLastError(L"error appending item to uiCombobox");
else if (res == (LRESULT) CB_ERRSPACE)
logLastError(L"memory exhausted appending item to uiCombobox");
uiFree(wtext);
uiprivFree(wtext);
}
int uiComboboxSelected(uiCombobox *c)

View File

@ -19,7 +19,7 @@ static WCHAR *expandYear(WCHAR *dts, int n)
int ny = 0;
// allocate more than we need to be safe
out = (WCHAR *) uiAlloc((n * 3) * sizeof (WCHAR), "WCHAR[]");
out = (WCHAR *) uiprivAlloc((n * 3) * sizeof (WCHAR), "WCHAR[]");
q = out;
for (p = dts; *p != L'\0'; p++) {
// first, if the current character is a y, increment the number of consecutive ys
@ -73,17 +73,17 @@ static void setDateTimeFormat(HWND hwnd)
ndate = GLI(LOCALE_SSHORTDATE, NULL, 0);
if (ndate == 0)
logLastError(L"error getting date string length");
date = (WCHAR *) uiAlloc(ndate * sizeof (WCHAR), "WCHAR[]");
date = (WCHAR *) uiprivAlloc(ndate * sizeof (WCHAR), "WCHAR[]");
if (GLI(LOCALE_SSHORTDATE, date, ndate) == 0)
logLastError(L"error geting date string");
unexpandedDate = date; // so we can free it
date = expandYear(unexpandedDate, ndate);
uiFree(unexpandedDate);
uiprivFree(unexpandedDate);
ntime = GLI(LOCALE_STIMEFORMAT, NULL, 0);
if (ndate == 0)
logLastError(L"error getting time string length");
time = (WCHAR *) uiAlloc(ntime * sizeof (WCHAR), "WCHAR[]");
time = (WCHAR *) uiprivAlloc(ntime * sizeof (WCHAR), "WCHAR[]");
if (GLI(LOCALE_STIMEFORMAT, time, ntime) == 0)
logLastError(L"error geting time string");
@ -91,9 +91,9 @@ static void setDateTimeFormat(HWND hwnd)
if (SendMessageW(hwnd, DTM_SETFORMAT, 0, (LPARAM) datetime) == 0)
logLastError(L"error applying format string to date/time picker");
uiFree(datetime);
uiFree(time);
uiFree(date);
uiprivFree(datetime);
uiprivFree(time);
uiprivFree(date);
}
// control implementation

View File

@ -26,7 +26,7 @@ HRESULT _logLastError(debugargs, const WCHAR *s)
if (useFormatted)
LocalFree(formatted); // ignore error
printDebug(msg);
uiFree(msg);
uiprivFree(msg);
DebugBreak();
SetLastError(le);
@ -53,7 +53,7 @@ HRESULT _logHRESULT(debugargs, const WCHAR *s, HRESULT hr)
if (useFormatted)
LocalFree(formatted); // ignore error
printDebug(msg);
uiFree(msg);
uiprivFree(msg);
DebugBreak();
return hr;
@ -71,14 +71,14 @@ void realbug(const char *file, const char *line, const char *func, const char *p
va_end(ap2);
n++; // terminating '\0'
msg = (char *) uiAlloc(n * sizeof (char), "char[]");
msg = (char *) uiprivAlloc(n * sizeof (char), "char[]");
// includes terminating '\0' according to example in https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx
vsprintf_s(msg, n, format, ap);
final = strf(L"[libui] %hs:%hs:%hs() %hs%hs\n", file, line, func, prefix, msg);
uiFree(msg);
uiprivFree(msg);
printDebug(final);
uiFree(final);
uiprivFree(final);
DebugBreak();
}

View File

@ -107,7 +107,7 @@ uiDrawContext *newContext(ID2D1RenderTarget *rt)
{
uiDrawContext *c;
c = uiNew(uiDrawContext);
c = uiprivNew(uiDrawContext);
c->rt = rt;
c->states = new std::vector<struct drawState>;
resetTarget(c->rt);
@ -122,7 +122,7 @@ void freeContext(uiDrawContext *c)
// TODO do this on other platforms
userbug("You did not balance uiDrawSave() and uiDrawRestore() calls.");
delete c->states;
uiFree(c);
uiprivFree(c);
}
static ID2D1Brush *makeSolidBrush(uiDrawBrush *b, ID2D1RenderTarget *rt, D2D1_BRUSH_PROPERTIES *props)
@ -152,7 +152,7 @@ static ID2D1GradientStopCollection *mkstops(uiDrawBrush *b, ID2D1RenderTarget *r
size_t i;
HRESULT hr;
stops = (D2D1_GRADIENT_STOP *) uiAlloc(b->NumStops * sizeof (D2D1_GRADIENT_STOP), "D2D1_GRADIENT_STOP[]");
stops = (D2D1_GRADIENT_STOP *) uiprivAlloc(b->NumStops * sizeof (D2D1_GRADIENT_STOP), "D2D1_GRADIENT_STOP[]");
for (i = 0; i < b->NumStops; i++) {
stops[i].position = b->Stops[i].Pos;
stops[i].color.r = b->Stops[i].R;
@ -170,7 +170,7 @@ static ID2D1GradientStopCollection *mkstops(uiDrawBrush *b, ID2D1RenderTarget *r
if (hr != S_OK)
logHRESULT(L"error creating stop collection", hr);
uiFree(stops);
uiprivFree(stops);
return s;
}
@ -365,7 +365,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b, uiDrawStrokeP
// TODO be sure to formally document this
if (sp->NumDashes != 0) {
dsp.dashStyle = D2D1_DASH_STYLE_CUSTOM;
dashes = (FLOAT *) uiAlloc(sp->NumDashes * sizeof (FLOAT), "FLOAT[]");
dashes = (FLOAT *) uiprivAlloc(sp->NumDashes * sizeof (FLOAT), "FLOAT[]");
for (i = 0; i < sp->NumDashes; i++)
dashes[i] = sp->Dashes[i] / sp->Thickness;
}
@ -378,7 +378,7 @@ void uiDrawStroke(uiDrawContext *c, uiDrawPath *p, uiDrawBrush *b, uiDrawStrokeP
if (hr != S_OK)
logHRESULT(L"error creating stroke style", hr);
if (sp->NumDashes != 0)
uiFree(dashes);
uiprivFree(dashes);
cliplayer = applyClip(c);
c->rt->DrawGeometry(

View File

@ -17,7 +17,7 @@ uiDrawPath *uiDrawNewPath(uiDrawFillMode fillmode)
uiDrawPath *p;
HRESULT hr;
p = uiNew(uiDrawPath);
p = uiprivNew(uiDrawPath);
hr = d2dfactory->CreatePathGeometry(&(p->path));
if (hr != S_OK)
logHRESULT(L"error creating path", hr);
@ -43,7 +43,7 @@ void uiDrawFreePath(uiDrawPath *p)
// TODO close sink first?
p->sink->Release();
p->path->Release();
uiFree(p);
uiprivFree(p);
}
void uiDrawPathNewFigure(uiDrawPath *p, double x, double y)

View File

@ -38,7 +38,7 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
FLOAT maxWidth;
HRESULT hr;
tl = uiNew(uiDrawTextLayout);
tl = uiprivNew(uiDrawTextLayout);
wDefaultFamily = toUTF16(p->DefaultFont->Family);
hr = dwfactory->CreateTextFormat(
@ -51,7 +51,7 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
// TODO use the current locale?
L"",
&(tl->format));
uiFree(wDefaultFamily);
uiprivFree(wDefaultFamily);
if (hr != S_OK)
logHRESULT(L"error creating IDWriteTextFormat", hr);
hr = tl->format->SetTextAlignment(dwriteAligns[p->Align]);
@ -95,14 +95,14 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
void uiDrawFreeTextLayout(uiDrawTextLayout *tl)
{
uiFree(tl->u16tou8);
uiFree(tl->u8tou16);
uiprivFree(tl->u16tou8);
uiprivFree(tl->u8tou16);
for (auto p : *(tl->backgroundParams))
uiprivFree(p);
delete tl->backgroundParams;
tl->layout->Release();
tl->format->Release();
uiFree(tl);
uiprivFree(tl);
}
// TODO make this shared code somehow

View File

@ -81,7 +81,7 @@ WCHAR *uiprivFontCollectionCorrectString(fontCollection *fc, IDWriteLocalizedStr
if (hr != S_OK)
logHRESULT(L"error getting length of font name", hr);
// GetStringLength() does not include the null terminator, but GetString() does
wname = (WCHAR *) uiAlloc((length + 1) * sizeof (WCHAR), "WCHAR[]");
wname = (WCHAR *) uiprivAlloc((length + 1) * sizeof (WCHAR), "WCHAR[]");
hr = names->GetString(index, wname, length + 1);
if (hr != S_OK)
logHRESULT(L"error getting font name", hr);

View File

@ -76,7 +76,7 @@ void uiEditableComboboxAppend(uiEditableCombobox *c, const char *text)
logLastError(L"error appending item to uiEditableCombobox");
else if (res == (LRESULT) CB_ERRSPACE)
logLastError(L"memory exhausted appending item to uiEditableCombobox");
uiFree(wtext);
uiprivFree(wtext);
}
char *uiEditableComboboxText(uiEditableCombobox *c)

View File

@ -121,7 +121,7 @@ static WCHAR *cbGetItemText(HWND cb, WPARAM item)
len = SendMessageW(cb, CB_GETLBTEXTLEN, item, 0);
if (len == (LRESULT) CB_ERR)
logLastError(L"error getting item text length from combobox");
text = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]");
text = (WCHAR *) uiprivAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]");
if (SendMessageW(cb, CB_GETLBTEXT, item, (LPARAM) text) != len)
logLastError(L"error getting item text from combobox");
return text;
@ -138,7 +138,7 @@ static BOOL cbTypeToSelect(HWND cb, LRESULT *posOut, BOOL restoreAfter)
text = windowText(cb);
pos = SendMessageW(cb, CB_FINDSTRINGEXACT, (WPARAM) (-1), (LPARAM) text);
if (pos == (LRESULT) CB_ERR) {
uiFree(text);
uiprivFree(text);
return FALSE;
}
cbSetCurSel(cb, (WPARAM) pos);
@ -147,7 +147,7 @@ static BOOL cbTypeToSelect(HWND cb, LRESULT *posOut, BOOL restoreAfter)
if (restoreAfter)
if (SendMessageW(cb, WM_SETTEXT, 0, (LPARAM) text) != (LRESULT) TRUE)
logLastError(L"error restoring old combobox text");
uiFree(text);
uiprivFree(text);
// and restore the selection like above
// TODO isn't there a 32-bit version of this
if (SendMessageW(cb, CB_SETEDITSEL, 0, MAKELPARAM(selStart, selEnd)) != (LRESULT) TRUE)
@ -254,7 +254,7 @@ static void familyChanged(struct fontDialog *f)
logHRESULT(L"error getting font for filling styles box", hr);
label = fontStyleName(f->fc, font);
pos = cbAddString(f->styleCombobox, label);
uiFree(label);
uiprivFree(label);
cbSetItemData(f->styleCombobox, (WPARAM) pos, (LPARAM) font);
if (font->GetWeight() == weight &&
font->GetStyle() == style &&
@ -386,7 +386,7 @@ static void fontDialogDrawSampleText(struct fontDialog *f, ID2D1RenderTarget *rt
&format);
if (hr != S_OK)
logHRESULT(L"error creating IDWriteTextFormat", hr);
uiFree(family);
uiprivFree(family);
rect.left = 0;
rect.top = 0;
@ -402,7 +402,7 @@ static void fontDialogDrawSampleText(struct fontDialog *f, ID2D1RenderTarget *rt
format->Release();
if (exists)
uiFree(sample);
uiprivFree(sample);
black->Release();
}
@ -466,7 +466,7 @@ static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam)
HWND samplePlacement;
HRESULT hr;
f = uiNew(struct fontDialog);
f = uiprivNew(struct fontDialog);
f->hwnd = hwnd;
f->params = (struct fontDialogParams *) lParam;
@ -482,7 +482,7 @@ static struct fontDialog *beginFontDialog(HWND hwnd, LPARAM lParam)
logHRESULT(L"error getting font family", hr);
wname = uiprivFontCollectionFamilyName(f->fc, family);
pos = cbAddString(f->familyCombobox, wname);
uiFree(wname);
uiprivFree(wname);
cbSetItemData(f->familyCombobox, (WPARAM) pos, (LPARAM) family);
}
@ -506,7 +506,7 @@ static void endFontDialog(struct fontDialog *f, INT_PTR code)
uiprivFontCollectionFree(f->fc);
if (EndDialog(f->hwnd, code) == 0)
logLastError(L"error ending font dialog");
uiFree(f);
uiprivFree(f);
}
static INT_PTR tryFinishDialog(struct fontDialog *f, WPARAM wParam)
@ -681,7 +681,7 @@ WCHAR *uiprivFontDialogParamsToString(struct fontDialogParams *params)
WCHAR *text;
// TODO dynamically allocate
text = (WCHAR *) uiAlloc(512 * sizeof (WCHAR), "WCHAR[]");
text = (WCHAR *) uiprivAlloc(512 * sizeof (WCHAR), "WCHAR[]");
_snwprintf(text, 512, L"%s %s %g",
params->familyName,
params->styleName,

View File

@ -266,7 +266,7 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy)
SS_LEFT | SS_NOPREFIX,
hInstance, NULL,
TRUE);
uiFree(wlabel);
uiprivFree(wlabel);
uiWindowsEnsureSetParentHWND(fc.label, f->hwnd);
fc.stretchy = stretchy;
uiControlSetParent(fc.c, uiControl(f));

View File

@ -17,7 +17,7 @@ struct graphemes *uiprivNewGraphemes(void *s, size_t len)
WCHAR *str;
size_t *pPTG, *pGTP;
g = uiNew(struct graphemes);
g = uiprivNew(struct graphemes);
g->len = 0;
str = (WCHAR *) s;
@ -27,8 +27,8 @@ struct graphemes *uiprivNewGraphemes(void *s, size_t len)
// no need to worry about surrogates if we're just counting
}
g->pointsToGraphemes = (size_t *) uiAlloc((len + 1) * sizeof (size_t), "size_t[] (graphemes)");
g->graphemesToPoints = (size_t *) uiAlloc((g->len + 1) * sizeof (size_t), "size_t[] (graphemes)");
g->pointsToGraphemes = (size_t *) uiprivAlloc((len + 1) * sizeof (size_t), "size_t[] (graphemes)");
g->graphemesToPoints = (size_t *) uiprivAlloc((g->len + 1) * sizeof (size_t), "size_t[] (graphemes)");
pPTG = g->pointsToGraphemes;
pGTP = g->graphemesToPoints;

View File

@ -418,7 +418,7 @@ static void uiGridDestroy(uiControl *c)
for (struct gridChild *gc : *(g->children)) {
uiControlSetParent(gc->c, NULL);
uiControlDestroy(gc->c);
uiFree(gc);
uiprivFree(gc);
}
delete g->indexof;
delete g->children;
@ -565,7 +565,7 @@ static struct gridChild *toChild(uiControl *c, int xspan, int yspan, int hexpand
userbug("You cannot have a negative xspan in a uiGrid cell.");
if (yspan < 0)
userbug("You cannot have a negative yspan in a uiGrid cell.");
gc = uiNew(struct gridChild);
gc = uiprivNew(struct gridChild);
gc->c = c;
gc->xspan = xspan;
gc->yspan = yspan;

View File

@ -208,7 +208,7 @@ uiGroup *uiNewGroup(const char *text)
BS_GROUPBOX,
hInstance, NULL,
TRUE);
uiFree(wtext);
uiprivFree(wtext);
if (SetWindowSubclass(g->hwnd, groupSubProc, 0, (DWORD_PTR) g) == FALSE)
logLastError(L"error subclassing groupbox to handle parent messages");

View File

@ -28,11 +28,11 @@ static const char *initerr(const char *message, const WCHAR *label, DWORD value)
wmessage,
value, value,
sysmsg);
uiFree(wmessage);
uiprivFree(wmessage);
if (hassysmsg)
LocalFree(sysmsg); // ignore error
out = toUTF8(wout);
uiFree(wout);
uiprivFree(wout);
return out + 1;
}
@ -157,7 +157,7 @@ void uiUninit(void)
void uiFreeInitError(const char *err)
{
if (*(err - 1) == '-')
uiFree((void *) (err - 1));
uiprivFree((void *) (err - 1));
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)

View File

@ -51,7 +51,7 @@ uiLabel *uiNewLabel(const char *text)
SS_LEFTNOWORDWRAP | SS_NOPREFIX,
hInstance, NULL,
TRUE);
uiFree(wtext);
uiprivFree(wtext);
return l;
}

View File

@ -115,10 +115,10 @@ static uiMenuItem *newItem(uiMenu *m, int type, const char *name)
if (m->len >= m->cap) {
m->cap += grow;
m->items = (uiMenuItem **) uiRealloc(m->items, m->cap * sizeof (uiMenuItem *), "uiMenuitem *[]");
m->items = (uiMenuItem **) uiprivRealloc(m->items, m->cap * sizeof (uiMenuItem *), "uiMenuitem *[]");
}
item = uiNew(uiMenuItem);
item = uiprivNew(uiMenuItem);
m->items[m->len] = item;
m->len++;
@ -207,10 +207,10 @@ uiMenu *uiNewMenu(const char *name)
userbug("You can not create a new menu after menus have been finalized.");
if (len >= cap) {
cap += grow;
menus = (uiMenu **) uiRealloc(menus, cap * sizeof (uiMenu *), "uiMenu *[]");
menus = (uiMenu **) uiprivRealloc(menus, cap * sizeof (uiMenu *), "uiMenu *[]");
}
m = uiNew(uiMenu);
m = uiprivNew(uiMenu);
menus[len] = m;
len++;
@ -237,7 +237,7 @@ static void appendMenuItem(HMENU menu, uiMenuItem *item)
if (item->len >= item->cap) {
item->cap += grow;
item->hmenus = (HMENU *) uiRealloc(item->hmenus, item->cap * sizeof (HMENU), "HMENU[]");
item->hmenus = (HMENU *) uiprivRealloc(item->hmenus, item->cap * sizeof (HMENU), "HMENU[]");
}
item->hmenus[item->len] = menu;
item->len++;
@ -348,22 +348,22 @@ void uninitMenus(void)
for (i = 0; i < len; i++) {
m = menus[i];
uiFree(m->name);
uiprivFree(m->name);
for (j = 0; j < m->len; j++) {
item = m->items[j];
if (item->len != 0)
// LONGTERM userbug()?
implbug("menu item %p (%ws) still has uiWindows attached; did you forget to destroy some windows?", item, item->name);
if (item->name != NULL)
uiFree(item->name);
uiprivFree(item->name);
if (item->hmenus != NULL)
uiFree(item->hmenus);
uiFree(item);
uiprivFree(item->hmenus);
uiprivFree(item);
}
if (m->items != NULL)
uiFree(m->items);
uiFree(m);
uiprivFree(m->items);
uiprivFree(m);
}
if (menus != NULL)
uiFree(menus);
uiprivFree(menus);
}

View File

@ -76,7 +76,7 @@ void uiMultilineEntrySetText(uiMultilineEntry *e, const char *text)
e->inhibitChanged = TRUE;
crlf = LFtoCRLF(text);
uiWindowsSetWindowText(e->hwnd, text);
uiFree(crlf);
uiprivFree(crlf);
e->inhibitChanged = FALSE;
// don't queue the control for resize; entry sizes are independent of their contents
}
@ -95,9 +95,9 @@ void uiMultilineEntryAppend(uiMultilineEntry *e, const char *text)
SendMessageW(e->hwnd, EM_SETSEL, n, n);
crlf = LFtoCRLF(text);
wtext = toUTF16(crlf);
uiFree(crlf);
uiprivFree(crlf);
SendMessageW(e->hwnd, EM_REPLACESEL, FALSE, (LPARAM) wtext);
uiFree(wtext);
uiprivFree(wtext);
e->inhibitChanged = FALSE;
}

View File

@ -140,7 +140,7 @@ void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
BS_RADIOBUTTON | groupTabStop,
hInstance, NULL,
TRUE);
uiFree(wtext);
uiprivFree(wtext);
uiWindowsEnsureSetParentHWND(hwnd, r->hwnd);
uiWindowsRegisterWM_COMMANDHandler(hwnd, onWM_COMMAND, uiControl(r));
r->hwnds->push_back(hwnd);

View File

@ -48,10 +48,10 @@ static BOOL onWM_COMMAND(uiControl *c, HWND hwnd, WORD code, LRESULT *lResult)
// This won't handle leading spaces, but spaces aren't allowed *anyway*.
wtext = windowText(s->edit);
if (wcscmp(wtext, L"-") == 0) {
uiFree(wtext);
uiprivFree(wtext);
return TRUE;
}
uiFree(wtext);
uiprivFree(wtext);
// value() does the work for us
value(s);
(*(s->onChanged))(s, s->onChangedData);

View File

@ -114,8 +114,8 @@ static void msgbox(HWND parent, const char *title, const char *description, TASK
if (hr != S_OK)
logHRESULT(L"error showing task dialog", hr);
uiFree(wdescription);
uiFree(wtitle);
uiprivFree(wdescription);
uiprivFree(wtitle);
}
void uiMsgBox(uiWindow *parent, const char *title, const char *description)

View File

@ -212,7 +212,7 @@ void uiTabInsertAt(uiTab *t, const char *name, int n, uiControl *child)
item.pszText = wname;
if (SendMessageW(t->tabHWND, TCM_INSERTITEM, (WPARAM) n, (LPARAM) (&item)) == (LRESULT) -1)
logLastError(L"error adding tab to uiTab");
uiFree(wname);
uiprivFree(wname);
// we need to do this because adding the first tab doesn't send a TCN_SELCHANGE; it just shows the page
show = curpage(t);

View File

@ -83,7 +83,7 @@ struct tabPage *newTabPage(uiControl *child)
struct tabPage *tp;
HRESULT hr;
tp = uiNew(struct tabPage);
tp = uiprivNew(struct tabPage);
// unfortunately this needs to be a proper dialog for EnableThemeDialogTexture() to work; CreateWindowExW() won't suffice
if (CreateDialogParamW(hInstance, MAKEINTRESOURCE(rcTabPageDialog),
@ -114,7 +114,7 @@ void tabPageDestroy(struct tabPage *tp)
uiWindowsControlSetParentHWND(uiWindowsControl(tp->child), NULL);
// don't call EndDialog(); that's for the DialogBox() family of functions instead of CreateDialog()
uiWindowsEnsureDestroyWindow(tp->hwnd);
uiFree(tp);
uiprivFree(tp);
}
void tabPageMinimumSize(struct tabPage *tp, int *width, int *height)

View File

@ -10,7 +10,7 @@ WCHAR *windowTextAndLen(HWND hwnd, LRESULT *len)
if (len != NULL)
*len = n;
// WM_GETTEXTLENGTH does not include the null terminator
text = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]");
text = (WCHAR *) uiprivAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]");
// note the comparison: the size includes the null terminator, but the return does not
if (GetWindowTextW(hwnd, text, n + 1) != n) {
logLastError(L"error getting window text");
@ -35,7 +35,7 @@ void setWindowText(HWND hwnd, WCHAR *wtext)
void uiFreeText(char *text)
{
uiFree(text);
uiprivFree(text);
}
int uiWindowsWindowTextWidth(HWND hwnd)
@ -78,11 +78,11 @@ int uiWindowsWindowTextWidth(HWND hwnd)
if (ReleaseDC(hwnd, dc) == 0)
logLastError(L"error releasing DC");
uiFree(text);
uiprivFree(text);
return size.cx;
noTextOrError:
uiFree(text);
uiprivFree(text);
return 0;
}
@ -93,7 +93,7 @@ char *uiWindowsWindowText(HWND hwnd)
wtext = windowText(hwnd);
text = toUTF8(wtext);
uiFree(wtext);
uiprivFree(wtext);
return text;
}
@ -103,7 +103,7 @@ void uiWindowsSetWindowText(HWND hwnd, const char *text)
wtext = toUTF16(text);
setWindowText(hwnd, wtext);
uiFree(wtext);
uiprivFree(wtext);
}
int uiprivStricmp(const char *a, const char *b)
@ -114,7 +114,7 @@ int uiprivStricmp(const char *a, const char *b)
wa = toUTF16(a);
wb = toUTF16(b);
ret = _wcsicmp(wa, wb);
uiFree(wb);
uiFree(wa);
uiprivFree(wb);
uiprivFree(wa);
return ret;
}

View File

@ -29,8 +29,8 @@ extern BOOL runWM_HSCROLL(WPARAM wParam, LPARAM lParam, LRESULT *lResult);
extern void issueWM_WININICHANGE(WPARAM wParam, LPARAM lParam);
// utf16.cpp
#define emptyUTF16() ((WCHAR *) uiAlloc(1 * sizeof (WCHAR), "WCHAR[]"))
#define emptyUTF8() ((char *) uiAlloc(1 * sizeof (char), "char[]"))
#define emptyUTF16() ((WCHAR *) uiprivAlloc(1 * sizeof (WCHAR), "WCHAR[]"))
#define emptyUTF8() ((char *) uiprivAlloc(1 * sizeof (char), "char[]"))
extern WCHAR *toUTF16(const char *str);
extern char *toUTF8(const WCHAR *wstr);
extern WCHAR *utf16dup(const WCHAR *orig);

View File

@ -13,7 +13,7 @@ WCHAR *toUTF16(const char *str)
if (*str == '\0') // empty string
return emptyUTF16();
n = utf8UTF16Count(str, 0);
wstr = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]");
wstr = (WCHAR *) uiprivAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]");
wp = wstr;
while (*str) {
str = utf8DecodeRune(str, 0, &rune);
@ -33,7 +33,7 @@ char *toUTF8(const WCHAR *wstr)
if (*wstr == L'\0') // empty string
return emptyUTF8();
n = utf16RuneCount(wstr, 0);
str = (char *) uiAlloc((n + 1) * sizeof (char), "char[]");
str = (char *) uiprivAlloc((n + 1) * sizeof (char), "char[]");
sp = str;
while (*wstr) {
wstr = utf16DecodeRune(wstr, 0, &rune);
@ -49,7 +49,7 @@ WCHAR *utf16dup(const WCHAR *orig)
size_t len;
len = wcslen(orig);
out = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]");
out = (WCHAR *) uiprivAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]");
wcscpy_s(out, len + 1, orig);
return out;
}
@ -79,7 +79,7 @@ WCHAR *vstrf(const WCHAR *format, va_list ap)
va_end(ap2);
n++; // terminating L'\0'
buf = (WCHAR *) uiAlloc(n * sizeof (WCHAR), "WCHAR[]");
buf = (WCHAR *) uiprivAlloc(n * sizeof (WCHAR), "WCHAR[]");
// includes terminating L'\0' according to example in https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx
vswprintf_s(buf, n, format, ap);
@ -97,7 +97,7 @@ char *LFtoCRLF(const char *lfonly)
char *out;
len = strlen(lfonly);
crlf = (char *) uiAlloc((len * 2 + 1) * sizeof (char), "char[]");
crlf = (char *) uiprivAlloc((len * 2 + 1) * sizeof (char), "char[]");
out = crlf;
for (i = 0; i < len; i++) {
if (*lfonly == '\n')

View File

@ -480,7 +480,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
NULL, NULL, hInstance, w);
if (w->hwnd == NULL)
logLastError(L"error creating window");
uiFree(wtitle);
uiprivFree(wtitle);
if (hasMenubar) {
w->menubar = makeMenubar();