diff options
| author | Brian Anderson <[email protected]> | 2011-04-07 20:37:56 -0400 |
|---|---|---|
| committer | Brian Anderson <[email protected]> | 2011-04-07 22:53:16 -0400 |
| commit | b883ec4c9d09848a9c9a0822cde4bef4a347cbab (patch) | |
| tree | 56880d5c7818ecd71d41ef8d061bea096b2b7223 /src/rt/rust_log.h | |
| parent | Add a test case for calling generic functions taking alias args with box types (diff) | |
| download | rust-b883ec4c9d09848a9c9a0822cde4bef4a347cbab.tar.xz rust-b883ec4c9d09848a9c9a0822cde4bef4a347cbab.zip | |
Avoid some gotchas with logging macros
I think this is sufficient to eliminate multiple evaluation and the
possibility of accidental miscompilation from the logging macros.
Diffstat (limited to 'src/rt/rust_log.h')
| -rw-r--r-- | src/rt/rust_log.h | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/rt/rust_log.h b/src/rt/rust_log.h index 8d3d4bcb..3b40869b 100644 --- a/src/rt/rust_log.h +++ b/src/rt/rust_log.h @@ -1,19 +1,27 @@ #ifndef RUST_LOG_H #define RUST_LOG_H -#define DLOG(dom, mask, ...) \ - if ((dom)->get_log().is_tracing(mask)) { \ - (dom)->log(mask, __VA_ARGS__); \ - } else -#define LOG(task, mask, ...) \ +#define DLOG(dom, mask, ...) \ + do { \ + rust_dom *_dom = dom; \ + uint32_t _mask = mask; \ + if ((_dom)->get_log().is_tracing(_mask)) { \ + (_dom)->log(_mask, __VA_ARGS__); \ + } \ + } while(0) +#define LOG(task, mask, ...) \ DLOG((task)->dom, mask, __VA_ARGS__) -#define LOG_I(task, mask, ...) \ - if ((task)->dom->get_log().is_tracing(mask)) { \ - (task)->dom->get_log().reset_indent(0); \ - (task)->dom->log(mask, __VA_ARGS__); \ - (task)->dom->get_log().indent(); \ - } else -#define LOGPTR(dom, msg, ptrval) \ +#define LOG_I(task, mask, ...) \ + do { \ + rust_task *_task = task; \ + uint32_t _mask = mask; \ + if ((_task)->dom->get_log().is_tracing(_mask)) { \ + (_task)->dom->get_log().reset_indent(0); \ + (_task)->dom->log(_mask, __VA_ARGS__); \ + (_task)->dom->get_log().indent(); \ + } \ + } while(0) +#define LOGPTR(dom, msg, ptrval) \ DLOG(dom, rust_log::MEM, "%s 0x%" PRIxPTR, msg, ptrval) class rust_dom; |