-
Notifications
You must be signed in to change notification settings - Fork 91
Closed
Labels
⚡ SafetyIssues related to Safety - considered critical, can justify a semver-breaking change.Issues related to Safety - considered critical, can justify a semver-breaking change.🪲 bugSomething isn't workingSomething isn't working
Description
Currently, QObjectExt::set_parent accepts a parent: &QObject
argument, which it then converts to a mutable pointer:
cxx-qt/crates/cxx-qt-lib/src/core/qobject.rs
Lines 94 to 99 in 511ec27
fn set_parent(self: Pin<&mut Self>, parent: &Self) { | |
unsafe { | |
cast_pin(self) | |
.set_parent(cast(parent) as *const QObjectExternal as *mut QObjectExternal); | |
} | |
} |
Is this really safe? QObject::setParent() requires a mutable pointer on Qt's side, and its implementation mutates the parent by appending the object to its list of children. It also triggers the ChildAdded event on the parent, which may perform arbitrary code in its event handler.
I would have expected something more like this:
fn set_parent<T>(self: Pin<&mut Self>, parent: Option<Pin<&mut T>>)
where
T: Upcast<QObject>,
{
unsafe {
let parent = match parent {
Some(parent) => ptr::from_mut(parent.upcast_pin().get_unchecked_mut()).cast(),
None => ptr::null_mut(),
};
cast_pin(self).set_parent(parent);
}
}
Metadata
Metadata
Assignees
Labels
⚡ SafetyIssues related to Safety - considered critical, can justify a semver-breaking change.Issues related to Safety - considered critical, can justify a semver-breaking change.🪲 bugSomething isn't workingSomething isn't working