discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ANN: GNUstep Objective-C Runtime 1.2


From: David Chisnall
Subject: Re: ANN: GNUstep Objective-C Runtime 1.2
Date: Mon, 21 Feb 2011 23:52:22 +0000

I just tried your test programs.  On FreeBSD/x86 with clang, non-fragile ABI, 
libobjc2 1.2 and -base from trunk, I get, for the first one:

2011-02-21 23:02:49.183 test[80244] Hello world
2011-02-21 23:02:49.195 test[80244] Hello world
2011-02-21 23:02:49.196 test[80244] Block went into array okay
2011-02-21 23:02:49.201 test[80244] Hello world

I get the same running it on Linux/x86-64, so I'll have to do a bit more 
chasing there.  Even valgrind doesn't report any problems.  However...

I did fix quite a few bugs in the blocks runtime in libobjc2 recently, and 
they've not been back-ported to the ObjectiveC2 framework in -base yet.  If 
you've not recompiled -base, then you may accidentally be using the wrong 
blocks runtime, which may account for this.  

For the second one:

2011-02-21 23:05:07.133 test[80261] Attempting to set nonatomic property
2011-02-21 23:05:07.137 test[80261] Set
2011-02-21 23:05:07.137 test[80261] Attempting to set atomic property
2011-02-21 23:05:07.138 test[80261] Set

Running it on Linux, I find the problem - it seems that clang is setting 
instance_size for metaclasses to 0, rather than to the size of the class 
structure.  I'm not sure if GCC does this correctly, but I think it does.  The 
sync_enter code is doing a hidden class transform.  

This is fixed in clang trunk.  This bug may also have caused some other subtle 
problems elsewhere, so please recompile everything and retest.

David

On 21 Feb 2011, at 22:49, Thomas Davie wrote:

> On 21 Feb 2011, at 22:38, David Chisnall wrote:
> 
>> Nope, that's expected.  The configure test is checking GNU Vs NeXT there.  
>> It places the GCC and GNUstep runtimes in one category and the NeXT (Apple 
>> Legacy) and Apple (Apple Modern) runtimes in the other category.  
>> 
>> This is because gcc and clang use -fgnu-runtime and -fnext-runtime to select 
>> between the two ABIs, with -fobjc-nonfragile-abi to differentiate within the 
>> group:
>> 
>> -fgnu-runtime:                                               GCC ABI 
>> (supported by GCC and GNUstep runtimes)
>> -fgnu-runtime -fobjc-nonfragile-abi:         GNUstep ABI (GNUstep runtime 
>> only, maybe GCC 4.7 runtime?)
>> -fnext-runtime:                                              Apple Legacy 
>> runtime / NeXT runtime
>> -fnext-runtime -fobjc-nonfragile-abi         Apple Modern runtime
>> 
>> On OS X, selecting -m32 or -m64 also slightly changes the ABI, but not much.
>> 
>> If you are using clang and the GNUstep runtime, I'd recommend that you also 
>> tell make's configure script that you want to use the non-fragile ABI.  This 
>> gives you a few extra things (non-fragile ivars, proper support for 
>> -forwardingTargetForSelector:, safe automatic IMP caching).  
> 
> Thanks very much,
> 
> Given this, I believe I now have gnustep-base compiled with the new runtime, 
> and am compiling a pair of test programs that seem to be exhibiting erroneous 
> behaviour:
> 
> The first[Test1] attempts to put a block in an array and take it out again, 
> and seg faults while doing so:
> 2011-02-21 22:43:23.246 Test[27776] Hello world
> 2011-02-21 22:43:23.251 Test[27776] Hello world
> Segmentation fault
> 
> The second[Test2] attempts to use @synchronized for an atomic setter method, 
> and similarly seg faults – the same happens when tried with @synthesized 
> atomic properties:
> 2011-02-21 22:43:46.807 Test[27828] Attempting to set nonatomic property
> 2011-02-21 22:43:46.813 Test[27828] Set
> 2011-02-21 22:43:46.813 Test[27828] Attempting to set atomic property
> Segmentation fault
> 
> Where is the correct place for me to put these?
> 
> Bob
> 
> 
> [Test1]
> #import <Foundation/Foundation.h>
> 
> int main (int argc, char **argv)
> {
>    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
>    void (^hello)(void) = ^() { NSLog(@"Hello world"); };
>    hello();
>    void (^helloCopy)(void) = Block_copy(hello);
>    helloCopy();
>    NSArray *blockArr = [NSArray arrayWithObject:helloCopy];
>    NSLog(@"Block went into array okay");
>    void (^helloArr)(void) = [blockArr objectAtIndex:0];
>    helloArr();
>    Block_release(helloCopy);
>    [pool drain];
>    return 0;
> }
> 
> [Test2]
> #import <Foundation/Foundation.h>
> 
> @interface A : NSObject
> {
> @private
>    NSObject *n;
>    NSObject *a;
> }
> 
> @property (nonatomic,readwrite,retain) NSObject *n;
> @property (readwrite,retain) NSObject *a;
> 
> @end
> 
> @implementation A
> 
> - (NSObject *)n
> {
>    return [[n retain] autorelease];
> }
> 
> - (void)setN:(NSObject *)newN
> {
>    if (n != newN)
>    {
>        [n release];
>        n = [newN retain];
>    }
> }
> 
> - (NSObject *)a
> {
>    return [[a retain] autorelease];
> }
> 
> - (void)setA:(NSObject *)newA
> {
>    @synchronized(self)
>    {
>        if (a != newA)
>        {
>            [a release];
>            a = [newA retain];
>        }
>    }
> }
> 
> @end
> 
> int main (int argc, char **argv)
> {
>    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
> 
>    A *a = [[[A alloc] init] autorelease];
>    NSObject *obj = [[[NSObject alloc] init] autorelease];
>    NSLog(@"Attempting to set nonatomic property");
>    a.n = obj;
>    NSLog(@"Set");
>    NSLog(@"Attempting to set atomic property");
>    a.a = obj;
>    NSLog(@"Set");
> 
>    [pool drain];
>    return 0;
> }
> 


-- Sent from my brain




reply via email to

[Prev in Thread] Current Thread [Next in Thread]