Skip to content

Commit

Permalink
Fix unsoundness in NSDictionary and NSSet creation/mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Sep 7, 2023
1 parent 00a86c6 commit 17e90c6
Show file tree
Hide file tree
Showing 18 changed files with 466 additions and 184 deletions.
15 changes: 15 additions & 0 deletions crates/icrate/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* Added missing `NSCopying` and `NSMutableCopying` zone methods.
* Added `Eq` and `Ord` implementations for `NSNumber`, since its
handling of floating point values allows it.
* Added `NS[Mutable]Dictionary::from_id_slice` and
`NS[Mutable]Dictionary::from_slice`.
* Added `NSMutableDictionary::insert` and `NSMutableSet::insert` which can
be more efficient than the previous insertion methods.

### Changed
* Moved the `ns_string!` macro to `icrate::Foundation::ns_string`. The old
Expand All @@ -44,13 +48,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
// Do something with `app` and `view`
```
* **BREAKING**: Changed the `NSApp` static to be a function taking `MainThreadMarker`.
* **BREAKING**: Renamed `NS[Mutable]Dictionary::from_keys_and_objects` to
`NS[Mutable]Dictionary::from_vec`.
* **BREAKING**: Renamed `NSMutableDictionary::insert` and
`NSMutableSet::insert` to `insert_id`.

### Removed
* **BREAKING**: Removed the `MainThreadMarker` argument from the closure
passed to `MainThreadBound::get_on_main`.
* **BREAKING**: Removed `Foundation::CopyHelper` since it is superseded by
`objc2::mutability::CounterpartOrSelf`

### Fixed
* **BREAKING**: Added `Eq + Hash` requirement on most `NSDictionary` and
`NSSet` methods, thereby making sure that the types are actually correct
to use in such hashing collections.
* **BREAKING**: Added `HasStableHash` requirement on `NSDictionary` and
`NSSet` creation methods, fixing a long-standing soundess issue.


## icrate 0.0.4 - 2023-07-31

Expand Down
4 changes: 2 additions & 2 deletions crates/icrate/examples/basic_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fn main() {

// Create a dictionary mapping strings to objects
let keys = &[string];
let vals = vec![obj];
let dict = NSDictionary::from_keys_and_objects(keys, vals);
let objects = &[obj];
let dict = NSDictionary::from_id_slice(keys, objects);
println!("{:?}", dict.get(string));
println!("{}", dict.len());
}
Loading

0 comments on commit 17e90c6

Please sign in to comment.