Commit 16d2453f authored by Simon McVittie's avatar Simon McVittie

Improve diagnostics for error assertion failures

Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
parent eef153e8
......@@ -192,7 +192,7 @@ void _dbus_real_assert_not_reached (const char *explanation,
#define _DBUS_ALIGNOF(type) \
(_DBUS_STRUCT_OFFSET (struct { char _1; type _2; }, _2))
#ifdef DBUS_DISABLE_CHECKS
#if defined(DBUS_DISABLE_CHECKS) || defined(DBUS_DISABLE_ASSERT)
/* this is an assert and not an error, but in the typical --disable-checks case (you're trying
* to really minimize code size), disabling these assertions makes sense.
*/
......@@ -201,35 +201,47 @@ void _dbus_real_assert_not_reached (const char *explanation,
#define _DBUS_ASSERT_ERROR_XOR_BOOL(error, retval) do { } while (0)
#else
static inline void
_dbus_assert_error_is_set (const DBusError *error)
_dbus_assert_error_is_set (const DBusError *error,
const char *file,
int line,
const char *func)
{
_dbus_assert (error == NULL || dbus_error_is_set (error));
_dbus_real_assert (error == NULL || dbus_error_is_set (error),
"error is set", file, line, func);
}
static inline void
_dbus_assert_error_is_clear (const DBusError *error)
_dbus_assert_error_is_clear (const DBusError *error,
const char *file,
int line,
const char *func)
{
_dbus_assert (error == NULL || !dbus_error_is_set (error));
_dbus_real_assert (error == NULL || !dbus_error_is_set (error),
"error is clear", file, line, func);
}
static inline void
_dbus_assert_error_xor_bool (const DBusError *error,
dbus_bool_t retval)
dbus_bool_t retval,
const char *file,
int line,
const char *func)
{
_dbus_assert (error == NULL || dbus_error_is_set (error) == !retval);
_dbus_real_assert (error == NULL || dbus_error_is_set (error) == !retval,
"error is consistent with boolean result", file, line, func);
}
/**
* Assert that error is set, unless it is NULL in which case we cannot
* tell whether it would have been set.
*/
#define _DBUS_ASSERT_ERROR_IS_SET(error) _dbus_assert_error_is_set(error)
#define _DBUS_ASSERT_ERROR_IS_SET(error) _dbus_assert_error_is_set (error, __FILE__, __LINE__, _DBUS_FUNCTION_NAME)
/**
* Assert that error is not set, unless it is NULL in which case we cannot
* tell whether it would have been set.
*/
#define _DBUS_ASSERT_ERROR_IS_CLEAR(error) _dbus_assert_error_is_clear(error)
#define _DBUS_ASSERT_ERROR_IS_CLEAR(error) _dbus_assert_error_is_clear (error, __FILE__, __LINE__, _DBUS_FUNCTION_NAME)
/**
* Assert that error is consistent with retval: if error is not NULL,
......@@ -237,7 +249,7 @@ _dbus_assert_error_xor_bool (const DBusError *error,
*
* retval can be a boolean expression like "result != NULL".
*/
#define _DBUS_ASSERT_ERROR_XOR_BOOL(error, retval), _dbus_assert_error_xor_bool (error, retval)
#define _DBUS_ASSERT_ERROR_XOR_BOOL(error, retval) _dbus_assert_error_xor_bool (error, retval, __FILE__, __LINE__, _DBUS_FUNCTION_NAME)
#endif
#define _dbus_return_if_error_is_set(error) _dbus_return_if_fail ((error) == NULL || !dbus_error_is_set ((error)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment