X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Ffatal.cc;h=99b15535e0ea45b4641c2b082d8f6a85ff152269;hb=48e6e1b70b3b79f79334bdea8bfbbb76d377be07;hp=cdccff82aec67818d1c51e0389c751abc1cbbf19;hpb=3db2fad1ae84c7235507bf1adf471461856ddee4;p=awesomized%2Flibmemcached diff --git a/libtest/fatal.cc b/libtest/fatal.cc index cdccff82..99b15535 100644 --- a/libtest/fatal.cc +++ b/libtest/fatal.cc @@ -34,35 +34,54 @@ * */ -#include +#include "libtest/yatlcon.h" #include #include namespace libtest { -exception::exception(const char *file_, int line_, const char *func_) : - std::runtime_error(func_), - _file(file_), - _line(line_), - _func(func_) +#pragma GCC diagnostic ignored "-Wformat-nonliteral" + +fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, ...) : + __test_result(file_arg, line_arg, func_arg), + _error_message(NULL), + _error_message_size(0) +{ + va_list args; + va_start(args, func_arg); + const char *format= va_arg(args, const char *); + _error_message_size= vasprintf(&_error_message, format, args); + assert(_error_message_size != -1); + if (_error_message_size > 0) { + _error_message_size++; } + va_end(args); +} -#ifndef __INTEL_COMPILER -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif - -fatal::fatal(const char *file_, int line_, const char *func_, const char *format, ...) : - exception(file_, line_, func_) +fatal::fatal( const fatal& other ) : + __test_result(other), + _error_message_size(other._error_message_size) +{ + _error_message= (char*) malloc(_error_message_size); + if (_error_message) + { + memcpy(_error_message, other._error_message, _error_message_size); + } + else { - va_list args; - va_start(args, format); - char last_error[BUFSIZ]; - int last_error_length= vsnprintf(last_error, sizeof(last_error), format, args); - va_end(args); + _error_message_size= -1; + } +} - snprintf(_error_message, sizeof(_error_message), "%.*s", last_error_length, last_error); +fatal::~fatal() throw() +{ + if ((_error_message_size > 0) and _error_message) + { + free(_error_message); + _error_message= NULL; } +} static bool _disabled= false; static uint32_t _counter= 0; @@ -74,11 +93,13 @@ bool fatal::is_disabled() void fatal::disable() { + _counter= 0; _disabled= true; } void fatal::enable() { + _counter= 0; _disabled= false; } @@ -92,29 +113,18 @@ void fatal::increment_disabled_counter() _counter++; } -disconnected::disconnected(const char *file_, int line_, const char *func_, - const std::string& instance, const in_port_t port, - const char *format, ...) : - exception(file_, line_, func_), - _port(port) -{ - va_list args; - va_start(args, format); - char last_error[BUFSIZ]; - (void)vsnprintf(last_error, sizeof(last_error), format, args); - va_end(args); - - snprintf(_error_message, sizeof(_error_message), "%s:%u %s", instance.c_str(), uint32_t(port), last_error); -} - -start::start(const char *file_, int line_, const char *func_, - const std::string& instance, const in_port_t port, - const char *format, ...) : - exception(file_, line_, func_), - _port(port) +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +disconnected::disconnected(const char *file_arg, int line_arg, const char *func_arg, + const std::string& instance, const in_port_t port, ...) : + std::runtime_error(func_arg), + _port(port), + _line(line_arg), + _file(file_arg), + _func(func_arg) { va_list args; - va_start(args, format); + va_start(args, port); + const char *format= va_arg(args, const char *); char last_error[BUFSIZ]; (void)vsnprintf(last_error, sizeof(last_error), format, args); va_end(args); @@ -123,4 +133,3 @@ start::start(const char *file_, int line_, const char *func_, } } // namespace libtest -