@@ -10,15 +10,15 @@ */ #include "config.h" #include -#include #include #include #import "OFBlock.h" +#import "OFExceptions.h" #import "atomic.h" /// \cond internal @protocol RetainRelease - retain; @@ -105,26 +105,32 @@ { __objc_exec_class(&module); } /* End of ObjC module */ #else -void *_NSConcreteStackBlock; -void *_NSConcreteGlobalBlock; -void *_NSConcreteMallocBlock; +extern void *_NSConcreteStackBlock; +extern void *_NSConcreteGlobalBlock; +extern void *_NSConcreteMallocBlock; #endif +#ifndef HAVE_BLOCK_COPY +static struct { + Class isa; +} alloc_failed_exception; + void* _Block_copy(const void *block_) { of_block_literal_t *block = (of_block_literal_t*)block_; if (block->isa == (Class)&_NSConcreteStackBlock) { of_block_literal_t *copy; if ((copy = malloc(block->descriptor->size)) == NULL) { - fputs("Not enough memory to copy block!\n", stderr); - exit(1); + alloc_failed_exception.isa = + [OFAllocFailedException class]; + @throw (OFAllocFailedException*)&alloc_failed_exception; } memcpy(copy, block, block->descriptor->size); copy->isa = (Class)&_NSConcreteMallocBlock; copy->reserved++; @@ -174,13 +180,14 @@ of_block_byref_t *src = (of_block_byref_t*)src_; of_block_byref_t **dst = (of_block_byref_t**)dst_; if ((src->flags & ~OF_BLOCK_HAS_COPY_DISPOSE) == 0) { if ((*dst = malloc(src->size)) == NULL) { - fputs("Not enough memory for block " - "variables!\n", stderr); - exit(1); + alloc_failed_exception.isa = + [OFAllocFailedException class]; + @throw (OFAllocFailedException*) + &alloc_failed_exception; } if (src->forwarding == src) src->forwarding = *dst; @@ -219,13 +226,18 @@ free(obj); } break; } } +#endif /// \cond internal @implementation OFBlock ++ (void)initialize +{ +} + + (Class)class { return self; } @@ -237,6 +249,17 @@ - (void)release { Block_release(self); } @end + +#if !defined(OF_GNU_RUNTIME) && !defined(OF_OBJFW_RUNTIME) +@implementation OFStackBlock +@end + +@implementation OFGlobalBlock +@end + +@implementation OFMallocBlock +@end +#endif /// \endcond