Skip to content

Commit

Permalink
Merge pull request #819 from al45tair/eng/PR-123945799
Browse files Browse the repository at this point in the history
Remove objc_retainAutoreleasedReturnValue workaround.
  • Loading branch information
al45tair authored Mar 4, 2024
2 parents 3a566c9 + daa2345 commit 292273a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 50 deletions.
13 changes: 0 additions & 13 deletions src/swift/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@

# NOTE(compnerd) Today regardless of whether or not ObjC interop is enabled,
# swift will use an autoreleased return value convention for certain CF
# functions (including some that are used/related to dispatch). This means that
# the swift compiler in callers to such functions will call the function, and
# then pass the result of the function to objc_retainAutoreleasedReturnValue. In
# a context where we have ObjC interop disabled, we do not have access to the
# objc runtime so an implementation of objc_retainAutoreleasedReturnValue is not
# available. To work around this, we provide a shim for
# objc_retainAutoreleasedReturnValue in DispatchStubs.cc that just calls retain
# on the object. Once we fix the swift compiler to switch to a different model
# for handling these arguments with objc-interop disabled these shims can be
# eliminated.
add_library(DispatchStubs STATIC
DispatchStubs.cc)
target_include_directories(DispatchStubs PRIVATE
Expand Down
37 changes: 0 additions & 37 deletions src/swift/DispatchStubs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,40 +56,3 @@ static void _dispatch_overlay_constructor() {
}

#endif /* USE_OBJC */

#if !USE_OBJC
DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" void * objc_retainAutoreleasedReturnValue(void *obj);
#endif

#if !USE_OBJC

// 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 non-ObjC platforms, 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 non-ObjC
// platforms.
extern "C"
#if defined(_WIN32)
__declspec(dllimport)
#endif
void swift_retain(void *);

DISPATCH_RUNTIME_STDLIB_INTERFACE
extern "C" void * objc_retainAutoreleasedReturnValue(void *obj) {
if (obj) {
swift_retain(obj);
return obj;
}
else return NULL;
}

#if defined(_WIN32)
extern "C" void *(*__imp_objc_retainAutoreleasedReturnValue)(void *) =
&objc_retainAutoreleasedReturnValue;
#endif

#endif // !USE_OBJC

0 comments on commit 292273a

Please sign in to comment.