Skip to content

Remove objc_retainAutoreleasedReturnValue workaround. #819

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 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
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
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