Fast enumeration, actually working this time.

View: New views
6 Messages — Rating Filter:   Alert me  

Fast enumeration, actually working this time.

by David Chisnall-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.



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

fastenumeration.diff (1K) Download Attachment

Re: Fast enumeration, actually working this time.

by David Chisnall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

Re: Fast enumeration, actually working this time.

by KNL :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

David,

Is this compiler with fast enumeration part of the release of GNUStep for windows? I ask I'm developing some code on Win XP using GNUStep and I get lots of compile time errors when trying to use fast enumeration.

Many thanks for your reply,

Ken



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.

Re: Fast enumeration, actually working this time.

by David Chisnall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 23 Oct 2009, at 22:21, KNL wrote:

> David,
>
> Is this compiler with fast enumeration part of the release of  
> GNUStep for
> windows? I ask I'm developing some code on Win XP using GNUStep and  
> I get
> lots of compile time errors when trying to use fast enumeration.

Fast enumeration is supported with clang, but not with GCC.  Clang  
builds on Windows with either Visual Studio or with CMake, but it is  
not (yet) part of the GNUstep Windows distribution.

David


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

Re: Fast enumeration, actually working this time.

by KNL :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Oh nice. Something I can download?

Sent from my iPhone: 917-940-2709

On Oct 24, 2009, at 9:33 AM, David Chisnall <theraven@...> wrote:

> On 23 Oct 2009, at 22:21, KNL wrote:
>
>> David,
>>
>> Is this compiler with fast enumeration part of the release of  
>> GNUStep for
>> windows? I ask I'm developing some code on Win XP using GNUStep and  
>> I get
>> lots of compile time errors when trying to use fast enumeration.
>
> Fast enumeration is supported with clang, but not with GCC.  Clang  
> builds on Windows with either Visual Studio or with CMake, but it is  
> not (yet) part of the GNUstep Windows distribution.
>
> David

Oh nice. Something I can download?

Sent from my iPhone: 917-940-2709

On Oct 24, 2009, at 9:33 AM, David Chisnall <theraven@...> wrote:

> On 23 Oct 2009, at 22:21, KNL wrote:
>
>> David,
>>
>> Is this compiler with fast enumeration part of the release of  
>> GNUStep for
>> windows? I ask I'm developing some code on Win XP using GNUStep and  
>> I get
>> lots of compile time errors when trying to use fast enumeration.
>
> Fast enumeration is supported with clang, but not with GCC.  Clang  
> builds on Windows with either Visual Studio or with CMake, but it is  
> not (yet) part of the GNUstep Windows distribution.
>
> David


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

Re: Fast enumeration, actually working this time.

by David Chisnall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 24 Oct 2009, at 17:34, Ken Linton wrote:

> Oh nice. Something I can download?


Just grab the latest llvm and trunk clang and build them.

David

-- Sent from my PDP-11



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