objc-foreach.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* GNU Objective C Runtime 'fast enumeration' implementation
  2. Copyright (C) 2010-2015 Free Software Foundation, Inc.
  3. Contributed by Nicola Pero <nicola.pero@meta-innovation.com>
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under the
  6. terms of the GNU General Public License as published by the Free Software
  7. Foundation; either version 3, or (at your option) any later version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  11. details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. /* This file implements objc_enumeration_mutation() and
  20. objc_set_enumeration_mutation_handler(), the two functions required
  21. to handle mutations during a fast enumeration. */
  22. #include "objc-private/common.h"
  23. #include "objc-private/error.h" /* For _objc_abort() */
  24. #include "objc/runtime.h" /* For objc_enumerationMutation() and objc_set_enumeration_mutation_handler() */
  25. /* The enumeration mutation handler currently in use. */
  26. static void (*__objc_enumeration_mutation_handler)(id) = NULL;
  27. void
  28. objc_setEnumerationMutationHandler (void (*handler)(id))
  29. {
  30. __objc_enumeration_mutation_handler = handler;
  31. }
  32. void
  33. objc_enumerationMutation (id collection)
  34. {
  35. if (__objc_enumeration_mutation_handler != NULL)
  36. (*__objc_enumeration_mutation_handler) (collection);
  37. /* We always abort if we get here; there is no point in going on as
  38. the next iteration in the fast enumeration would probably go
  39. deeply wrong. */
  40. _objc_abort ("Collection %p mutated during fast enumeration", collection);
  41. }