wrap c callbacks by blocks (__bridge_transfer and blocks)
===

I'm writing an Obj-C wrapper to a standard C API. I would like to replace C callbacks into blocks.

Let imagine a C API:

    void my_async_function(void (* callback)(void *), void *udata);

The Obj-C wrapper looks like this:

    - (void)myAsyncFunction:(dispatch_block_t)block
    {
        void *udata = (__bridge_retained void *)block;
        my_async_function(my_callback, udata);
    }

    void my_callback(void *udata)
    {
        dispatch_block_t block = (__bridge_transfer dispatch_block_t)udata;
        block();
    }

`__bridge_retained` and `__bridge_transfer` work well in many cases but on blocks, they result in a very strange behavior.

The assembly code of myAsyncFunction: in ARC O3 has no retain at all.

What is very strange is that the following core, generate a `_objc_retainBlock`, what I expected for myAsyncFunction:

    void *a_global_var;

    - (void)myAsyncFunction2:(dispatch_block_t)block
    {
        void *udata = (__bridge_retained void *)block;
        a_global_var = udata;
        my_async_function(my_callback, udata);
    }

Can we call that a bug of the compiler?
If not, what rule the compiler is following?

Similar topics:

- http://stackoverflow.com/questions/8824996/ios-block-property-directly-set-crashes-when-accessed
- http://stackoverflow.com/questions/11106224/how-to-cast-blocks-to-and-from-void
