Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -140,11 +140,11 @@ of_method_not_found_stret(void *st, id obj, SEL sel) { of_method_not_found(obj, sel); } -#ifndef HAVE_OBJC_ENUMERATIONMUTATION +#if !defined(OF_OBJFW_RUNTIME) && !defined(HAVE_OBJC_ENUMERATIONMUTATION) void objc_enumerationMutation(id object) { enumerationMutationHandler(object); } @@ -226,11 +226,11 @@ objc_setForwardHandler((void*)&of_forward, (void*)&of_forward_stret); #else objc_setForwardHandler((IMP)&of_forward, (IMP)&of_forward_stret); #endif -#ifdef HAVE_OBJC_ENUMERATIONMUTATION +#if defined(OF_OBJFW_RUNTIME) || defined(HAVE_OBJC_ENUMERATIONMUTATION) objc_setEnumerationMutationHandler(enumerationMutationHandler); #endif of_hash_seed = 0; while (of_hash_seed == 0) { Index: src/runtime/Makefile ================================================================== --- src/runtime/Makefile +++ src/runtime/Makefile @@ -11,10 +11,11 @@ dtable.m \ exception.m \ hashtable.m \ init.m \ lookup.m \ + misc.m \ property.m \ protocol.m \ selector.m \ sparsearray.m \ static-instances.m \ ADDED src/runtime/misc.m Index: src/runtime/misc.m ================================================================== --- /dev/null +++ src/runtime/misc.m @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include +#include + +#include "runtime.h" +#include "runtime-private.h" + +static void (*enumeration_mutation_handler)(id) = NULL; + +void +objc_enumerationMutation(id obj) +{ + if (enumeration_mutation_handler != NULL) + enumeration_mutation_handler(obj); + else + OBJC_ERROR("Object was mutated during enumeration!"); +} + +void +objc_setEnumerationMutationHandler(void (*handler)(id)) +{ + enumeration_mutation_handler = handler; +} Index: src/runtime/runtime.h ================================================================== --- src/runtime/runtime.h +++ src/runtime/runtime.h @@ -237,10 +237,12 @@ /* Used by the compiler, but can be called manually. */ extern IMP objc_msg_lookup(id, SEL); extern IMP objc_msg_lookup_stret(id, SEL); extern IMP objc_msg_lookup_super(struct objc_super*, SEL); extern IMP objc_msg_lookup_super_stret(struct objc_super*, SEL); +extern void objc_enumerationMutation(id); +extern void objc_setEnumerationMutationHandler(void (*handler)(id)); #ifdef __cplusplus } #endif #undef OBJC_UNSAFE_UNRETAINED