mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 10:40:08 +01:00
platform: improve nmp_object_stackinit_id() for types that don't implement cmd_plobj_id_copy()
An object type that doesn't implement cmd_plobj_id_copy(), either: - implements cmd_obj_copy(), but then we cannot copy the ID only to a stack instance, because that cannot track ownership. This is a bug in the caller. We cannot use stackinit for an object of a type that is not a plain old data (in C++ terms). - fallback to plain memcpy(). That is in line with nmp_object_clone(). and nmp_object_copy().
This commit is contained in:
parent
52c8ee2c9d
commit
a242d41cc0
1 changed files with 11 additions and 0 deletions
|
|
@ -840,6 +840,17 @@ nmp_object_stackinit_id(NMPObject *obj, const NMPObject *src)
|
|||
_nmp_object_stackinit_from_class(obj, klass);
|
||||
if (klass->cmd_plobj_id_copy)
|
||||
klass->cmd_plobj_id_copy(&obj->object, &src->object);
|
||||
else {
|
||||
/* This object must not implement cmd_obj_copy().
|
||||
* If it would, it would mean that we require a deep copy
|
||||
* of the data. As @obj is stack-allocated, it cannot track
|
||||
* ownership. The caller must not use nmp_object_stackinit_id()
|
||||
* with an object of such a type. */
|
||||
nm_assert(!klass->cmd_obj_copy);
|
||||
|
||||
/* plain memcpy of the public part suffices. */
|
||||
memcpy(&obj->object, &src->object, klass->sizeof_data);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue