]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/basic/macro.h
basic: nicer assert messages
authorMichal Schmidt <mschmidt@redhat.com>
Mon, 14 Sep 2015 13:53:36 +0000 (15:53 +0200)
committerMichal Schmidt <mschmidt@redhat.com>
Wed, 16 Sep 2015 13:48:00 +0000 (15:48 +0200)
commit34c38d2aaa2535cb40d0157b0e4a84e6be72ee9a
tree245c96b64e0f9fa1abe9756da813e737035c5919
parent7f39a2104532e38d77a66c15fdb9e33e30ee7004
basic: nicer assert messages

Make sure the assert expression is not macro-expanded before
stringification. This makes several assertion failure messages more
readable.

As an example:
  assert(streq("foo", "bar"));

I'd rather see this:

Assertion 'streq("foo", "bar")' failed at foo.c:5, function main(). Aborting.

...than this, though awesome, incomprehensible truncated mess:

Assertion '(__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p ((
"foo")) && __builtin_constant_p (("bar")) && (__s1_len = strlen (("foo")), __s2_
len = strlen (("bar")), (!((size_t)(const void *)((("foo")) + 1) - (size_t)(cons
t void *)(("foo")) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((("bar")
) + 1) - (size_t)(const void *)(("bar")) == 1) || __s2_len >= 4)) ? __builtin_st
rcmp (("foo"), ("bar")) : (__builtin_constant_p (("foo")) && ((size_t)(const voi
d *)((("foo")) + 1) - (size_t)(const void *)(("foo")) == 1) && (__s1_len = strle
n (("foo")), __s1_len < 4) ? (__builtin_constant_p (("bar")) && ((size_t)(const
void *)((("bar")) + 1) - (size_t)(const void *)(("bar")) == 1) ? __builtin_strcm
p (("foo"), ("bar")) : (__extension__ ({ const unsigned char *__s2 = (const unsi
gned char *) (const char *) (("bar")); int __result = (((const unsigned char *)
(const char *) (("foo")))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __
result = (((const unsigned char *) (const char *) (("foo")))[1] - __s2[1]); if (
__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const cha
r *) (("foo")))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((
const unsigned char *) (const char *) (("foo")))[3] - __s2[3]); } } __result; })
)) : (__builtin_constant_p (("bar")) && ((size_t)(const void *)((("bar")) + 1) -
 (size_t)(const void *)(("bar")) == 1) && (__s2_len = strlen (("bar")), __s2_len
 < 4) ? (__builtin_constant_p (("foo")) && ((size_t)(const void *)((("foo")) + 1
) - (size_t)(const void *)(("foo")) == 1) ? __builtin_strcmp (("foo"), ("bar"))
: (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (cons
t char *) (("foo")); int __result = (((const unsigned char *) (const char *) (("
bar")))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const
unsigned char *) (const char *) (("bar")))[1] - __s2[1]); if (__s2_len > 1 && __
result == 0) { __result = (((const unsigned char *) (const char *) (("bar")))[2]
 - __s2[2]); if (__s2_len > 2 && __result == 0)
src/basic/macro.h
src/libsystemd/sd-bus/bus-internal.h