[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about message forwarding
From: |
Issac Trotts |
Subject: |
Re: Question about message forwarding |
Date: |
Mon, 17 Apr 2006 15:30:12 -0700 |
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
> ***********************************************
>