Find a solution to make sure there is no several &mut reference to a QObject or QGadget #11
Labels
I-unsound
Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
Currently, when one use
#[derive(QObject)] struct RustName { ... }
it is possible to get several mutable reference to the same object at the same time.Also we must ensure that mutable references are not moved.
For any QObject, there is the CPP object, and the Rust object. each must contains a pointer to the other. Currently, the CPP object contains a
*mut BaseTrait
TraitObject pointer, whereBaseTrait
is the trait in theqt_base_class!()
. But then this is transfomred in a reference&mut StructName
which is then passed a a&mut self
to the setter or qt_method. Or within virtual functions.There is also the QPointer class which allow a cast to
&StructName
I was thinking that instead of putting the StructName in a
Box<StructName>
, I would instead useBox<RefCell<StructName>>
and store a*const RefCell<BaseTrait>
in the CPP object. (I would still need to store a*const QObject
for Drop and to get the actual pointer`) This way, one can safely access this.There is still the problem of the feature that currently, RustName don't necessarily need to be on the heap. We could change that.
But there is still the current feature of property whose type derives from QObject, these are not on the heap, not in a refcell. Maybe we need to force the property in a refcell then.
As to force the location: I am makng a wrapper around
&RefCell<T> where T : QObject + ?Sized
And the borrow_mut returns:So this make sure nobody moves the RustName away.
I have some work in progress, let's see if it is the best approach.
The text was updated successfully, but these errors were encountered: