Skip to content

[SR-7263] Treat APIs returning unmanaged CF types as NS_RETURNS_INNER… #16129

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

Merged
merged 3 commits into from
May 17, 2018

Conversation

ChristopherRogers
Copy link
Contributor

…_POINTER

I've pretty much obeyed the instructions in the bug tracker to the letter, which were pretty straightforward. The only thing I added to that was the optional unwrapping. This is needed to handle when the nullability of the return value is specified as _Nullable or isn't specified, which in this case is very likely. I assumed if it was an Optional multiply nested that it shouldn't behave like NS_RETURNS_INNER_POINTER.

This will make self autoreleased so this may slightly impact the memory footprint of some code.

The bug mentioned (@jrose-apple) getting someone to suggest some test code to add for this. I can add that if still necessary. There was already a test that failed from this change, so maybe that would suffice...? 🤷‍♂️

Resolves SR-7263.

(I've run -r --verification-test on my Mac and everything passes at this point.)

Testing Time: 756.14s
  Expected Passes    : 10858
  Expected Failures  : 26
  Unsupported Tests  : 157
-- check-swift-validation-macosx-x86_64 finished --

@harlanhaskins
Copy link
Contributor

@swift-ci please smoke test

@jrose-apple jrose-apple self-requested a review May 2, 2018 02:35
@jrose-apple
Copy link
Contributor

I'm glad this was so straightforward! Yes, I do think it should still have a test—I'd go all the way to making an execution test where the object would be prematurely released otherwise. The basic setup would be a lot like test/Interpreter/SDK/block_globals.swift, with both a .swift file and a .m file to control the behavior on both sides, and we'd want to test what happens in an optimized build. Maybe the Objective-C class that returns the CF type can print something in its -dealloc so we can tell when that final release happens?

Let me know if my scattering of suggestions here isn't enough to go on. Thanks for doing this!

@ChristopherRogers
Copy link
Contributor Author

I wasn't totally sure where to put the test code so I just put it where I found other test code for returns_inner_pointer stuff. ("Interpreter" didn't make much sense to me.)

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks reasonable to me! Just one comment about the specific object chosen for the test case…

}

- (id)init {
_bar = (__bridge_retained CFTypeRef)[[NSNumber alloc] initWithInt:1234567891];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it's probably best not to use an NSNumber, because those can get uniqued! Maybe an NSMutableString? ("mutable" avoids uniquing there)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*slaps forehead* Thanks. I was trying to avoid the tagged pointers thing but this is much simpler.

@jrose-apple
Copy link
Contributor

@swift-ci Please test macOS

@jrose-apple
Copy link
Contributor

@swift-ci Please smoke test Linux

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - eea57a0

@jrose-apple
Copy link
Contributor

preset=buildbot_incremental,tools=RA,stdlib=RA,test=macOS,type=device
@swift-ci Please test with preset

@ChristopherRogers
Copy link
Contributor Author

Hi, I just wanted to make sure there wasn't anything else I need to do on my end... especially since there was that "build failed" message from swift-ci. Everything's green so I assume it was just a fluke.

@jrose-apple
Copy link
Contributor

Oops! No, just forgot to add this to my list of "things to circle back on once tests pass". Thanks, Christopher!

(I'm still not sure why the preset build didn't work, but I don't foresee any problems regardless.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants