discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Question about message forwarding


From: Adam Fedor
Subject: Re: Question about message forwarding
Date: Mon, 17 Apr 2006 21:17:16 -0600

It seems that in some cases the forwarding mechanism can't figure out the method signature and get's it wrong. Adding

@protocol Del
-(void)foo;
-(void)bar:(int)key;
-(void)baz:(NSNumber*)key;
@end

and making Forward respond to the <Del> protocol makes it work. Do you know if you are using ffcall or libffi?

On 2006-04-17 16:30:12 -0600 Issac Trotts <issac.trotts@gmail.com> wrote:

Here is some more information that may be useful.  The crash happened
on a Gentoo Linux i686 box, using gcc version 3.3.5 and gnustep-base
1.10.3.  Adding a respondsToSelector method has no effect.

The same program runs fine under Cocoa:

ijtrotts@issac-trotts-powerbook-g4-15:~/downloads$ gcc
forwardingTest.m -framework Cocoa && ./a.out
Delegate 0x5042a0 foo
Delegate 0x5042a0 bar: 1234
Delegate 0x5042a0 baz: 1234


Here is a test I wrote to track down a problem with message forwarding
in another program I'm writing.

// fowardingTest.m
#import <Foundation/Foundation.h>
#import <stdio.h>

@interface Delegate: NSObject
{

}
-(void)foo;
-(void)bar:(int)key;
-(void)baz:(NSNumber*)key;
@end

@implementation Delegate
-(void)foo
{
     printf("Delegate %p foo\n",self);
}

-(void)bar:(int)key
{
     printf("Delegate %p bar: %i\n",self,key);
}

-(void)baz:(NSNumber*)key
{
     printf("Delegate %p baz: %i\n",self,[key intValue]);
}
@end


@interface Forwarder: NSObject
{
     Delegate* delegate;
}
-(id)initWithDelegate:(Delegate*)d;
@end

@implementation Forwarder
-(id)initWithDelegate:(Delegate*)d
{
     if((self=[super init])==nil) { return nil ; }
     delegate = d;
     return self;
}

-(void)forwardInvocation:(NSInvocation*)invo
{
     [invo invokeWithTarget:delegate];
}

-(NSMethodSignature *)methodSignatureForSelector:(SEL)sel
{
     return [delegate methodSignatureForSelector:sel];
}
@end

int main()
{
     NSAutoreleasePool* pool = [NSAutoreleasePool new];
     Delegate* d = [Delegate new];
     Forwarder* f = [[Forwarder alloc] initWithDelegate:d];
     [f foo];
     [f bar:1234];
     [f baz:[NSNumber numberWithInt:1234]];
     [pool release];
     return 0;
}


Here is the output:

Delegate 0x8063bf0 foo
Delegate 0x8063bf0 bar: -1078528424
Segmentation fault

So I would like to know why bar does not show 1234.  Looking at a
stack trace, baz does get called, but I think the `key' argument is
corrupted, hence the crash.  So, why are the args getting trashed?

Thanks,
Issac




------------------------------

_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnustep


End of Discuss-gnustep Digest, Vol 41, Issue 18
***********************************************



_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnustep






reply via email to

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