Commit eef153e8 authored by Simon McVittie's avatar Simon McVittie

_DBUS_ASSERT_ERROR_XOR_BOOL: Add and use

As suggested by Philip Withnall in !43.
Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
parent 3987f5a4
......@@ -821,10 +821,7 @@ update_directory (BusActivation *activation,
retval = TRUE;
out:
if (!retval)
_DBUS_ASSERT_ERROR_IS_SET (error);
else
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
_DBUS_ASSERT_ERROR_XOR_BOOL (error, retval);
if (iter != NULL)
_dbus_directory_close (iter);
......
......@@ -688,11 +688,7 @@ bus_desktop_file_load (DBusString *filename,
parser.desktop_file = NULL;
out:
if (result != NULL)
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
else
_DBUS_ASSERT_ERROR_IS_SET (error);
_DBUS_ASSERT_ERROR_XOR_BOOL (error, result != NULL);
parser_clear (&parser);
return result;
}
......
......@@ -2310,10 +2310,7 @@ bus_driver_handle_become_monitor (DBusConnection *connection,
ret = TRUE;
out:
if (ret)
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
else
_DBUS_ASSERT_ERROR_IS_SET (error);
_DBUS_ASSERT_ERROR_XOR_BOOL (error, ret);
for (iter = _dbus_list_get_first_link (&rules);
iter != NULL;
......
......@@ -310,9 +310,7 @@ _dbus_string_save_to_file (const DBusString *str,
_dbus_string_free (&tmp_filename);
if (!retval)
_DBUS_ASSERT_ERROR_IS_SET (error);
_DBUS_ASSERT_ERROR_XOR_BOOL (error, retval);
return retval;
}
......
......@@ -198,6 +198,7 @@ void _dbus_real_assert_not_reached (const char *explanation,
*/
#define _DBUS_ASSERT_ERROR_IS_SET(error) do { } while (0)
#define _DBUS_ASSERT_ERROR_IS_CLEAR(error) do { } while (0)
#define _DBUS_ASSERT_ERROR_XOR_BOOL(error, retval) do { } while (0)
#else
static inline void
_dbus_assert_error_is_set (const DBusError *error)
......@@ -211,8 +212,32 @@ _dbus_assert_error_is_clear (const DBusError *error)
_dbus_assert (error == NULL || !dbus_error_is_set (error));
}
static inline void
_dbus_assert_error_xor_bool (const DBusError *error,
dbus_bool_t retval)
{
_dbus_assert (error == NULL || dbus_error_is_set (error) == !retval);
}
/**
* 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)
/**
* 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)
/**
* Assert that error is consistent with retval: if error is not NULL,
* it must be set if and only if retval is false.
*
* retval can be a boolean expression like "result != NULL".
*/
#define _DBUS_ASSERT_ERROR_XOR_BOOL(error, retval), _dbus_assert_error_xor_bool (error, retval)
#endif
#define _dbus_return_if_error_is_set(error) _dbus_return_if_fail ((error) == NULL || !dbus_error_is_set ((error)))
......
......@@ -4052,10 +4052,7 @@ _read_subprocess_line_argv (const char *progpath,
out:
sigprocmask (SIG_SETMASK, &old_set, NULL);
if (retval)
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
else
_DBUS_ASSERT_ERROR_IS_SET (error);
_DBUS_ASSERT_ERROR_XOR_BOOL (error, retval);
if (result_pipe[0] != -1)
close (result_pipe[0]);
......
......@@ -3217,11 +3217,7 @@ _dbus_get_autolaunch_address (const char *scope, DBusString *address,
}
out:
if (retval)
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
else
_DBUS_ASSERT_ERROR_IS_SET (error);
_DBUS_ASSERT_ERROR_XOR_BOOL (error, retval);
_dbus_global_unlock (mutex);
_dbus_string_free (&shm_name);
......
......@@ -301,10 +301,7 @@ _dbus_transport_new_for_autolaunch (const char *scope, DBusError *error)
}
result = check_address (_dbus_string_get_const_data (&address), error);
if (result == NULL)
_DBUS_ASSERT_ERROR_IS_SET (error);
else
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
_DBUS_ASSERT_ERROR_XOR_BOOL (error, result != NULL);
out:
_dbus_string_free (&address);
......
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