Bug 39636 - statically assert about invariants
Summary: statically assert about invariants
Status: RESOLVED FIXED
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: 1.4.x
Hardware: Other All
: medium enhancement
Assignee: Simon McVittie
QA Contact: John (J5) Palmieri
URL:
Whiteboard: review+
Keywords: patch
Depends on:
Blocks: dbus-1.5
  Show dependency treegraph
 
Reported: 2011-07-28 09:52 UTC by Simon McVittie
Modified: 2011-08-11 04:00 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
[PATCH 1/2] Add _DBUS_STATIC_ASSERT (based on GLib's G_STATIC_ASSERT) and use it (2.66 KB, patch)
2011-07-28 09:54 UTC, Simon McVittie
Details | Splinter Review
[PATCH 2/2] dbus-marshal-basic: assert that the size and (on gcc) alignment of all types is as expected (2.03 KB, patch)
2011-07-28 09:55 UTC, Simon McVittie
Details | Splinter Review

Description Simon McVittie 2011-07-28 09:52:03 UTC
Various libraries use "static assertions" to check invariants at compile-time, with no runtime overhead. For instance, it's easy to check that things have the expected sizeof(). Under gcc 4, __alignof__() is also easy to check.
Comment 1 Simon McVittie 2011-07-28 09:54:02 UTC
Created attachment 49677 [details] [review]
[PATCH 1/2] Add _DBUS_STATIC_ASSERT (based on GLib's  G_STATIC_ASSERT) and use it
Comment 2 Simon McVittie 2011-07-28 09:55:44 UTC
Created attachment 49678 [details] [review]
[PATCH 2/2] dbus-marshal-basic: assert that the size and (on gcc)  alignment of all types is as expected

The __alignof__() checks here will fail if compiling for an architecture
where more-than-natural alignment is needed.

---

Possibly those architectures can't exist, or can't implement ISO C; I don't really care. If they exist, the checks will make D-Bus fail to compile there (where previously it failed at runtime), and if they don't, the checks have no effect at runtime anyway.
Comment 3 Will Thompson 2011-08-05 05:00:10 UTC
Review of attachment 49677 [details] [review]:

++
Comment 4 Will Thompson 2011-08-05 05:06:16 UTC
Review of attachment 49678 [details] [review]:

Looks fine!
Comment 5 Simon McVittie 2011-08-11 04:00:01 UTC
Thanks, fixed in 1.4.16, 1.5.8


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.