Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -355,19 +355,27 @@ #endif #define OF_RETAIN_COUNT_MAX UINT_MAX #define OF_NOT_FOUND SIZE_MAX -#define OF_ENSURE(cond) \ +#ifdef OBJC_COMPILING_RUNTIME +# define OF_ENSURE(cond) \ + do { \ + if OF_UNLIKELY (!(cond)) \ + OBJC_ERROR("Failed to ensure condition:\n" #cond); \ + } while(0) +#else +# define OF_ENSURE(cond) \ do { \ - if (!(cond)) { \ + if OF_UNLIKELY (!(cond)) { \ fprintf(stderr, "Failed to ensure condition " \ "in " __FILE__ ":%d:\n" #cond "\n", \ __LINE__); \ abort(); \ } \ } while (0) +#endif #define OF_UNRECOGNIZED_SELECTOR of_method_not_found(self, _cmd); #if __has_feature(objc_arc) # define OF_INVALID_INIT_METHOD of_method_not_found(self, _cmd); #else Index: src/runtime/Makefile ================================================================== --- src/runtime/Makefile +++ src/runtime/Makefile @@ -56,11 +56,12 @@ ${CVINCLUDE_INLINE_H}: morphos.fd morphos-clib.h cvinclude.pl --quiet --fd=morphos.fd --clib=morphos-clib.h --inlines=$@ CPPFLAGS += -I. -I.. -I../.. \ + -DOBJC_COMPILING_RUNTIME \ -DOBJFWRT_AMIGA_LIB=\"${OBJFWRT_AMIGA_LIB}\" \ -DOBJFWRT_LIB_MAJOR=${OBJFWRT_LIB_MAJOR} \ -DOBJFWRT_LIB_MINOR=${OBJFWRT_LIB_MINOR} AMIGA_LIB_CFLAGS += -DOBJC_COMPILING_AMIGA_LIBRARY LD = ${OBJC} FRAMEWORK_LIBS = ${LIBS} Index: src/runtime/amiga-library.m ================================================================== --- src/runtime/amiga-library.m +++ src/runtime/amiga-library.m @@ -485,59 +485,10 @@ free(void *ptr) { libc.free(ptr); } -int -fprintf(FILE *restrict stream, const char *restrict fmt, ...) -{ - int ret; - va_list args; - - va_start(args, fmt); - ret = libc.vfprintf(stream, fmt, args); - va_end(args); - - return ret; -} - -int -fflush(FILE *restrict stream) -{ - return libc.fflush(stream); -} - -#ifdef OF_AMIGAOS_M68K -int -snprintf(char *restrict str, size_t size, const char *restrict fmt, ...) -{ - va_list args; - int ret; - - va_start(args, fmt); - ret = vsnprintf(str, size, fmt, args); - va_end(args); - - return ret; -} - -int -vsnprintf(char *restrict str, size_t size, const char *restrict fmt, - va_list args) -{ - return libc.vsnprintf(str, size, fmt, args); -} -#endif - -void -abort(void) -{ - libc.abort(); - - OF_UNREACHABLE -} - #ifdef HAVE_SJLJ_EXCEPTIONS int _Unwind_SjLj_RaiseException(void *ex) { return libc._Unwind_SjLj_RaiseException(ex); @@ -621,10 +572,40 @@ 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; + int ret; + + va_start(args, fmt); + ret = vsnprintf(str, size, fmt, args); + va_end(args); + + return ret; +} + +int +vsnprintf(char *restrict str, size_t size, const char *restrict fmt, + va_list args) +{ + return libc.vsnprintf(str, size, fmt, args); +} +#endif + +void +abort(void) +{ + libc.abort(); + + OF_UNREACHABLE +} #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" static CONST_APTR functionTable[] = { #ifdef OF_MORPHOS Index: src/runtime/arc.m ================================================================== --- src/runtime/arc.m +++ src/runtime/arc.m @@ -50,11 +50,11 @@ { hashtable = objc_hashtable_new(hash, equal, 2); #ifdef OF_HAVE_THREADS if (!of_spinlock_new(&spinlock)) - OBJC_ERROR("Failed to create spinlock!") + OBJC_ERROR("Failed to create spinlock!"); #endif } id objc_retain(id object) @@ -121,11 +121,11 @@ { struct weak_ref *old; #ifdef OF_HAVE_THREADS if (!of_spinlock_lock(&spinlock)) - OBJC_ERROR("Failed to lock spinlock!") + OBJC_ERROR("Failed to lock spinlock!"); #endif if (*object != nil && (old = objc_hashtable_get(hashtable, *object)) != NULL) { for (size_t i = 0; i < old->count; i++) { @@ -168,21 +168,21 @@ } if ((ref->locations = realloc(ref->locations, (ref->count + 1) * sizeof(id *))) == NULL) OBJC_ERROR("Not enough memory to allocate weak " - "reference!") + "reference!"); ref->locations[ref->count++] = object; } else value = nil; *object = value; #ifdef OF_HAVE_THREADS if (!of_spinlock_unlock(&spinlock)) - OBJC_ERROR("Failed to unlock spinlock!") + OBJC_ERROR("Failed to unlock spinlock!"); #endif return value; } @@ -192,20 +192,20 @@ id value = nil; struct weak_ref *ref; #ifdef OF_HAVE_THREADS if (!of_spinlock_lock(&spinlock)) - OBJC_ERROR("Failed to lock spinlock!") + 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)) - OBJC_ERROR("Failed to unlock spinlock!") + OBJC_ERROR("Failed to unlock spinlock!"); #endif if (class_respondsToSelector(object_getClass(value), @selector(retainWeakReference)) && [value retainWeakReference]) return value; @@ -243,11 +243,11 @@ { struct weak_ref *ref; #ifdef OF_HAVE_THREADS if (!of_spinlock_lock(&spinlock)) - OBJC_ERROR("Failed to lock spinlock!") + OBJC_ERROR("Failed to lock spinlock!"); #endif if (*src != nil && (ref = objc_hashtable_get(hashtable, *src)) != NULL) { for (size_t i = 0; i < ref->count; i++) { @@ -261,11 +261,11 @@ *dest = *src; *src = nil; #ifdef OF_HAVE_THREADS if (!of_spinlock_unlock(&spinlock)) - OBJC_ERROR("Failed to unlock spinlock!") + OBJC_ERROR("Failed to unlock spinlock!"); #endif } void objc_zero_weak_references(id value) @@ -272,11 +272,11 @@ { struct weak_ref *ref; #ifdef OF_HAVE_THREADS if (!of_spinlock_lock(&spinlock)) - OBJC_ERROR("Failed to lock spinlock!") + OBJC_ERROR("Failed to lock spinlock!"); #endif if ((ref = objc_hashtable_get(hashtable, value)) != NULL) { for (size_t i = 0; i < ref->count; i++) *ref->locations[i] = nil; @@ -286,8 +286,8 @@ free(ref); } #ifdef OF_HAVE_THREADS if (!of_spinlock_unlock(&spinlock)) - OBJC_ERROR("Failed to unlock spinlock!") + OBJC_ERROR("Failed to unlock spinlock!"); #endif } Index: src/runtime/class.m ================================================================== --- src/runtime/class.m +++ src/runtime/class.m @@ -468,16 +468,16 @@ { struct objc_class *class, *metaclass; Class iter, rootclass = Nil; if (extraBytes > LONG_MAX) - OBJC_ERROR("extraBytes out of range!") + OBJC_ERROR("extraBytes out of range!"); if ((class = calloc(1, sizeof(*class))) == NULL || (metaclass = calloc(1, sizeof(*class))) == NULL) OBJC_ERROR("Not enough memory to allocate class pair for class " - "%s!", name) + "%s!", name); class->isa = metaclass; class->superclass = superclass; class->name = name; class->info = OBJC_CLASS_INFO_CLASS; Index: src/runtime/exception.m ================================================================== --- src/runtime/exception.m +++ src/runtime/exception.m @@ -247,11 +247,11 @@ static of_spinlock_t emergencyExceptionsSpinlock; OF_CONSTRUCTOR() { if (!of_spinlock_new(&emergencyExceptionsSpinlock)) - OBJC_ERROR("Cannot create spinlock!") + OBJC_ERROR("Cannot create spinlock!"); } #endif static uint64_t readULEB128(const uint8_t **ptr) @@ -308,11 +308,11 @@ case DW_EH_PE_textrel: return _Unwind_GetTextRelBase(ctx); #endif } - OBJC_ERROR("Unknown encoding!") + OBJC_ERROR("Unknown encoding!"); } static size_t sizeForEncoding(uint8_t enc) { @@ -328,20 +328,20 @@ return 4; case DW_EH_PE_udata8: return 8; } - OBJC_ERROR("Unknown encoding!") + OBJC_ERROR("Unknown encoding!"); } static uint64_t readValue(uint8_t enc, const uint8_t **ptr) { uint64_t value; if (enc == DW_EH_PE_aligned) - OBJC_ERROR("DW_EH_PE_aligned is not implemented!") + OBJC_ERROR("DW_EH_PE_aligned is not implemented!"); #define READ(type) \ { \ type tmp; \ memcpy(&tmp, *ptr, sizeof(type)); \ @@ -369,11 +369,11 @@ case DW_EH_PE_sdata4: READ(int32_t) case DW_EH_PE_sdata8: READ(int64_t) default: - OBJC_ERROR("Unknown encoding!") + OBJC_ERROR("Unknown encoding!"); } #undef READ return value; } @@ -558,11 +558,11 @@ return HANDLER_FOUND; } } else if (filter == 0) return CLEANUP_FOUND; else if (filter < 0) - OBJC_ERROR("Invalid filter!") + OBJC_ERROR("Invalid filter!"); } while (displacement != 0); return 0; } @@ -690,11 +690,12 @@ _Unwind_SetIP(ctx, landingpad); return _URC_INSTALL_CONTEXT; } - OBJC_ERROR("Neither _UA_SEARCH_PHASE nor _UA_CLEANUP_PHASE in actions!") + OBJC_ERROR( + "Neither _UA_SEARCH_PHASE nor _UA_CLEANUP_PHASE in actions!"); } static void cleanup(_Unwind_Reason_Code reason, struct _Unwind_Exception *ex) { @@ -745,11 +746,11 @@ OBJC_ERROR("Cannot lock spinlock!"); #endif } if (e == NULL) - OBJC_ERROR("Not enough memory to allocate exception!") + OBJC_ERROR("Not enough memory to allocate exception!"); e->exception.class = GNUCOBJC_EXCEPTION_CLASS; e->exception.cleanup = (emergency ? emergencyExceptionCleanup : cleanup); e->object = object; @@ -757,11 +758,11 @@ _Unwind_RaiseException(&e->exception); if (uncaughtExceptionHandler != NULL) uncaughtExceptionHandler(object); - OBJC_ERROR("_Unwind_RaiseException() returned!") + OBJC_ERROR("_Unwind_RaiseException() returned!"); } objc_uncaught_exception_handler_t objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler_t handler) { Index: src/runtime/linklib/linklib.m ================================================================== --- src/runtime/linklib/linklib.m +++ src/runtime/linklib/linklib.m @@ -83,16 +83,10 @@ struct objc_libc libc = { .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free, - .vfprintf = vfprintf, - .fflush = fflush, -#ifdef OF_AMIGAOS_M68K - .vsnprintf = vsnprintf, -#endif - .abort = abort, #ifdef HAVE_SJLJ_EXCEPTIONS ._Unwind_SjLj_RaiseException = _Unwind_SjLj_RaiseException, #else ._Unwind_RaiseException = _Unwind_RaiseException, #endif @@ -118,10 +112,14 @@ #ifdef OF_MORPHOS .__register_frame = __register_frame, .__deregister_frame = __deregister_frame, #endif .get_errno = get_errno, +#ifdef OF_AMIGAOS_M68K + .vsnprintf = vsnprintf, +#endif + .abort = abort, }; if (initialized) return; Index: src/runtime/private.h ================================================================== --- src/runtime/private.h +++ src/runtime/private.h @@ -223,17 +223,10 @@ struct objc_libc { void *_Nullable (*_Nonnull malloc)(size_t); void *_Nullable (*_Nonnull calloc)(size_t, size_t); void *_Nullable (*_Nonnull realloc)(void *_Nullable, size_t); void (*_Nonnull free)(void *_Nullable); - int (*_Nonnull vfprintf)(FILE *_Nonnull, const char *_Nonnull, va_list); - int (*_Nonnull fflush)(FILE *_Nonnull); -# ifdef OF_AMIGAOS_M68K - int (*_Nonnull vsnprintf)(char *restrict _Nonnull str, size_t size, - const char *_Nonnull restrict fmt, va_list args); -# endif - void (*_Nonnull abort)(void); # ifdef HAVE_SJLJ_EXCEPTIONS int (*_Nonnull _Unwind_SjLj_RaiseException)(void *_Nonnull); # else int (*_Nonnull _Unwind_RaiseException)(void *_Nonnull); # endif @@ -260,10 +253,15 @@ # 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 + void (*_Nonnull abort)(void); }; #endif #ifdef OBJC_COMPILING_AMIGA_LIBRARY # if defined(__MORPHOS__) @@ -351,11 +349,11 @@ #endif } extern void OF_NO_RETURN_FUNC objc_error(const char *file, unsigned int line, const char *format, ...); -#define OBJC_ERROR(...) objc_error(__FILE__, __LINE__, __VA_ARGS__); +#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) || \ defined(OF_MIPS64_N64) || defined(OF_MIPS) || \ Index: src/runtime/property.m ================================================================== --- src/runtime/property.m +++ src/runtime/property.m @@ -32,11 +32,11 @@ #ifdef OF_HAVE_THREADS OF_CONSTRUCTOR() { for (size_t i = 0; i < NUM_SPINLOCKS; i++) if (!of_spinlock_new(&spinlocks[i])) - OBJC_ERROR("Failed to initialize spinlocks!") + OBJC_ERROR("Failed to initialize spinlocks!"); } #endif id objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, bool atomic) Index: src/runtime/synchronized.m ================================================================== --- src/runtime/synchronized.m +++ src/runtime/synchronized.m @@ -36,11 +36,11 @@ static of_mutex_t mutex; OF_CONSTRUCTOR() { if (!of_mutex_new(&mutex)) - OBJC_ERROR("Failed to create mutex!") + OBJC_ERROR("Failed to create mutex!"); } #endif int objc_sync_enter(id object)