30 const static size_t MAX_FMT = 256;
35 va_start(args, format);
37 const int strChk = vsnprintf_s(buf, MAX_FMT, MAX_FMT, format, args);
39 const int strChk = vsnprintf(buf, MAX_FMT, format, args);
43 strChk >= 0 && (
size_t)strChk < MAX_FMT,
44 "String length larger than buffer. Shorten"
45 " string or increase buffer size defined in \"MAX_FMT\".");
46 return ::std::string(buf);
51 libff::UNUSED(format);
59 assert(num <= INT_MAX && num >= INT_MIN);
76 ::std::cerr <<
"ERROR: " << msg << ::std::endl << ::std::endl;
78 throw ::std::runtime_error(msg);
81 const ::std::string releaseMsg(
82 "Fatal error encountered. Run debug build for more"
83 " information and stack trace.");
84 ::std::cerr <<
"ERROR: " << releaseMsg << ::std::endl << ::std::endl;
85 throw ::std::runtime_error(releaseMsg);
97 std::cerr <<
"Stack trace (pipe through c++filt to demangle identifiers):"
99 const int maxFrames = 100;
100 void *frames[maxFrames];
102 int numFrames = backtrace(frames, maxFrames);
104 backtrace_symbols_fd(frames, numFrames, STDERR_FILENO);
108 std::cerr <<
" (stack trace not available on this platform)" << std::endl;
116 double Log2(
double n) {
return log(n) / log((
double)2); }
122 int retval = i ? 1 : 0;
130 bool IsPower2(
const long x) {
return ((x > 0) && ((x & (x - 1)) == 0)); }