mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 21:00:16 +01:00
libnm: assert initialization in _NM_OBJECT_CLASS_INIT_FIELD_INFO()
_NM_OBJECT_CLASS_INIT_FIELD_INFO() is a bit odd, because it defines a static variable and initialized it at the moment when being "called". This is in fact correct, because this code only gets called from inside the _class_init() function, which is executed at most once. Add an assertion to ensure that the static variables is not yet initialized.
This commit is contained in:
parent
b92d8f5a2d
commit
ddd6587a6f
1 changed files with 23 additions and 15 deletions
|
|
@ -758,21 +758,29 @@ struct _NMObjectClass {
|
|||
} \
|
||||
G_STMT_END
|
||||
|
||||
#define _NM_OBJECT_CLASS_INIT_FIELD_INFO(_nm_object_class, _field_name, _offset, _num) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
(_nm_object_class)->_field_name = ({ \
|
||||
static _NMObjectClassFieldInfo _f; \
|
||||
\
|
||||
_f = (_NMObjectClassFieldInfo){ \
|
||||
.parent = (_nm_object_class)->_field_name, \
|
||||
.klass = (_nm_object_class), \
|
||||
.offset = _offset, \
|
||||
.num = _num, \
|
||||
}; \
|
||||
&_f; \
|
||||
}); \
|
||||
} \
|
||||
#define _NM_OBJECT_CLASS_INIT_FIELD_INFO(nm_object_class, field_name, _offset, _num) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
NMObjectClass *const _klass = (nm_object_class); \
|
||||
\
|
||||
_klass->field_name = ({ \
|
||||
static _NMObjectClassFieldInfo _f; \
|
||||
\
|
||||
/* this code is called inside a _class_init() function, it thus
|
||||
* is only executed once, so we are fine to initialize a static
|
||||
* variable here. */ \
|
||||
nm_assert(!_f.klass); \
|
||||
\
|
||||
_f = (_NMObjectClassFieldInfo){ \
|
||||
.parent = _klass->field_name, \
|
||||
.klass = _klass, \
|
||||
.offset = (_offset), \
|
||||
.num = (_num), \
|
||||
}; \
|
||||
\
|
||||
&_f; \
|
||||
}); \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
#define _NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1(nm_object_class, type_name, field_name) \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue