Fast enumeration, actually working this time.

2009-02-03 Thread David Chisnall
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 

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
___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: Fast enumeration, actually working this time.

2009-02-03 Thread David Chisnall

On 3 Feb 2009, at 21:12, David Chisnall wrote:

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)


Much faster than I expected.  Clang trunk now supports fast  
enumeration with the GNU runtime.


Note that ccc, the clang driver, currently dies if you pass it -g (no  
idea why) so you have to build with debug=no and you will need a line  
like this in your GNUmakefile to use it:


CC=~/llvm/tools/clang/utils/ccc

David


___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev