GDBusMessage: Assert various things when serializing to a blob
authorDavid Zeuthen <davidz@redhat.com>
Wed, 4 Aug 2010 16:24:22 +0000 (12:24 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Wed, 4 Aug 2010 16:24:22 +0000 (12:24 -0400)
commit6e723e8b3e5f138f8e0b4fe45c5872a92510d5d3
tree114ca66ff9d9546f5d91a9d4d4ad15e9ec022693
parent5bd34a820eb79f0765e312215e0a3e0a339ace78
GDBusMessage: Assert various things when serializing to a blob

We use g_assert() instead of setting the GError because it is a
programming error if the GVariant contains invalid data - see commit
5e6f762d61db1a5c64bd1d33e5ba112755106581 for where the last hole in
GVariant was closed.

So if we can trust GVariant to only contain valid data (ignoring the
case where unsafe API such as g_variant_new_from_data() is used), why
g_assert() at all with costly g_utf8_validate() checks? Because a) it
is relatively inexpensive; and b) it helps find bugs such as the one
fixed in commit 5e6f762d61db1a5c64bd1d33e5ba112755106581.

If performance is a concern we can play games like introducing
environment variables or other machinery to avoid such "costly"
checks. I doubt it will ever be an issue.

Also replace two "Hmm" TODO item with a static assert - the code that
serializes a gdouble into the D-Bus wire format by treating it as a
guint64 is indeed correct - endianess needs to be taken into account
(see the D-Bus reference implementation for similar code). But we want
to make sure that we're indeed using an architecture/compiler where a
gdouble takes up 8 bytes - hence the assertion.

Signed-off-by: David Zeuthen <davidz@redhat.com>
gio/gdbusmessage.c