Target.m
changeset 1 e55a17cdabd2
parent 0 d84d25d6cdbb
child 7 59addced5e2a
     1.1 --- a/Target.m	Sat Mar 08 21:04:41 2008 -0800
     1.2 +++ b/Target.m	Thu Mar 20 09:05:58 2008 -0700
     1.3 @@ -28,26 +28,30 @@
     1.4  
     1.5  id $calltarget( NSInvocation *target, id param )
     1.6  {
     1.7 +    id result = nil;
     1.8      if( target && target.target ) {
     1.9 -        [target setArgument: &param atIndex: 2];
    1.10 -        [target invoke];
    1.11 -        
    1.12 -        NSMethodSignature *sig = target.methodSignature;
    1.13 -        NSUInteger returnLength = sig.methodReturnLength;
    1.14 -        if( returnLength==0 )
    1.15 -            return nil; // void
    1.16 -        else {
    1.17 -            const char *returnType = sig.methodReturnType;
    1.18 -            if( returnType[0]=='@' ) {
    1.19 -                id returnObject;
    1.20 -                [target getReturnValue: &returnObject];
    1.21 -                return returnObject;
    1.22 +        [target retain];
    1.23 +        @try{
    1.24 +            [target setArgument: &param atIndex: 2];
    1.25 +            [target invoke];
    1.26 +            
    1.27 +            NSMethodSignature *sig = target.methodSignature;
    1.28 +            NSUInteger returnLength = sig.methodReturnLength;
    1.29 +            if( returnLength==0 ) {
    1.30 +                result = nil; // void
    1.31              } else {
    1.32 -                UInt8 returnBuffer[returnLength];
    1.33 -                [target getReturnValue: &returnBuffer];
    1.34 -                return [NSValue valueWithBytes: &returnBuffer objCType: returnType];
    1.35 +                const char *returnType = sig.methodReturnType;
    1.36 +                if( returnType[0]=='@' ) {
    1.37 +                    [target getReturnValue: &result];
    1.38 +                } else {
    1.39 +                    UInt8 returnBuffer[returnLength];
    1.40 +                    [target getReturnValue: &returnBuffer];
    1.41 +                    result = [NSValue valueWithBytes: &returnBuffer objCType: returnType];
    1.42 +                }
    1.43              }
    1.44 +        }@finally{
    1.45 +            [target release];
    1.46          }
    1.47 -    } else
    1.48 -        return nil;
    1.49 +    }
    1.50 +    return result;
    1.51  }