148fb7bfaSmrg /* GNU Objective C Runtime 'fast enumeration' implementation 2*b1e83836Smrg Copyright (C) 2010-2022 Free Software Foundation, Inc. 348fb7bfaSmrg Contributed by Nicola Pero <nicola.pero@meta-innovation.com> 448fb7bfaSmrg 548fb7bfaSmrg This file is part of GCC. 648fb7bfaSmrg 748fb7bfaSmrg GCC is free software; you can redistribute it and/or modify it under the 848fb7bfaSmrg terms of the GNU General Public License as published by the Free Software 948fb7bfaSmrg Foundation; either version 3, or (at your option) any later version. 1048fb7bfaSmrg 1148fb7bfaSmrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY 1248fb7bfaSmrg WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 1348fb7bfaSmrg FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 1448fb7bfaSmrg details. 1548fb7bfaSmrg 1648fb7bfaSmrg Under Section 7 of GPL version 3, you are granted additional 1748fb7bfaSmrg permissions described in the GCC Runtime Library Exception, version 1848fb7bfaSmrg 3.1, as published by the Free Software Foundation. 1948fb7bfaSmrg 2048fb7bfaSmrg You should have received a copy of the GNU General Public License and 2148fb7bfaSmrg a copy of the GCC Runtime Library Exception along with this program; 2248fb7bfaSmrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 2348fb7bfaSmrg <http://www.gnu.org/licenses/>. */ 2448fb7bfaSmrg 2548fb7bfaSmrg /* This file implements objc_enumeration_mutation() and 2648fb7bfaSmrg objc_set_enumeration_mutation_handler(), the two functions required 2748fb7bfaSmrg to handle mutations during a fast enumeration. */ 2848fb7bfaSmrg #include "objc-private/common.h" 2948fb7bfaSmrg #include "objc-private/error.h" /* For _objc_abort() */ 3048fb7bfaSmrg #include "objc/runtime.h" /* For objc_enumerationMutation() and objc_set_enumeration_mutation_handler() */ 3148fb7bfaSmrg 3248fb7bfaSmrg /* The enumeration mutation handler currently in use. */ 3348fb7bfaSmrg static void (*__objc_enumeration_mutation_handler)(id) = NULL; 3448fb7bfaSmrg 3548fb7bfaSmrg void objc_setEnumerationMutationHandler(void (* handler)(id))3648fb7bfaSmrgobjc_setEnumerationMutationHandler (void (*handler)(id)) 3748fb7bfaSmrg { 3848fb7bfaSmrg __objc_enumeration_mutation_handler = handler; 3948fb7bfaSmrg } 4048fb7bfaSmrg 4148fb7bfaSmrg void objc_enumerationMutation(id collection)4248fb7bfaSmrgobjc_enumerationMutation (id collection) 4348fb7bfaSmrg { 4448fb7bfaSmrg if (__objc_enumeration_mutation_handler != NULL) 4548fb7bfaSmrg (*__objc_enumeration_mutation_handler) (collection); 4648fb7bfaSmrg 4748fb7bfaSmrg /* We always abort if we get here; there is no point in going on as 4848fb7bfaSmrg the next iteration in the fast enumeration would probably go 4948fb7bfaSmrg deeply wrong. */ 5048fb7bfaSmrg _objc_abort ("Collection %p mutated during fast enumeration", collection); 5148fb7bfaSmrg } 52