summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-12-22 21:51:01 -0500
committerPietro Gagliardi <[email protected]>2014-12-22 21:51:01 -0500
commitc016143d8051cb5c38812376106e4a7849af9e2d (patch)
treecaf1ed081ebc4b7bee09c5cc0b97ed0b438fd657
parent733254586bd6aee88f1ef1574524d2d1a5a06edb (diff)
Changed the memory allocator used in util.h so that code will work on real Windowss because LocalAlloc() doesn't want to.
-rw-r--r--wintable/new/util.h23
1 files changed, 16 insertions, 7 deletions
diff --git a/wintable/new/util.h b/wintable/new/util.h
index d23ac27..4dd73d6 100644
--- a/wintable/new/util.h
+++ b/wintable/new/util.h
@@ -16,31 +16,39 @@ static BOOL runHandlers(const handlerfunc list[], struct table *t, UINT uMsg, WP
// memory allocation stuff
// each of these functions do an implicit ZeroMemory()
// these also make tableRealloc(NULL, ...)/tableFree(NULL) act like realloc(NULL, ...)/free(NULL) (that is, same as tableAlloc(...)/malloc(...) and a no-op, respectively)
-// we're using LocalAlloc() because:
+// we /would/ use LocalAlloc() here because
// - whether the malloc() family supports the last-error code is undefined
// - the HeapAlloc() family DOES NOT support the last-error code; you're supposed to use Windows exceptions, and I can't find a clean way to do this with MinGW-w64 that doesn't rely on inline assembly or external libraries (unless they added __try/__except blocks)
// - there's no VirtualReAlloc() to complement VirtualAlloc() and I'm not sure if we can even get the original allocated size back out reliably to write it ourselves (http://blogs.msdn.com/b/oldnewthing/archive/2012/03/16/10283988.aspx)
+// alas, LocalAlloc() doesn't want to work on real Windows 7 after a few times, throwing up ERROR_NOT_ENOUGH_MEMORY after three (3) ints or so :|
+// we'll use malloc() until then
// needless to say, TODO
static void *tableAlloc(size_t size, const char *panicMessage)
{
- HLOCAL out;
+// HLOCAL out;
+ void *out;
- out = LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, size);
+// out = LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, size);
+ out = malloc(size);
if (out == NULL)
panic(panicMessage);
+ ZeroMemory(out, size);
return (void *) out;
}
static void *tableRealloc(void *p, size_t size, const char *panicMessage)
{
- HLOCAL out;
+// HLOCAL out;
+ void *out;
if (p == NULL)
return tableAlloc(size, panicMessage);
- out = LocalReAlloc((HLOCAL) p, size, LMEM_ZEROINIT);
+// out = LocalReAlloc((HLOCAL) p, size, LMEM_ZEROINIT);
+ out = realloc(p, size);
if (out == NULL)
panic(panicMessage);
+ // TODO zero the extra memory
return (void *) out;
}
@@ -48,8 +56,9 @@ static void tableFree(void *p, const char *panicMessage)
{
if (p == NULL)
return;
- if (LocalFree((HLOCAL) p) != NULL)
- panic(panicMessage);
+// if (LocalFree((HLOCAL) p) != NULL)
+// panic(panicMessage);
+ free(p);
}
// font selection