rules: improve error logging macros
authorRan Benita <ran234@gmail.com>
Tue, 8 Oct 2013 19:37:53 +0000 (22:37 +0300)
committerRan Benita <ran234@gmail.com>
Thu, 10 Oct 2013 19:02:30 +0000 (22:02 +0300)
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 <ran234@gmail.com>
src/xkbcomp/rules.c

index 58e7c8a..1963802 100644 (file)
@@ -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)