summaryrefslogtreecommitdiff
path: root/alf/alf.cpp
diff options
context:
space:
mode:
authorJonas Kümmerlin <jonas@kuemmerlin.eu>2019-01-25 21:45:01 +0100
committerJonas Kümmerlin <jonas@kuemmerlin.eu>2019-01-25 21:45:01 +0100
commit55211af76164fe6c39249c14be47363d35a4db0f (patch)
tree417d9e8805c52d6421798331bea59993e7f1fa1a /alf/alf.cpp
parent02d94ecd62e11e28ba87451c392cc6b633bb5c56 (diff)
add memory allocation functions
Diffstat (limited to 'alf/alf.cpp')
-rw-r--r--alf/alf.cpp45
1 files changed, 33 insertions, 12 deletions
diff --git a/alf/alf.cpp b/alf/alf.cpp
index f10bdd3..06e6e0c 100644
--- a/alf/alf.cpp
+++ b/alf/alf.cpp
@@ -25,9 +25,7 @@ ALF_DestroyWindowPriv(ALFWindowPriv *priv)
if (priv->fonts.hMessageFont)
DeleteObject(priv->fonts.hMessageFont);
- HeapFree(GetProcessHeap(), 0, priv->layout.columns);
- HeapFree(GetProcessHeap(), 0, priv->layout.rows);
- HeapFree(GetProcessHeap(), 0, priv);
+ ALF_Free(priv);
}
int
@@ -319,7 +317,7 @@ ALF_WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
if (msg == WM_NCCREATE) {
CREATESTRUCT *cs = (CREATESTRUCT*)(void*)lparam;
if (cs->lpCreateParams) {
- ALFWindowPriv *priv = (ALFWindowPriv*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY|HEAP_GENERATE_EXCEPTIONS, sizeof(ALFWindowPriv));
+ ALFWindowPriv *priv = ALF_New(ALFWindowPriv, 1);
SetWindowLongPtr(hwnd, 0, (LONG_PTR)priv);
ALF_InitializeWindowPriv(hwnd, priv, *((void**)cs->lpCreateParams));
}
@@ -340,7 +338,7 @@ ALF_WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
ALFAPP
ALF_CreateApplication(HINSTANCE hInstance)
{
- ALFAPP app = (ALFAPP)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY|HEAP_GENERATE_EXCEPTIONS, sizeof(struct ALFAppPriv));
+ ALFAPP app = ALF_New(struct ALFAppPriv, 1);
app->hInstance = hInstance;
InitCommonControls();
@@ -358,7 +356,30 @@ ALF_TeardownApplication(ALFAPP app)
UnregisterClass(app->comboClass, app->hInstance);
UnregisterClass(app->panelClass, app->hInstance);
UnregisterClass(app->spacerClass, app->hInstance);
- HeapFree(GetProcessHeap(), 0, app);
+ ALF_Free(app);
+}
+
+void *
+ALF_Alloc(SIZE_T nmemb, SIZE_T size)
+{
+ // FIXME! potential overflow
+ return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY|HEAP_GENERATE_EXCEPTIONS, nmemb * size);
+}
+
+void *
+ALF_ReAlloc(void *ptr, SIZE_T nmemb, SIZE_T size)
+{
+ // FIXME! potential overflow
+ if (ptr)
+ return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY|HEAP_GENERATE_EXCEPTIONS, ptr, nmemb * size);
+ else
+ return ALF_Alloc(nmemb, size);
+}
+
+void
+ALF_Free(const void *p)
+{
+ HeapFree(GetProcessHeap(), 0, (void*)p);
}
void
@@ -407,7 +428,7 @@ ALF_RegisterWindowClass(ALFAPP app, const ALFWindowClassParams *params)
if (!classatom)
return NULL;
- ALFWindowVTable *pvtbl = (ALFWindowVTable*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY|HEAP_GENERATE_EXCEPTIONS, sizeof(ALFWindowVTable));
+ ALFWindowVTable *pvtbl = ALF_New(ALFWindowVTable, 1);
*pvtbl = params->vtbl;
// XXX: This could have been a HWND_MESSAGE window, but Win95 doesn't support these
@@ -426,7 +447,7 @@ ALF_UnregisterWindowClass(ALFAPP app, LPCTSTR className)
ALFWindowVTable *pvtbl = (ALFWindowVTable*)GetClassLongPtr(tmp, 0);
DestroyWindow(tmp);
- HeapFree(GetProcessHeap(), 0, pvtbl);
+ ALF_Free(pvtbl);
UnregisterClass(className, app->hInstance);
}
@@ -590,23 +611,23 @@ ALF_SetWidgetText(HWND parent, WORD id, const TCHAR *text)
ALF_SetText(h, text);
}
-TCHAR * // free with HeapFree
+TCHAR * // free with ALF_Free
ALF_Text(HWND hwnd)
{
int len = GetWindowTextLengthA(hwnd);
if (len > 0) {
- TCHAR *buf = (TCHAR*)HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY, (len + 1)*sizeof(TCHAR));
+ TCHAR *buf = ALF_New(TCHAR, len+1);
if (GetWindowText(hwnd, buf, len)) {
return buf;
} else {
- HeapFree(GetProcessHeap(), 0, buf);
+ ALF_Free(buf);
}
}
return NULL;
}
-TCHAR * // free with HeapFree
+TCHAR * // free with ALF_Free
ALF_WidgetText(HWND parent, WORD id)
{
HWND h = ALF_WidgetHwndById(parent, id);