diff options
author | Thomas Haller <thaller@redhat.com> | 2022-11-07 17:31:25 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-11-08 12:54:44 +0100 |
commit | dd2c5044f6ff7eb1605a3e62f6dc9a95cdbd4567 (patch) | |
tree | a17b5aa895b9394da879822ca3a7a9b53d7afa90 | |
parent | c9123c2eced0e321939d7bd51071225f2b27c1ab (diff) | |
download | NetworkManager-dd2c5044f6ff7eb1605a3e62f6dc9a95cdbd4567.tar.gz |
platform: add internal helper function to get full NMPObject size
-rw-r--r-- | src/libnm-platform/nmp-object.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/libnm-platform/nmp-object.c b/src/libnm-platform/nmp-object.c index 5192cb2135..fdd0a9e418 100644 --- a/src/libnm-platform/nmp-object.c +++ b/src/libnm-platform/nmp-object.c @@ -762,17 +762,23 @@ _vt_cmd_obj_dispose_lnk_wireguard(NMPObject *obj) _wireguard_clear(&obj->_lnk_wireguard); } +static gsize +_NMP_OBJECT_STRUCT_SIZE(const NMPClass *klass) +{ + nm_assert(klass); + nm_assert(klass->sizeof_public > 0); + nm_assert(klass->sizeof_public <= klass->sizeof_data); + + return klass->sizeof_data + G_STRUCT_OFFSET(NMPObject, object); +} + static NMPObject * _nmp_object_new_from_class(const NMPClass *klass) { NMPObject *obj; - nm_assert(klass); - nm_assert(klass->sizeof_data > 0); - nm_assert(klass->sizeof_public > 0 && klass->sizeof_public <= klass->sizeof_data); - - obj = g_slice_alloc0(klass->sizeof_data + G_STRUCT_OFFSET(NMPObject, object)); - obj->_class = klass; + obj = g_slice_alloc0(_NMP_OBJECT_STRUCT_SIZE(klass)); + obj->_class = klass; obj->parent._ref_count = 1; return obj; } @@ -1880,7 +1886,7 @@ _vt_dedup_obj_destroy(NMDedupMultiObj *obj) klass = o->_class; if (klass->cmd_obj_dispose) klass->cmd_obj_dispose(o); - g_slice_free1(klass->sizeof_data + G_STRUCT_OFFSET(NMPObject, object), o); + g_slice_free1(_NMP_OBJECT_STRUCT_SIZE(klass), o); } static const NMDedupMultiObj * |