Skip to content

Add objc_retainAutoreleasedReturnValue() #10355

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions stdlib/public/runtime/HeapObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,26 @@ void SWIFT_RT_ENTRY_IMPL(swift_nonatomic_retain_n)(HeapObject *object, uint32_t
object->refCounts.incrementNonAtomic(n);
}

#if !SWIFT_OBJC_INTEROP

// For CF functions with 'Get' semantics, the compiler currently assumes that
// the result is autoreleased and must be retained. It does so on all platforms
// by emitting a call to objc_retainAutoreleasedReturnValue. On Darwin, this is
// implemented by the ObjC runtime. On Linux, there is no runtime, and therefore
// we have to stub it out here ourselves. The compiler will eventually call
// swift_release to balance the retain below. This is a workaround until the
// compiler no longer emits this callout on Linux.
SWIFT_RT_ENTRY_VISIBILITY
extern "C"
void *objc_retainAutoreleasedReturnValue(HeapObject *obj) {
if (obj) {
swift::swift_retain(obj);
return obj;
}
else return NULL;
}
#endif

void swift::swift_release(HeapObject *object)
SWIFT_CC(RegisterPreservingCC_IMPL) {
SWIFT_RT_ENTRY_REF(swift_release)(object);
Expand Down