[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fast enumeration, actually working this time.
From: |
David Chisnall |
Subject: |
Fast enumeration, actually working this time. |
Date: |
Tue, 3 Feb 2009 21:12:30 +0000 |
Now I have a compiler that supports fast enumeration on the GNU
runtime (no one else does yet, but I hope to fix that soon) I am able
to actually test the implementation... and it's all wrong.
This diff fixes it. I've tested it with this program:
#import <Foundation/Foundation.h>
void objc_enumerationMutation(id obj)
{
NSLog(@"%@ changed during enumeration", obj);
}
int main(void)
{
[NSAutoreleasePool new];
id array = [NSArray arrayWithObjects:@"0", @"1", @"2", @"3",
@"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12", @ "13",
@"14", @"15", @"16", @"17", @"18", @"19", nil];
NSLog(@"Starting enumeration fish");
for (id i in array) { NSLog(@"i: %@", i); }
array = [array mutableCopy];
for (id i in array) { NSLog(@"i: %@", i); }
for (id i in [array objectEnumerator]) { NSLog(@"i: %@", i); }
NSLog(@"finished enumeration");
return 0;
}
And it prints 0..19 three times. Note that objc_enumerationMutation()
needs to be set. Ideally this would be a symbol defined in GNU
libobjc and the function pointer provided by Foundation, but for now
we can probably just define it ourselves. The correct definition for
Apple compatibility would be:
void objc_enumerationMutation(id obj)
{
[NSException raise: NSGenericException format: @"Collection %@ was
mutated while being enumerated", objc];
}
David
P.S. In most of the world it is considered bad form to commit other
people's patches without acknowledging them in the commit message.
For those of us in the EU, it is also illegal.
fastenumeration.diff
Description: Binary data
- Fast enumeration, actually working this time.,
David Chisnall <=