Finished the complain() migration.
This commit is contained in:
parent
8067dc76b7
commit
aafb27cb2c
|
@ -13,6 +13,10 @@ extern void *uiAlloc(size_t, const char *);
|
|||
extern void *uiRealloc(void *, size_t, const char *);
|
||||
extern void uiFree(void *);
|
||||
|
||||
// ugh, this was only introduced in MSVC 2015...
|
||||
#ifdef _MSC_VER
|
||||
#define __func__ __FUNCTION__
|
||||
#endif
|
||||
extern void realbug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap);
|
||||
#define _ns2(s) #s
|
||||
#define _ns(s) _ns2(s)
|
||||
|
|
|
@ -13,20 +13,15 @@ void initAlloc(void)
|
|||
|
||||
void uninitAlloc(void)
|
||||
{
|
||||
BOOL hasEntry;
|
||||
std::ostringstream oss;
|
||||
|
||||
hasEntry = FALSE;
|
||||
for (const auto &alloc : heap) {
|
||||
if (!hasEntry) {
|
||||
fprintf(stderr, "[libui] leaked allocations:\n");
|
||||
hasEntry = TRUE;
|
||||
}
|
||||
fprintf(stderr, "[libui] %p %s\n",
|
||||
alloc.first,
|
||||
types[alloc.second]);
|
||||
}
|
||||
if (hasEntry)
|
||||
complain("either you left something around or there's a bug in libui");
|
||||
if (heap.size() == 0)
|
||||
return;
|
||||
for (const auto &alloc : heap)
|
||||
// note the void * cast; otherwise it'll be treated as a string
|
||||
oss << (void *) (alloc.first) << " " << types[alloc.second] << "\n";
|
||||
// TODO keep oss.str() alive?
|
||||
userbug("Some data was leaked; either you left a uiControl lying around or there's a bug in libui itself. Leaked data:\n%s", oss.str().c_str());
|
||||
}
|
||||
|
||||
#define rawBytes(pa) (&((*pa)[0]))
|
||||
|
|
|
@ -41,7 +41,6 @@ HRESULT _logLastError(debugargs, const WCHAR *s)
|
|||
|
||||
HRESULT _logHRESULT(debugargs, const WCHAR *s, HRESULT hr)
|
||||
{
|
||||
DWORD le;
|
||||
WCHAR *msg;
|
||||
WCHAR *formatted;
|
||||
BOOL useFormatted;
|
||||
|
@ -73,7 +72,7 @@ void realbug(const char *file, const char *line, const char *func, const char *p
|
|||
va_end(ap2);
|
||||
n++; // terminating '\0'
|
||||
|
||||
buf = (char *) uiAlloc(n * sizeof (char), "char[]");
|
||||
msg = (char *) uiAlloc(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);
|
||||
|
||||
|
|
|
@ -23,15 +23,13 @@ static const char *initerr(const char *message, const WCHAR *label, DWORD value)
|
|||
if (!hassysmsg)
|
||||
sysmsg = L"";
|
||||
wmessage = toUTF16(message + 1);
|
||||
wout = debugstrf(L"-error initializing libui: %s; code %I32d (0x%08I32X) %s",
|
||||
wout = strf(L"-error initializing libui: %s; code %I32d (0x%08I32X) %s",
|
||||
wmessage,
|
||||
value, value,
|
||||
sysmsg);
|
||||
uiFree(wmessage);
|
||||
if (hassysmsg)
|
||||
LocalFree(sysmsg); // ignore error
|
||||
if (wout == NULL) // debugstrf() failed; return message raw
|
||||
return message + 1;
|
||||
out = toUTF8(wout);
|
||||
uiFree(wout);
|
||||
return out + 1;
|
||||
|
|
|
@ -47,4 +47,5 @@
|
|||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue