Skip to content

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

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