~brianaker/libmemcached/update-m4-sept

« back to all changes in this revision

Viewing changes to libtest/fatal.cc

  • Committer: Brian Aker
  • Date: 2013-01-28 22:51:05 UTC
  • mfrom: (1079.1.65 workspace)
  • mto: This revision was merged to the branch mainline in revision 1099.
  • Revision ID: brian@tangent.org-20130128225105-8z352439kwu8vgku
Merge with 1.0 trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
44
44
 
45
45
fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, ...) :
46
 
  __test_result(file_arg, line_arg, func_arg),
47
 
  _error_message(NULL),
48
 
  _error_message_size(0)
 
46
  __test_result(file_arg, line_arg, func_arg)
49
47
{
50
48
  va_list args;
51
49
  va_start(args, func_arg);
52
 
  const char *format= va_arg(args, const char *);
53
 
  _error_message_size= vasprintf(&_error_message, format, args);
54
 
  assert(_error_message_size != -1);
55
 
  if (_error_message_size > 0)
56
 
  {
57
 
    _error_message_size++;
58
 
  }
 
50
  init(args);
59
51
  va_end(args);
60
52
}
61
53
 
62
54
fatal::fatal( const fatal& other ) :
63
 
  __test_result(other),
64
 
  _error_message_size(other._error_message_size)
65
 
{
66
 
  _error_message= (char*) malloc(_error_message_size);
67
 
  if (_error_message)
68
 
  {
69
 
    memcpy(_error_message, other._error_message, _error_message_size);
70
 
  }
71
 
  else
72
 
  {
73
 
    _error_message_size= -1;
74
 
  }
75
 
}
76
 
 
77
 
fatal::~fatal() throw()
78
 
{
79
 
  if ((_error_message_size > 0) and _error_message)
80
 
  {
81
 
    free(_error_message);
82
 
    _error_message= NULL;
83
 
  }
 
55
  __test_result(other)
 
56
{
84
57
}
85
58
 
86
59
static bool _disabled= false;
87
60
static uint32_t _counter= 0;
88
61
 
89
 
bool fatal::is_disabled()
 
62
bool fatal::is_disabled() throw()
90
63
{
91
64
  return _disabled;
92
65
}
93
66
 
94
 
void fatal::disable()
 
67
void fatal::disable() throw()
95
68
{
96
69
  _counter= 0;
97
70
  _disabled= true;
98
71
}
99
72
 
100
 
void fatal::enable()
 
73
void fatal::enable() throw()
101
74
{
102
75
  _counter= 0;
103
76
  _disabled= false;
104
77
}
105
78
 
106
 
uint32_t fatal::disabled_counter()
 
79
uint32_t fatal::disabled_counter() throw()
107
80
{
108
81
  return _counter;
109
82
}
110
83
 
111
 
void fatal::increment_disabled_counter()
 
84
void fatal::increment_disabled_counter() throw()
112
85
{
113
86
  _counter++;
114
87
}
132
105
  snprintf(_error_message, sizeof(_error_message), "%s:%u %s", instance.c_str(), uint32_t(port), last_error);
133
106
}
134
107
 
 
108
disconnected::disconnected(const disconnected& other):
 
109
  std::runtime_error(other._func),
 
110
  _port(other._port),
 
111
  _line(other._line),
 
112
  _file(other._file),
 
113
  _func(other._func)
 
114
{
 
115
  strncpy(_error_message, other._error_message, BUFSIZ);
 
116
  strncpy(_instance, other._instance, BUFSIZ);
 
117
}
 
118
 
135
119
} // namespace libtest