Problem with assertion is that it logs on stderr. Add two macros:
PJDLOG_ASSERT() and PJDLOG_VERIFY() that will check the given condition and log the problem where appropriate. The difference between those two is that PJDLOG_VERIFY() always work and PJDLOG_ASSERT() can be turned off by defining NDEBUG. MFC after: 1 month
This commit is contained in:
parent
60e1759be6
commit
524840d8d0
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=210875
@ -365,3 +365,23 @@ pjdlog_exitx(int exitcode, const char *fmt, ...)
|
|||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Log assertion and exit.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
pjdlog_verify(const char *func, const char *file, int line,
|
||||||
|
const char *failedexpr)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (func == NULL) {
|
||||||
|
pjdlog_critical("Assertion failed: (%s), file %s, line %d.",
|
||||||
|
failedexpr, file, line);
|
||||||
|
} else {
|
||||||
|
pjdlog_critical("Assertion failed: (%s), function %s, file %s, line %d.",
|
||||||
|
failedexpr, func, file, line);
|
||||||
|
}
|
||||||
|
abort();
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -85,4 +85,17 @@ void pjdlogv_exit(int exitcode, const char *fmt, va_list ap) __printflike(2, 0)
|
|||||||
void pjdlog_exitx(int exitcode, const char *fmt, ...) __printflike(2, 3) __dead2;
|
void pjdlog_exitx(int exitcode, const char *fmt, ...) __printflike(2, 3) __dead2;
|
||||||
void pjdlogv_exitx(int exitcode, const char *fmt, va_list ap) __printflike(2, 0) __dead2;
|
void pjdlogv_exitx(int exitcode, const char *fmt, va_list ap) __printflike(2, 0) __dead2;
|
||||||
|
|
||||||
|
void pjdlog_verify(const char *func, const char *file, int line,
|
||||||
|
const char *failedexpr) __dead2;
|
||||||
|
|
||||||
|
#define PJDLOG_VERIFY(expr) do { \
|
||||||
|
if (!(expr)) \
|
||||||
|
pjdlog_verify(__func__, __FILE__, __LINE__, #expr); \
|
||||||
|
} while (0)
|
||||||
|
#ifdef NDEBUG
|
||||||
|
#define PJDLOG_ASSERT(expr) do { } while (0)
|
||||||
|
#else
|
||||||
|
#define PJDLOG_ASSERT(expr) PJDLOG_VERIFY(expr)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* !_PJDLOG_H_ */
|
#endif /* !_PJDLOG_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user