aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-04-16 09:50:50 -0400
committerGitHub <noreply@github.com>2017-04-16 09:50:50 -0400
commitedb8075ae0c0986fb168b464b05e0b54537f8f30 (patch)
treefcce54a1332d699fb5ecaef85b5fba70066713de
parent4b3e533a5946c0cb8f3f80421918ff809e4059a3 (diff)
parent709b53bd4347ee0ba4925ae02a5f89ca15f380c8 (diff)
downloadsway-edb8075ae0c0986fb168b464b05e0b54537f8f30.zip
sway-edb8075ae0c0986fb168b464b05e0b54537f8f30.tar.gz
sway-edb8075ae0c0986fb168b464b05e0b54537f8f30.tar.bz2
Merge pull request #1175 from JerziKaminsky/fix_sway_assert_variadic
Fix multiple issues in sway_assert
-rw-r--r--common/log.c17
-rw-r--r--include/log.h7
2 files changed, 16 insertions, 8 deletions
diff --git a/common/log.c b/common/log.c
index c3809c6..8e5b71f 100644
--- a/common/log.c
+++ b/common/log.c
@@ -63,7 +63,8 @@ void sway_abort(const char *format, ...) {
sway_terminate(EXIT_FAILURE);
}
-void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) {
+void _sway_vlog(const char *filename, int line, log_importance_t verbosity,
+ const char *format, va_list args) {
if (verbosity <= v) {
// prefix the time to the log message
static struct tm result;
@@ -99,10 +100,7 @@ void _sway_log(const char *filename, int line, log_importance_t verbosity, const
fprintf(stderr, "[%s:%d] ", file, line);
}
- va_list args;
- va_start(args, format);
vfprintf(stderr, format, args);
- va_end(args);
if (colored && isatty(STDERR_FILENO)) {
fprintf(stderr, "\x1B[0m");
@@ -111,6 +109,13 @@ void _sway_log(const char *filename, int line, log_importance_t verbosity, const
}
}
+void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) {
+ va_list args;
+ va_start(args, format);
+ _sway_vlog(filename, line, verbosity, format, args);
+ va_end(args);
+}
+
void sway_log_errno(log_importance_t verbosity, char* format, ...) {
if (verbosity <= v) {
unsigned int c = verbosity;
@@ -137,14 +142,14 @@ void sway_log_errno(log_importance_t verbosity, char* format, ...) {
}
}
-bool _sway_assert(bool condition, const char* format, ...) {
+bool _sway_assert(bool condition, const char *filename, int line, const char* format, ...) {
if (condition) {
return true;
}
va_list args;
va_start(args, format);
- sway_log(L_ERROR, format, args);
+ _sway_vlog(filename, line, L_ERROR, format, args);
va_end(args);
#ifndef NDEBUG
diff --git a/include/log.h b/include/log.h
index 2c4150e..32981b6 100644
--- a/include/log.h
+++ b/include/log.h
@@ -19,15 +19,18 @@ void sway_log_colors(int mode);
void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3)));
void sway_abort(const char* format, ...) __attribute__((format(printf,1,2)));
-bool _sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3)));
+bool _sway_assert(bool condition, const char *filename, int line, const char* format, ...) __attribute__((format(printf,4,5)));
#define sway_assert(COND, FMT, ...) \
- _sway_assert(COND, "%s:" FMT, __PRETTY_FUNCTION__, ##__VA_ARGS__)
+ _sway_assert(COND, __FILE__, __LINE__, "%s:" FMT, __PRETTY_FUNCTION__, ##__VA_ARGS__)
void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,4,5)));
#define sway_log(VERBOSITY, FMT, ...) \
_sway_log(__FILE__, __LINE__, VERBOSITY, FMT, ##__VA_ARGS__)
+#define sway_vlog(VERBOSITY, FMT, VA_ARGS) \
+ _sway_vlog(__FILE__, __LINE__, VERBOSITY, FMT, VA_ARGS)
+
void error_handler(int sig);
#endif