ObjFW  View Ticket

Ticket UUID: 5b31b3f45e9a8150eef903081594e04beea8f4f5
Title: Weak references are broken with the Apple runtime
Status: Fixed Type: Code Defect
Severity: Severe Priority: Immediate
Subsystem: Resolution: Fixed
Last Modified: 2024-05-22 20:14:03
Version Found In: Milestone: 1.0
User Comments:
js added on 2020-10-25 21:09:05:

The Apple runtime seems to make some assumptions about root objects being NSObject, and as a result segfaults when using weak.


js added on 2020-10-25 22:10:52:

Looking at the code, it seems that objc_destructInstance() does not zero weak references at all in the Apple runtime. It seems to make weak references work at all, it is necessary to call into the runtime functions to allocate, retain, release and dealloc objects. Unfortunately, this does not allow to have some extra space before the object, as the current +[alloc] does for memory blocks belonging to the object.


js added on 2020-11-12 00:34:04:

Turns out the configure check for objc_constructInstance was broken, and hence runtime/instance.m was used for objc_destructInstance instead of the runtime's, resulting in weak references not being handled on dealloc.

Fixed in [4c16806252].