[cfe-dev] Blocks: implementation details
Chris Lattner
clattner at apple.com
Sun Oct 12 10:32:23 PDT 2008
On Sep 1, 2008, at 8:42 AM, Johannes Fortmann wrote:
> Looking at the implementation of blocks in gcc, it seems that while
> the block struct is documented like
> struct block_1 {
> struct invok_impl impl;
> void *CopyFuncPtr; // only if BLOCK_HAS_COPY_DISPOSE is set
> void *DestroyFuncPtr; // only if BLOCK_HAS_COPY_DISPOSE is set
> int x; // ref variable list ...
> int *y; // byref variable list
> };
> (that's roughly consistent with how the test is built, with the first
> bytes of the block being an isa pointer), but the actual code defines
> it as
> struct block_1 {
> struct invok_impl *impl;
> ...
> };
> (i.e. the first bytes of the block point to something with an isa
> pointer; not nearly as useful)
>
> Is there a reason for this? It doesn't seem to be just an oversight;
> but of course defining blocks that way would take away a lot of the
> neatness of the whole implementation.
> Being able to store raw blocks in objc data structures would be so
> much cooler than having to define a wrapper class.
Blocks do end up having an "isa", but the only messages you can really
send to them are retain/release. This does allow you to add them to
collections etc without a wrapper.
-Chris
More information about the cfe-dev
mailing list