mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
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 <wk@gnupg.org>
This commit is contained in:
parent
cb4fee8bb6
commit
9740dff9f4
@ -919,18 +919,37 @@ log_clock (const char *string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
|
#ifdef GPGRT_HAVE_MACRO_FUNCTION
|
||||||
void
|
void
|
||||||
bug_at( const char *file, int line, const char *func )
|
bug_at( const char *file, int line, const char *func )
|
||||||
{
|
{
|
||||||
log_log (GPGRT_LOG_BUG, ("... this is a bug (%s:%d:%s)\n"), file, line, func);
|
log_log (GPGRT_LOG_BUG, "... this is a bug (%s:%d:%s)\n", file, line, func);
|
||||||
abort (); /* Never called; just to make the compiler happy. */
|
abort (); /* Never called; just to make the compiler happy. */
|
||||||
}
|
}
|
||||||
#else
|
#else /*!GPGRT_HAVE_MACRO_FUNCTION*/
|
||||||
void
|
void
|
||||||
bug_at( const char *file, int line )
|
bug_at( const char *file, int line )
|
||||||
{
|
{
|
||||||
log_log (GPGRT_LOG_BUG, _("you found a bug ... (%s:%d)\n"), file, line);
|
log_log (GPGRT_LOG_BUG, "you found a bug ... (%s:%d)\n", file, line);
|
||||||
abort (); /* Never called; just to make the compiler happy. */
|
abort (); /* Never called; just to make the compiler happy. */
|
||||||
}
|
}
|
||||||
#endif
|
#endif /*!GPGRT_HAVE_MACRO_FUNCTION*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef GPGRT_HAVE_MACRO_FUNCTION
|
||||||
|
void
|
||||||
|
_log_assert (const char *expr, const char *file, int line, const char *func)
|
||||||
|
{
|
||||||
|
log_log (GPGRT_LOG_BUG, "Assertion \"%s\" in %s failed (%s:%d)\n",
|
||||||
|
expr, func, file, line);
|
||||||
|
abort (); /* Never called; just to make the compiler happy. */
|
||||||
|
}
|
||||||
|
#else /*!GPGRT_HAVE_MACRO_FUNCTION*/
|
||||||
|
void
|
||||||
|
_log_assert (const char *expr, const char *file, int line)
|
||||||
|
{
|
||||||
|
log_log (GPGRT_LOG_BUG, "Assertion \"%s\" failed (%s:%d)\n",
|
||||||
|
file, line, func);
|
||||||
|
abort (); /* Never called; just to make the compiler happy. */
|
||||||
|
}
|
||||||
|
#endif /*!GPGRT_HAVE_MACRO_FUNCTION*/
|
||||||
|
@ -52,11 +52,22 @@ estream_t log_get_stream (void);
|
|||||||
#ifdef GPGRT_HAVE_MACRO_FUNCTION
|
#ifdef GPGRT_HAVE_MACRO_FUNCTION
|
||||||
void bug_at (const char *file, int line, const char *func)
|
void bug_at (const char *file, int line, const char *func)
|
||||||
GPGRT_ATTR_NORETURN;
|
GPGRT_ATTR_NORETURN;
|
||||||
# define BUG() bug_at( __FILE__ , __LINE__, __FUNCTION__ )
|
void _log_assert (const char *expr, const char *file, int line,
|
||||||
#else
|
const char *func) GPGRT_ATTR_NORETURN;
|
||||||
void bug_at( const char *file, int line );
|
# 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__ )
|
# 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. */
|
/* Flag values for log_set_prefix. */
|
||||||
#define GPGRT_LOG_WITH_PREFIX 1
|
#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_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_logv (int level, const char *fmt, va_list arg_ptr);
|
||||||
void log_string (int level, const char *string);
|
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_bug (const char *fmt, ...) GPGRT_ATTR_NR_PRINTF(1,2);
|
||||||
void log_fatal (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);
|
void log_error (const char *fmt, ...) GPGRT_ATTR_PRINTF(1,2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user