Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -771,39 +771,10 @@ ]) AS_IF([test x"$ac_cv_c_bigendian" = x"universal"], [ AC_DEFINE(OF_UNIVERSAL, 1, [Whether we are building a universal binary]) ]) -AC_MSG_CHECKING(for SIZE_MAX) -AC_EGREP_CPP(egrep_cpp_yes, [ - #include - #include - - #ifdef SIZE_MAX - egrep_cpp_yes - #endif -], [ - AC_MSG_RESULT(yes) -], [ - AC_MSG_RESULT(no) - AC_MSG_CHECKING(for SIZE_T_MAX) - AC_EGREP_CPP(egrep_cpp_yes, [ - #include - #include - - #ifdef SIZE_T_MAX - egrep_cpp_yes - #endif - ], [ - AC_MSG_RESULT(yes) - size_max="SIZE_T_MAX" - ], [ - AC_MSG_RESULT(no) - size_max="(~(size_t)0)" - ]) - AC_DEFINE_UNQUOTED(SIZE_MAX, $size_max, [Maximum value for size_t]) -]) AC_MSG_CHECKING(for SSIZE_MAX) AC_EGREP_CPP(egrep_cpp_yes, [ #include #include @@ -812,12 +783,11 @@ #endif ], [ AC_MSG_RESULT(yes) ], [ AC_MSG_RESULT(no) - AC_DEFINE(SSIZE_MAX, [((ssize_t)(SIZE_MAX / 2))], - [Maximum value for ssize_t]) + AC_DEFINE(SSIZE_MAX, [(SIZE_MAX / 2)], [Maximum value for ssize_t]) ]) AC_MSG_CHECKING(for UINTPTR_MAX) AC_EGREP_CPP(egrep_cpp_yes, [ #include #include @@ -827,11 +797,13 @@ #endif ], [ AC_MSG_RESULT(yes) ], [ AC_MSG_RESULT(no) - AC_DEFINE(UINTPTR_MAX, [(~(uintptr_t)0)], [Maximum value for uintptr_t]) + AC_CHECK_SIZEOF(uintptr_t) + AC_DEFINE(UINTPTR_MAX, + [(SIZEOF_UINTPTR_T * CHAR_BIT)], [Maximum value for uintptr_t]) ]) AC_CHECK_HEADER(inttypes.h, [AC_DEFINE(OF_HAVE_INTTYPES_H, 1, [Whether we have inttypes.h])]) @@ -877,41 +849,10 @@ AC_MSG_RESULT($fp_endianess) AS_IF([test x"$fp_endianess" = x"unknown"], [ AC_MSG_ERROR( [Floating point implementation does not conform to IEEE 754!])]) -AC_MSG_CHECKING(for INFINITY) -AC_COMPILE_IFELSE([ - AC_LANG_PROGRAM([ - #include - #include - ], [ - printf("%f", INFINITY); - ]) -], [ - AC_MSG_RESULT(yes) -], [ - AC_MSG_RESULT(no) - - AC_MSG_CHECKING(for __builtin_inf) - AC_COMPILE_IFELSE([ - AC_LANG_PROGRAM([ - #include - ], [ - printf("%f", __builtin_inf()); - ]) - ], [ - AC_MSG_RESULT(yes) - AC_DEFINE(INFINITY, [(__builtin_inf())], - [Workaround for missing INFINITY]) - ], [ - AC_MSG_RESULT(no) - - AC_MSG_ERROR([Neither INFINITY or __builtin_inf was found!]) - ]) -]) - case "$host_cpu" in arm* | earm*) AC_MSG_CHECKING(for VFP2 or above) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([], [ Index: src/OFBlock.m ================================================================== --- src/OFBlock.m +++ src/OFBlock.m @@ -191,13 +191,13 @@ #ifdef OF_HAVE_ATOMIC_OPS of_atomic_int_inc(&block->flags); #else unsigned hash = SPINLOCK_HASH(block); - OF_ENSURE(of_spinlock_lock(&blockSpinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&blockSpinlocks[hash]) == 0); block->flags++; - OF_ENSURE(of_spinlock_unlock(&blockSpinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&blockSpinlocks[hash]) == 0); #endif } return block; } @@ -218,22 +218,22 @@ free(block); } #else unsigned hash = SPINLOCK_HASH(block); - OF_ENSURE(of_spinlock_lock(&blockSpinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&blockSpinlocks[hash]) == 0); if ((--block->flags & OF_BLOCK_REFCOUNT_MASK) == 0) { - OF_ENSURE(of_spinlock_unlock(&blockSpinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&blockSpinlocks[hash]) == 0); if (block->flags & OF_BLOCK_HAS_COPY_DISPOSE) block->descriptor->dispose_helper(block); free(block); return; } - OF_ENSURE(of_spinlock_unlock(&blockSpinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&blockSpinlocks[hash]) == 0); #endif } void _Block_object_assign(void *dst_, const void *src_, const int flags_) @@ -283,32 +283,33 @@ *dst = src->forwarding; } #else unsigned hash = SPINLOCK_HASH(src); - OF_ENSURE(of_spinlock_lock(&byrefSpinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&byrefSpinlocks[hash]) == 0); if (src->forwarding == src) src->forwarding = *dst; else { src->byref_dispose(*dst); free(*dst); *dst = src->forwarding; } - OF_ENSURE(of_spinlock_unlock(&byrefSpinlocks[hash])); + OF_ENSURE( + of_spinlock_unlock(&byrefSpinlocks[hash]) == 0); #endif } else *dst = src; #ifdef OF_HAVE_ATOMIC_OPS of_atomic_int_inc(&(*dst)->flags); #else unsigned hash = SPINLOCK_HASH(*dst); - OF_ENSURE(of_spinlock_lock(&byrefSpinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&byrefSpinlocks[hash]) == 0); (*dst)->flags++; - OF_ENSURE(of_spinlock_unlock(&byrefSpinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&byrefSpinlocks[hash]) == 0); #endif break; } } @@ -343,20 +344,21 @@ free(object); } #else unsigned hash = SPINLOCK_HASH(object); - OF_ENSURE(of_spinlock_lock(&byrefSpinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&byrefSpinlocks[hash]) == 0); if ((--object->flags & OF_BLOCK_REFCOUNT_MASK) == 0) { - OF_ENSURE(of_spinlock_unlock(&byrefSpinlocks[hash])); + OF_ENSURE( + of_spinlock_unlock(&byrefSpinlocks[hash]) == 0); if (object->flags & OF_BLOCK_HAS_COPY_DISPOSE) object->byref_dispose(object); free(object); } - OF_ENSURE(of_spinlock_unlock(&byrefSpinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&byrefSpinlocks[hash]) == 0); #endif break; } } @@ -363,12 +365,12 @@ @implementation OFBlock + (void)load { #ifndef OF_HAVE_ATOMIC_OPS for (size_t i = 0; i < NUM_SPINLOCKS; i++) - if (!of_spinlock_new(&blockSpinlocks[i]) || - !of_spinlock_new(&byrefSpinlocks[i])) + if (of_spinlock_new(&blockSpinlocks[i]) != 0 || + of_spinlock_new(&byrefSpinlocks[i]) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; #endif #ifdef OF_APPLE_RUNTIME Index: src/OFCondition.m ================================================================== --- src/OFCondition.m +++ src/OFCondition.m @@ -36,11 +36,11 @@ - (instancetype)init { self = [super init]; - if (!of_condition_new(&_condition)) { + if (of_condition_new(&_condition) != 0) { Class c = self.class; [self release]; @throw [OFInitializationFailedException exceptionWithClass: c]; } @@ -50,12 +50,14 @@ } - (void)dealloc { if (_conditionInitialized) { - if (!of_condition_free(&_condition)) { - OF_ENSURE(errno == EBUSY); + int error = of_condition_free(&_condition); + + if (error != 0) { + OF_ENSURE(error == EBUSY); @throw [OFConditionStillWaitingException exceptionWithCondition: self]; } } @@ -63,53 +65,60 @@ [super dealloc]; } - (void)wait { - if (!of_condition_wait(&_condition, &_mutex)) + int error = of_condition_wait(&_condition, &_mutex); + + if (error != 0) @throw [OFConditionWaitFailedException exceptionWithCondition: self - errNo: errno]; + errNo: error]; } #ifdef OF_AMIGAOS - (void)waitForConditionOrExecSignal: (ULONG *)signalMask { - if (!of_condition_wait_or_signal(&_condition, &_mutex, signalMask)) + int error = of_condition_wait_or_signal(&_condition, &_mutex, + signalMask); + + if (error != 0) @throw [OFConditionWaitFailedException exceptionWithCondition: self - errNo: errno]; + errNo: error]; } #endif - (bool)waitForTimeInterval: (of_time_interval_t)timeInterval { - if (!of_condition_timed_wait(&_condition, &_mutex, timeInterval)) { - if (errno == ETIMEDOUT) - return false; - else - @throw [OFConditionWaitFailedException - exceptionWithCondition: self - errNo: errno]; - } + int error = of_condition_timed_wait(&_condition, &_mutex, timeInterval); + + if (error == ETIMEDOUT) + return false; + + if (error != 0) + @throw [OFConditionWaitFailedException + exceptionWithCondition: self + errNo: error]; return true; } #ifdef OF_AMIGAOS - (bool)waitForTimeInterval: (of_time_interval_t)timeInterval orExecSignal: (ULONG *)signalMask { - if (!of_condition_timed_wait_or_signal(&_condition, &_mutex, - timeInterval, signalMask)) { - if (errno == ETIMEDOUT) - return false; - else - @throw [OFConditionWaitFailedException - exceptionWithCondition: self - errNo: errno]; - } + int error = of_condition_timed_wait_or_signal(&_condition, &_mutex, + timeInterval, signalMask); + + if (error == ETIMEDOUT) + return false; + + if (error != 0) + @throw [OFConditionWaitFailedException + exceptionWithCondition: self + errNo: error]; return true; } #endif @@ -127,19 +136,23 @@ } #endif - (void)signal { - if (!of_condition_signal(&_condition)) + int error = of_condition_signal(&_condition); + + if (error != 0) @throw [OFConditionSignalFailedException exceptionWithCondition: self - errNo: errno]; + errNo: error]; } - (void)broadcast { - if (!of_condition_broadcast(&_condition)) + int error = of_condition_broadcast(&_condition); + + if (error != 0) @throw [OFConditionBroadcastFailedException exceptionWithCondition: self - errNo: errno]; + errNo: error]; } @end Index: src/OFFileURLHandler.m ================================================================== --- src/OFFileURLHandler.m +++ src/OFFileURLHandler.m @@ -716,12 +716,17 @@ date.ds_Days = modificationTime / 86400; date.ds_Minute = ((LONG)modificationTime % 86400) / 60; date.ds_Tick = fmod(modificationTime, 60) * TICKS_PER_SECOND; +# ifdef OF_AMIGAOS4 + if (!SetDate([path cStringWithEncoding: [OFLocale encoding]], + &date) != 0) { +# else if (!SetFileDate([path cStringWithEncoding: [OFLocale encoding]], &date) != 0) { +# endif setErrno(); @throw [OFSetItemAttributesFailedException exceptionWithURL: URL attributes: attributes Index: src/OFMutex.m ================================================================== --- src/OFMutex.m +++ src/OFMutex.m @@ -37,11 +37,11 @@ - (instancetype)init { self = [super init]; - if (!of_mutex_new(&_mutex)) { + if (of_mutex_new(&_mutex) != 0) { Class c = self.class; [self release]; @throw [OFInitializationFailedException exceptionWithClass: c]; } @@ -51,12 +51,14 @@ } - (void)dealloc { if (_initialized) { - if (!of_mutex_free(&_mutex)) { - OF_ENSURE(errno == EBUSY); + int error = of_mutex_free(&_mutex); + + if (error != 0) { + OF_ENSURE(error == EBUSY); @throw [OFStillLockedException exceptionWithLock: self]; } } @@ -65,33 +67,39 @@ [super dealloc]; } - (void)lock { - if (!of_mutex_lock(&_mutex)) + int error = of_mutex_lock(&_mutex); + + if (error != 0) @throw [OFLockFailedException exceptionWithLock: self - errNo: errno]; + errNo: error]; } - (bool)tryLock { - if (!of_mutex_trylock(&_mutex)) { - if (errno == EBUSY) + int error = of_mutex_trylock(&_mutex); + + if (error != 0) { + if (error == EBUSY) return false; else @throw [OFLockFailedException exceptionWithLock: self - errNo: errno]; + errNo: error]; } return true; } - (void)unlock { - if (!of_mutex_unlock(&_mutex)) + int error = of_mutex_unlock(&_mutex); + + if (error != 0) @throw [OFUnlockFailedException exceptionWithLock: self - errNo: errno]; + errNo: error]; } - (OFString *)description { if (_name == nil) Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -321,12 +321,12 @@ } ((struct pre_ivar *)instance)->retainCount = 1; #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) - if OF_UNLIKELY (!of_spinlock_new( - &((struct pre_ivar *)instance)->retainCountSpinlock)) { + if OF_UNLIKELY (of_spinlock_new( + &((struct pre_ivar *)instance)->retainCountSpinlock) != 0) { free(instance); @throw [OFInitializationFailedException exceptionWithClass: class]; } #endif @@ -1131,13 +1131,13 @@ PRE_IVARS->retainCount++; # ifndef OF_AMIGAOS_M68K Permit(); # endif #else - OF_ENSURE(of_spinlock_lock(&PRE_IVARS->retainCountSpinlock)); + OF_ENSURE(of_spinlock_lock(&PRE_IVARS->retainCountSpinlock) == 0); PRE_IVARS->retainCount++; - OF_ENSURE(of_spinlock_unlock(&PRE_IVARS->retainCountSpinlock)); + OF_ENSURE(of_spinlock_unlock(&PRE_IVARS->retainCountSpinlock) == 0); #endif return self; } @@ -1167,13 +1167,13 @@ if (retainCount == 0) [self dealloc]; #else int retainCount; - OF_ENSURE(of_spinlock_lock(&PRE_IVARS->retainCountSpinlock)); + OF_ENSURE(of_spinlock_lock(&PRE_IVARS->retainCountSpinlock) == 0); retainCount = --PRE_IVARS->retainCount; - OF_ENSURE(of_spinlock_unlock(&PRE_IVARS->retainCountSpinlock)); + OF_ENSURE(of_spinlock_unlock(&PRE_IVARS->retainCountSpinlock) == 0); if (retainCount == 0) [self dealloc]; #endif } Index: src/OFRecursiveMutex.m ================================================================== --- src/OFRecursiveMutex.m +++ src/OFRecursiveMutex.m @@ -37,11 +37,11 @@ - (instancetype)init { self = [super init]; - if (!of_rmutex_new(&_rmutex)) { + if (of_rmutex_new(&_rmutex) != 0) { Class c = self.class; [self release]; @throw [OFInitializationFailedException exceptionWithClass: c]; } @@ -51,12 +51,14 @@ } - (void)dealloc { if (_initialized) { - if (!of_rmutex_free(&_rmutex)) { - OF_ENSURE(errno == EBUSY); + int error = of_rmutex_free(&_rmutex); + + if (error != 0) { + OF_ENSURE(error == EBUSY); @throw [OFStillLockedException exceptionWithLock: self]; } } @@ -65,33 +67,39 @@ [super dealloc]; } - (void)lock { - if (!of_rmutex_lock(&_rmutex)) + int error = of_rmutex_lock(&_rmutex); + + if (error != 0) @throw [OFLockFailedException exceptionWithLock: self - errNo: errno]; + errNo: error]; } - (bool)tryLock { - if (!of_rmutex_trylock(&_rmutex)) { - if (errno == EBUSY) + int error = of_rmutex_trylock(&_rmutex); + + if (error != 0) { + if (error == EBUSY) return false; else @throw [OFLockFailedException exceptionWithLock: self - errNo: errno]; + errNo: error]; } return true; } - (void)unlock { - if (!of_rmutex_unlock(&_rmutex)) + int error = of_rmutex_unlock(&_rmutex); + + if (error != 0) @throw [OFUnlockFailedException exceptionWithLock: self - errNo: errno]; + errNo: error]; } - (OFString *)description { if (_name == nil) Index: src/OFSecureData.m ================================================================== --- src/OFSecureData.m +++ src/OFSecureData.m @@ -121,21 +121,21 @@ # endif numPreallocatedPages--; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OF_ENSURE(of_tlskey_set(numPreallocatedPagesKey, - (void *)numPreallocatedPages)); + (void *)numPreallocatedPages) == 0); # endif page = preallocatedPages[numPreallocatedPages]; if (numPreallocatedPages == 0) { free(preallocatedPages); preallocatedPages = NULL; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OF_ENSURE(of_tlskey_set(preallocatedPagesKey, - preallocatedPages)); + preallocatedPages) == 0); # endif } return page; } @@ -171,14 +171,14 @@ lastPage = page; if (firstPage == NULL) firstPage = page; # else - OF_ENSURE(of_tlskey_set(lastPageKey, page)); + OF_ENSURE(of_tlskey_set(lastPageKey, page) == 0); if (of_tlskey_get(firstPageKey) == NULL) - OF_ENSURE(of_tlskey_set(firstPageKey, page)); + OF_ENSURE(of_tlskey_set(firstPageKey, page) == 0); # endif return page; } @@ -207,13 +207,13 @@ firstPage = page->next; if (lastPage == page) lastPage = page->previous; # else if (of_tlskey_get(firstPageKey) == page) - OF_ENSURE(of_tlskey_set(firstPageKey, page->next)); + OF_ENSURE(of_tlskey_set(firstPageKey, page->next) == 0); if (of_tlskey_get(lastPageKey) == page) - OF_ENSURE(of_tlskey_set(lastPageKey, page->previous)); + OF_ENSURE(of_tlskey_set(lastPageKey, page->previous) == 0); # endif free(page); } @@ -272,13 +272,14 @@ + (void)initialize { if (self != [OFSecureData class]) return; - if (!of_tlskey_new(&firstPageKey) || !of_tlskey_new(&lastPageKey) || - !of_tlskey_new(&preallocatedPagesKey) || - !of_tlskey_new(&numPreallocatedPagesKey)) + if (of_tlskey_new(&firstPageKey) != 0 || + of_tlskey_new(&lastPageKey) != 0 || + of_tlskey_new(&preallocatedPagesKey) != 0 || + of_tlskey_new(&numPreallocatedPagesKey) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; } #endif @@ -296,11 +297,11 @@ if (preallocatedPages != NULL) @throw [OFInvalidArgumentException exception]; preallocatedPages = of_alloc_zeroed(numPages, sizeof(struct page)); # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) - of_tlskey_set(preallocatedPagesKey, preallocatedPages); + OF_ENSURE(of_tlskey_set(preallocatedPagesKey, preallocatedPages) == 0); # endif @try { for (i = 0; i < numPages; i++) preallocatedPages[i] = addPage(false); @@ -314,12 +315,12 @@ @throw e; } numPreallocatedPages = numPages; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) - of_tlskey_set(numPreallocatedPagesKey, - (void *)(uintptr_t)numPreallocatedPages); + OF_ENSURE(of_tlskey_set(numPreallocatedPagesKey, + (void *)(uintptr_t)numPreallocatedPages) == 0); # endif #else @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; #endif Index: src/OFString+JSONParsing.m ================================================================== --- src/OFString+JSONParsing.m +++ src/OFString+JSONParsing.m @@ -29,10 +29,14 @@ #import "OFDictionary.h" #import "OFNumber.h" #import "OFNull.h" #import "OFInvalidJSONException.h" + +#ifndef INFINITY +# define INFINITY __builtin_inf() +#endif int _OFString_JSONParsing_reference; static id nextObject(const char **pointer, const char *stop, size_t *line, size_t depthLimit); Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -74,10 +74,14 @@ #ifdef OF_AMIGAOS_M68K /* libnix has strtod, but not strtof */ # define strtof strtod #endif + +#ifndef INFINITY +# define INFINITY __builtin_inf() +#endif static struct { Class isa; } placeholder; Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -101,11 +101,11 @@ callMain(id object) { OFThread *thread = (OFThread *)object; OFString *name; - if (!of_tlskey_set(threadSelfKey, thread)) + if (of_tlskey_set(threadSelfKey, thread) != 0) @throw [OFInitializationFailedException exceptionWithClass: thread.class]; #ifndef OF_OBJFW_RUNTIME thread->_pool = objc_autoreleasePoolPush(); @@ -164,11 +164,11 @@ + (void)initialize { if (self != [OFThread class]) return; - if (!of_tlskey_new(&threadSelfKey)) + if (of_tlskey_new(&threadSelfKey) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; } + (instancetype)thread @@ -348,21 +348,21 @@ { mainThread = [[OFThread alloc] init]; mainThread->_thread = of_thread_current(); mainThread->_running = OF_THREAD_RUNNING; - if (!of_tlskey_set(threadSelfKey, mainThread)) + if (of_tlskey_set(threadSelfKey, mainThread) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; } - (instancetype)init { self = [super init]; @try { - if (!of_thread_attr_init(&_attr)) + if (of_thread_attr_init(&_attr) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } @catch (id e) { [self release]; @throw e; @@ -409,10 +409,12 @@ # endif } - (void)start { + int error; + if (_running == OF_THREAD_RUNNING) @throw [OFThreadStillRunningException exceptionWithThread: self]; if (_running == OF_THREAD_WAITING_FOR_JOIN) { @@ -422,30 +424,31 @@ [self retain]; _running = OF_THREAD_RUNNING; - if (!of_thread_new(&_thread, - [_name cStringWithEncoding: [OFLocale encoding]], callMain, self, - &_attr)) { + if ((error = of_thread_new(&_thread, [_name cStringWithEncoding: + [OFLocale encoding]], callMain, self, &_attr)) != 0) { [self release]; @throw [OFThreadStartFailedException exceptionWithThread: self - errNo: errno]; + errNo: error]; } } - (id)join { + int error; + if (_running == OF_THREAD_NOT_RUNNING) @throw [OFThreadJoinFailedException exceptionWithThread: self errNo: EINVAL]; - if (!of_thread_join(_thread)) + if ((error = of_thread_join(_thread)) != 0) @throw [OFThreadJoinFailedException exceptionWithThread: self - errNo: errno]; + errNo: error]; _running = OF_THREAD_NOT_RUNNING; return _returnValue; } Index: src/condition.h ================================================================== --- src/condition.h +++ src/condition.h @@ -50,21 +50,21 @@ #endif #ifdef __cplusplus extern "C" { #endif -extern bool of_condition_new(of_condition_t *condition); -extern bool of_condition_signal(of_condition_t *condition); -extern bool of_condition_broadcast(of_condition_t *condition); -extern bool of_condition_wait(of_condition_t *condition, of_mutex_t *mutex); -extern bool of_condition_timed_wait(of_condition_t *condition, +extern int of_condition_new(of_condition_t *condition); +extern int of_condition_signal(of_condition_t *condition); +extern int of_condition_broadcast(of_condition_t *condition); +extern int of_condition_wait(of_condition_t *condition, of_mutex_t *mutex); +extern int of_condition_timed_wait(of_condition_t *condition, of_mutex_t *mutex, of_time_interval_t timeout); #ifdef OF_AMIGAOS -extern bool of_condition_wait_or_signal(of_condition_t *condition, +extern int of_condition_wait_or_signal(of_condition_t *condition, of_mutex_t *mutex, ULONG *signalMask); -extern bool of_condition_timed_wait_or_signal(of_condition_t *condition, +extern int of_condition_timed_wait_or_signal(of_condition_t *condition, of_mutex_t *mutex, of_time_interval_t timeout, ULONG *signalMask); #endif -extern bool of_condition_free(of_condition_t *condition); +extern int of_condition_free(of_condition_t *condition); #ifdef __cplusplus } #endif Index: src/exceptions/OFException.m ================================================================== --- src/exceptions/OFException.m +++ src/exceptions/OFException.m @@ -73,11 +73,11 @@ #if !defined(HAVE_STRERROR_R) && defined(OF_HAVE_THREADS) static of_mutex_t mutex; OF_CONSTRUCTOR() { - if (!of_mutex_new(&mutex)) + if (of_mutex_new(&mutex) != 0) @throw [OFInitializationFailedException exception]; } #endif OFString * @@ -187,21 +187,21 @@ ret = [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; #else # ifdef OF_HAVE_THREADS - if (!of_mutex_lock(&mutex)) + if (of_mutex_lock(&mutex) != 0) @throw [OFLockFailedException exception]; @try { # endif ret = [OFString stringWithCString: strerror(errNo) encoding: [OFLocale encoding]]; # ifdef OF_HAVE_THREADS } @finally { - if (!of_mutex_unlock(&mutex)) + if (of_mutex_unlock(&mutex) != 0) @throw [OFUnlockFailedException exception]; } # endif #endif Index: src/mutex.h ================================================================== --- src/mutex.h +++ src/mutex.h @@ -14,10 +14,12 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "objfw-defs.h" + +#include #include "platform.h" #if !defined(OF_HAVE_THREADS) || \ (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS)) @@ -63,20 +65,20 @@ #endif #ifdef __cplusplus extern "C" { #endif -extern bool of_mutex_new(of_mutex_t *mutex); -extern bool of_mutex_lock(of_mutex_t *mutex); -extern bool of_mutex_trylock(of_mutex_t *mutex); -extern bool of_mutex_unlock(of_mutex_t *mutex); -extern bool of_mutex_free(of_mutex_t *mutex); -extern bool of_rmutex_new(of_rmutex_t *rmutex); -extern bool of_rmutex_lock(of_rmutex_t *rmutex); -extern bool of_rmutex_trylock(of_rmutex_t *rmutex); -extern bool of_rmutex_unlock(of_rmutex_t *rmutex); -extern bool of_rmutex_free(of_rmutex_t *rmutex); +extern int of_mutex_new(of_mutex_t *mutex); +extern int of_mutex_lock(of_mutex_t *mutex); +extern int of_mutex_trylock(of_mutex_t *mutex); +extern int of_mutex_unlock(of_mutex_t *mutex); +extern int of_mutex_free(of_mutex_t *mutex); +extern int of_rmutex_new(of_rmutex_t *rmutex); +extern int of_rmutex_lock(of_rmutex_t *rmutex); +extern int of_rmutex_trylock(of_rmutex_t *rmutex); +extern int of_rmutex_unlock(of_rmutex_t *rmutex); +extern int of_rmutex_free(of_rmutex_t *rmutex); #ifdef __cplusplus } #endif /* Spinlocks are inlined for performance. */ @@ -89,83 +91,83 @@ #elif defined(OF_WINDOWS) Sleep(0); #endif } -static OF_INLINE bool +static OF_INLINE int of_spinlock_new(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) *spinlock = 0; - return true; + return 0; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) - return (pthread_spin_init(spinlock, 0) == 0); + return pthread_spin_init(spinlock, 0); #else return of_mutex_new(spinlock); #endif } -static OF_INLINE bool +static OF_INLINE int of_spinlock_trylock(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) if (of_atomic_int_cmpswap(spinlock, 0, 1)) { of_memory_barrier_acquire(); - return true; + return 0; } - return false; + return EBUSY; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) - return (pthread_spin_trylock(spinlock) == 0); + return pthread_spin_trylock(spinlock); #else return of_mutex_trylock(spinlock); #endif } -static OF_INLINE bool +static OF_INLINE int of_spinlock_lock(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) size_t i; for (i = 0; i < OF_SPINCOUNT; i++) - if (of_spinlock_trylock(spinlock)) - return true; + if (of_spinlock_trylock(spinlock) == 0) + return 0; - while (!of_spinlock_trylock(spinlock)) + while (of_spinlock_trylock(spinlock) == EBUSY) of_thread_yield(); - return true; + return 0; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) - return (pthread_spin_lock(spinlock) == 0); + return pthread_spin_lock(spinlock); #else return of_mutex_lock(spinlock); #endif } -static OF_INLINE bool +static OF_INLINE int of_spinlock_unlock(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) bool ret = of_atomic_int_cmpswap(spinlock, 1, 0); of_memory_barrier_release(); - return ret; + return (ret ? 0 : EINVAL); #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) - return (pthread_spin_unlock(spinlock) == 0); + return pthread_spin_unlock(spinlock); #else return of_mutex_unlock(spinlock); #endif } -static OF_INLINE bool +static OF_INLINE int of_spinlock_free(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) - return true; + return 0; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) - return (pthread_spin_destroy(spinlock) == 0); + return pthread_spin_destroy(spinlock); #else return of_mutex_free(spinlock); #endif } Index: src/objfw-defs.h.in ================================================================== --- src/objfw-defs.h.in +++ src/objfw-defs.h.in @@ -1,8 +1,5 @@ -#undef INFINITY -#undef LLONG_MAX -#undef LLONG_MIN #undef OF_APPLE_RUNTIME #undef OF_BIG_ENDIAN #undef OF_FLOAT_BIG_ENDIAN #undef OF_HAVE_ATOMIC_BUILTINS #undef OF_HAVE_ATOMIC_OPS @@ -46,9 +43,5 @@ #undef OF_NINTENDO_DS #undef OF_NO_SHARED #undef OF_OBJFW_RUNTIME #undef OF_UNIVERSAL #undef OF_WII -#undef SIZE_MAX -#undef UINTPTR_MAX -#undef ULLONG_MAX -#undef __have_longlong64 Index: src/platform/amiga/condition.m ================================================================== --- src/platform/amiga/condition.m +++ src/platform/amiga/condition.m @@ -25,44 +25,44 @@ #include #ifndef OF_AMIGAOS4 # include #endif -bool +int of_condition_new(of_condition_t *condition) { condition->waitingTasks = NULL; - return true; + return 0; } -bool +int of_condition_signal(of_condition_t *condition) { Forbid(); @try { if (condition->waitingTasks == NULL) - return true; + return 0; Signal(condition->waitingTasks->task, (1ul << condition->waitingTasks->sigBit)); condition->waitingTasks = condition->waitingTasks->next; } @finally { Permit(); } - return true; + return 0; } -bool +int of_condition_broadcast(of_condition_t *condition) { Forbid(); @try { if (condition->waitingTasks == NULL) - return true; + return 0; while (condition->waitingTasks != NULL) { Signal(condition->waitingTasks->task, (1ul << condition->waitingTasks->sigBit)); @@ -70,77 +70,73 @@ } } @finally { Permit(); } - return true; + return 0; } -bool +int of_condition_wait(of_condition_t *condition, of_mutex_t *mutex) { ULONG signalMask = 0; return of_condition_wait_or_signal(condition, mutex, &signalMask); } -bool +int of_condition_wait_or_signal(of_condition_t *condition, of_mutex_t *mutex, ULONG *signalMask) { struct of_condition_waiting_task waitingTask = { .task = FindTask(NULL), .sigBit = AllocSignal(-1) }; - bool ret; + int error = 0; ULONG mask; - if (waitingTask.sigBit == -1) { - errno = EAGAIN; - return false; - } + if (waitingTask.sigBit == -1) + return EAGAIN; Forbid(); - if (!of_mutex_unlock(mutex)) { + if ((error = of_mutex_unlock(mutex)) != 0) { FreeSignal(waitingTask.sigBit); - return false; + return error; } waitingTask.next = condition->waitingTasks; condition->waitingTasks = &waitingTask; mask = Wait((1ul << waitingTask.sigBit) | *signalMask); if (mask & (1ul << waitingTask.sigBit) || (*signalMask &= mask)) - ret = of_mutex_lock(mutex); - else { + error = of_mutex_lock(mutex); + else /* * This should not happen - it means something interrupted the * Wait(), so the best we can do is return EINTR. */ - ret = false; - errno = EINTR; - } + error = EINTR; FreeSignal(waitingTask.sigBit); Permit(); - return ret; + return error; } -bool +int of_condition_timed_wait(of_condition_t *condition, of_mutex_t *mutex, of_time_interval_t timeout) { ULONG signalMask = 0; return of_condition_timed_wait_or_signal(condition, mutex, timeout, &signalMask); } -bool +int of_condition_timed_wait_or_signal(of_condition_t *condition, of_mutex_t *mutex, of_time_interval_t timeout, ULONG *signalMask) { struct of_condition_waiting_task waitingTask = { .task = FindTask(NULL), @@ -180,29 +176,29 @@ .tv_sec = (ULONG)timeout, .tv_micro = (timeout - request.tr_time.tv_sec) * 1000000 #endif } }; + int error = 0; ULONG mask; - bool ret; NewList(&port.mp_MsgList); if (waitingTask.sigBit == -1 || port.mp_SigBit == -1) { - errno = EAGAIN; + error = EAGAIN; goto fail; } if (OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest *)&request, 0) != 0) { - errno = EAGAIN; + error = EAGAIN; goto fail; } Forbid(); - if (!of_mutex_unlock(mutex)) { + if ((error = of_mutex_unlock(mutex)) != 0) { Permit(); goto fail; } waitingTask.next = condition->waitingTasks; @@ -211,22 +207,19 @@ SendIO((struct IORequest *)&request); mask = Wait((1ul << waitingTask.sigBit) | (1ul << port.mp_SigBit) | *signalMask); if (mask & (1ul << waitingTask.sigBit) || (*signalMask &= mask)) - ret = of_mutex_lock(mutex); - else if (mask & (1ul << port.mp_SigBit)) { - ret = false; - errno = ETIMEDOUT; - } else { + error = of_mutex_lock(mutex); + else if (mask & (1ul << port.mp_SigBit)) + error = ETIMEDOUT; + else /* * This should not happen - it means something interrupted the * Wait(), so the best we can do is return EINTR. */ - ret = false; - errno = EINTR; - } + error = EINTR; condition->waitingTasks = waitingTask.next; if (!CheckIO((struct IORequest *)&request)) { AbortIO((struct IORequest *)&request); @@ -234,34 +227,27 @@ } CloseDevice((struct IORequest *)&request); Permit(); - FreeSignal(waitingTask.sigBit); - FreeSignal(port.mp_SigBit); - - return ret; - fail: if (waitingTask.sigBit != -1) FreeSignal(waitingTask.sigBit); if (port.mp_SigBit != -1) FreeSignal(port.mp_SigBit); - return false; + return error; } -bool +int of_condition_free(of_condition_t *condition) { Forbid(); @try { - if (condition->waitingTasks != NULL) { - errno = EBUSY; - return false; - } + if (condition->waitingTasks != NULL) + return EBUSY; } @finally { Permit(); } - return true; + return 0; } Index: src/platform/amiga/mutex.m ================================================================== --- src/platform/amiga/mutex.m +++ src/platform/amiga/mutex.m @@ -21,75 +21,73 @@ #import "mutex.h" #include -bool +int of_mutex_new(of_mutex_t *mutex) { InitSemaphore(mutex); - return true; + return 0; } -bool +int of_mutex_lock(of_mutex_t *mutex) { ObtainSemaphore(mutex); - return true; + return 0; } -bool +int of_mutex_trylock(of_mutex_t *mutex) { - if (!AttemptSemaphore(mutex)) { - errno = EBUSY; - return false; - } + if (!AttemptSemaphore(mutex)) + return EBUSY; - return true; + return 0; } -bool +int of_mutex_unlock(of_mutex_t *mutex) { ReleaseSemaphore(mutex); - return true; + return 0; } -bool +int of_mutex_free(of_mutex_t *mutex) { - return true; + return 0; } -bool +int of_rmutex_new(of_rmutex_t *rmutex) { return of_mutex_new(rmutex); } -bool +int of_rmutex_lock(of_rmutex_t *rmutex) { return of_mutex_lock(rmutex); } -bool +int of_rmutex_trylock(of_rmutex_t *rmutex) { return of_mutex_trylock(rmutex); } -bool +int of_rmutex_unlock(of_rmutex_t *rmutex) { return of_mutex_unlock(rmutex); } -bool +int of_rmutex_free(of_rmutex_t *rmutex) { return of_mutex_free(rmutex); } Index: src/platform/amiga/thread.m ================================================================== --- src/platform/amiga/thread.m +++ src/platform/amiga/thread.m @@ -34,20 +34,20 @@ #endif static of_tlskey_t threadKey; OF_CONSTRUCTOR() { - OF_ENSURE(of_tlskey_new(&threadKey)); + OF_ENSURE(of_tlskey_new(&threadKey) == 0); } static void functionWrapper(void) { bool detached = false; of_thread_t thread = (of_thread_t)((struct Process *)FindTask(NULL))->pr_ExitData; - OF_ENSURE(of_tlskey_set(threadKey, thread)); + OF_ENSURE(of_tlskey_set(threadKey, thread) == 0); thread->function(thread->object); ObtainSemaphore(&thread->semaphore); @try { @@ -67,29 +67,27 @@ if (detached) free(thread); } -bool +int of_thread_attr_init(of_thread_attr_t *attr) { attr->priority = 0; attr->stackSize = 0; - return true; + return 0; } -bool +int of_thread_new(of_thread_t *thread, const char *name, void (*function)(id), id object, const of_thread_attr_t *attr) { OFMutableData *tags = nil; - if ((*thread = calloc(1, sizeof(**thread))) == NULL) { - errno = ENOMEM; - return false; - } + if ((*thread = calloc(1, sizeof(**thread))) == NULL) + return ENOMEM; @try { (*thread)->function = function; (*thread)->object = object; InitSemaphore(&(*thread)->semaphore); @@ -122,14 +120,12 @@ ADD_TAG(NP_CloseInput, FALSE) ADD_TAG(NP_CloseOutput, FALSE) ADD_TAG(NP_CloseError, FALSE) if (attr != NULL && attr->priority != 0) { - if (attr->priority < 1 || attr->priority > 1) { - errno = EINVAL; - return false; - } + if (attr->priority < 1 || attr->priority > 1) + return EINVAL; /* * -1 should be -128 (lowest possible priority) while * +1 should be +127 (highest possible priority). */ @@ -147,51 +143,46 @@ #undef ADD_TAG (*thread)->task = (struct Task *)CreateNewProc(tags.items); if ((*thread)->task == NULL) { free(*thread); - errno = EAGAIN; - return false; + return EAGAIN; } } @catch (id e) { free(*thread); @throw e; } @finally { [tags release]; } - return true; + return 0; } of_thread_t of_thread_current(void) { return of_tlskey_get(threadKey); } -bool +int of_thread_join(of_thread_t thread) { ObtainSemaphore(&thread->semaphore); if (thread->done) { ReleaseSemaphore(&thread->semaphore); free(thread); - return true; + return 0; } @try { - if (thread->detached || thread->joinTask != NULL) { - errno = EINVAL; - return false; - } - - if ((thread->joinSigBit = AllocSignal(-1)) == -1) { - errno = EAGAIN; - return false; - } + if (thread->detached || thread->joinTask != NULL) + return EINVAL; + + if ((thread->joinSigBit = AllocSignal(-1)) == -1) + return EAGAIN; thread->joinTask = FindTask(NULL); } @finally { ReleaseSemaphore(&thread->semaphore); } @@ -200,14 +191,14 @@ FreeSignal(thread->joinSigBit); assert(thread->done); free(thread); - return true; + return 0; } -bool +int of_thread_detach(of_thread_t thread) { ObtainSemaphore(&thread->semaphore); if (thread->done) @@ -215,12 +206,12 @@ else thread->detached = true; ReleaseSemaphore(&thread->semaphore); - return true; + return 0; } void of_thread_set_name(const char *name) { } Index: src/platform/amiga/tlskey.m ================================================================== --- src/platform/amiga/tlskey.m +++ src/platform/amiga/tlskey.m @@ -50,11 +50,11 @@ InitSemaphore(&semaphore); semaphoreInitialized = true; } } -bool +int of_tlskey_new(of_tlskey_t *key) { if (!semaphoreInitialized) { /* * We might be called from another constructor, while ours has @@ -64,11 +64,11 @@ InitSemaphore(&semaphore); semaphoreInitialized = true; } if ((*key = malloc(sizeof(**key))) == NULL) - return false; + return ENOMEM; (*key)->table = NULL; ObtainSemaphore(&semaphore); @try { @@ -85,14 +85,14 @@ } @finally { ReleaseSemaphore(&semaphore); } /* We create the hash table lazily. */ - return true; + return 0; } -bool +int of_tlskey_free(of_tlskey_t key) { ObtainSemaphore(&semaphore); @try { if (key->previous != NULL) @@ -109,11 +109,11 @@ free(key); } @finally { ReleaseSemaphore(&semaphore); } - return true; + return 0; } void * of_tlskey_get(of_tlskey_t key) { @@ -130,11 +130,11 @@ } return ret; } -bool +int of_tlskey_set(of_tlskey_t key, void *ptr) { ObtainSemaphore(&semaphore); @try { struct Task *task = FindTask(NULL); @@ -144,17 +144,15 @@ if (ptr == NULL) objc_hashtable_delete(key->table, task); else objc_hashtable_set(key->table, task, ptr); - } @catch (id e) { - return false; } @finally { ReleaseSemaphore(&semaphore); } - return true; + return 0; } void of_tlskey_thread_exited(void) { Index: src/platform/morphos/tlskey.m ================================================================== --- src/platform/morphos/tlskey.m +++ src/platform/morphos/tlskey.m @@ -17,16 +17,21 @@ #include "config.h" #import "tlskey.h" -bool +int of_tlskey_new(of_tlskey_t *key) { - return ((*key = TLSAllocA(NULL)) != TLS_INVALID_INDEX); + *key = TLSAllocA(NULL); + + if (*key == TLS_INVALID_INDEX) + return EAGAIN; + + return 0; } -bool +int of_tlskey_free(of_tlskey_t key) { - return TLSFree(key); + return (TLSFree(key) ? 0 : EINVAL); } Index: src/platform/posix/condition.m ================================================================== --- src/platform/posix/condition.m +++ src/platform/posix/condition.m @@ -17,46 +17,46 @@ #include "config.h" #import "condition.h" -bool +int of_condition_new(of_condition_t *condition) { - return (pthread_cond_init(condition, NULL) == 0); + return pthread_cond_init(condition, NULL); } -bool +int of_condition_signal(of_condition_t *condition) { - return (pthread_cond_signal(condition) == 0); + return pthread_cond_signal(condition); } -bool +int of_condition_broadcast(of_condition_t *condition) { - return (pthread_cond_broadcast(condition) == 0); + return pthread_cond_broadcast(condition); } -bool +int of_condition_wait(of_condition_t *condition, of_mutex_t *mutex) { - return (pthread_cond_wait(condition, mutex) == 0); + return pthread_cond_wait(condition, mutex); } -bool +int of_condition_timed_wait(of_condition_t *condition, of_mutex_t *mutex, of_time_interval_t timeout) { struct timespec ts; ts.tv_sec = (time_t)timeout; ts.tv_nsec = (long)((timeout - ts.tv_sec) * 1000000000); - return (pthread_cond_timedwait(condition, mutex, &ts) == 0); + return pthread_cond_timedwait(condition, mutex, &ts); } -bool +int of_condition_free(of_condition_t *condition) { - return (pthread_cond_destroy(condition) == 0); + return pthread_cond_destroy(condition); } Index: src/platform/posix/mutex.m ================================================================== --- src/platform/posix/mutex.m +++ src/platform/posix/mutex.m @@ -17,171 +17,183 @@ #include "config.h" #import "mutex.h" -bool +int of_mutex_new(of_mutex_t *mutex) { - return (pthread_mutex_init(mutex, NULL) == 0); + return pthread_mutex_init(mutex, NULL); } -bool +int of_mutex_lock(of_mutex_t *mutex) { - return (pthread_mutex_lock(mutex) == 0); + return pthread_mutex_lock(mutex); } -bool +int of_mutex_trylock(of_mutex_t *mutex) { - return (pthread_mutex_trylock(mutex) == 0); + return pthread_mutex_trylock(mutex); } -bool +int of_mutex_unlock(of_mutex_t *mutex) { - return (pthread_mutex_unlock(mutex) == 0); + return pthread_mutex_unlock(mutex); } -bool +int of_mutex_free(of_mutex_t *mutex) { - return (pthread_mutex_destroy(mutex) == 0); + return pthread_mutex_destroy(mutex); } #ifdef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES -bool +int of_rmutex_new(of_rmutex_t *rmutex) { + int error; pthread_mutexattr_t attr; - if (pthread_mutexattr_init(&attr) != 0) - return false; - - if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) - return false; - - if (pthread_mutex_init(rmutex, &attr) != 0) - return false; - - if (pthread_mutexattr_destroy(&attr) != 0) - return false; - - return true; -} - -bool + if ((error = pthread_mutexattr_init(&attr)) != 0) + return error; + + if ((error = pthread_mutexattr_settype(&attr, + PTHREAD_MUTEX_RECURSIVE)) != 0) + return error; + + if ((error = pthread_mutex_init(rmutex, &attr)) != 0) + return error; + + if ((error = pthread_mutexattr_destroy(&attr)) != 0) + return error; + + return 0; +} + +int of_rmutex_lock(of_rmutex_t *rmutex) { return of_mutex_lock(rmutex); } -bool +int of_rmutex_trylock(of_rmutex_t *rmutex) { return of_mutex_trylock(rmutex); } -bool +int of_rmutex_unlock(of_rmutex_t *rmutex) { return of_mutex_unlock(rmutex); } -bool +int of_rmutex_free(of_rmutex_t *rmutex) { return of_mutex_free(rmutex); } #else -bool +int of_rmutex_new(of_rmutex_t *rmutex) { - if (!of_mutex_new(&rmutex->mutex)) - return false; + int error; + + if ((error = of_mutex_new(&rmutex->mutex)) != 0) + return error; - if (!of_tlskey_new(&rmutex->count)) - return false; + if ((error = of_tlskey_new(&rmutex->count)) != 0) + return error; - return true; + return 0; } -bool +int of_rmutex_lock(of_rmutex_t *rmutex) { uintptr_t count = (uintptr_t)of_tlskey_get(rmutex->count); - - if (count > 0) { - if (!of_tlskey_set(rmutex->count, (void *)(count + 1))) - return false; - - return true; - } - - if (!of_mutex_lock(&rmutex->mutex)) - return false; - - if (!of_tlskey_set(rmutex->count, (void *)1)) { - of_mutex_unlock(&rmutex->mutex); - return false; - } - - return true; -} - -bool + int error; + + if (count > 0) { + if ((error = of_tlskey_set(rmutex->count, + (void *)(count + 1))) != 0) + return error; + + return 0; + } + + if ((error = of_mutex_lock(&rmutex->mutex)) != 0) + return error; + + if ((error = of_tlskey_set(rmutex->count, (void *)1)) != 0) { + of_mutex_unlock(&rmutex->mutex); + return error; + } + + return 0; +} + +int of_rmutex_trylock(of_rmutex_t *rmutex) { uintptr_t count = (uintptr_t)of_tlskey_get(rmutex->count); - - if (count > 0) { - if (!of_tlskey_set(rmutex->count, (void *)(count + 1))) - return false; - - return true; - } - - if (!of_mutex_trylock(&rmutex->mutex)) - return false; - - if (!of_tlskey_set(rmutex->count, (void *)1)) { - of_mutex_unlock(&rmutex->mutex); - return false; - } - - return true; -} - -bool + int error; + + if (count > 0) { + if ((error = of_tlskey_set(rmutex->count, + (void *)(count + 1))) != 0) + return error; + + return 0; + } + + if ((error = of_mutex_trylock(&rmutex->mutex)) != 0) + return error; + + if ((error = of_tlskey_set(rmutex->count, (void *)1)) != 0) { + of_mutex_unlock(&rmutex->mutex); + return error; + } + + return 0; +} + +int of_rmutex_unlock(of_rmutex_t *rmutex) { uintptr_t count = (uintptr_t)of_tlskey_get(rmutex->count); - - if (count > 1) { - if (!of_tlskey_set(rmutex->count, (void *)(count - 1))) - return false; - - return true; - } - - if (!of_tlskey_set(rmutex->count, (void *)0)) - return false; - - if (!of_mutex_unlock(&rmutex->mutex)) - return false; - - return true; -} - -bool -of_rmutex_free(of_rmutex_t *rmutex) -{ - if (!of_mutex_free(&rmutex->mutex)) - return false; - - if (!of_tlskey_free(rmutex->count)) - return false; - - return true; + int error; + + if (count > 1) { + if ((error = of_tlskey_set(rmutex->count, + (void *)(count - 1))) != 0) + return error; + + return 0; + } + + if ((error = of_tlskey_set(rmutex->count, (void *)0)) != 0) + return error; + + if ((error = of_mutex_unlock(&rmutex->mutex)) != 0) + return error; + + return 0; +} + +int +of_rmutex_free(of_rmutex_t *rmutex) +{ + int error; + + if ((error = of_mutex_free(&rmutex->mutex)) != 0) + return error; + + if ((error = of_tlskey_free(rmutex->count)) != 0) + return error; + + return 0; } #endif Index: src/platform/posix/thread.m ================================================================== --- src/platform/posix/thread.m +++ src/platform/posix/thread.m @@ -85,55 +85,50 @@ pthread_cleanup_pop(1); return NULL; } -bool +int of_thread_attr_init(of_thread_attr_t *attr) { + int error; pthread_attr_t pattr; - if (pthread_attr_init(&pattr) != 0) - return false; - - @try { - attr->priority = 0; - - if (pthread_attr_getstacksize(&pattr, &attr->stackSize) != 0) - return false; - } @finally { - pthread_attr_destroy(&pattr); - } - - return true; -} - -bool + if ((error = pthread_attr_init(&pattr)) != 0) + return error; + + attr->priority = 0; + error = pthread_attr_getstacksize(&pattr, &attr->stackSize); + + pthread_attr_destroy(&pattr); + + return error; +} + +int of_thread_new(of_thread_t *thread, const char *name, void (*function)(id), id object, const of_thread_attr_t *attr) { - bool ret; + int error = 0; pthread_attr_t pattr; - if (pthread_attr_init(&pattr) != 0) - return false; + if ((error = pthread_attr_init(&pattr)) != 0) + return error; @try { struct thread_ctx *ctx; if (attr != NULL) { struct sched_param param; - if (attr->priority < -1 || attr->priority > 1) { - errno = EINVAL; - return false; - } + if (attr->priority < -1 || attr->priority > 1) + return EINVAL; #ifdef HAVE_PTHREAD_ATTR_SETINHERITSCHED - if (pthread_attr_setinheritsched(&pattr, - PTHREAD_EXPLICIT_SCHED) != 0) - return false; + if ((error = pthread_attr_setinheritsched(&pattr, + PTHREAD_EXPLICIT_SCHED)) != 0) + return error; #endif if (attr->priority < 0) { param.sched_priority = minPrio + (1.0f + attr->priority) * @@ -140,50 +135,48 @@ (normalPrio - minPrio); } else param.sched_priority = normalPrio + attr->priority * (maxPrio - normalPrio); - if (pthread_attr_setschedparam(&pattr, ¶m) != 0) - return false; + if ((error = pthread_attr_setschedparam(&pattr, + ¶m)) != 0) + return error; if (attr->stackSize > 0) { - if (pthread_attr_setstacksize(&pattr, - attr->stackSize) != 0) - return false; + if ((error = pthread_attr_setstacksize(&pattr, + attr->stackSize)) != 0) + return error; } } - if ((ctx = malloc(sizeof(*ctx))) == NULL) { - errno = ENOMEM; - return false; - } + if ((ctx = malloc(sizeof(*ctx))) == NULL) + return ENOMEM; ctx->function = function; ctx->object = object; ctx->name = name; - ret = (pthread_create(thread, &pattr, - functionWrapper, ctx) == 0); + error = pthread_create(thread, &pattr, functionWrapper, ctx); } @finally { pthread_attr_destroy(&pattr); } - return ret; + return error; } -bool +int of_thread_join(of_thread_t thread) { void *ret; - return (pthread_join(thread, &ret) == 0); + return pthread_join(thread, &ret); } -bool +int of_thread_detach(of_thread_t thread) { - return (pthread_detach(thread) == 0); + return pthread_detach(thread); } void of_thread_set_name(const char *name) { Index: src/platform/posix/tlskey.m ================================================================== --- src/platform/posix/tlskey.m +++ src/platform/posix/tlskey.m @@ -17,16 +17,16 @@ #include "config.h" #import "tlskey.h" -bool +int of_tlskey_new(of_tlskey_t *key) { - return (pthread_key_create(key, NULL) == 0); + return pthread_key_create(key, NULL); } -bool +int of_tlskey_free(of_tlskey_t key) { - return (pthread_key_delete(key) == 0); + return pthread_key_delete(key); } Index: src/platform/windows/condition.m ================================================================== --- src/platform/windows/condition.m +++ src/platform/windows/condition.m @@ -21,66 +21,63 @@ #import "condition.h" #include -bool +int of_condition_new(of_condition_t *condition) { condition->count = 0; - if ((condition->event = CreateEvent(NULL, FALSE, 0, NULL)) == NULL) { - errno = EAGAIN; - return false; - } + if ((condition->event = CreateEvent(NULL, FALSE, 0, NULL)) == NULL) + return EAGAIN; - return true; + return 0; } -bool +int of_condition_signal(of_condition_t *condition) { if (!SetEvent(condition->event)) { switch (GetLastError()) { case ERROR_INVALID_HANDLE: - errno = EINVAL; - return false; + return EINVAL; default: OF_ENSURE(0); } } - return true; + return 0; } -bool +int of_condition_broadcast(of_condition_t *condition) { int count = condition->count; for (int i = 0; i < count; i++) { if (!SetEvent(condition->event)) { switch (GetLastError()) { case ERROR_INVALID_HANDLE: - errno = EINVAL; - return false; + return EINVAL; default: OF_ENSURE(0); } } } - return true; + return 0; } -bool +int of_condition_wait(of_condition_t *condition, of_mutex_t *mutex) { + int error; DWORD status; - if (!of_mutex_unlock(mutex)) - return false; + if ((error = of_mutex_unlock(mutex)) != 0) + return error; of_atomic_int_inc(&condition->count); status = WaitForSingleObject(condition->event, INFINITE); of_atomic_int_dec(&condition->count); @@ -88,57 +85,53 @@ case WAIT_OBJECT_0: return of_mutex_lock(mutex); case WAIT_FAILED: switch (GetLastError()) { case ERROR_INVALID_HANDLE: - errno = EINVAL; - return false; + return EINVAL; default: OF_ENSURE(0); } default: OF_ENSURE(0); } } -bool +int of_condition_timed_wait(of_condition_t *condition, of_mutex_t *mutex, of_time_interval_t timeout) { + int error; DWORD status; - if (!of_mutex_unlock(mutex)) - return false; + if ((error = of_mutex_unlock(mutex)) != 0) + return error; of_atomic_int_inc(&condition->count); status = WaitForSingleObject(condition->event, timeout * 1000); of_atomic_int_dec(&condition->count); switch (status) { case WAIT_OBJECT_0: return of_mutex_lock(mutex); case WAIT_TIMEOUT: - errno = ETIMEDOUT; - return false; + return ETIMEDOUT; case WAIT_FAILED: switch (GetLastError()) { case ERROR_INVALID_HANDLE: - errno = EINVAL; - return false; + return EINVAL; default: OF_ENSURE(0); } default: OF_ENSURE(0); } } -bool +int of_condition_free(of_condition_t *condition) { - if (condition->count != 0) { - errno = EBUSY; - return false; - } + if (condition->count != 0) + return EBUSY; - return CloseHandle(condition->event); + return (CloseHandle(condition->event) ? 0 : EINVAL); } Index: src/platform/windows/mutex.m ================================================================== --- src/platform/windows/mutex.m +++ src/platform/windows/mutex.m @@ -21,77 +21,75 @@ #import "mutex.h" #include -bool +int of_mutex_new(of_mutex_t *mutex) { InitializeCriticalSection(mutex); - return true; + return 0; } -bool +int of_mutex_lock(of_mutex_t *mutex) { EnterCriticalSection(mutex); - return true; + return 0; } -bool +int of_mutex_trylock(of_mutex_t *mutex) { - if (!TryEnterCriticalSection(mutex)) { - errno = EBUSY; - return false; - } + if (!TryEnterCriticalSection(mutex)) + return EBUSY; - return true; + return 0; } -bool +int of_mutex_unlock(of_mutex_t *mutex) { LeaveCriticalSection(mutex); - return true; + return 0; } -bool +int of_mutex_free(of_mutex_t *mutex) { DeleteCriticalSection(mutex); - return true; + return 0; } -bool +int of_rmutex_new(of_rmutex_t *rmutex) { return of_mutex_new(rmutex); } -bool +int of_rmutex_lock(of_rmutex_t *rmutex) { return of_mutex_lock(rmutex); } -bool +int of_rmutex_trylock(of_rmutex_t *rmutex) { return of_mutex_trylock(rmutex); } -bool +int of_rmutex_unlock(of_rmutex_t *rmutex) { return of_mutex_unlock(rmutex); } -bool +int of_rmutex_free(of_rmutex_t *rmutex) { return of_mutex_free(rmutex); } Index: src/platform/windows/thread.m ================================================================== --- src/platform/windows/thread.m +++ src/platform/windows/thread.m @@ -35,32 +35,30 @@ context->function(context->object); free(context); } -bool +int of_thread_attr_init(of_thread_attr_t *attr) { attr->priority = 0; attr->stackSize = 0; - return true; + return 0; } -bool +int of_thread_new(of_thread_t *thread, const char *name, void (*function)(id), id object, const of_thread_attr_t *attr) { DWORD priority = THREAD_PRIORITY_NORMAL; struct thread_context *context; DWORD threadID; if (attr != NULL && attr->priority != 0) { - if (attr->priority < -1 || attr->priority > 1) { - errno = EINVAL; - return false; - } + if (attr->priority < -1 || attr->priority > 1) + return EINVAL; if (attr->priority < 0) priority = THREAD_PRIORITY_LOWEST + (1.0 + attr->priority) * (THREAD_PRIORITY_NORMAL - THREAD_PRIORITY_LOWEST); @@ -68,73 +66,69 @@ priority = THREAD_PRIORITY_NORMAL + attr->priority * (THREAD_PRIORITY_HIGHEST - THREAD_PRIORITY_NORMAL); } - if ((context = malloc(sizeof(*context))) == NULL) { - errno = ENOMEM; - return false; - } + if ((context = malloc(sizeof(*context))) == NULL) + return ENOMEM; context->function = function; context->object = object; *thread = CreateThread(NULL, (attr != NULL ? attr->stackSize : 0), (LPTHREAD_START_ROUTINE)functionWrapper, context, 0, &threadID); if (thread == NULL) { - int errNo; + int error; switch (GetLastError()) { case ERROR_NOT_ENOUGH_MEMORY: - errNo = ENOMEM; + error = ENOMEM; break; case ERROR_ACCESS_DENIED: - errNo = EACCES; + error = EACCES; break; default: OF_ENSURE(0); } free(context); - errno = errNo; - return false; + return error; } if (attr != NULL && attr->priority != 0) OF_ENSURE(!SetThreadPriority(*thread, priority)); - return true; + return 0; } -bool +int of_thread_join(of_thread_t thread) { switch (WaitForSingleObject(thread, INFINITE)) { case WAIT_OBJECT_0: CloseHandle(thread); - return true; + return 0; case WAIT_FAILED: switch (GetLastError()) { case ERROR_INVALID_HANDLE: - errno = EINVAL; - return false; + return EINVAL; default: OF_ENSURE(0); } default: OF_ENSURE(0); } } -bool +int of_thread_detach(of_thread_t thread) { CloseHandle(thread); - return true; + return 0; } void of_thread_set_name(const char *name) { } Index: src/platform/windows/tlskey.m ================================================================== --- src/platform/windows/tlskey.m +++ src/platform/windows/tlskey.m @@ -17,16 +17,21 @@ #include "config.h" #import "tlskey.h" -bool +int of_tlskey_new(of_tlskey_t *key) { - return ((*key = TlsAlloc()) != TLS_OUT_OF_INDEXES); + *key = TlsAlloc(); + + if (*key == TLS_OUT_OF_INDEXES) + return EAGAIN; + + return 0; } -bool +int of_tlskey_free(of_tlskey_t key) { - return TlsFree(key); + return (TlsFree(key) ? 0 : EINVAL); } Index: src/runtime/amiga-library.h ================================================================== --- src/runtime/amiga-library.h +++ src/runtime/amiga-library.h @@ -58,11 +58,10 @@ # endif # ifdef OF_MORPHOS void (*_Nonnull __register_frame)(void *_Nonnull); void (*_Nonnull __deregister_frame)(void *_Nonnull); # endif - int *_Nonnull (*_Nonnull get_errno)(void); # ifdef OF_AMIGAOS_M68K int (*_Nonnull vsnprintf)(char *restrict _Nonnull str, size_t size, const char *_Nonnull restrict fmt, va_list args); # endif int (*_Nonnull atexit)(void (*_Nonnull)(void)); Index: src/runtime/amiga-library.m ================================================================== --- src/runtime/amiga-library.m +++ src/runtime/amiga-library.m @@ -575,16 +575,10 @@ { libc._Unwind_Resume(ex); } #endif -int * -objc_get_errno(void) -{ - return libc.get_errno(); -} - #ifdef OF_AMIGAOS_M68K int snprintf(char *restrict str, size_t size, const char *restrict fmt, ...) { va_list args; Index: src/runtime/arc.m ================================================================== --- src/runtime/arc.m +++ src/runtime/arc.m @@ -49,11 +49,11 @@ OF_CONSTRUCTOR() { hashtable = objc_hashtable_new(hash, equal, 2); #ifdef OF_HAVE_THREADS - if (!of_spinlock_new(&spinlock)) + if (of_spinlock_new(&spinlock) != 0) OBJC_ERROR("Failed to create spinlock!"); #endif } id @@ -120,11 +120,11 @@ objc_storeWeak(id *object, id value) { struct weak_ref *old; #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&spinlock)) + if (of_spinlock_lock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif if (*object != nil && (old = objc_hashtable_get(hashtable, *object)) != NULL) { @@ -177,11 +177,11 @@ value = nil; *object = value; #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&spinlock)) + if (of_spinlock_unlock(&spinlock) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif return value; } @@ -191,20 +191,20 @@ { id value = nil; struct weak_ref *ref; #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&spinlock)) + if (of_spinlock_lock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif if (*object != nil && (ref = objc_hashtable_get(hashtable, *object)) != NULL) value = *object; #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&spinlock)) + if (of_spinlock_unlock(&spinlock) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif if (class_respondsToSelector(object_getClass(value), @selector(retainWeakReference)) && [value retainWeakReference]) @@ -242,11 +242,11 @@ objc_moveWeak(id *dest, id *src) { struct weak_ref *ref; #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&spinlock)) + if (of_spinlock_lock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif if (*src != nil && (ref = objc_hashtable_get(hashtable, *src)) != NULL) { @@ -260,11 +260,11 @@ *dest = *src; *src = nil; #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&spinlock)) + if (of_spinlock_unlock(&spinlock) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif } void @@ -271,11 +271,11 @@ objc_zero_weak_references(id value) { struct weak_ref *ref; #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&spinlock)) + if (of_spinlock_lock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif if ((ref = objc_hashtable_get(hashtable, value)) != NULL) { for (size_t i = 0; i < ref->count; i++) @@ -285,9 +285,9 @@ free(ref->locations); free(ref); } #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&spinlock)) + if (of_spinlock_unlock(&spinlock) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif } Index: src/runtime/autorelease.m ================================================================== --- src/runtime/autorelease.m +++ src/runtime/autorelease.m @@ -51,13 +51,13 @@ #endif #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OF_CONSTRUCTOR() { - OF_ENSURE(of_tlskey_new(&objectsKey)); - OF_ENSURE(of_tlskey_new(&countKey)); - OF_ENSURE(of_tlskey_new(&sizeKey)); + OF_ENSURE(of_tlskey_new(&objectsKey) == 0); + OF_ENSURE(of_tlskey_new(&countKey) == 0); + OF_ENSURE(of_tlskey_new(&sizeKey) == 0); } #endif void * objc_autoreleasePoolPush() @@ -98,17 +98,17 @@ free(objects); objects = NULL; #if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS) size = 0; #else - OF_ENSURE(of_tlskey_set(objectsKey, objects)); - OF_ENSURE(of_tlskey_set(sizeKey, (void *)0)); + OF_ENSURE(of_tlskey_set(objectsKey, objects) == 0); + OF_ENSURE(of_tlskey_set(sizeKey, (void *)0) == 0); #endif } #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) - OF_ENSURE(of_tlskey_set(countKey, (void *)count)); + OF_ENSURE(of_tlskey_set(countKey, (void *)count) == 0); #endif } id _objc_rootAutorelease(id object) @@ -127,18 +127,18 @@ OF_ENSURE((objects = realloc(objects, size * sizeof(id))) != NULL); #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) - OF_ENSURE(of_tlskey_set(objectsKey, objects)); - OF_ENSURE(of_tlskey_set(sizeKey, (void *)size)); + OF_ENSURE(of_tlskey_set(objectsKey, objects) == 0); + OF_ENSURE(of_tlskey_set(sizeKey, (void *)size) == 0); #endif } objects[count++] = object; #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) - OF_ENSURE(of_tlskey_set(countKey, (void *)count)); + OF_ENSURE(of_tlskey_set(countKey, (void *)count) == 0); #endif return object; } Index: src/runtime/exception.m ================================================================== --- src/runtime/exception.m +++ src/runtime/exception.m @@ -246,11 +246,11 @@ #ifdef OF_HAVE_THREADS static of_spinlock_t emergencyExceptionsSpinlock; OF_CONSTRUCTOR() { - if (!of_spinlock_new(&emergencyExceptionsSpinlock)) + if (of_spinlock_new(&emergencyExceptionsSpinlock) != 0) OBJC_ERROR("Cannot create spinlock!"); } #endif static uint64_t @@ -705,18 +705,18 @@ static void emergencyExceptionCleanup(_Unwind_Reason_Code reason, struct _Unwind_Exception *ex) { #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&emergencyExceptionsSpinlock)) + if (of_spinlock_lock(&emergencyExceptionsSpinlock) != 0) OBJC_ERROR("Cannot lock spinlock!"); #endif ex->class = 0; #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&emergencyExceptionsSpinlock)) + if (of_spinlock_unlock(&emergencyExceptionsSpinlock) != 0) OBJC_ERROR("Cannot unlock spinlock!"); #endif } void @@ -725,11 +725,11 @@ struct objc_exception *e = calloc(1, sizeof(*e)); bool emergency = false; if (e == NULL) { #ifdef OF_HAVE_THREADS - if (!of_spinlock_lock(&emergencyExceptionsSpinlock)) + if (of_spinlock_lock(&emergencyExceptionsSpinlock) != 0) OBJC_ERROR("Cannot lock spinlock!"); #endif for (uint_fast8_t i = 0; i < NUM_EMERGENCY_EXCEPTIONS; i++) { if (emergencyExceptions[i].exception.class == 0) { @@ -740,11 +740,11 @@ break; } } #ifdef OF_HAVE_THREADS - if (!of_spinlock_unlock(&emergencyExceptionsSpinlock)) + if (of_spinlock_unlock(&emergencyExceptionsSpinlock) != 0) OBJC_ERROR("Cannot lock spinlock!"); #endif } if (e == NULL) Index: src/runtime/linklib/linklib.m ================================================================== --- src/runtime/linklib/linklib.m +++ src/runtime/linklib/linklib.m @@ -27,11 +27,10 @@ struct ObjFWRTBase; #import "inline.h" -#include #include #include #if defined(OF_AMIGAOS_M68K) # include @@ -79,13 +78,13 @@ if (IntuitionBase != NULL) { struct EasyStruct easy = { .es_StructSize = sizeof(easy), .es_Flags = 0, - .es_Title = (UBYTE *)NULL, - .es_TextFormat = (UBYTE *)string, - (UBYTE *)"OK" + .es_Title = (void *)NULL, + .es_TextFormat = (void *)string, + (void *)"OK" }; EasyRequest(NULL, &easy, NULL, arg); CloseLibrary(IntuitionBase); @@ -92,16 +91,10 @@ } exit(EXIT_FAILURE); } -static int * -get_errno(void) -{ - return &errno; -} - static void __attribute__((__used__)) ctor(void) { static bool initialized = false; struct objc_libc libc = { @@ -135,11 +128,10 @@ #endif #ifdef OF_MORPHOS .__register_frame = __register_frame, .__deregister_frame = __deregister_frame, #endif - .get_errno = get_errno, #ifdef OF_AMIGAOS_M68K .vsnprintf = vsnprintf, #endif .atexit = atexit, .exit = exit, Index: src/runtime/misc.m ================================================================== --- src/runtime/misc.m +++ src/runtime/misc.m @@ -15,10 +15,11 @@ * file. */ #include "config.h" +#include #include #include #include "ObjFWRT.h" #include "private.h" @@ -26,11 +27,13 @@ #ifdef OF_AMIGAOS # define USE_INLINE_STDARG # include # include # define __NOLIBBASE__ +# define Class IntuitionClass # include +# undef Class # undef __NOLIBBASE__ #endif static objc_enumeration_mutation_handler_t enumerationMutationHandler = NULL; @@ -57,10 +60,14 @@ char title[BUF_LEN]; char message[BUF_LEN]; int status; va_list args; struct Library *IntuitionBase; +# ifdef OF_AMIGAOS4 + struct IntuitionIFace *IIntuition; +# endif + struct EasyStruct easy; status = snprintf(title, BUF_LEN, "ObjFWRT @ %s:%u", file, line); if (status <= 0 || status >= BUF_LEN) title[0] = '\0'; @@ -68,41 +75,51 @@ status = vsnprintf(message, BUF_LEN, format, args); if (status <= 0 || status >= BUF_LEN) message[0] = '\0'; va_end(args); +# ifndef OF_AMIGAOS4 kprintf("[%s] %s\n", title, message); - - IntuitionBase = OpenLibrary("intuition.library", 0); - if (IntuitionBase != NULL) { - struct EasyStruct easy = { - .es_StructSize = sizeof(easy), - .es_Flags = 0, - .es_Title = (UBYTE *)title, - .es_TextFormat = (UBYTE *)"%s", - (UBYTE *)"OK" - }; - - EasyRequest(NULL, &easy, NULL, (ULONG)message); - - CloseLibrary(IntuitionBase); - } +# endif + + if ((IntuitionBase = OpenLibrary("intuition.library", 0)) == NULL) + exit(EXIT_FAILURE); + +# ifdef OF_AMIGAOS4 + if ((IIntuition = (struct IntuitionIFace *)GetInterface(IntuitionBase, + "main", 1, NULL)) == NULL) + exit(EXIT_FAILURE); +# endif + + easy.es_StructSize = sizeof(easy); + easy.es_Flags = 0; + easy.es_Title = (void *)title; + easy.es_TextFormat = (void *)"%s"; + easy.es_GadgetFormat = (void *)"OK"; + + EasyRequest(NULL, &easy, NULL, (ULONG)message); + +# ifdef OF_AMIGAOS4 + DropInterface((struct Interface *)IIntuition); +# endif + + CloseLibrary(IntuitionBase); exit(EXIT_FAILURE); # undef BUF_LEN #else va_list args; va_start(args, format); - vfprintf(stderr, "[ObjFWRT @ %s:%u] ", file, line); + fprintf(stderr, "[ObjFWRT @ %s:%u] ", file, line); vfprintf(stderr, format, args); - vfprintf(stderr, "\n"); + fprintf(stderr, "\n"); fflush(stderr); va_end(args); abort(); #endif OF_UNREACHABLE } Index: src/runtime/private.h ================================================================== --- src/runtime/private.h +++ src/runtime/private.h @@ -214,16 +214,10 @@ IMP _Nullable buckets[256]; #endif } *_Nonnull buckets[256]; }; -#ifdef OBJC_COMPILING_AMIGA_LIBRARY -# undef errno -extern int *_Nonnull objc_get_errno(void); -# define errno (*objc_get_errno()) -#endif - extern void objc_register_all_categories(struct objc_symtab *_Nonnull); extern struct objc_category *_Nullable *_Nullable objc_categories_for_class(Class _Nonnull); extern void objc_unregister_all_categories(void); extern void objc_initialize_class(Class _Nonnull); @@ -289,12 +283,12 @@ return dtable->buckets[i]->buckets[j]; #endif } -extern void OF_NO_RETURN_FUNC objc_error(const char *file, unsigned int line, - const char *format, ...); +extern void OF_NO_RETURN_FUNC objc_error(const char *_Nonnull file, + unsigned int line, const char *_Nonnull format, ...); #define OBJC_ERROR(...) objc_error(__FILE__, __LINE__, __VA_ARGS__) #if defined(OF_ELF) # if defined(OF_X86_64) || defined(OF_X86) || defined(OF_POWERPC) || \ defined(OF_ARM64) || defined(OF_ARM) || \ Index: src/runtime/property.m ================================================================== --- src/runtime/property.m +++ src/runtime/property.m @@ -31,11 +31,11 @@ #ifdef OF_HAVE_THREADS OF_CONSTRUCTOR() { for (size_t i = 0; i < NUM_SPINLOCKS; i++) - if (!of_spinlock_new(&spinlocks[i])) + if (of_spinlock_new(&spinlocks[i]) != 0) OBJC_ERROR("Failed to initialize spinlocks!"); } #endif id @@ -44,15 +44,15 @@ if (atomic) { id *ptr = (id *)(void *)((char *)self + offset); #ifdef OF_HAVE_THREADS unsigned hash = SPINLOCK_HASH(ptr); - OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&spinlocks[hash]) == 0); @try { return [[*ptr retain] autorelease]; } @finally { - OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&spinlocks[hash]) == 0); } #else return [[*ptr retain] autorelease]; #endif } @@ -67,11 +67,11 @@ if (atomic) { id *ptr = (id *)(void *)((char *)self + offset); #ifdef OF_HAVE_THREADS unsigned hash = SPINLOCK_HASH(ptr); - OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&spinlocks[hash]) == 0); @try { #endif id old = *ptr; switch (copy) { @@ -86,11 +86,11 @@ } [old release]; #ifdef OF_HAVE_THREADS } @finally { - OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&spinlocks[hash]) == 0); } #endif return; } @@ -119,15 +119,15 @@ { if (atomic) { #ifdef OF_HAVE_THREADS unsigned hash = SPINLOCK_HASH(src); - OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&spinlocks[hash]) == 0); #endif memcpy(dest, src, size); #ifdef OF_HAVE_THREADS - OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&spinlocks[hash]) == 0); #endif return; } @@ -140,15 +140,15 @@ { if (atomic) { #ifdef OF_HAVE_THREADS unsigned hash = SPINLOCK_HASH(src); - OF_ENSURE(of_spinlock_lock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_lock(&spinlocks[hash]) == 0); #endif memcpy(dest, src, size); #ifdef OF_HAVE_THREADS - OF_ENSURE(of_spinlock_unlock(&spinlocks[hash])); + OF_ENSURE(of_spinlock_unlock(&spinlocks[hash]) == 0); #endif return; } Index: src/runtime/synchronized.m ================================================================== --- src/runtime/synchronized.m +++ src/runtime/synchronized.m @@ -35,11 +35,11 @@ static of_mutex_t mutex; OF_CONSTRUCTOR() { - if (!of_mutex_new(&mutex)) + if (of_mutex_new(&mutex) != 0) OBJC_ERROR("Failed to create mutex!"); } #endif int @@ -49,46 +49,46 @@ return 0; #ifdef OF_HAVE_THREADS struct lock_s *lock; - if (!of_mutex_lock(&mutex)) + if (of_mutex_lock(&mutex) != 0) OBJC_ERROR("Failed to lock mutex!"); /* Look if we already have a lock */ for (lock = locks; lock != NULL; lock = lock->next) { if (lock->object != object) continue; lock->count++; - if (!of_mutex_unlock(&mutex)) + if (of_mutex_unlock(&mutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); - if (!of_rmutex_lock(&lock->rmutex)) + if (of_rmutex_lock(&lock->rmutex) != 0) OBJC_ERROR("Failed to lock mutex!"); return 0; } /* Create a new lock */ if ((lock = malloc(sizeof(*lock))) == NULL) OBJC_ERROR("Failed to allocate memory for mutex!"); - if (!of_rmutex_new(&lock->rmutex)) + if (of_rmutex_new(&lock->rmutex) != 0) OBJC_ERROR("Failed to create mutex!"); lock->object = object; lock->count = 1; lock->next = locks; locks = lock; - if (!of_mutex_unlock(&mutex)) + if (of_mutex_unlock(&mutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); - if (!of_rmutex_lock(&lock->rmutex)) + if (of_rmutex_lock(&lock->rmutex) != 0) OBJC_ERROR("Failed to lock mutex!"); #endif return 0; } @@ -100,24 +100,24 @@ return 0; #ifdef OF_HAVE_THREADS struct lock_s *lock, *last = NULL; - if (!of_mutex_lock(&mutex)) + if (of_mutex_lock(&mutex) != 0) OBJC_ERROR("Failed to lock mutex!"); for (lock = locks; lock != NULL; lock = lock->next) { if (lock->object != object) { last = lock; continue; } - if (!of_rmutex_unlock(&lock->rmutex)) + if (of_rmutex_unlock(&lock->rmutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); if (--lock->count == 0) { - if (!of_rmutex_free(&lock->rmutex)) + if (of_rmutex_free(&lock->rmutex) != 0) OBJC_ERROR("Failed to destroy mutex!"); if (last != NULL) last->next = lock->next; if (locks == lock) @@ -124,11 +124,11 @@ locks = lock->next; free(lock); } - if (!of_mutex_unlock(&mutex)) + if (of_mutex_unlock(&mutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); return 0; } Index: src/runtime/threading.m ================================================================== --- src/runtime/threading.m +++ src/runtime/threading.m @@ -28,25 +28,25 @@ static of_rmutex_t globalMutex; static void init(void) { - if (!of_rmutex_new(&globalMutex)) + if (of_rmutex_new(&globalMutex) != 0) OBJC_ERROR("Failed to create global mutex!"); } void objc_global_mutex_lock(void) { static of_once_t once_control = OF_ONCE_INIT; of_once(&once_control, init); - if (!of_rmutex_lock(&globalMutex)) + if (of_rmutex_lock(&globalMutex) != 0) OBJC_ERROR("Failed to lock global mutex!"); } void objc_global_mutex_unlock(void) { - if (!of_rmutex_unlock(&globalMutex)) + if (of_rmutex_unlock(&globalMutex) != 0) OBJC_ERROR("Failed to unlock global mutex!"); } Index: src/socket.m ================================================================== --- src/socket.m +++ src/socket.m @@ -77,15 +77,15 @@ #endif #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) OF_CONSTRUCTOR() { - if (!of_tlskey_new(&of_socket_base_key)) + if (of_tlskey_new(&of_socket_base_key) != 0) @throw [OFInitializationFailedException exception]; # ifdef OF_AMIGAOS4 - if (!of_tlskey_new(&of_socket_interface_key)) + if (of_tlskey_new(&of_socket_interface_key) != 0) @throw [OFInitializationFailedException exception]; # endif } #endif @@ -123,15 +123,15 @@ atexit((void (*)(void))socExit); # endif # if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) - if (!of_mutex_new(&mutex)) + if (of_mutex_new(&mutex) != 0) return; # ifdef OF_WII - if (!of_spinlock_new(&spinlock)) + if (of_spinlock_new(&spinlock) != 0) return; # endif # endif initSuccessful = true; @@ -181,20 +181,20 @@ CloseLibrary(socketBase); return false; } # endif - if (!of_tlskey_set(of_socket_base_key, socketBase)) { + if (of_tlskey_set(of_socket_base_key, socketBase) != 0) { CloseLibrary(socketBase); # ifdef OF_AMIGAOS4 DropInterface((struct Interface *)socketInterface); # endif return false; } # ifdef OF_AMIGAOS4 - if (!of_tlskey_set(of_socket_interface_key, socketInterface)) { + if (of_tlskey_set(of_socket_interface_key, socketInterface) != 0) { CloseLibrary(socketBase); DropInterface((struct Interface *)socketInterface); return false; } # endif @@ -327,19 +327,19 @@ socklen_t *restrict addrLen) { int ret; # if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) - if (!of_mutex_lock(&mutex)) + if (of_mutex_lock(&mutex) != 0) @throw [OFLockFailedException exception]; # endif ret = getsockname(sock, addr, addrLen); # if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) - if (!of_mutex_unlock(&mutex)) + if (of_mutex_unlock(&mutex) != 0) @throw [OFUnlockFailedException exception]; # endif return ret; } Index: src/thread.h ================================================================== --- src/thread.h +++ src/thread.h @@ -63,14 +63,14 @@ #endif #ifdef __cplusplus extern "C" { #endif -extern bool of_thread_attr_init(of_thread_attr_t *attr); -extern bool of_thread_new(of_thread_t *thread, const char *name, +extern int of_thread_attr_init(of_thread_attr_t *attr); +extern int of_thread_new(of_thread_t *thread, const char *name, void (*function)(id), id object, const of_thread_attr_t *attr); extern void of_thread_set_name(const char *name); -extern bool of_thread_join(of_thread_t thread); -extern bool of_thread_detach(of_thread_t thread); +extern int of_thread_join(of_thread_t thread); +extern int of_thread_detach(of_thread_t thread); #ifdef __cplusplus } #endif Index: src/tlskey.h ================================================================== --- src/tlskey.h +++ src/tlskey.h @@ -14,10 +14,12 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "objfw-defs.h" + +#include #include "platform.h" #if !defined(OF_HAVE_THREADS) || \ (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS)) @@ -43,12 +45,12 @@ #endif #ifdef __cplusplus extern "C" { #endif -extern bool of_tlskey_new(of_tlskey_t *key); -extern bool of_tlskey_free(of_tlskey_t key); +extern int of_tlskey_new(of_tlskey_t *key); +extern int of_tlskey_free(of_tlskey_t key); #ifdef __cplusplus } #endif /* TLS keys are inlined for performance. */ @@ -58,45 +60,45 @@ of_tlskey_get(of_tlskey_t key) { return pthread_getspecific(key); } -static OF_INLINE bool +static OF_INLINE int of_tlskey_set(of_tlskey_t key, void *ptr) { - return (pthread_setspecific(key, ptr) == 0); + return pthread_setspecific(key, ptr); } #elif defined(OF_WINDOWS) static OF_INLINE void * of_tlskey_get(of_tlskey_t key) { return TlsGetValue(key); } -static OF_INLINE bool +static OF_INLINE int of_tlskey_set(of_tlskey_t key, void *ptr) { - return TlsSetValue(key, ptr); + return (TlsSetValue(key, ptr) ? 0 : EINVAL); } #elif defined(OF_MORPHOS) static OF_INLINE void * of_tlskey_get(of_tlskey_t key) { return (void *)TLSGetValue(key); } -static OF_INLINE bool +static OF_INLINE int of_tlskey_set(of_tlskey_t key, void *ptr) { - return TLSSetValue(key, (APTR)ptr); + return (TLSSetValue(key, (APTR)ptr) ? 0 : EINVAL); } #elif defined(OF_AMIGAOS) /* Those are too big too inline. */ # ifdef __cplusplus extern "C" { # endif extern void *of_tlskey_get(of_tlskey_t key); -extern bool of_tlskey_set(of_tlskey_t key, void *ptr); +extern int of_tlskey_set(of_tlskey_t key, void *ptr); # ifdef __cplusplus } # endif #endif Index: tests/OFStringTests.m ================================================================== --- tests/OFStringTests.m +++ tests/OFStringTests.m @@ -24,10 +24,14 @@ #import "TestsAppDelegate.h" #import "OFString.h" #import "OFMutableUTF8String.h" #import "OFUTF8String.h" + +#ifndef INFINITY +# define INFINITY __builtin_inf() +#endif static OFString *module = nil; static OFString *whitespace[] = { @" \r \t\n\t \tasd \t \t\t\r\n", @" \t\t \t\t \t \t"