Skip to content

Commit ded5bab

Browse files
authored
Merge pull request #258 from spevans/pr_expose_symbol
Export objc_retainAutoreleasedReturnValue()
2 parents e591e7e + b756329 commit ded5bab

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/swift/DispatchStubs.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,25 @@ SOURCE(VNODE)
199199
#endif
200200
SOURCE(WRITE)
201201

202-
// See comment in CFFuntime.c explaining why objc_retainAutoreleasedReturnValue is needed.
202+
#if !USE_OBJC
203+
204+
// For CF functions with 'Get' semantics, the compiler currently assumes that
205+
// the result is autoreleased and must be retained. It does so on all platforms
206+
// by emitting a call to objc_retainAutoreleasedReturnValue. On Darwin, this is
207+
// implemented by the ObjC runtime. On non-ObjC platforms, there is no runtime,
208+
// and therefore we have to stub it out here ourselves. The compiler will
209+
// eventually call swift_release to balance the retain below. This is a
210+
// workaround until the compiler no longer emits this callout on non-ObjC
211+
// platforms.
203212
extern "C" void swift_retain(void *);
213+
214+
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
204215
extern "C" void * objc_retainAutoreleasedReturnValue(void *obj) {
205216
if (obj) {
206217
swift_retain(obj);
207218
return obj;
208219
}
209220
else return NULL;
210221
}
222+
223+
#endif // !USE_OBJC

0 commit comments

Comments
 (0)