Refactor dbp. NFC.

After this commit, dbp() is renamed to DebugPrint() and moved to
platform.cpp, next to other similar functions. The existing short
name is provided by a preprocessor macro, similar to ssassert().

This leaves just the (rather hacky) temporary heap in util*.cpp.
This commit is contained in:
whitequark 2020-05-10 08:28:01 +00:00
parent 9951da8965
commit e00d4867e1
5 changed files with 56 additions and 36 deletions

View File

@ -633,5 +633,53 @@ std::vector<std::string> InitCli(int argc, char **argv) {
#endif #endif
//-----------------------------------------------------------------------------
// Debug output, on *nix.
//-----------------------------------------------------------------------------
#if defined(WIN32)
void DebugPrint(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
int len = _vscprintf(fmt, va) + 1;
va_end(va);
va_start(va, fmt);
char *buf = (char *)_alloca(len);
_vsnprintf(buf, len, fmt, va);
va_end(va);
// The native version of OutputDebugString, unlike most others,
// is OutputDebugStringA.
OutputDebugStringA(buf);
OutputDebugStringA("\n");
#ifndef NDEBUG
// Duplicate to stderr in debug builds, but not in release; this is slow.
fputs(buf, stderr);
fputc('\n', stderr);
#endif
}
#endif
//-----------------------------------------------------------------------------
// Debug output, on *nix.
//-----------------------------------------------------------------------------
#if !defined(WIN32)
void DebugPrint(const char *fmt, ...) {
va_list va;
va_start(va, fmt);
vfprintf(stderr, fmt, va);
fputc('\n', stderr);
va_end(va);
}
#endif
} }
} }

View File

@ -67,6 +67,9 @@ const void *LoadResource(const std::string &name, size_t *size);
// Startup and command-line argument handling. // Startup and command-line argument handling.
std::vector<std::string> InitCli(int argc, char **argv); std::vector<std::string> InitCli(int argc, char **argv);
// Debug print function.
void DebugPrint(const char *fmt, ...);
} }
#endif #endif

View File

@ -8,17 +8,6 @@
namespace SolveSpace { namespace SolveSpace {
void dbp(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
vfprintf(stdout, fmt, va);
fputc('\n', stdout);
va_end(va);
fflush(stdout);
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// A separate heap, on which we allocate expressions. Maybe a bit faster, // A separate heap, on which we allocate expressions. Maybe a bit faster,
// since fragmentation is less of a concern, and it also makes it possible // since fragmentation is less of a concern, and it also makes it possible

View File

@ -10,26 +10,6 @@
namespace SolveSpace { namespace SolveSpace {
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);
// The native version of OutputDebugString, unlike most others,
// is OutputDebugStringA.
OutputDebugStringA(buf);
OutputDebugStringA("\n");
#ifndef NDEBUG
// Duplicate to stderr in debug builds, but not in release; this is slow.
fputs(buf, stderr);
fputc('\n', stderr);
#endif
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// A separate heap, on which we allocate expressions. Maybe a bit faster, // A separate heap, on which we allocate expressions. Maybe a bit faster,
// since no fragmentation issues whatsoever, and it also makes it possible // since no fragmentation issues whatsoever, and it also makes it possible

View File

@ -71,6 +71,11 @@ typedef struct _cairo_surface cairo_surface_t;
} while(0) } while(0)
#endif #endif
#define dbp SolveSpace::Platform::DebugPrint
#define DBPTRI(tri) \
dbp("tri: (%.3f %.3f %.3f) (%.3f %.3f %.3f) (%.3f %.3f %.3f)", \
CO((tri).a), CO((tri).b), CO((tri).c))
#ifndef isnan #ifndef isnan
# define isnan(x) (((x) != (x)) || (x > 1e11) || (x < -1e11)) # define isnan(x) (((x) != (x)) || (x > 1e11) || (x < -1e11))
#endif #endif
@ -141,11 +146,6 @@ const size_t MAX_RECENT = 8;
#define AUTOSAVE_EXT "slvs~" #define AUTOSAVE_EXT "slvs~"
void dbp(const char *str, ...);
#define DBPTRI(tri) \
dbp("tri: (%.3f %.3f %.3f) (%.3f %.3f %.3f) (%.3f %.3f %.3f)", \
CO((tri).a), CO((tri).b), CO((tri).c))
void *AllocTemporary(size_t n); void *AllocTemporary(size_t n);
void FreeAllTemporary(); void FreeAllTemporary();