Commit 764204b25998ccf8daecfc4aa6caabeb5aebfd01
1 parent
350c0377
Ignoring strict aliasing in some usages of libev macros.
With compiler warning -Wstrict-aliasing enabled, usage of the macros ev_async_timer and ev_timer_init yields said warnings. Created templates to locally turn off these warnings. Compiles without warnings with gcc 4.9.2 and clang 3.5.
Showing
1 changed file
with
28 additions
and
6 deletions
src/client.cpp
| @@ -24,6 +24,28 @@ | @@ -24,6 +24,28 @@ | ||
| 24 | 24 | ||
| 25 | using namespace std; | 25 | using namespace std; |
| 26 | 26 | ||
| 27 | +namespace { | ||
| 28 | + | ||
| 29 | +template<typename tev, typename tcb> | ||
| 30 | +void redox_ev_async_init(tev ev, tcb cb) | ||
| 31 | +{ | ||
| 32 | +#pragma GCC diagnostic push | ||
| 33 | +#pragma GCC diagnostic ignored "-Wstrict-aliasing" | ||
| 34 | + ev_async_init(ev,cb); | ||
| 35 | +#pragma GCC diagnostic pop | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +template<typename ttimer, typename tcb, typename tafter, typename trepeat> | ||
| 39 | +void redox_ev_timer_init(ttimer timer, tcb cb, tafter after, trepeat repeat) | ||
| 40 | +{ | ||
| 41 | +#pragma GCC diagnostic push | ||
| 42 | +#pragma GCC diagnostic ignored "-Wstrict-aliasing" | ||
| 43 | + ev_timer_init(timer,cb,after,repeat); | ||
| 44 | +#pragma GCC diagnostic pop | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +} // anonymous | ||
| 48 | + | ||
| 27 | namespace redox { | 49 | namespace redox { |
| 28 | 50 | ||
| 29 | Redox::Redox(ostream &log_stream, log::Level log_level) | 51 | Redox::Redox(ostream &log_stream, log::Level log_level) |
| @@ -275,16 +297,16 @@ void Redox::runEventLoop() { | @@ -275,16 +297,16 @@ void Redox::runEventLoop() { | ||
| 275 | 297 | ||
| 276 | // Set up asynchronous watcher which we signal every | 298 | // Set up asynchronous watcher which we signal every |
| 277 | // time we add a command | 299 | // time we add a command |
| 278 | - ev_async_init(&watcher_command_, processQueuedCommands); | 300 | + redox_ev_async_init(&watcher_command_, processQueuedCommands); |
| 279 | ev_async_start(evloop_, &watcher_command_); | 301 | ev_async_start(evloop_, &watcher_command_); |
| 280 | 302 | ||
| 281 | // Set up an async watcher to break the loop | 303 | // Set up an async watcher to break the loop |
| 282 | - ev_async_init(&watcher_stop_, breakEventLoop); | 304 | + redox_ev_async_init(&watcher_stop_, breakEventLoop); |
| 283 | ev_async_start(evloop_, &watcher_stop_); | 305 | ev_async_start(evloop_, &watcher_stop_); |
| 284 | 306 | ||
| 285 | // Set up an async watcher which we signal every time | 307 | // Set up an async watcher which we signal every time |
| 286 | // we want a command freed | 308 | // we want a command freed |
| 287 | - ev_async_init(&watcher_free_, freeQueuedCommands); | 309 | + redox_ev_async_init(&watcher_free_, freeQueuedCommands); |
| 288 | ev_async_start(evloop_, &watcher_free_); | 310 | ev_async_start(evloop_, &watcher_free_); |
| 289 | 311 | ||
| 290 | setRunning(true); | 312 | setRunning(true); |
| @@ -307,7 +329,7 @@ void Redox::runEventLoop() { | @@ -307,7 +329,7 @@ void Redox::runEventLoop() { | ||
| 307 | // Wait to receive server replies for clean hiredis disconnect | 329 | // Wait to receive server replies for clean hiredis disconnect |
| 308 | this_thread::sleep_for(chrono::milliseconds(10)); | 330 | this_thread::sleep_for(chrono::milliseconds(10)); |
| 309 | ev_run(evloop_, EVRUN_NOWAIT); | 331 | ev_run(evloop_, EVRUN_NOWAIT); |
| 310 | - | 332 | + |
| 311 | if (getConnectState() == CONNECTED) { | 333 | if (getConnectState() == CONNECTED) { |
| 312 | redisAsyncDisconnect(ctx_); | 334 | redisAsyncDisconnect(ctx_); |
| 313 | } | 335 | } |
| @@ -410,7 +432,7 @@ template <class ReplyT> bool Redox::processQueuedCommand(long id) { | @@ -410,7 +432,7 @@ template <class ReplyT> bool Redox::processQueuedCommand(long id) { | ||
| 410 | } else { | 432 | } else { |
| 411 | 433 | ||
| 412 | c->timer_.data = (void *)c->id_; | 434 | c->timer_.data = (void *)c->id_; |
| 413 | - ev_timer_init(&c->timer_, submitCommandCallback<ReplyT>, c->after_, c->repeat_); | 435 | + redox_ev_timer_init(&c->timer_, submitCommandCallback<ReplyT>, c->after_, c->repeat_); |
| 414 | ev_timer_start(evloop_, &c->timer_); | 436 | ev_timer_start(evloop_, &c->timer_); |
| 415 | 437 | ||
| 416 | c->timer_guard_.unlock(); | 438 | c->timer_guard_.unlock(); |
| @@ -610,7 +632,7 @@ string Redox::get(const string &key) { | @@ -610,7 +632,7 @@ string Redox::get(const string &key) { | ||
| 610 | string reply = c.reply(); | 632 | string reply = c.reply(); |
| 611 | c.free(); | 633 | c.free(); |
| 612 | return reply; | 634 | return reply; |
| 613 | -}; | 635 | +} |
| 614 | 636 | ||
| 615 | bool Redox::set(const string &key, const string &value) { return commandSync({"SET", key, value}); } | 637 | bool Redox::set(const string &key, const string &value) { return commandSync({"SET", key, value}); } |
| 616 | 638 |