diff --git a/ChangeLog b/ChangeLog index 4bf985c49..704639f26 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-12-27 David Chisnall + + * Headers/Additions/GNUstepBase/GSBlocks.h: Added block macros. + 2009-12-23 Wolfgang Lux * Source/NSUndoManager.m (_canCoalesceUndoWithTarget:selector:object): diff --git a/Headers/Additions/GNUstepBase/GSBlocks.h b/Headers/Additions/GNUstepBase/GSBlocks.h new file mode 100644 index 000000000..a9532771b --- /dev/null +++ b/Headers/Additions/GNUstepBase/GSBlocks.h @@ -0,0 +1,32 @@ + +/* Define the has_feature pseudo-macro for GCC. */ +#ifndef __has_feature +#define __has_feature(x) 0 +#endif + +#if __has_feature(blocks) +/** + * Defines a block type. Will work whether or not the compiler natively + * supports blocks. + */ +#define DEFINE_BLOCK_TYPE(name, retTy, argTys, ...) \ +typedef retTy(^name)(argTys, ## __VA_ARGS__) +/** + * Calls a block. Works irrespective of whether the compiler supports blocks. + */ +#define CALL_BLOCK(block, args, ...) \ + block(args, ## __VA_ARGS__) +/* Fall-back versions for when the compiler doesn't have native blocks support. + */ +#else +#define DEFINE_BLOCK_TYPE(name, retTy, argTys, ...) \ + typedef struct {\ + void *isa;\ + int flags;\ + int reserved;\ + retTy (*invoke)(void*, argTys, ## __VA_ARGS__);\ + } *name +#define CALL_BLOCK(block, args, ...) \ + block->invoke(block, args, ## __VA_ARGS__) +#endif +