[Top][All Lists]

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

Question about message forwarding

From: Issac Trotts
Subject: Question about message forwarding
Date: Fri, 14 Apr 2006 22:15:46 -0700

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


@implementation Delegate
    printf("Delegate %p foo\n",self);

    printf("Delegate %p bar: %i\n",self,key);

    printf("Delegate %p baz: %i\n",self,[key intValue]);

@interface Forwarder: NSObject
    Delegate* delegate;

@implementation Forwarder
    if((self=[super init])==nil) { return nil ; }
    delegate = d;
    return self;

    [invo invokeWithTarget:delegate];

-(NSMethodSignature *)methodSignatureForSelector:(SEL)sel
    return [delegate methodSignatureForSelector:sel];

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?


reply via email to

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