summaryrefslogtreecommitdiff
path: root/dbus/dbus-macros.h
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2017-07-21 19:12:30 +0100
committerSimon McVittie <smcv@debian.org>2017-07-30 08:48:43 +0100
commite13f29cae788ee0d0d16352c9be2d9e14a5a0b3d (patch)
treee3bf2e0d7e270c8145f85f74e0f1f5cf8ee6b3f7 /dbus/dbus-macros.h
parente9974f76a938e155c7d16c913b8cae41ef9cb9fe (diff)
downloaddbus-e13f29cae788ee0d0d16352c9be2d9e14a5a0b3d.tar.gz
Implement dbus_clear_connection(), etc.
These are inspired by GLib's g_clear_pointer() and g_clear_object(), which in turn is descended from CPython's Py_CLEAR_OBJECT. They should make our code a lot less repetitive. Signed-off-by: Simon McVittie <smcv@collabora.com> Reviewed-by: Philip Withnall <withnall@endlessm.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101895
Diffstat (limited to 'dbus/dbus-macros.h')
-rw-r--r--dbus/dbus-macros.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/dbus/dbus-macros.h b/dbus/dbus-macros.h
index 0e784fe1..2c8956e3 100644
--- a/dbus/dbus-macros.h
+++ b/dbus/dbus-macros.h
@@ -215,6 +215,26 @@
# define DBUS_PRIVATE_EXPORT /* no decoration */
#endif
+/* Implementation for dbus_clear_message() etc. This is not API,
+ * do not use it directly.
+ *
+ * We're using a specific type (T ** and T *) instead of void ** and
+ * void * partly for type-safety, partly to be strict-aliasing-compliant,
+ * and partly to keep C++ compilers happy. This code is inlined into
+ * users of libdbus, so we can't rely on it having dbus' own compiler
+ * settings. */
+#define _dbus_clear_pointer_impl(T, pointer_to_pointer, destroy) \
+ do { \
+ T **_pp = (pointer_to_pointer); \
+ T *_value = *_pp; \
+ \
+ *_pp = NULL; \
+ \
+ if (_value != NULL) \
+ destroy (_value); \
+ } while (0)
+/* Not (destroy) (_value) in case destroy() is a function-like macro */
+
/** @} */
#endif /* DBUS_MACROS_H */