allending/Kiwi — pull request #413 by sharplet (2013-11-26 21:34:32+00:00)
Title: Fix build errors when compiling `let` under ARC

Created a `KW_LET_REF` macro to abstract the complexity of getting
pointer to a `__block` variable on the heap. It works like so:

```objc
(__autoreleasing id *) /* (5) cast result as `id *` */
(
(void *(^)(void)) /* (3) cast back to a block */
KW_ARC_AUTORELEASE( /* (2) if not ARC, autorelease the block */
[^{
void *ref = &var; return ref;
} copy] /* (1) block returns a pointer to a copied block object */
)
)() /* (4) invoke the block immediately */
```

This resolves two issues that occurred under ARC:

- Using `__autoreleasing id *` to capture a reference to a `__block id`
variable gave this error:

initializing '__autoreleasing id *' with an expression of type
'__strong id *' changes retain/release properties of pointer

Changing to `__strong id *` yielded this:

passing address of non-local object to __autoreleasing parameter for
write-back

Using `void *` opts us out of reference counting, resolving the errors.

- Switching to `copy` instead of `Block_copy` caused the static analyser
to reveal an issue where the block is never released when compiled
without ARC. Added the `KW_ARC_AUTORELEASE` macro that wraps the block
in a call to `autorelease` when ARC is not present.