Text system misuses objc_{load,store}Weak in some cases

Originator:twiomood
Number:rdar://30860017 Date Originated:05-Mar-2017 04:57 PM
Status:Open Resolved:
Product:macOS Product Version:10.12.3
Classification:Other Bug Reproducible:Always
 
Area:
AppKit

Summary:
When setting up a text system manually in order to use custom subclasses, the text system provokes a warning about objc_{load,store}Weak being used incorrectly.

Steps to Reproduce:
- Open the attached sample
- Enable the "Malloc Scribble" diagnostic option (and possible Malloc History to track down the identities of the objects involved later)
- Set a symbolic breakpoint on "objc_weak_error"
- Run the app
- The load time code will build up a text system attached to a text storage
- Click the button, this will tear down the old text system and replace it with a new one (still attached to the same text storage)

Expected Results:
- No misuse of ObjC weak references.

Actual Results:
- Breakpoint is hit

Version:
macOS 10.12.3


Notes:
Poking around, it looks like maybe the storage that is being misused is the private _textView ivar in NSTextContainer. Perhaps the "default text system" code is OK, but the manual setup path is directly assigning to the ivar instead of doing objc_storeWeak to clear the _textView.

Configuration:
Xcode 8.2.1


Attachments:
'TextContainerWeakTextView.zip' was successfully uploaded.

Sample code at <https://www.dropbox.com/s/k9ef9400gqmlxmk/TextContainerWeakTextView.zip?dl=0>

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!