manager: preserve constness in NM_MANAGER_GET_PRIVATE() and add compile-time type check

This commit is contained in:
Thomas Haller 2016-07-01 15:23:29 +02:00
parent e5430a182c
commit 5b4581b361

View file

@ -147,14 +147,25 @@ typedef struct {
struct _NMManager {
NMExportedObject parent;
NMManagerPrivate priv;
NMManagerPrivate _priv;
};
typedef struct {
NMExportedObjectClass parent;
} NMManagerClass;
#define NM_MANAGER_GET_PRIVATE(o) ({ nm_assert (NM_IS_MANAGER (o)); &((o)->priv); })
#define NM_MANAGER_GET_PRIVATE(self) \
({ \
/* 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 NMManager *_self2 = (_self); \
\
nm_assert (NM_IS_MANAGER (_self)); \
&_self->_priv; \
})
G_DEFINE_TYPE (NMManager, nm_manager, NM_TYPE_EXPORTED_OBJECT)