From: Ran Benita Date: Tue, 8 Oct 2013 19:37:53 +0000 (+0300) Subject: rules: improve error logging macros X-Git-Tag: xkbcommon-0.3.2~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=efe5b036ee5b8b8a20b1e5395cfa1152218fe60c;p=platform%2Fupstream%2Flibxkbcommon.git rules: improve error logging macros Improve safety with parenthesis, make the matcher macros use the scanner ones, and make the 1 variant use %s instead of embedding the msg; this way the compiler can reuse the string in the binary. Signed-off-by: Ran Benita --- diff --git a/src/xkbcomp/rules.c b/src/xkbcomp/rules.c index 58e7c8a..1963802 100644 --- a/src/xkbcomp/rules.c +++ b/src/xkbcomp/rules.c @@ -158,11 +158,11 @@ enum rules_token { /* C99 is stupid. Just use the 1 variant when there are no args. */ #define scanner_error1(scanner, loc, msg) \ - log_warn(scanner->ctx, "rules/%s:%d:%d: " msg "\n", \ - scanner->file_name, loc->line, loc->column) + log_warn((scanner)->ctx, "rules/%s:%d:%d: %s\n", \ + (scanner)->file_name, (loc)->line, (loc)->column, msg) #define scanner_error(scanner, loc, fmt, ...) \ - log_warn(scanner->ctx, "rules/%s:%d:%d: " fmt "\n", \ - scanner->file_name, loc->line, loc->column, __VA_ARGS__) + log_warn((scanner)->ctx, "rules/%s:%d:%d: " fmt "\n", \ + (scanner)->file_name, (loc)->line, (loc)->column, __VA_ARGS__) static enum rules_token lex(struct scanner *s, union lvalue *val, struct location *loc) @@ -404,15 +404,10 @@ matcher_free(struct matcher *m) free(m); } -/* C99 is stupid. Just use the 1 variant when there are no args. */ #define matcher_error1(matcher, msg) \ - log_warn(matcher->ctx, "rules/%s:%d:%d: " msg "\n", \ - matcher->scanner.file_name, matcher->loc.line, \ - matcher->loc.column) + scanner_error1(&(matcher)->scanner, &(matcher)->loc, msg) #define matcher_error(matcher, fmt, ...) \ - log_warn(matcher->ctx, "rules/%s:%d:%d: " fmt "\n", \ - matcher->scanner.file_name, matcher->loc.line, \ - matcher->loc.column, __VA_ARGS__) + scanner_error(&(matcher)->scanner, &(matcher)->loc, fmt, __VA_ARGS__) static void matcher_group_start_new(struct matcher *m, struct sval name)