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:
Thomas Haller 2021-06-07 17:27:53 +02:00
parent b92d8f5a2d
commit ddd6587a6f
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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) \