mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 05:18:23 +02:00
manager: preserve constness in NM_MANAGER_GET_PRIVATE() and add compile-time type check
This commit is contained in:
parent
e5430a182c
commit
5b4581b361
1 changed files with 13 additions and 2 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue