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 <ran234@gmail.com>
master
Ran Benita 2013-10-08 22:37:53 +03:00
parent 5af688e694
commit efe5b036ee
1 changed files with 6 additions and 11 deletions

View 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)