[cfe-dev] Blocks: implementation details

Johannes Fortmann johannes.fortmann at googlemail.com
Mon Sep 1 08:42:12 PDT 2008


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.

Just curious, and thanks for implementing this!

Cheers,
Johannes Fortmann



More information about the cfe-dev mailing list