From e13f29cae788ee0d0d16352c9be2d9e14a5a0b3d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 21 Jul 2017 19:12:30 +0100 Subject: 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 Reviewed-by: Philip Withnall Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101895 --- dbus/dbus-macros.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'dbus/dbus-macros.h') 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 */ -- cgit v1.2.1