[Top][All Lists]

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

Re: NSProtocolChecker doesn't forward messages

From: Richard Frith-Macdonald
Subject: Re: NSProtocolChecker doesn't forward messages
Date: Sun, 25 Apr 2004 08:42:05 +0100

On 25 Apr 2004, at 03:37, 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?

I looked at the source for this class, and it appears nobody has ever used/tested it since it was written in 1998! It looks completely broken, with a couple of memory
leaks, missing method implementations, extra bogus code etc.

I have placed a rewritten version in CVS, which should actually work now I hope.

reply via email to

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