Merge lp:~stewart/percona-playback/cassert-header into lp:~percona-dev/percona-playback/light

Proposed by Stewart Smith
Status: Merged
Merged at revision: 121
Proposed branch: lp:~stewart/percona-playback/cassert-header
Merge into: lp:~percona-dev/percona-playback/light
Prerequisite: lp:~stewart/percona-playback/remove-null-deref
Diff against target: 628 lines (+80/-74)
12 files modified
src/common.h (+10/-12)
src/long_string.cc (+4/-3)
src/long_string.h (+2/-1)
src/mysql_client.cc (+6/-5)
src/options.cc (+2/-1)
src/query.cc (+7/-9)
src/queue.h (+26/-25)
src/reader.cc (+2/-1)
src/sheduler.cc (+8/-7)
src/slow_query_log_parser.h (+2/-1)
src/supervisor.cc (+6/-5)
src/worker.cc (+5/-4)
To merge this branch: bzr merge lp:~stewart/percona-playback/cassert-header
Reviewer Review Type Date Requested Status
Percona developers Pending
Review via email: mp+67501@code.launchpad.net

Description of the change

correctly include the cassert header for assert() and also use standard assert() instead of custom ASSERT(). If people really want to not run the asserts, they can change this via compile option (which, IMNSHO is silly to do)

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/common.h'
2--- src/common.h 2011-06-23 06:11:17 +0000
3+++ src/common.h 2011-07-11 07:37:28 +0000
4@@ -25,6 +25,7 @@
5 #include <map>
6 #include <set>
7 #include <deque>
8+#include <cassert>
9 #include <boost/shared_ptr.hpp>
10 #include <pthread.h>
11
12@@ -35,22 +36,21 @@
13
14 #include <cassert>
15 #define MAX_C_STRING_LENGTH (1024*1024)
16-#define ASSERT(condition) assert(condition)
17 #define CHECK_C_STRING(value) do \
18 { \
19- ASSERT(value != NULL && "NULL is not string" && __FILE__ && __LINE__); \
20- ASSERT(value != 0 && "0 is not string" && __FILE__ && __LINE__); \
21- ASSERT((memchr(value, 0, MAX_C_STRING_LENGTH) != NULL) \
22+ assert(value != NULL && "NULL is not string" && __FILE__ && __LINE__); \
23+ assert(value != 0 && "0 is not string" && __FILE__ && __LINE__); \
24+ assert((memchr(value, 0, MAX_C_STRING_LENGTH) != NULL) \
25 && "too long C string" && __FILE__ && __LINE__); \
26 } \
27 while(false)
28 #define CHECK_C_STRING_LENGTH(value,length) do \
29 { \
30- ASSERT(value != NULL && "NULL is not string" && __FILE__ && __LINE__); \
31- ASSERT(value != 0 && "0 is not string" && __FILE__ && __LINE__); \
32- ASSERT(((length == 0) || (memchr(value, 0, length) == NULL)) \
33+ assert(value != NULL && "NULL is not string" && __FILE__ && __LINE__); \
34+ assert(value != 0 && "0 is not string" && __FILE__ && __LINE__); \
35+ assert(((length == 0) || (memchr(value, 0, length) == NULL)) \
36 && "incorrect C string length" && __FILE__ && __LINE__); \
37- ASSERT(value[length] == 0 \
38+ assert(value[length] == 0 \
39 && "incorrect C string length" && __FILE__ && __LINE__); \
40 } \
41 while(false)
42@@ -72,8 +72,6 @@
43
44 #else // DEBUG
45
46-#define ASSERT(condition) /* removed ASSERT(condition) */
47-
48 #define CHECK_C_STRING(value) \
49 /* removed CHECK_C_STRING(value) */
50 #define CHECK_C_STRING_LENGTH(value,length) \
51@@ -159,12 +157,12 @@
52 }
53 void add(T *a_item)
54 {
55- ASSERT(!has(a_item));
56+ assert(!has(a_item));
57 m_set.insert(a_item);
58 }
59 void del(T *a_item)
60 {
61- ASSERT(has(a_item));
62+ assert(has(a_item));
63 if (m_free_count > 0 && m_free_count > m_queue.size())
64 {
65 m_queue.push_back(a_item);
66
67=== modified file 'src/long_string.cc'
68--- src/long_string.cc 2011-07-11 07:37:28 +0000
69+++ src/long_string.cc 2011-07-11 07:37:28 +0000
70@@ -18,6 +18,7 @@
71
72 #include <strings.h>
73 #include <iostream>
74+#include <cassert>
75 #include "common.h"
76 #include "long_string.h"
77
78@@ -205,7 +206,7 @@
79 if (from >= m_length)
80 return m_length;
81 CHECK_C_STRING_LENGTH(m_data, m_length);
82- ASSERT(from < m_length);
83+ assert(from < m_length);
84 const char* result=
85 (const char*)memchr(m_data + from, c, m_length - from);
86 if (NULL == result)
87@@ -352,7 +353,7 @@
88 {
89 if (m_null)
90 {
91- ASSERT(false && "Impossible call method length when Nullable_String is null");
92+ assert(false && "Impossible call method length when Nullable_String is null");
93 throw String_Null_Error("length");
94 }
95 else
96@@ -362,7 +363,7 @@
97 {
98 if (m_null)
99 {
100- ASSERT(false && "Impossible call method length when Nullable_String is null");
101+ assert(false && "Impossible call method length when Nullable_String is null");
102 throw String_Null_Error("length");
103 }
104 else
105
106=== modified file 'src/long_string.h'
107--- src/long_string.h 2011-06-23 06:11:17 +0000
108+++ src/long_string.h 2011-07-11 07:37:28 +0000
109@@ -21,6 +21,7 @@
110
111 #include <strings.h>
112 #include <string>
113+#include <cassert>
114 #include <boost/utility.hpp>
115 #include "introspection.h"
116 #include "queue.h"
117@@ -107,7 +108,7 @@
118 CHECK_C_STRING_LENGTH(value.m_data, value.m_length);
119 action.begin_compound(value);
120 action.member("m_length", value.m_length);
121- ASSERT(value.m_max >= value.m_length);
122+ assert(value.m_max >= value.m_length);
123 action.read((void*)value.m_data, value.m_length + 1);
124 action.end_compound(value);
125 CHECK_C_STRING_LENGTH(value.m_data, value.m_length);
126
127=== modified file 'src/mysql_client.cc'
128--- src/mysql_client.cc 2011-06-23 06:11:17 +0000
129+++ src/mysql_client.cc 2011-07-11 07:37:28 +0000
130@@ -17,6 +17,7 @@
131 */
132
133 #include <iomanip>
134+#include <cassert>
135 #include <boost/date_time/posix_time/posix_time.hpp>
136 #include "query.h"
137 #include "mysql_client.h"
138@@ -124,7 +125,7 @@
139 if (previous != current)
140 {
141 int result= snprintf(m_set.data(), m_set.max(), "set %s=%lld;", name, current);
142- ASSERT(result > 0);
143+ assert(result > 0);
144 m_set.length(result);
145 previous= current;
146 execute(r, m_set, eQuery_Type_Write);
147@@ -172,13 +173,13 @@
148 if (type == eQuery_Type_Unknown)
149 {
150 Query_Parse_State state= query_parse(eQuery_Detect_Type, sql.data(), sql.length());
151- ASSERT(end_of_query(state));
152+ assert(end_of_query(state));
153 type= query_type(state);
154- ASSERT(type != eQuery_Type_Unknown);
155+ assert(type != eQuery_Type_Unknown);
156 }
157 else
158 {
159- ASSERT(end_of_query(query_parse(eQuery_Detect_Correct, sql.data(), sql.length())));
160+ assert(end_of_query(query_parse(eQuery_Detect_Correct, sql.data(), sql.length())));
161 }
162 start_timer(r);
163 CHECK_C_STRING_LENGTH(sql.data(), sql.length());
164@@ -226,7 +227,7 @@
165 , (old_length == 0 ? "" : "\n")
166 , mysql_errno(handle())
167 , mysql_error(handle()));
168- ASSERT(new_length > 0);
169+ assert(new_length > 0);
170 error.length(old_length + new_length);
171 }
172 }
173
174=== modified file 'src/options.cc'
175--- src/options.cc 2011-06-23 06:11:17 +0000
176+++ src/options.cc 2011-07-11 07:37:28 +0000
177@@ -18,6 +18,7 @@
178
179 #include <iostream>
180 #include <fstream>
181+#include <cassert>
182 #include <boost/program_options.hpp>
183 #include <boost/program_options/parsers.hpp>
184 #include <boost/lexical_cast.hpp>
185@@ -287,7 +288,7 @@
186 custom_verbose_callback_vector.push_back(Verbose_Callback_Pointer(new Verbose_Callback_Fill()));
187 fill= custom_verbose_callback_vector.back().get()->fill();
188 }
189- ASSERT(fill);
190+ assert(fill);
191 fill->add(*mask);
192 }
193 }
194
195=== modified file 'src/query.cc'
196--- src/query.cc 2011-06-23 06:11:17 +0000
197+++ src/query.cc 2011-07-11 07:37:28 +0000
198@@ -18,6 +18,7 @@
199
200 #include <strings.h>
201 #include <iostream>
202+#include <cassert>
203 #include "query.h"
204 #include "options.h"
205
206@@ -49,7 +50,7 @@
207 case (eQuery_Type_Unknown): return "unknown";
208 case (eQuery_Type_Read): return "read";
209 case (eQuery_Type_Write): return "write";
210- default: ASSERT(false && "make gcc happy"); return "const char* to_c_str(Enum_Query_Type type) FAILED";
211+ default: assert(false && "make gcc happy"); return "const char* to_c_str(Enum_Query_Type type) FAILED";
212 };
213 }
214 std::ostream& operator<<(std::ostream&s , Enum_Query_Type type)
215@@ -236,7 +237,7 @@
216 }
217 std::size_t query_parse_stupid(Query_Parse_State &state, const char* data, std::size_t length)
218 {
219- ASSERT(eQuery_Detect_Stupid == query_detect(state));
220+ assert(eQuery_Detect_Stupid == query_detect(state));
221 const char* result= (const char*)memchr(data, ';', length);
222 if (result == NULL)
223 return length;
224@@ -418,7 +419,7 @@
225 #define LETTER_END(state) STATE_JUMP(state, ZERO);
226 #define QUERY_TYPE(state, new_type) \
227 STATE_LABEL(state); \
228- ASSERT(type == eQuery_Type_Unknown); \
229+ assert(type == eQuery_Type_Unknown); \
230 type= new_type; \
231 JUMP(ZERO)
232
233@@ -521,13 +522,10 @@
234 Query_Parse_State query_parse(Enum_Query_Detect detect, const char* data, std::size_t length)
235 {
236 Query_Parse_State state= query_parse_state_begin(detect);
237-#ifdef DEBUG
238- std::size_t result=
239-#endif //DEBUG
240- query_parse(state, data, length);
241+ std::size_t result= query_parse(state, data, length);
242 //if (!end_of_query(state))
243 // std::cout << *reinterpret_cast<int*>(0);
244- ASSERT(end_of_query(state));
245- ASSERT(result == length);
246+ assert(end_of_query(state));
247+ assert(result == length);
248 return state;
249 }
250
251=== modified file 'src/queue.h'
252--- src/queue.h 2011-06-23 06:11:17 +0000
253+++ src/queue.h 2011-07-11 07:37:28 +0000
254@@ -23,6 +23,7 @@
255 #include <string.h>
256 #include <queue>
257 #include <sstream>
258+#include <cassert>
259 #include "common.h"
260 #include "introspection.h"
261
262@@ -205,14 +206,14 @@
263 if(m_read_offset == m_write_offset) // queue is (empty or full).
264 {
265 // invariant
266- ASSERT((m_read_pass == m_write_pass) || (m_read_pass + 1 == m_write_pass));
267+ assert((m_read_pass == m_write_pass) || (m_read_pass + 1 == m_write_pass));
268 if(m_read_pass < m_write_pass)
269 {
270 // queue full
271 return false;
272 }
273 // queue empty
274- ASSERT(m_read_pass == m_write_pass);
275+ assert(m_read_pass == m_write_pass);
276 // move to begin
277 m_write_offset= m_read_offset= 0;
278 m_padd_offset= m_buffer_size;
279@@ -233,7 +234,7 @@
280 public:
281 void unsafety_push(T const &value)
282 {
283- ASSERT(can_push(value));
284+ assert(can_push(value));
285 Writer action(*this);
286 ::apply(action, value);
287 if(m_write_offset == m_buffer_size)
288@@ -245,7 +246,7 @@
289 public:
290 void unsafety_pop(T &value)
291 {
292- ASSERT(!empty());
293+ assert(!empty());
294 Reader action(*this);
295 ::apply(action, value);
296 if(m_read_offset == m_padd_offset)
297@@ -258,11 +259,11 @@
298 private:
299 queue_item_length free_size() const
300 {
301- ASSERT(m_write_offset < m_buffer_size);
302- ASSERT(m_read_offset < m_buffer_size);
303+ assert(m_write_offset < m_buffer_size);
304+ assert(m_read_offset < m_buffer_size);
305 if(m_read_offset == m_write_offset) // queue is empty or full.
306 {
307- ASSERT((m_read_pass == m_write_pass) || (m_read_pass + 1 == m_write_pass));
308+ assert((m_read_pass == m_write_pass) || (m_read_pass + 1 == m_write_pass));
309 if(m_read_pass == m_write_pass)
310 return m_buffer_size - m_write_offset; // queue is empty
311 else
312@@ -278,18 +279,18 @@
313 void write_check(queue_item_length size) const
314 {
315 // check for enough space
316- ASSERT(free_size() >= size);
317- ASSERT(m_write_offset + size <= m_buffer_size);
318+ assert(free_size() >= size);
319+ assert(m_write_offset + size <= m_buffer_size);
320 // check what we stay on free block
321- ASSERT((state(m_write_offset) == eFree) || (state(m_write_offset) == ePad));
322+ assert((state(m_write_offset) == eFree) || (state(m_write_offset) == ePad));
323 }
324 void read_check(queue_item_length size) const
325 {
326 // check what we stay on data block
327- ASSERT(state(m_read_offset) == eData);
328+ assert(state(m_read_offset) == eData);
329 // check what data place on buffer
330- ASSERT(m_padd_offset <= m_buffer_size);
331- ASSERT(m_read_offset + size <= m_padd_offset);
332+ assert(m_padd_offset <= m_buffer_size);
333+ assert(m_read_offset + size <= m_padd_offset);
334 }
335 #else // DEBUG
336 void write_check(queue_item_length) const {}
337@@ -326,13 +327,13 @@
338 private:
339 State state(queue_item_length offset) const
340 {
341- ASSERT(offset <= m_buffer_size);
342+ assert(offset <= m_buffer_size);
343 if(m_write_offset == m_read_offset)
344 {
345 if(m_read_pass < m_write_pass)
346 {
347 // queue is full
348- ASSERT(m_read_pass + 1 == m_write_pass);
349+ assert(m_read_pass + 1 == m_write_pass);
350 if(offset >= m_padd_offset)
351 return ePad;
352 else
353@@ -341,8 +342,8 @@
354 else
355 {
356 // queue is empty
357- ASSERT(m_read_pass == m_write_pass);
358- ASSERT(m_padd_offset == m_buffer_size);
359+ assert(m_read_pass == m_write_pass);
360+ assert(m_padd_offset == m_buffer_size);
361 return eFree;
362 }
363 }
364@@ -402,7 +403,7 @@
365 /*std::ostringstream s;
366 s << *this << " : " << this << " ctor " << m_max_count << "\n";
367 std::cout << s.str() << std::flush;*/
368- ASSERT(m_max_count > 0);
369+ assert(m_max_count > 0);
370 }
371 void reset()
372 {
373@@ -435,7 +436,7 @@
374 s << m_queue.size();
375 s << " AND MAX_COUNT " << m_max_count << "\n";
376 std::cout << s.str() << std::flush;*/
377- ASSERT(m_queue.size() < m_max_count);
378+ assert(m_queue.size() < m_max_count);
379 m_queue.push_back(a_item);
380 }
381 bool unsafety_pop(T*& a_item)
382@@ -444,7 +445,7 @@
383 s << *this << " : " << this << " UNSAFETY_POP: QUEUE SIZE IS ";
384 s << m_queue.size();
385 s << " AND MAX_COUNT " << m_max_count << "\n";*/
386- ASSERT(false == m_queue.empty());
387+ assert(false == m_queue.empty());
388 a_item= m_queue.front();
389 m_queue.pop_front();
390 return true;
391@@ -545,8 +546,8 @@
392 }
393 while(false);*/
394 }
395- ASSERT(m_run);
396- ASSERT(!m_container.empty());
397+ assert(m_run);
398+ assert(!m_container.empty());
399 /*do
400 {
401 std::ostringstream s;
402@@ -608,7 +609,7 @@
403 }
404 while(false);*/
405 }
406- ASSERT(m_container.can_push(value));
407+ assert(m_container.can_push(value));
408 /*do
409 {
410 std::ostringstream s;
411@@ -657,7 +658,7 @@
412 }
413 else
414 {
415- ASSERT(m_flush || m_run);
416+ assert(m_flush || m_run);
417 }
418 s << "\n";
419 do
420@@ -667,7 +668,7 @@
421 std::cout << s.str() << std::flush;
422 }
423 while(false);*/
424- ASSERT(m_flush || !m_run);
425+ assert(m_flush || !m_run);
426 m_not_full.notify_all();
427 m_not_empty.notify_all();
428 return false;
429
430=== modified file 'src/reader.cc'
431--- src/reader.cc 2011-06-23 06:11:17 +0000
432+++ src/reader.cc 2011-07-11 07:37:28 +0000
433@@ -17,6 +17,7 @@
434 */
435
436 #include <iostream>
437+#include <cassert>
438 #include "reader.h"
439
440 Reader_Source::Reader_Source(std::size_t a_page_size, std::size_t a_page_count) :
441@@ -66,7 +67,7 @@
442 int length= m_source->read(string.data(), string.max());
443 if (length > 0)
444 {
445- ASSERT(static_cast<std::size_t>(length) <= string.max());
446+ assert(static_cast<std::size_t>(length) <= string.max());
447 string.length(length);
448 if (static_cast<std::size_t>(length) < string.max())
449 bzero(string.data() + length, string.max() - length + 1);
450
451=== modified file 'src/sheduler.cc'
452--- src/sheduler.cc 2011-06-23 06:11:17 +0000
453+++ src/sheduler.cc 2011-07-11 07:37:28 +0000
454@@ -20,6 +20,7 @@
455 #include <map>
456 #include <queue>
457 #include <memory>
458+#include <cassert>
459 #include "sheduler.h"
460 #include "worker.h"
461 #include "query.h"
462@@ -53,7 +54,7 @@
463 Task_Manager(std::size_t a_buffer_size) :
464 Base(::max_idle_thread_count()), m_buffer_size(a_buffer_size)
465 {
466- ASSERT(m_buffer_size);
467+ assert(m_buffer_size);
468 /*do
469 {
470 std::ostringstream s;
471@@ -193,7 +194,7 @@
472 std::pair< Map::iterator, bool > task_result;
473
474 task_result= m_task.insert(task_insert);
475- ASSERT(true == task_result.second);
476+ assert(true == task_result.second);
477
478 Task* task= task_result.first->second;
479 typedef std::auto_ptr<Connection_Worker> Pointer;
480@@ -218,7 +219,7 @@
481
482 if (is_stop() || is_flush())
483 {
484- ASSERT(false == is_flush());
485+ assert(false == is_flush());
486 return false;
487 }
488
489@@ -245,7 +246,7 @@
490 {
491 i= create(thread_id);
492 }
493- ASSERT(active(i));
494+ assert(active(i));
495 //static std::size_t count= 0;
496 //std::cout << "PUSH QUERY " << ++count << "\n" << std::flush;
497 task(i)->push(a_query);
498@@ -285,7 +286,7 @@
499 }
500 Task* complete(Map::iterator a_task)
501 {
502- ASSERT(active(a_task));
503+ assert(active(a_task));
504 Task *result= task(a_task);
505 result->flush();
506 m_map.erase(a_task);
507@@ -293,7 +294,7 @@
508 }
509 Task* begin(const Query &a_query)
510 {
511- ASSERT(false == active(task(a_query)));
512+ assert(false == active(task(a_query)));
513 std::pair< Thread_Id, Task* > insert;
514 std::pair< Map::iterator, bool > result;
515
516@@ -303,7 +304,7 @@
517 insert.second->push(a_query);
518
519 result= m_map.insert(insert);
520- ASSERT(result.second);
521+ assert(result.second);
522
523 return 0;
524 }
525
526=== modified file 'src/slow_query_log_parser.h'
527--- src/slow_query_log_parser.h 2011-06-23 06:11:17 +0000
528+++ src/slow_query_log_parser.h 2011-07-11 07:37:28 +0000
529@@ -23,6 +23,7 @@
530 #include <sstream>
531 #include <set>
532 #include <vector>
533+#include <cassert>
534 #include "common.h"
535 #include "options.h"
536 #include "queue.h"
537@@ -326,7 +327,7 @@
538 || (('A' <= current()) && (current() <= 'Z'))))
539 bool do_skip(std::size_t count)
540 {
541- ASSERT(has_count(count));
542+ assert(has_count(count));
543 m_current += count;
544 return true;
545 }
546
547=== modified file 'src/supervisor.cc'
548--- src/supervisor.cc 2011-06-23 06:11:17 +0000
549+++ src/supervisor.cc 2011-07-11 07:37:28 +0000
550@@ -17,6 +17,7 @@
551 */
552
553 #include <deque>
554+#include <cassert>
555 #include "supervisor.h"
556 #include "options.h"
557 #include "worker.h"
558@@ -61,7 +62,7 @@
559 public:
560 void start()
561 {
562- ASSERT(false == m_gc.run());
563+ assert(false == m_gc.run());
564 m_active= 0;
565 m_join.reset();
566 m_flush= false;
567@@ -70,18 +71,18 @@
568 }
569 void join()
570 {
571- ASSERT(m_flush || m_stop);
572- ASSERT(true == m_gc.run());
573+ assert(m_flush || m_stop);
574+ assert(true == m_gc.run());
575 m_gc.join();
576 }
577 void flush()
578 {
579- ASSERT(m_gc.run());
580+ assert(m_gc.run());
581 m_flush= true;
582 }
583 void stop()
584 {
585- ASSERT(m_gc.run());
586+ assert(m_gc.run());
587 m_stop= true;
588 }
589 bool start(Worker *a_worker)
590
591=== modified file 'src/worker.cc'
592--- src/worker.cc 2011-06-23 06:11:17 +0000
593+++ src/worker.cc 2011-07-11 07:37:28 +0000
594@@ -19,6 +19,7 @@
595 #include <vector>
596 #include <sstream>
597 #include <map>
598+#include <cassert>
599 #include <boost/shared_ptr.hpp>
600 #include "options.h"
601 #include "worker.h"
602@@ -55,9 +56,9 @@
603 Query_Parse_State state= query_parse(eQuery_Detect_Type
604 , a_query.sql.data()
605 , a_query.sql.length());
606- ASSERT(end_of_query(state));
607+ assert(end_of_query(state));
608 a_query.type= query_type(state);
609- ASSERT(a_query.type != eQuery_Type_Unknown);
610+ assert(a_query.type != eQuery_Type_Unknown);
611 }
612 a_result.thread_id= a_worker_thread_id;
613 a_client.run(a_result, a_query);
614@@ -87,12 +88,12 @@
615 }
616 void Worker::start()
617 {
618- ASSERT(false == m_thread.run());
619+ assert(false == m_thread.run());
620 m_thread.start();
621 }
622 void Worker::join()
623 {
624- ASSERT(true == m_thread.run());
625+ assert(true == m_thread.run());
626 m_thread.join();
627 }
628 Task* Worker::first()

Subscribers

People subscribed via source and target branches