Skip to content

Commit b4cb59e

Browse files
committed
Fix unsoundness in NSDictionary and NSSet creation/mutation
Almost at least, some generic types like `NSArray<NSView>` is still incorrectly allowed as a key
1 parent 3661935 commit b4cb59e

File tree

18 files changed

+493
-184
lines changed

18 files changed

+493
-184
lines changed

crates/icrate/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1818
* Added missing `NSCopying` and `NSMutableCopying` zone methods.
1919
* Added `Eq` and `Ord` implementations for `NSNumber`, since its
2020
handling of floating point values allows it.
21+
* Added `NS[Mutable]Dictionary::from_id_slice` and
22+
`NS[Mutable]Dictionary::from_slice`.
23+
* Added `NSMutableDictionary::insert` and `NSMutableSet::insert` which can
24+
be more efficient than the previous insertion methods.
2125

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

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

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

5570
## icrate 0.0.4 - 2023-07-31
5671

crates/icrate/examples/basic_usage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ fn main() {
3636

3737
// Create a dictionary mapping strings to objects
3838
let keys = &[string];
39-
let vals = vec![obj];
40-
let dict = NSDictionary::from_keys_and_objects(keys, vals);
39+
let objects = &[obj];
40+
let dict = NSDictionary::from_id_slice(keys, objects);
4141
println!("{:?}", dict.get(string));
4242
println!("{}", dict.len());
4343
}

0 commit comments

Comments
 (0)