Index: src/OFAutoreleasePool.m ================================================================== --- src/OFAutoreleasePool.m +++ src/OFAutoreleasePool.m @@ -16,23 +16,22 @@ #include "config.h" #include -#include - #import "OFAutoreleasePool.h" #import "OFArray.h" +#import "OFNotImplementedException.h" + +#import "macros.h" #ifndef OF_COMPILER_TLS # import "threading.h" # import "OFInitializationFailedException.h" #endif -#import "OFNotImplementedException.h" - extern id _objc_rootAutorelease(id); extern void* objc_autoreleasePoolPush(void); extern void objc_autoreleasePoolPop(void*); #ifdef OF_COMPILER_TLS @@ -88,11 +87,11 @@ if (first == NULL) #ifdef OF_COMPILER_TLS first = pool; #else - assert(of_tlskey_set(firstKey, pool)); + OF_ENSURE(of_tlskey_set(firstKey, pool)); #endif _objc_rootAutorelease(self); } @catch (id e) { [self release]; @@ -134,11 +133,11 @@ #ifdef OF_COMPILER_TLS if (first == pool) first = NULL; #else if (of_tlskey_get(firstKey) == pool) - assert(of_tlskey_set(firstKey, NULL)); + OF_ENSURE(of_tlskey_set(firstKey, NULL)); #endif objc_autoreleasePoolPop(pool); [super dealloc]; Index: src/OFBlock.m ================================================================== --- src/OFBlock.m +++ src/OFBlock.m @@ -18,12 +18,10 @@ #include #include #include -#include - #if defined(OF_APPLE_RUNTIME) && !defined(__OBJC2__) # import #elif defined(OF_OBJFW_RUNTIME) # import "runtime-private.h" #endif @@ -32,10 +30,11 @@ #import "OFAllocFailedException.h" #import "OFInitializationFailedException.h" #import "OFNotImplementedException.h" +#import "macros.h" #ifdef OF_ATOMIC_OPS # import "atomic.h" #endif #ifdef OF_THREADS # import "threading.h" @@ -199,13 +198,13 @@ #if defined(OF_ATOMIC_OPS) of_atomic_inc_int(&block->flags); #else unsigned hash = SPINLOCK_HASH(block); - assert(of_spinlock_lock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); block->flags++; - assert(of_spinlock_unlock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); #endif } return block; } @@ -226,22 +225,22 @@ free(block); } #else unsigned hash = SPINLOCK_HASH(block); - assert(of_spinlock_lock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); if ((--block->flags & OF_BLOCK_REFCOUNT_MASK) == 0) { - assert(of_spinlock_unlock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); if (block->flags & OF_BLOCK_HAS_COPY_DISPOSE) block->descriptor->dispose_helper(block); free(block); return; } - assert(of_spinlock_unlock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); #endif } void _Block_object_assign(void *dst_, const void *src_, const int flags_) Index: src/OFDate.m ================================================================== --- src/OFDate.m +++ src/OFDate.m @@ -20,11 +20,10 @@ #include #include #include #include #include -#include #include #import "OFDate.h" #import "OFString.h" @@ -217,11 +216,11 @@ { struct timeval t; self = [super init]; - assert(!gettimeofday(&t, NULL)); + OF_ENSURE(!gettimeofday(&t, NULL)); seconds = t.tv_sec; seconds += (double)t.tv_usec / 1000000; return self; @@ -623,11 +622,11 @@ - (double)timeIntervalSinceNow { struct timeval t; double seconds_; - assert(!gettimeofday(&t, NULL)); + OF_ENSURE(!gettimeofday(&t, NULL)); seconds_ = t.tv_sec; seconds_ += (double)t.tv_usec / 1000000; return seconds - seconds_; Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -727,13 +727,13 @@ - retain { #if defined(OF_ATOMIC_OPS) of_atomic_inc_32(&PRE_IVAR->retainCount); #elif defined(OF_THREADS) - assert(of_spinlock_lock(&PRE_IVAR->retainCountSpinlock)); + OF_ENSURE(of_spinlock_lock(&PRE_IVAR->retainCountSpinlock)); PRE_IVAR->retainCount++; - assert(of_spinlock_unlock(&PRE_IVAR->retainCountSspinlock)); + OF_ENSURE(of_spinlock_unlock(&PRE_IVAR->retainCountSspinlock)); #else PRE_IVAR->retainCount++; #endif return self; @@ -751,13 +751,13 @@ if (of_atomic_dec_32(&PRE_IVAR->retainCount) <= 0) [self dealloc]; #elif defined(OF_THREADS) size_t c; - assert(of_spinlock_lock(&PRE_IVAR->retainCountSpinlock)); + OF_ENSURE(of_spinlock_lock(&PRE_IVAR->retainCountSpinlock)); c = --PRE_IVAR->retainCount; - assert(of_spinlock_unlock(&PRE_IVAR->retainCountSpinlock)); + OF_ENSURE(of_spinlock_unlock(&PRE_IVAR->retainCountSpinlock)); if (c == 0) [self dealloc]; #else if (--PRE_IVAR->retainCount == 0) Index: src/OFStreamObserver.m ================================================================== --- src/OFStreamObserver.m +++ src/OFStreamObserver.m @@ -17,12 +17,13 @@ #include "config.h" #define OF_STREAM_OBSERVER_M #define __NO_EXT_QNX -#include #include + +#include #import "OFStreamObserver.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFStream.h" @@ -44,10 +45,12 @@ #endif #import "OFInitializationFailedException.h" #import "OFNotImplementedException.h" #import "OFOutOfRangeException.h" + +#import "macros.h" enum { QUEUE_ADD = 0, QUEUE_REMOVE = 1, QUEUE_READ = 0, @@ -194,13 +197,13 @@ } @finally { [mutex unlock]; } #ifndef _WIN32 - assert(write(cancelFD[1], "", 1) > 0); + OF_ENSURE(write(cancelFD[1], "", 1) > 0); #else - assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, + OF_ENSURE(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, sizeof(cancelAddr)) > 0); #endif } - (void)addStreamForWriting: (OFStream*)stream @@ -216,13 +219,13 @@ } @finally { [mutex unlock]; } #ifndef _WIN32 - assert(write(cancelFD[1], "", 1) > 0); + OF_ENSURE(write(cancelFD[1], "", 1) > 0); #else - assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, + OF_ENSURE(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, sizeof(cancelAddr)) > 0); #endif } - (void)removeStreamForReading: (OFStream*)stream @@ -238,13 +241,13 @@ } @finally { [mutex unlock]; } #ifndef _WIN32 - assert(write(cancelFD[1], "", 1) > 0); + OF_ENSURE(write(cancelFD[1], "", 1) > 0); #else - assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, + OF_ENSURE(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, sizeof(cancelAddr)) > 0); #endif } - (void)removeStreamForWriting: (OFStream*)stream @@ -260,13 +263,13 @@ } @finally { [mutex unlock]; } #ifndef _WIN32 - assert(write(cancelFD[1], "", 1) > 0); + OF_ENSURE(write(cancelFD[1], "", 1) > 0); #else - assert(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, + OF_ENSURE(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, sizeof(cancelAddr)) > 0); #endif } - (void)_addFileDescriptorForReading: (int)fd Index: src/OFStreamObserver_kqueue.m ================================================================== --- src/OFStreamObserver_kqueue.m +++ src/OFStreamObserver_kqueue.m @@ -29,10 +29,12 @@ #import "OFDataArray.h" #import "OFAutoreleasePool.h" #import "OFInitializationFailedException.h" #import "OFOutOfMemoryException.h" + +#import "macros.h" #define EVENTLIST_SIZE 64 @implementation OFStreamObserver_kqueue - init @@ -137,11 +139,11 @@ for (i = 0; i < events; i++) { if (eventList[i].ident == cancelFD[0]) { char buffer; - assert(read(cancelFD[0], &buffer, 1) > 0); + OF_ENSURE(read(cancelFD[0], &buffer, 1) > 0); continue; } if (eventList[i].flags & EV_ERROR) { Index: src/OFStreamObserver_poll.m ================================================================== --- src/OFStreamObserver_poll.m +++ src/OFStreamObserver_poll.m @@ -16,19 +16,20 @@ #include "config.h" #define __NO_EXT_QNX -#include #include #include #import "OFStreamObserver_poll.h" #import "OFDataArray.h" #import "OFAutoreleasePool.h" #import "OFOutOfRangeException.h" + +#import "macros.h" @implementation OFStreamObserver_poll - init { self = [super init]; @@ -148,11 +149,11 @@ for (i = 0; i < nFDs; i++) { if (FDsCArray[i].revents & POLLIN) { if (FDsCArray[i].fd == cancelFD[0]) { char buffer; - assert(read(cancelFD[0], &buffer, 1) > 0); + OF_ENSURE(read(cancelFD[0], &buffer, 1) > 0); FDsCArray[i].revents = 0; continue; } Index: src/OFStreamObserver_select.m ================================================================== --- src/OFStreamObserver_select.m +++ src/OFStreamObserver_select.m @@ -17,17 +17,18 @@ #include "config.h" #define __NO_EXT_QNX #include -#include #include #import "OFStreamObserver_select.h" #import "OFStream.h" #import "OFArray.h" #import "OFAutoreleasePool.h" + +#import "macros.h" @implementation OFStreamObserver_select - init { self = [super init]; @@ -105,13 +106,13 @@ } if (FD_ISSET(cancelFD[0], &readFDs_)) { char buffer; #ifndef _WIN32 - assert(read(cancelFD[0], &buffer, 1) > 0); + OF_ENSURE(read(cancelFD[0], &buffer, 1) > 0); #else - assert(recvfrom(cancelFD[0], &buffer, 1, 0, NULL, NULL) > 0); + OF_ENSURE(recvfrom(cancelFD[0], &buffer, 1, 0, NULL, NULL) > 0); #endif } objects = [readStreams objects]; count = [readStreams count]; Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -16,10 +16,12 @@ #import "OFObject.h" #include #include +#include +#include #if defined(OF_APPLE_RUNTIME) # import #endif @@ -76,10 +78,17 @@ # define OF_PPC_ASM # elif defined(__arm__) || defined(__ARM__) # define OF_ARM_ASM # endif #endif + +#define OF_ENSURE(cond) \ + if (!(cond)) { \ + fprintf(stderr, "Failed to ensure condition in " \ + __FILE__ ":%d:\n" #cond "\n", __LINE__); \ + abort(); \ + } #ifdef OF_OBJFW_RUNTIME # define objc_lookUpClass objc_lookup_class #endif Index: src/runtime/property.m ================================================================== --- src/runtime/property.m +++ src/runtime/property.m @@ -16,14 +16,13 @@ #include "config.h" #include -#include - #import "OFObject.h" +#import "macros.h" #ifdef OF_THREADS # import "threading.h" # define NUM_SPINLOCKS 8 /* needs to be a power of 2 */ # define SPINLOCK_HASH(p) ((unsigned)((uintptr_t)p >> 4) & (NUM_SPINLOCKS - 1)) static of_spinlock_t spinlocks[NUM_SPINLOCKS]; @@ -49,16 +48,15 @@ if (atomic) { id *ptr = (id*)(void*)((char*)self + offset); #ifdef OF_THREADS unsigned hash = SPINLOCK_HASH(ptr); - assert(of_spinlock_lock(&spinlocks[hash])); - + OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); @try { return [[*ptr retain] autorelease]; } @finally { - assert(of_spinlock_unlock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); } #else return [[*ptr retain] autorelease]; #endif } @@ -73,12 +71,11 @@ if (atomic) { id *ptr = (id*)(void*)((char*)self + offset); #ifdef OF_THREADS unsigned hash = SPINLOCK_HASH(ptr); - assert(of_spinlock_lock(&spinlocks[hash])); - + OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); @try { #endif id old = *ptr; switch (copy) { @@ -93,11 +90,11 @@ } [old release]; #ifdef OF_THREADS } @finally { - assert(of_spinlock_unlock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); } #endif return; } @@ -130,17 +127,15 @@ { if (atomic) { #ifdef OF_THREADS unsigned hash = SPINLOCK_HASH(src); - assert(of_spinlock_lock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); #endif - memcpy(dest, src, size); - #ifdef OF_THREADS - assert(of_spinlock_unlock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); #endif return; } @@ -153,19 +148,17 @@ { if (atomic) { #ifdef OF_THREADS unsigned hash = SPINLOCK_HASH(src); - assert(of_spinlock_lock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); #endif - memcpy(dest, src, size); - #ifdef OF_THREADS - assert(of_spinlock_unlock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); #endif return; } memcpy(dest, src, size); }