[Top][All Lists]

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

Re: NSProtocolChecker doesn't forward messages

From: Kazunobu Kuriyama
Subject: Re: NSProtocolChecker doesn't forward messages
Date: Sun, 25 Apr 2004 13:01:35 +0900
User-agent: Mozilla/5.0 (X11; U; Linux i686; ja-JP; rv:1.4) Gecko/20030624 Netscape/7.1

J.F.Costa wrote:

Hi, everybody.

        NSProtocolChecker instances don't forward the messages that are in
it's protocol. Here is NSProtocolChecker's forwarding method:

- (void) forwardInvocation: (NSInvocation*)anInvocation
 unsigned int   length;
 void           *buffer;

 if ((struct objc_method_description *)NULL
   != [self methodDescriptionForSelector: [anInvocation selector]])
   [[NSException exceptionWithName: NSInvalidArgumentException
                  reason: @"Method not declared in current protocol"
                  userInfo: nil] raise];

 [anInvocation invokeWithTarget: _myTarget];

 length = [[anInvocation methodSignature] methodReturnLength];
 buffer = (void *)malloc(length);
 [anInvocation getReturnValue: buffer];

 if (0 == strcmp([[anInvocation methodSignature] methodReturnType],
                  [[anInvocation methodSignatureForSelector:
                                  @selector(init: )] methodReturnType]) )
     if (((id)buffer) == _myTarget)
          buffer = self;
          [anInvocation setReturnValue: buffer];


        Notice that the comparison symbol in the protocol check is wrong, it
should be '=='. Besides that, there is something wrong with the
condition in the second 'if', because the former segfaults. What is
the correct condition?

In addition to the issues above, there's a memory leak.

BTW, when should we use objc_malloc() instead of malloc()? Is there any plan
to make objc_malloc() better than malloc()?

- Kazunobu Kuriyama

reply via email to

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