-
Notifications
You must be signed in to change notification settings - Fork 51
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
Add rc::Unknown
and rc::MaybeOwnership
#87
Comments
Not that it matters much, but this could be accomplished without breaking changes. |
What about naming? And which requirements are imposed by
|
This comment was marked as outdated.
This comment was marked as outdated.
|
Thinking about it again, there are three orthogonal pieces of information that we might know, and want to encode this knowledge:
With that,
Only remaining question is: How important it actually is to know you don't know the ownership, vs. just using |
Another name for |
Reconsidering: Reasoning: The data is already guaranteed to be allocated when you hold a let obj: Id<Allocated<T>, Owned> = msg_send_id![cls, alloc];
// Is effectively the same as
let item: Box<MaybeUninit<T>> = Box::new_zeroed(); But then again, the data is not truly maybe-uninitialized, parts of it is guaranteed to be valid (e.g. valid isa pointer and so on), which is not the case for Also, if we want to have special methods, a new struct is better. |
Still uncertain whether Since One thing though: let obj: Id<Object, Shared> = ...;
// Get immutable reference to ivar
let ivar: &i32 = obj.ivar("ivar");
// Modify `ivar` through shared reference to `obj`
let _: () = msg_send![obj, setIvar: *ivar];
// UB
println!("{}", *ivar); So if we want to "bless" EDIT: Fixed by better safety docs, see #182 |
I don't think EDIT: That issue will have very significant implications on the entire API if we can't fix it otherwise, but whether |
I've removed ownership from |
In #264 I'll probably be using At this point I really doubt |
Rough sketch:
When generating bindings to Objective-C classes automatically (e.g. with
bindgen
, see #85), it would be nice to return a reference counting pointer (e.g. anId
). Sadly, however, it is not possible to know the ownership of that without inspection of the entire class; even handing out immutable references can easily trigger undefined behaviour (e.g. if there was aId<T, Owned>
somewhere else in the program).Therefore it would be beneficial to add a reference-counting pointer that does not guarantee any form of ownership, like the
StrongPtr
removed in e08e87d. See also upstream SSheldon/rust-objc#24.This can probably be accomplished by adding a
rc::Unknown
, similar torc::Owned
andrc::Shared
.On initial inspection, you would just implement
rc::Ownership
forrc::Unknown
, but that makes all high-level code unable to deal with the "normal" case where you want to know the ownership, so we should consider addingrc::MaybeOwnership
as well to deal with this case.Example code changes:
The text was updated successfully, but these errors were encountered: