Index: src/OFBlock.m ================================================================== --- src/OFBlock.m +++ src/OFBlock.m @@ -117,12 +117,11 @@ 8, sizeof(module), NULL, (struct objc_abi_symtab*)&symtab }; extern void __objc_exec_class(struct objc_abi_module*); -static void __attribute__((__constructor__)) -constructor(void) +OF_CONSTRUCTOR() { __objc_exec_class(&module); } /* End of ObjC module */ #elif defined(OF_APPLE_RUNTIME) Index: src/autorelease.m ================================================================== --- src/autorelease.m +++ src/autorelease.m @@ -37,12 +37,11 @@ static id *top = NULL; static size_t size = 0; #endif #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) -static void __attribute__((__constructor__)) -init(void) +OF_CONSTRUCTOR() { OF_ENSURE(of_tlskey_new(&objectsKey)); OF_ENSURE(of_tlskey_new(&topKey)); OF_ENSURE(of_tlskey_new(&sizeKey)); } Index: src/exceptions/OFException.m ================================================================== --- src/exceptions/OFException.m +++ src/exceptions/OFException.m @@ -86,12 +86,11 @@ #endif #if !defined(HAVE_STRERROR_R) && defined(OF_HAVE_THREADS) static of_mutex_t mutex; -static void __attribute__((__constructor__)) -init(void) +OF_CONSTRUCTOR() { if (!of_mutex_new(&mutex)) @throw [OFInitializationFailedException exception]; } #endif Index: src/foundation-compat.m ================================================================== --- src/foundation-compat.m +++ src/foundation-compat.m @@ -53,12 +53,11 @@ [OFAutoreleasePool addObject: self]; return self; } -static void __attribute__((__constructor__)) -init(void) +OF_CONSTRUCTOR() { Class NSAutoreleasePool = objc_getClass("NSAutoreleasePool"); Class NSObject = objc_getClass("NSObject"); Method allocMethod; Method addObjectMethod; Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -336,10 +336,17 @@ \ abort(); \ \ [super dealloc]; /* Get rid of a stupid warning */ #endif + +#define OF_CONSTRUCTOR(prio) \ + static void __attribute__((__constructor__(prio))) \ + constructor##__LINE__(void) +#define OF_DESTRUCTOR(prio) \ + static void __attribute__((__destructor__(prio))) \ + destructor##__LINE__(void) static OF_INLINE uint16_t OF_CONST_FUNC OF_BSWAP16_CONST(uint16_t i) { return (i & UINT16_C(0xFF00)) >> 8 | Index: src/of_asprintf.m ================================================================== --- src/of_asprintf.m +++ src/of_asprintf.m @@ -80,12 +80,11 @@ }; #ifdef HAVE_ASPRINTF_L static locale_t cLocale; -static void __attribute__((constructor)) -init(void) +OF_CONSTRUCTOR() { if ((cLocale = newlocale(LC_ALL_MASK, "C", NULL)) == NULL) @throw [OFInitializationFailedException exception]; } #endif Index: src/resolver.m ================================================================== --- src/resolver.m +++ src/resolver.m @@ -44,12 +44,11 @@ #import "socket_helpers.h" #if !defined(HAVE_THREADSAFE_GETADDRINFO) && defined(OF_HAVE_THREADS) static of_mutex_t mutex; -static void __attribute__((__constructor__)) -init(void) +OF_CONSTRUCTOR() { if (!of_mutex_new(&mutex)) @throw [OFInitializationFailedException exception]; } #endif Index: src/runtime/arc.m ================================================================== --- src/runtime/arc.m +++ src/runtime/arc.m @@ -46,12 +46,11 @@ obj_equal(const void *obj1, const void *obj2) { return (obj1 == obj2); } -static void __attribute__((__constructor__)) -init(void) +OF_CONSTRUCTOR() { hashtable = objc_hashtable_new(obj_hash, obj_equal, 2); #ifdef OF_HAVE_THREADS if (!of_spinlock_new(&spinlock)) Index: src/runtime/exception.m ================================================================== --- src/runtime/exception.m +++ src/runtime/exception.m @@ -697,12 +697,11 @@ #ifdef HAVE_SEH_EXCEPTIONS typedef EXCEPTION_DISPOSITION (*seh_personality_fn)(PEXCEPTION_RECORD, void*, PCONTEXT, PDISPATCHER_CONTEXT); static seh_personality_fn __gxx_personality_seh0 = NULL; -static void __attribute__((__constructor__)) -gxx_personality_init(void) +OF_CONSTRUCTOR() { /* * This only works if the application uses libstdc++-6.dll. * There is unfortunately no other way, as Windows does not support * proper weak linking. Index: src/runtime/property.m ================================================================== --- src/runtime/property.m +++ src/runtime/property.m @@ -29,12 +29,11 @@ # define SPINLOCK_HASH(p) ((unsigned)((uintptr_t)p >> 4) & (NUM_SPINLOCKS - 1)) static of_spinlock_t spinlocks[NUM_SPINLOCKS]; #endif #ifdef OF_HAVE_THREADS -static void __attribute__((__constructor__)) -init(void) +OF_CONSTRUCTOR() { for (size_t i = 0; i < NUM_SPINLOCKS; i++) if (!of_spinlock_new(&spinlocks[i])) OBJC_ERROR("Failed to initialize spinlocks!") } Index: src/runtime/synchronized.m ================================================================== --- src/runtime/synchronized.m +++ src/runtime/synchronized.m @@ -32,12 +32,11 @@ struct lock_s *next; } *locks = NULL; static of_mutex_t mutex; -static void __attribute__((__constructor__)) -init(void) +OF_CONSTRUCTOR() { if (!of_mutex_new(&mutex)) OBJC_ERROR("Failed to create mutex!") } #endif Index: src/threading_pthread.m ================================================================== --- src/threading_pthread.m +++ src/threading_pthread.m @@ -35,12 +35,11 @@ /* * This is done here to make sure this is done as early as possible in the main * thread. */ -static void __attribute__((constructor)) -init(void) +OF_CONSTRUCTOR() { pthread_attr_t pattr; int policy; struct sched_param param; Index: tests/plugin/TestPlugin.m ================================================================== --- tests/plugin/TestPlugin.m +++ tests/plugin/TestPlugin.m @@ -19,12 +19,11 @@ #import "TestPlugin.h" #ifdef OF_OBJFW_RUNTIME # import "runtime-private.h" -static void __attribute__((destructor)) -unload(void) +OF_DESTRUCTOR() { objc_unregister_class(objc_getClass("TestPlugin")); } #endif