summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2021-12-10 15:12:59 +0000
committerSimon McVittie <smcv@collabora.com>2021-12-17 12:57:42 +0000
commitb44e0cc9f456449e1378e4b03bcb7ad3db094725 (patch)
tree4e8035518087193942d0d32ba6e8620339f15698
parentd13349f25ce6160695237cb1715bc3a8e2fa8985 (diff)
downloaddbus-b44e0cc9f456449e1378e4b03bcb7ad3db094725.tar.gz
internals: Use Standard C offsetof macro if available
clang 13 fails to compile our current implementation with: .../dbus/dbus-message.c:2070:3: error: variable length array folded to constant array as an extension [-Werror,-Wgnu-folding-constant] _DBUS_STATIC_ASSERT (_DBUS_ALIGNOF (DBusMessageRealIter) <= ^ .../dbus/dbus-internals.h:460:25: note: expanded from macro '_DBUS_STATIC_ASSERT' typedef struct { char _assertion[(expr) ? 1 : -1]; } \ This appears to be because the "traditional" definition of offsetof(), which we're hard-coding here, does not qualify as a constant expression under C rules due to its use of pointer casts. Modern compilers like gcc and clang have a built-in implementation of offsetof that *is* a constant expression. Signed-off-by: Simon McVittie <smcv@collabora.com> (cherry picked from commit a24cf746e2a8191070efd1300a15d37284aaf2fa)
-rw-r--r--dbus/dbus-internals.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h
index e7649e1d..281d6af2 100644
--- a/dbus/dbus-internals.h
+++ b/dbus/dbus-internals.h
@@ -192,8 +192,13 @@ void _dbus_real_assert_not_reached (const char *explanation,
#define _DBUS_ZERO(object) (memset (&(object), '\0', sizeof ((object))))
+#ifdef offsetof
+#define _DBUS_STRUCT_OFFSET(struct_type, member) \
+ (offsetof (struct_type, member))
+#else
#define _DBUS_STRUCT_OFFSET(struct_type, member) \
((intptr_t) ((unsigned char*) &((struct_type*) 0)->member))
+#endif
#define _DBUS_ALIGNOF(type) \
(_DBUS_STRUCT_OFFSET (struct { char _1; type _2; }, _2))