Skip to content

[5.9][Runtime] Immediate release and return when destroying partial instance of pure ObjC class. #65822

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
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
11 changes: 11 additions & 0 deletions stdlib/public/runtime/HeapObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,17 @@ void swift::swift_deallocPartialClassInstance(HeapObject *object,
// Destroy ivars
auto *classMetadata = _swift_getClassOfAllocated(object)->getClassObject();
assert(classMetadata && "Not a class?");

#if SWIFT_OBJC_INTEROP
// If the object's class is already pure ObjC class, just release it and move
// on. There are no ivar destroyers. This avoids attempting to mutate
// placeholder objects statically created in read-only memory.
if (classMetadata->isPureObjC()) {
objc_release((id)object);
return;
}
#endif

while (classMetadata != metadata) {
#if SWIFT_OBJC_INTEROP
// If we have hit a pure Objective-C class, we won't see another ivar
Expand Down