-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[interop][SwiftToCxx] bridge ObjC class types to C++ (without Obj… #61268
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
Conversation
// CHECK-NEXT: void $s9UseObjCTy04takeB14CClassNullableyySo0B6CKlassCSgF(ObjCKlass *_Nullable x) SWIFT_NOEXCEPT SWIFT_CALL; | ||
|
||
// CHECK: inline ObjCKlass *_Nonnull retObjClass() noexcept SWIFT_WARN_UNUSED_RESULT { | ||
// CHECK-NEXT: return (__bridge_transfer __autoreleasing ObjCKlass *)(__bridge void *)_impl::$s9UseObjCTy03retB5ClassSo0B6CKlassCyF(); |
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.
@mikeash is this the best approach to take here for ARC?
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.
What's the goal of the casting? Can this just return _impl::$s9UseObjCTy03retB5ClassSo0B6CKlassCyF();
?
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.
In that case there's an extra retain on the object, so it's leaked.
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.
Oh, because we're following Swift conventions and returning at +1, rather than ObjC conventions returning at +0?
I believe the __autoreleasing
is unnecessary, but the rest seems fine, then. I personally prefer the CFBridgingRelease
function over __bridge_transfer
as I think it's a lot more understandable, but it's probably not a good choice in this context.
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.
basically Swift's s9UseObjCTy03retB5ClassSo0B6CKlassCyF
returns at +2 here, so I need to autorelease once to get back to +1.
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.
yeah.
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.
sounds good, I can try without __autoreleasing
then. Cheers!
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.
ARC will automatically autorelease the return value regardless.
@swift-ci please test |
@swift-ci please test source compatibility |
87b9b16
to
e6a94bf
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
e6a94bf
to
bded6c5
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
@swift-ci please test macOS platform |
…C guards first)
In the future we should add
#if __OBJC__
guards.