Skip to content

Fix ownership in objc2-foundation #29

Description

@madsmtm

After #21 I can go through objc2-foundation and re-evaluate how we should do the ownership stuff. Especially difficult with generic objects like NSArray!

The idea is it we fix the soundness issues in SSheldon/rust-objc-foundation#10, see my comment there.

Probably some rework of INSObject is required.

Should also figure out the safety of "downgrading" (e.g. &MyObject -> &NSObject)? And from there &NSObject -> Id<NSObject, Shared> (which deletes the original lifetime). What about when MyObject<'a> itself carries lifetime information? Maybe add lifetime to Id? Moved to #58

Also, should we add an ObjectType/RetainAble/... type, since not all Message types can actually be used in Id? Moved to #66

Idea:

unsafe trait INSObject {
    type Own: Ownership;
    // ...

    fn new() -> Id<Self, O> { ... }
}

unsafe trait INSCopying: INSObject {
    fn copy(&self) -> Id<Self, Shared>;
}

unsafe trait INSMutableCopying: INSObject<Own = Owned> {
    fn copy_mut(&self) -> Id<Self, Owned>;
}

unsafe impl INSObject for NSString {
    type Own = Shared; // This means there may never exist an `&mut NSString` (and by extension no `Id<NSString, Owned>`)!
}
unsafe impl INSObject for NSMutableString {
    type Own = Owned; // Both `Id<NSString, Owned>` and `Id<NSString, Shared>` are possible
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions