Skip to content

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

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

Conversation

mikeash
Copy link
Contributor

@mikeash mikeash commented May 8, 2023

Make swift_deallocPartialClassInstance check if the object's class is a pure ObjC class, in which case there are no ivar destroyers and we can just return immediately.

It's possible for an allocWithZone: override to cause self to be a special object constructed in read-only memory. swift_deallocPartialClassInstance calls object_setClass to avoid running the dealloc method of any Swift subclasses, but this call crashes if self is read-only. It's unnecessary when the object's class is pure ObjC and therefore there are no Swift subclasses, so just skip it entirely.

rdar://107756747

@mikeash mikeash requested a review from al45tair May 8, 2023 21:25
@mikeash mikeash requested a review from jckarter May 8, 2023 21:30
@mikeash
Copy link
Contributor Author

mikeash commented May 9, 2023

@swift-ci please test and merge

// 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. Looks like this file somehow doesn't include the definition of id; seems odd that it's got objc_release(), but not id.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh silly me, this needs to be guarded by OBJC_INTEROP too.

…ce of pure ObjC class.

Make swift_deallocPartialClassInstance check if the object's class is a pure ObjC class, in which case there are no ivar destroyers and we can just return immediately.

It's possible for an allocWithZone: override to cause self to be a special object constructed in read-only memory. swift_deallocPartialClassInstance calls object_setClass to avoid running the dealloc method of any Swift subclasses, but this call crashes if self is read-only. It's unnecessary when the object's class is pure ObjC and therefore there are no Swift subclasses, so just skip it entirely.

rdar://107756747
@mikeash mikeash force-pushed the dealloc-partial-class-instance-setclass-readonly branch from 90e1e0a to 3a396af Compare May 9, 2023 20:47
@mikeash
Copy link
Contributor Author

mikeash commented May 9, 2023

@swift-ci please test and merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants