-
Notifications
You must be signed in to change notification settings - Fork 75
Enable Clone for CpuId, Msrs and MsrList #13
Conversation
To enable `Clone` for the safe wrappers `CpuId`, `Msrs` and `MsrList` we need to implement `Clone` for `kvm_cpuid2`, `kvm_msrs` and respectively `kvm_msr_list`. Signed-off-by: Adrian Catangiu <[email protected]>
kvm_cpuid2 { | ||
nent: self.nent, | ||
padding: self.padding, | ||
entries: self.entries.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Field entries
is type of __IncompleteArrayField, is it safe to clone it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is like phantomdata safe to clone. The cloning of actual data is done by the Clone
implementation of FamStructWrapper
.
The clone implementation added by this PR is not even actually used. But it is needed to satisfy the
impl<T: Default + FamStruct + Clone> Clone for FamStructWrapper<T>
requirement.
Another option would be to remove Clone
from the FamStructWrapper
requirements as it's not actually needed AFAICT.
CC @serban300 as the FamStructWrapper op.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need Clone
functionality for an instance of FamStructWrapper
, T
needs to implement Clone
, otherwise the code won't build, because mem_allocator
is a Vec<T>
.
impl<T: Default + FamStruct + Clone> Clone for FamStructWrapper<T> {
fn clone(&self) -> Self {
FamStructWrapper {
mem_allocator: self.mem_allocator.to_vec(),
}
}
}
I think it's ok to implement Clone
for kvm_cpuid2
, kvm_msrs
and kvm_msr_list
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise the code won't build, because
mem_allocator
is aVec<T>
that's right.
Let's stick to the strategy implemented in this PR then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__IncompleteArrayField are not safe to clone as @jiangliu also said in the previous commit. More details on this issue: rust-lang/rust-bindgen#1431. I am not sure what is the best way to move forward here honestly, but adding clone doesn't seem right to me.
Yes, having read that thread I agree the using the result of that Even so, I agree we should not expose an implementation of the I am closing this PR and attempting a fix directly in the |
To enable
Clone
for the safe wrappersCpuId
,Msrs
andMsrList
we need to implementClone
forkvm_cpuid2
,kvm_msrs
and respectivelykvm_msr_list
.Fixed #12