objc: create new blocks as stack blocks so Copy moves them - #518
Conversation
|
Let's continue the discussion at #523 |
|
Sure, keeping the discussion in #523. Outcome there: this is not a use-after-free. I left the change as a naming/clarity one only: the constant stays |
NewBlock built its template with an __NSMallocBlock__ isa, for which _Block_copy is a no-op retain of the Go-side allocation. The Block then points at Go memory invisible to the collector. Start from __NSStackBlock__ so Copy relocates the block to the heap as the ABI requires.
Block_copy chooses its path from the flags word and gives the relocated block its __NSMallocBlock__ isa itself, so the isa of the template is a naming matter: __NSStackBlock__ describes a block that has not been copied to the heap yet, as the Block ABI prescribes.
d08147b to
346e3c8
Compare
hajimehoshi
left a comment
There was a problem hiding this comment.
LGTM, assuming this is just a code clarification, not a bug fix
|
@TotallyGamerJet PTAL |
What issue is this addressing?
Closes #523
What type of issue is this addressing?
bug
What this PR does | solves
NewBlock built its template with an NSMallocBlock isa, for which _Block_copy is a no-op retain of the Go-side allocation. The Block then points at Go memory invisible to the collector. Start from NSStackBlock so Copy relocates the block to the heap as the ABI requires.