From adbba0fb395b9910c4615e7be91ffe5b3ef70d6a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 16 May 2016 18:53:01 +0200 Subject: [PATCH] device: assertion object in NM_DEVICE_GET_PRIVATE() --- src/devices/nm-device.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index b8cbe8bc1..3046b71a7 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -72,7 +72,18 @@ _LOG_DECLARE_SELF (NMDevice); G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_EXPORTED_OBJECT) -#define NM_DEVICE_GET_PRIVATE(o) ((o)->priv) +#define NM_DEVICE_GET_PRIVATE(o) \ + ({ \ + /* preserve the const-ness of self. Unfortunately, that + * way, @self cannot be a void pointer */ \ + typeof (self) _self = (self); \ + \ + /* Get compiler error if variable is of wrong type */ \ + _nm_unused const NMDevice *_self2 = (_self); \ + \ + nm_assert (NM_IS_DEVICE (_self)); \ + _self->priv; \ + }) enum { STATE_CHANGED,