aboutsummaryrefslogtreecommitdiffstats
path: root/common/logging.h
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2016-04-29 09:04:04 +0000
committerWerner Koch <[email protected]>2016-04-29 09:04:04 +0000
commit9740dff9f4d18ba764dc7173d4902e94e3f0c2e8 (patch)
tree3fb4d6c799e410af9b52f0efc02238230ec66f62 /common/logging.h
parentscd: Fix error return path. (diff)
downloadgnupg-9740dff9f4d18ba764dc7173d4902e94e3f0c2e8.tar.gz
gnupg-9740dff9f4d18ba764dc7173d4902e94e3f0c2e8.zip
common: Improve log_assert.
* common/logging.c (bug_at): Do not i18n the string. (_log_assert): New. * common/logging.h (log_assert): Use new function and pass line information. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to '')
-rw-r--r--common/logging.h25
1 files changed, 15 insertions, 10 deletions
diff --git a/common/logging.h b/common/logging.h
index d0b159700..2f0b504a6 100644
--- a/common/logging.h
+++ b/common/logging.h
@@ -52,11 +52,22 @@ estream_t log_get_stream (void);
#ifdef GPGRT_HAVE_MACRO_FUNCTION
void bug_at (const char *file, int line, const char *func)
GPGRT_ATTR_NORETURN;
-# define BUG() bug_at( __FILE__ , __LINE__, __FUNCTION__ )
-#else
- void bug_at( const char *file, int line );
+ void _log_assert (const char *expr, const char *file, int line,
+ const char *func) GPGRT_ATTR_NORETURN;
+# define BUG() bug_at( __FILE__ , __LINE__, __FUNCTION__)
+# define log_assert(expr) do { \
+ if (!(expr)) \
+ _log_assert (#expr, __FILE__, __LINE__, __FUNCTION__); \
+ } while (0)
+#else /*!GPGRT_HAVE_MACRO_FUNCTION*/
+ void bug_at (const char *file, int line);
+ void _log_assert (const char *expr, const char *file, int line;
# define BUG() bug_at( __FILE__ , __LINE__ )
-#endif
+# define log_assert(expr) do { \
+ if (!(expr)) \
+ _log_assert (#expr, __FILE__, __LINE__); \
+ } while (0)
+#endif /*!GPGRT_HAVE_MACRO_FUNCTION*/
/* Flag values for log_set_prefix. */
#define GPGRT_LOG_WITH_PREFIX 1
@@ -79,12 +90,6 @@ enum jnlib_log_levels {
void log_log (int level, const char *fmt, ...) GPGRT_ATTR_PRINTF(2,3);
void log_logv (int level, const char *fmt, va_list arg_ptr);
void log_string (int level, const char *string);
-
-
-#define log_assert(expr) \
- do \
- if (! (expr)) log_bug ("Assertion " #expr " failed.\n"); \
- while (0)
void log_bug (const char *fmt, ...) GPGRT_ATTR_NR_PRINTF(1,2);
void log_fatal (const char *fmt, ...) GPGRT_ATTR_NR_PRINTF(1,2);
void log_error (const char *fmt, ...) GPGRT_ATTR_PRINTF(1,2);