136ac495dSmrg /* GNU Objective C Runtime 'fast enumeration' implementation 2*8feb0f0bSmrg Copyright (C) 2010-2020 Free Software Foundation, Inc. 336ac495dSmrg Contributed by Nicola Pero <nicola.pero@meta-innovation.com> 436ac495dSmrg 536ac495dSmrg This file is part of GCC. 636ac495dSmrg 736ac495dSmrg GCC is free software; you can redistribute it and/or modify it under the 836ac495dSmrg terms of the GNU General Public License as published by the Free Software 936ac495dSmrg Foundation; either version 3, or (at your option) any later version. 1036ac495dSmrg 1136ac495dSmrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY 1236ac495dSmrg WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 1336ac495dSmrg FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 1436ac495dSmrg details. 1536ac495dSmrg 1636ac495dSmrg Under Section 7 of GPL version 3, you are granted additional 1736ac495dSmrg permissions described in the GCC Runtime Library Exception, version 1836ac495dSmrg 3.1, as published by the Free Software Foundation. 1936ac495dSmrg 2036ac495dSmrg You should have received a copy of the GNU General Public License and 2136ac495dSmrg a copy of the GCC Runtime Library Exception along with this program; 2236ac495dSmrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 2336ac495dSmrg <http://www.gnu.org/licenses/>. */ 2436ac495dSmrg 2536ac495dSmrg /* This file implements objc_enumeration_mutation() and 2636ac495dSmrg objc_set_enumeration_mutation_handler(), the two functions required 2736ac495dSmrg to handle mutations during a fast enumeration. */ 2836ac495dSmrg #include "objc-private/common.h" 2936ac495dSmrg #include "objc-private/error.h" /* For _objc_abort() */ 3036ac495dSmrg #include "objc/runtime.h" /* For objc_enumerationMutation() and objc_set_enumeration_mutation_handler() */ 3136ac495dSmrg 3236ac495dSmrg /* The enumeration mutation handler currently in use. */ 3336ac495dSmrg static void (*__objc_enumeration_mutation_handler)(id) = NULL; 3436ac495dSmrg 3536ac495dSmrg void objc_setEnumerationMutationHandler(void (* handler)(id))3636ac495dSmrgobjc_setEnumerationMutationHandler (void (*handler)(id)) 3736ac495dSmrg { 3836ac495dSmrg __objc_enumeration_mutation_handler = handler; 3936ac495dSmrg } 4036ac495dSmrg 4136ac495dSmrg void objc_enumerationMutation(id collection)4236ac495dSmrgobjc_enumerationMutation (id collection) 4336ac495dSmrg { 4436ac495dSmrg if (__objc_enumeration_mutation_handler != NULL) 4536ac495dSmrg (*__objc_enumeration_mutation_handler) (collection); 4636ac495dSmrg 4736ac495dSmrg /* We always abort if we get here; there is no point in going on as 4836ac495dSmrg the next iteration in the fast enumeration would probably go 4936ac495dSmrg deeply wrong. */ 5036ac495dSmrg _objc_abort ("Collection %p mutated during fast enumeration", collection); 5136ac495dSmrg } 52