-
Notifications
You must be signed in to change notification settings - Fork 57
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 autoreleasepool functionality. #67
Conversation
src/autorelease.rs
Outdated
} | ||
|
||
impl AutoReleaseHelper { | ||
fn new() -> AutoReleaseHelper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Self
src/autorelease.rs
Outdated
use runtime::{objc_autoreleasePoolPush, objc_autoreleasePoolPop}; | ||
|
||
struct AutoReleaseHelper { | ||
context: *mut c_void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be something more specific?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what the runtime returns.
src/autorelease.rs
Outdated
} | ||
} | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this meant to be a doc comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep.
src/autorelease.rs
Outdated
after the execution of `f` completes. This corresponds to @autoreleasepool blocks | ||
in Objective-c and Swift. | ||
*/ | ||
pub fn autoreleasepool<F: FnOnce()>(f: F) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps, we should just make it a method of AutoReleaseHelper
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. That would be unsafe because we can't guarantee that drop() will be called.
CI went crazy, eh |
80dd4ac
to
4b2976f
Compare
4b2976f
to
baa5586
Compare
1e5874e
to
4b2976f
Compare
It looks the ci failure is unrelated to the change. |
@jrmuizel this looks great, but I'm not sure about adding it to objc right now. I don't completely understand the relationship between libobjc and reference counting. These functions aren't defined in the public headers for libobjc. Although Apple's libobjc bakes in some parts of Foundation (like the implementation of NSObject and this), for now I've kept reference-counting stuff out of the objc crate (though it used to be here and #24 was filed when it was removed). I'm not sure where the best home for this is then. If y'all would be interested in adding this to objc_id, I'd be happy to accept it there! If that's no good for you, maybe in the foundation module of the cocoa crate to replace its NSAutoreleasePool? Let me know what you think! |
src/autorelease.rs
Outdated
|
||
impl AutoReleaseHelper { | ||
unsafe fn new() -> Self { | ||
AutoReleaseHelper{ context: objc_autoreleasePoolPush()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIt: spacing got a little inconsistent here :)
IIRC, the functions are part of the interface between the compiler and the runtime. They're not normally called from user code, hence not exposed in the normal runtime headers.
There might be a compatibiltiy shim for the legacy gcc runtime in Gnustep's Foundation library, but the modern runtime definitely implements them directly. |
Ah, I must've confused |
4b2976f
to
7e4f432
Compare
I've fixed the spacing and it sounds like everyone agrees that this rust-objc is the right place for this? |
Review ping. |
@SSheldon ping |
Sorry, procrastinated responding because I wasn't sure what to say without more time to think, and last weekend I was out of town. This weekend I've had some time though! It feels very odd to have autorelease pool functionality without retain/release functionality in the objc crate, so after adding this I'm also going to add retain/release functionality. I think I've gotten some ideas of how I want to do that. Current problem, though, is how to test any reference counting functionality. The problem is that the reference counting implementations basically require that your object subclass NSObject (like having retain/release/autorelease/dealloc methods). And unfortunately the tests can't currently use NSObject, because it's not available from the GNUstep runtime. So I'm currently investigating if I can get the GNUstep Foundation working. When that's figured out, we can merge this and write some tests for it. |
Okay, after a very long struggle: I've gotten to an okay place with the GNUstep tests and I've added some reference counting utils on master. Can you rebase this change and:
|
This replicates the behaviour of @autoreleasepool blocks in Objective-C and allows higher performance creation of autorelease pools.
7e4f432
to
2f906ee
Compare
Done. I added a test of the autorelease functionality as well. |
Thank you! Looks great. |
What would be even better if |
@SSheldon how do you feel about yanking the version, fixing |
This replicates the behaviour of @autoreleasepool blocks in
Objective-C and allows higher performance creation of autorelease pools.