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

Improve safety in foundation arrays wrt. ownership #232

Merged
merged 7 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion objc2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
`objc2-foundation`.

### Changed
* Change selector syntax in `declare_class!` macro to be more Rust-like.
* **BREAKING**: Change selector syntax in `declare_class!` macro to be more Rust-like.


## 0.3.0-beta.1 - 2022-07-19
Expand Down
3 changes: 3 additions & 0 deletions objc2/CHANGELOG_FOUNDATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
of the `NSValue` matches the encoding of the given type.
* Added functions `get_range`, `get_point`, `get_size` and `get_rect` to
`NSValue` to help safely returning various types it will commonly contain.
* `NSArray` and `NSMutableArray` now have sensible defaults for the ownership
of the objects they contain.

### Changed
* **BREAKING**: Moved from external crate `objc2_foundation` into
`objc2::foundation`.
* **BREAKING**: Made `NSValue` not generic any more. While we loose some
type-safety from this, it makes `NSValue` much more useful in the real
world!
* **BREAKING**: Made `NSArray::new` generic over ownership.

### Fixed
* Made `Debug` impls for all objects print something useful.
Expand Down
25 changes: 16 additions & 9 deletions objc2/src/__macro_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,13 @@ mod tests {

#[test]
fn test_alloc_with_zone() {
let expected = ThreadTestData::current();
let mut expected = ThreadTestData::current();
let cls = RcTestObject::class();

let zone: *const NSZone = ptr::null();
let _obj: Id<Allocated<RcTestObject>, Owned> =
unsafe { msg_send_id![cls, allocWithZone: zone].unwrap() };
// `+[NSObject alloc]` delegates to `+[NSObject allocWithZone:]`, but
// `RcTestObject` only catches `alloc`.
// expected.alloc += 1;
expected.alloc += 1;
expected.assert_current();
}

Expand Down Expand Up @@ -325,9 +323,18 @@ mod tests {
expected.init += 1;
expected.assert_current();

// TODO:
// let copy: Id<RcTestObject, Shared> = unsafe { msg_send_id![&obj, copy].unwrap() };
// let mutable_copy: Id<RcTestObject, Shared> = unsafe { msg_send_id![&obj, mutableCopy].unwrap() };
let _copy: Id<RcTestObject, Shared> = unsafe { msg_send_id![&obj, copy].unwrap() };
expected.copy += 1;
expected.alloc += 1;
expected.init += 1;
expected.assert_current();

let _mutable_copy: Id<RcTestObject, Shared> =
unsafe { msg_send_id![&obj, mutableCopy].unwrap() };
expected.mutable_copy += 1;
expected.alloc += 1;
expected.init += 1;
expected.assert_current();

let _self: Id<RcTestObject, Shared> = unsafe { msg_send_id![&obj, self].unwrap() };
expected.retain += 1;
Expand All @@ -337,8 +344,8 @@ mod tests {
unsafe { msg_send_id![&obj, description] };
expected.assert_current();
});
expected.release += 3;
expected.dealloc += 2;
expected.release += 5;
expected.dealloc += 4;
expected.assert_current();
}

Expand Down
Loading