Skip to content

Commit 3e04a72

Browse files
committed
Document a few quick observations
1 parent 3d67323 commit 3e04a72

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

objc2-encode/src/encode.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ pub unsafe trait RefEncode {
147147
const ENCODING_REF: Encoding<'static>;
148148
}
149149

150+
// TODO: Implement for `PhantomData` and `PhantomPinned`?
151+
150152
/// Simple helper for implementing [`Encode`].
151153
macro_rules! encode_impls {
152154
($($t:ty => $e:ident,)*) => ($(
@@ -318,6 +320,7 @@ unsafe impl<T: RefEncode + ?Sized> RefEncode for ManuallyDrop<T> {
318320
// core::cell::Ref?
319321
// core::cell::RefCell?
320322
// core::cell::RefMut?
323+
// core::panic::AssertUnwindSafe<T>
321324

322325
// SAFETY: `Pin` is `repr(transparent)`.
323326
unsafe impl<T: Encode> Encode for Pin<T> {
@@ -341,6 +344,8 @@ unsafe impl<T: RefEncode> RefEncode for Wrapping<T> {
341344
const ENCODING_REF: Encoding<'static> = T::ENCODING_REF;
342345
}
343346

347+
// TODO: core::num::Saturating when that is stabilized
348+
344349
// TODO: core::cmp::Reverse?
345350

346351
/// Helper for implementing `Encode`/`RefEncode` for pointers to types that

objc2/src/exception.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ extern "C" {
3737
/// (and would probably give us a bit better performance), but it gets
3838
/// unwieldy _very_ quickly, so I chose the much more stable option.
3939
///
40+
/// Another thing to remember: While Rust's and Objective-C's unwinding
41+
/// mechanisms are similar now, Rust's is explicitly unspecified, and they
42+
/// may diverge significantly in the future; so handling this in pure Rust
43+
/// (using mechanisms like core::intrinsics::r#try) is not an option!
44+
///
4045
/// [manual-asm]: https://gitlab.com/objrs/objrs/-/blob/b4f6598696b3fa622e6fddce7aff281770b0a8c2/src/exception.rs
4146
fn rust_objc_try_catch_exception(
4247
f: extern "C" fn(*mut c_void),

objc2/src/rc/autorelease.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use crate::ffi;
1818
/// pool on the current thread.
1919
#[derive(Debug)]
2020
pub struct AutoreleasePool {
21+
/// This is an opaque handle, and is not guaranteed to be neither a valid
22+
/// nor aligned pointer.
2123
context: *mut c_void,
2224
// May pointer to data that is mutated (even though we hold shared access)
2325
p: PhantomData<*mut UnsafeCell<c_void>>,
@@ -140,9 +142,13 @@ impl Drop for AutoreleasePool {
140142
/// > Not draining the pool during an unwind is apparently required by the
141143
/// > Objective-C exceptions implementation.
142144
///
143-
/// This was true in the past, but since [revision `371`] of objc4 (ships
144-
/// with MacOS 10.5) the exception is now retained when `@throw` is
145-
/// encountered.
145+
/// However, we would like to do this anyway whenever possible, since the
146+
/// unwind is probably caused by Rust, and forgetting to pop the pool will
147+
/// likely leak memory.
148+
///
149+
/// Fortunately, the above statement was true in the past, but since
150+
/// [revision `371`] of objc4 (ships with MacOS 10.5) the exception is now
151+
/// retained when `@throw` is encountered.
146152
///
147153
/// Hence it is safe to drain the pool when unwinding.
148154
///

objc2/src/rc/weak_id.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct WeakId<T: ?Sized> {
2525
/// an UnsafeCell to get a *mut without self being mutable.
2626
///
2727
/// TODO: Verify the need for UnsafeCell?
28+
/// TODO: Investigate if we can avoid some allocations using `Pin`.
2829
inner: Box<UnsafeCell<*mut T>>,
2930
/// WeakId inherits variance, dropck and various marker traits from
3031
/// `Id<T, Shared>` because it can be upgraded to a shared Id.

0 commit comments

Comments
 (0)