discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Replacement for descriptionForInstanceMethod:


From: Fred Kiefer
Subject: Re: Replacement for descriptionForInstanceMethod:
Date: Tue, 8 May 2018 19:32:26 +0200


> Am 08.05.2018 um 19:26 schrieb Andreas Höschler <ahoesch@smartsoft.de>:
> 
>> Most likely it isn’t working for the same reason as that code wasn’t working 
>> on GNUstep :-)
>> The runtime function will only check for methods defined by the protocol 
>> directly not for inherited ones. That is why the GNUstep function has 
>> „recursive“ in its name. It is checking in the ancestry of the protocol.
> 
> My test code was
> 
> @protocol TestProtocol
> 
> - (void)doIt;
> 
> @end
> 
>    
>    Protocol *_protocol = @protocol(TestProtocol);
>    SEL aSelector = @selector(doIt);
>    struct objc_method_description _methodDescription = 
> protocol_getMethodDescription(_protocol, aSelector, NO, YES);
>    if (_methodDescription.name == NULL) _methodDescription = 
> protocol_getMethodDescription(_protocol, aSelector, NO, NO);
>    NSLog(@"_methodDescription.name %@", 
> NSStringFromSelector(_methodDescription.name));
>    
> Where is the ancestry here? Isn't "doIt" defined directly in this example?

Here is the GNUstep code for this function: 

struct objc_method_description
GSProtocolGetMethodDescriptionRecursive(Protocol *aProtocol, SEL aSel, BOOL 
isRequired, BOOL isInstance)
{
  struct objc_method_description desc;

  desc = protocol_getMethodDescription(aProtocol, aSel, isRequired, isInstance);
  if (desc.name == NULL && desc.types == NULL)
    {
      Protocol **list;
      unsigned int count;

      list = protocol_copyProtocolList(aProtocol, &count);
      if (list != NULL)
        {
          unsigned int i;

          for (i = 0; i < count; i++)
            {
              desc = GSProtocolGetMethodDescriptionRecursive(list[i],
                aSel, isRequired, isInstance);
              if (desc.name != NULL || desc.types != NULL)
                {
                  break;
                }
            }
          free(list);
        }
    }

  return desc;
}

As you can see, the difference must either be in the recursive call or in the 
isRequired parameter. You could try to set that to YES for your direct call.




reply via email to

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