
This commit consists of numerous small changes, none significant enough to merit a commit on their own: * Added extra braces to quash for-loop variable scoping issues for older compilers (or "g++ -fno-for-scope") * Appeased "unreachable code" warnings, spurious or otherwise * Added casts to fix integer-variable signedness warnings * Added a dummy virtual method to the VectorFileWriter class to silence the -Wweak-vtables warning from Clang++ * Renamed some parameters in the Expr and GraphicsWindow classes to eliminate "parameter shadows a field" warnings * Removed an inert "0 ||" from a conditional, and changed a "&& 0" into an "#if 0" * Added missing elements to array/struct/class initializers to zap further warnings * Indented some cpp conditionals where appropriate * Qualified some variables and functions as static to quiet "no previous declaration" warnings * toolbar.cpp needed to #include<icons-proto.h> to fix those same "no previous declaration" warnings from icons.h * Added some casts and const qualifiers to the Win32 code to address warnings produced by g++ when compiling under MinGW * Rewrote Cnf{Freeze,Thaw}Float() to use a union rather than pointer aliasing; this makes g++ a lot happier * Removed redundant #includes from win32/w32util.cpp * With Jonathan's blessing, shortened the last line of the About dialog text to better match the preceding lines
85 lines
2.5 KiB
C++
85 lines
2.5 KiB
C++
//-----------------------------------------------------------------------------
|
|
// Utility functions that depend on Win32. Notably, our memory allocation;
|
|
// we use two separate allocators, one for long-lived stuff and one for
|
|
// stuff that gets freed after every regeneration of the model, to save us
|
|
// the trouble of freeing the latter explicitly.
|
|
//
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
|
//-----------------------------------------------------------------------------
|
|
#include "solvespace.h"
|
|
|
|
static HANDLE PermHeap, TempHeap;
|
|
|
|
void dbp(const char *str, ...)
|
|
{
|
|
va_list f;
|
|
static char buf[1024*50];
|
|
va_start(f, str);
|
|
_vsnprintf(buf, sizeof(buf), str, f);
|
|
va_end(f);
|
|
|
|
OutputDebugString(buf);
|
|
}
|
|
|
|
void GetAbsoluteFilename(char *file)
|
|
{
|
|
char absoluteFile[MAX_PATH];
|
|
GetFullPathName(file, sizeof(absoluteFile), absoluteFile, NULL);
|
|
strcpy(file, absoluteFile);
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// A separate heap, on which we allocate expressions. Maybe a bit faster,
|
|
// since no fragmentation issues whatsoever, and it also makes it possible
|
|
// to be sloppy with our memory management, and just free everything at once
|
|
// at the end.
|
|
//-----------------------------------------------------------------------------
|
|
void *AllocTemporary(size_t n)
|
|
{
|
|
void *v = HeapAlloc(TempHeap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, n);
|
|
if(!v) oops();
|
|
return v;
|
|
}
|
|
void FreeTemporary(void *p) {
|
|
HeapFree(TempHeap, HEAP_NO_SERIALIZE, p);
|
|
}
|
|
void FreeAllTemporary(void)
|
|
{
|
|
if(TempHeap) HeapDestroy(TempHeap);
|
|
TempHeap = HeapCreate(HEAP_NO_SERIALIZE, 1024*1024*20, 0);
|
|
// This is a good place to validate, because it gets called fairly
|
|
// often.
|
|
vl();
|
|
}
|
|
|
|
void *MemRealloc(void *p, size_t n) {
|
|
if(!p) {
|
|
return MemAlloc(n);
|
|
}
|
|
|
|
p = HeapReAlloc(PermHeap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, p, n);
|
|
if(!p) oops();
|
|
return p;
|
|
}
|
|
void *MemAlloc(size_t n) {
|
|
void *p = HeapAlloc(PermHeap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, n);
|
|
if(!p) oops();
|
|
return p;
|
|
}
|
|
void MemFree(void *p) {
|
|
HeapFree(PermHeap, HEAP_NO_SERIALIZE, p);
|
|
}
|
|
|
|
void vl(void) {
|
|
if(!HeapValidate(TempHeap, HEAP_NO_SERIALIZE, NULL)) oops();
|
|
if(!HeapValidate(PermHeap, HEAP_NO_SERIALIZE, NULL)) oops();
|
|
}
|
|
|
|
void InitHeaps(void) {
|
|
// Create the heap used for long-lived stuff (that gets freed piecewise).
|
|
PermHeap = HeapCreate(HEAP_NO_SERIALIZE, 1024*1024*20, 0);
|
|
// Create the heap that we use to store Exprs and other temp stuff.
|
|
FreeAllTemporary();
|
|
}
|
|
|