Skip to content

Commit e5919bb

Browse files
authored
Merge pull request #232 from madsmtm/foundation-id-usage
Improve safety in foundation collection types wrt. ownership
2 parents 92ccbef + a270d44 commit e5919bb

15 files changed

+379
-214
lines changed

objc2/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1616
`objc2-foundation`.
1717

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

2121

2222
## 0.3.0-beta.1 - 2022-07-19

objc2/CHANGELOG_FOUNDATION.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2020
of the `NSValue` matches the encoding of the given type.
2121
* Added functions `get_range`, `get_point`, `get_size` and `get_rect` to
2222
`NSValue` to help safely returning various types it will commonly contain.
23+
* `NSArray` and `NSMutableArray` now have sensible defaults for the ownership
24+
of the objects they contain.
2325

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

3134
### Fixed
3235
* Made `Debug` impls for all objects print something useful.

objc2/src/__macro_helpers.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,13 @@ mod tests {
274274

275275
#[test]
276276
fn test_alloc_with_zone() {
277-
let expected = ThreadTestData::current();
277+
let mut expected = ThreadTestData::current();
278278
let cls = RcTestObject::class();
279279

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

@@ -325,9 +323,18 @@ mod tests {
325323
expected.init += 1;
326324
expected.assert_current();
327325

328-
// TODO:
329-
// let copy: Id<RcTestObject, Shared> = unsafe { msg_send_id![&obj, copy].unwrap() };
330-
// let mutable_copy: Id<RcTestObject, Shared> = unsafe { msg_send_id![&obj, mutableCopy].unwrap() };
326+
let _copy: Id<RcTestObject, Shared> = unsafe { msg_send_id![&obj, copy].unwrap() };
327+
expected.copy += 1;
328+
expected.alloc += 1;
329+
expected.init += 1;
330+
expected.assert_current();
331+
332+
let _mutable_copy: Id<RcTestObject, Shared> =
333+
unsafe { msg_send_id![&obj, mutableCopy].unwrap() };
334+
expected.mutable_copy += 1;
335+
expected.alloc += 1;
336+
expected.init += 1;
337+
expected.assert_current();
331338

332339
let _self: Id<RcTestObject, Shared> = unsafe { msg_send_id![&obj, self].unwrap() };
333340
expected.retain += 1;
@@ -337,8 +344,8 @@ mod tests {
337344
unsafe { msg_send_id![&obj, description] };
338345
expected.assert_current();
339346
});
340-
expected.release += 3;
341-
expected.dealloc += 2;
347+
expected.release += 5;
348+
expected.dealloc += 4;
342349
expected.assert_current();
343350
}
344351

0 commit comments

Comments
 (0)