Skip to content

Commit 6e4fa86

Browse files
committed
Offer an objc_enumerationMutation hook for platforms without weak imports.
1 parent 8c8534e commit 6e4fa86

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

mutation.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22
#include <stdlib.h>
33
#include "objc/runtime.h"
44

5-
// This function is exported as a weak symbol to enable GNUstep or some other
6-
// framework to replace it trivially
7-
void __attribute__((weak)) objc_enumerationMutation(id obj)
5+
static void objc_enumeration_mutation_fallback(id object)
86
{
97
fprintf(stderr, "Mutation occured during enumeration.");
108
abort();
119
}
1210

11+
void (*_objc_enumeration_mutation)(id object) = &objc_enumeration_mutation_fallback;
12+
13+
// This function is exported as a weak symbol to enable GNUstep or some other
14+
// framework to replace it trivially. On platforms with linkers that cannot handle weak exports,
15+
// the objc_enumeration_mutation hook is the preferred override point.
16+
void __attribute__((weak)) objc_enumerationMutation(id obj)
17+
{
18+
_objc_enumeration_mutation(obj);
19+
}
20+

objc/hooks.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ typedef IMP (*objc_tracing_hook)(id, SEL, IMP, int, void*);
110110
*/
111111
int objc_registerTracingHook(SEL, objc_tracing_hook);
112112

113+
/**
114+
* Hook called when a collection is mutated while it is being enumerated.
115+
*/
116+
OBJC_HOOK void(*_objc_enumeration_mutation)(id object);
117+
113118
#ifdef __cplusplus
114119
}
115120
#endif

0 commit comments

Comments
 (0)