summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2017-04-16 09:50:50 -0400
committerLibravatar GitHub <noreply@github.com>2017-04-16 09:50:50 -0400
commitedb8075ae0c0986fb168b464b05e0b54537f8f30 (patch)
treefcce54a1332d699fb5ecaef85b5fba70066713de
parentMerge pull request #1171 from JerziKaminsky/misc_fixes (diff)
parentFix location reported by sway_assert (diff)
downloadsway-edb8075ae0c0986fb168b464b05e0b54537f8f30.tar.gz
sway-edb8075ae0c0986fb168b464b05e0b54537f8f30.tar.zst
sway-edb8075ae0c0986fb168b464b05e0b54537f8f30.zip
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 c3809c69..8e5b71f9 100644
--- a/common/log.c
+++ b/common/log.c
@@ -63,7 +63,8 @@ void sway_abort(const char *format, ...) {
63 sway_terminate(EXIT_FAILURE); 63 sway_terminate(EXIT_FAILURE);
64} 64}
65 65
66void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) { 66void _sway_vlog(const char *filename, int line, log_importance_t verbosity,
67 const char *format, va_list args) {
67 if (verbosity <= v) { 68 if (verbosity <= v) {
68 // prefix the time to the log message 69 // prefix the time to the log message
69 static struct tm result; 70 static struct tm result;
@@ -99,10 +100,7 @@ void _sway_log(const char *filename, int line, log_importance_t verbosity, const
99 fprintf(stderr, "[%s:%d] ", file, line); 100 fprintf(stderr, "[%s:%d] ", file, line);
100 } 101 }
101 102
102 va_list args;
103 va_start(args, format);
104 vfprintf(stderr, format, args); 103 vfprintf(stderr, format, args);
105 va_end(args);
106 104
107 if (colored && isatty(STDERR_FILENO)) { 105 if (colored && isatty(STDERR_FILENO)) {
108 fprintf(stderr, "\x1B[0m"); 106 fprintf(stderr, "\x1B[0m");
@@ -111,6 +109,13 @@ void _sway_log(const char *filename, int line, log_importance_t verbosity, const
111 } 109 }
112} 110}
113 111
112void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) {
113 va_list args;
114 va_start(args, format);
115 _sway_vlog(filename, line, verbosity, format, args);
116 va_end(args);
117}
118
114void sway_log_errno(log_importance_t verbosity, char* format, ...) { 119void sway_log_errno(log_importance_t verbosity, char* format, ...) {
115 if (verbosity <= v) { 120 if (verbosity <= v) {
116 unsigned int c = verbosity; 121 unsigned int c = verbosity;
@@ -137,14 +142,14 @@ void sway_log_errno(log_importance_t verbosity, char* format, ...) {
137 } 142 }
138} 143}
139 144
140bool _sway_assert(bool condition, const char* format, ...) { 145bool _sway_assert(bool condition, const char *filename, int line, const char* format, ...) {
141 if (condition) { 146 if (condition) {
142 return true; 147 return true;
143 } 148 }
144 149
145 va_list args; 150 va_list args;
146 va_start(args, format); 151 va_start(args, format);
147 sway_log(L_ERROR, format, args); 152 _sway_vlog(filename, line, L_ERROR, format, args);
148 va_end(args); 153 va_end(args);
149 154
150#ifndef NDEBUG 155#ifndef NDEBUG
diff --git a/include/log.h b/include/log.h
index 2c4150e4..32981b62 100644
--- a/include/log.h
+++ b/include/log.h
@@ -19,15 +19,18 @@ void sway_log_colors(int mode);
19void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3))); 19void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3)));
20void sway_abort(const char* format, ...) __attribute__((format(printf,1,2))); 20void sway_abort(const char* format, ...) __attribute__((format(printf,1,2)));
21 21
22bool _sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3))); 22bool _sway_assert(bool condition, const char *filename, int line, const char* format, ...) __attribute__((format(printf,4,5)));
23#define sway_assert(COND, FMT, ...) \ 23#define sway_assert(COND, FMT, ...) \
24 _sway_assert(COND, "%s:" FMT, __PRETTY_FUNCTION__, ##__VA_ARGS__) 24 _sway_assert(COND, __FILE__, __LINE__, "%s:" FMT, __PRETTY_FUNCTION__, ##__VA_ARGS__)
25 25
26void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,4,5))); 26void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,4,5)));
27 27
28#define sway_log(VERBOSITY, FMT, ...) \ 28#define sway_log(VERBOSITY, FMT, ...) \
29 _sway_log(__FILE__, __LINE__, VERBOSITY, FMT, ##__VA_ARGS__) 29 _sway_log(__FILE__, __LINE__, VERBOSITY, FMT, ##__VA_ARGS__)
30 30
31#define sway_vlog(VERBOSITY, FMT, VA_ARGS) \
32 _sway_vlog(__FILE__, __LINE__, VERBOSITY, FMT, VA_ARGS)
33
31void error_handler(int sig); 34void error_handler(int sig);
32 35
33#endif 36#endif