Skip to content
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

Foundation ownership fixes #40

Merged
merged 17 commits into from
Nov 2, 2021
Merged

Foundation ownership fixes #40

merged 17 commits into from
Nov 2, 2021

Conversation

madsmtm
Copy link
Owner

@madsmtm madsmtm commented Oct 5, 2021

Intended to fix most of the soundness issues discussed in #29.

I also renamed a lot of methods to better match Rust naming.

@madsmtm madsmtm added bug Something isn't working enhancement New feature or request labels Oct 5, 2021
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).
INSArray::Own -> INSArray::ItemOwnership
INSDictionary::Own -> INSDictionary::ValueOwnership

Also remove `NSSharedArray` and `NSMutableSharedArray`
Also add a few bound checks since throwing exceptions from Objective-C is still UB
See the code comments and my explanation here: SSheldon/rust-objc#103 (comment)

This also has the nice "side-effect" of fixing the memory leaks that as_str was otherwise exhibiting when using non-ascii strings, see SSheldon/rust-objc-foundation#15.
@madsmtm madsmtm mentioned this pull request Oct 30, 2021
2 tasks
The `Any` bound is equivalent to 'static, and that is too restrictive; we want to allow creating custom classes which reference something from the outer environment
Anything else would be unsound, since the user must verify that the object actually implements the protocols / inherits the classes!
@madsmtm madsmtm changed the title Ownership fixes (WIP) Foundation ownership fixes Oct 31, 2021
NSValue implements `INSObject`, and therefore has a blank `new` method, but the extractor method did not account for this discrepancy.
@madsmtm madsmtm force-pushed the ownership-fixes branch 2 times, most recently from fdcecc4 to 2fb4fb8 Compare November 1, 2021 21:05
Some classes (NSValue is the current example of this, but it's probably not the only case) don't want to handle cases where the users didn't supply a value, and implement `init` with throwing an exception or returning `nil`.

We could panic in those cases (though we can't currently catch GNUStep exceptions), but instead we should just simply not provide a way to construct these invalid instances.
@madsmtm madsmtm merged commit 854711e into master Nov 2, 2021
@madsmtm madsmtm deleted the ownership-fixes branch November 2, 2021 13:07
madsmtm added a commit that referenced this pull request Nov 2, 2021
madsmtm added a commit that referenced this pull request Nov 2, 2021
@madsmtm madsmtm added the I-unsound A soundness hole label Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request I-unsound A soundness hole
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant