-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Violating soundness requirements #10
Comments
As far as I can see, this is only a problem with the specific In step 2 ( pub struct CopiedId<'a, T> {
id: Id<T>,
lifetime: PhantomData<&'a T>,
}
impl<'a, T> Deref<Target = T> for CopiedId<'a, T> {
...
}
pub trait INSCopying: INSObject {
type Output: INSObject;
fn copy<'a>(&'a self) -> CopiedId<'a, Self::Output> { }
} Or alternatively, if this is a more common problem, we could change pub struct Id<'a, T, O = Owned> { } I've outlined these to solve the general cases, but in this instance |
Immutable types like NSString implement `copy` by simply retaining the pointer; hence, having an `Owned` NSString (which allows access to `&mut NSString`) is never valid, since it would be possible to create an aliased mutable reference. So instead we now have an `Ownership` type on INSObject that indicates whether the type is mutable. Fixes SSheldon/rust-objc-foundation#10 (see that issue for alternative ways to fix this).
Immutable types like NSString implement `copy` by simply retaining the pointer; hence, having an `Owned` NSString (which allows access to `&mut NSString`) is never valid, since it would be possible to create an aliased mutable reference. So instead we now have an `Ownership` type on INSObject that indicates whether the type is mutable. Fixes SSheldon/rust-objc-foundation#10 (see that issue for alternative ways to fix this).
Immutable types like NSString implement `copy` by simply retaining the pointer; hence, having an `Owned` NSString (which allows access to `&mut NSString`) is never valid, since it would be possible to create an aliased mutable reference. So instead we now have an `Ownership` type on INSObject that indicates whether the type is mutable. Fixes SSheldon/rust-objc-foundation#10 (see that issue for alternative ways to fix this).
Treating Foundation objects as rust references is hard. Currently this crate can be used to violate soundness rules within safe code, which could result in undefined behavior.
One problem right now comes from
NSCopying
:This code results in an owned
Id
and aShareId
of the same object, allowing an&mut
reference to an address while a&
reference exists for the same address. This violates the aliasing requirements.It may be the case that it's just too difficult to safely treat Objective-C objects as rust references and this crate is a failed experiment.
The text was updated successfully, but these errors were encountered: