discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Porting to 64Bit -descriptionForInstanceMethod:


From: Andreas Höschler
Subject: Re: Porting to 64Bit -descriptionForInstanceMethod:
Date: Tue, 18 Jun 2019 15:58:32 +0200

Hi David and all,

a google search for Objective-C runtime functions of course led to 

https://developer.apple.com/documentation/objectivec/objective-c_runtime?language=objc

and I thought I just had to select the proper method from the list and am done. But this does not seem to be that simple!? I found

         NSMethodSignature *methodSig = [[self class] instanceMethodSignatureForSelector:mySelector];
         NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSig]; 

for getting the method signature of an instance method for a known class. But in my case I just have a protocol. What would be the replacement for

        methodDescription = [_protocol descriptionForInstanceMethod:aSelector];
        char *types = methodDescription->types;
        NSMethodSignature *methodSig  = [NSMethodSignature signatureWithObjCTypes:types];

with current objective-C runtime functions? Is that still possible at all? My search attempts for the proper runtime function so far led to 

void method_getReturnType(Method m, char *dst, size_t dst_len);
void method_getArgumentType(Method m, unsigned int index, char *dst, size_t dst_len);
unsigned int method_getNumberOfArguments(Method m);

So I might be able to construct 

         char *types = NULL;

from this and then do 

        NSMethodSignature *methodSig  = [NSMethodSignature signatureWithObjCTypes:types];

but how do I get a Method from a given selector and protocol??

I am lost! :-(

Thanks a lot,

 Andreas


On 18 Jun 2019, at 14:12, David Chisnall <gnustep@theravensnest.org> wrote:

*SRProxy.m:419:29: **warning: **instance method '-descriptionForInstanceMethod:' not found (return type defaults to 'id') [-Wobjc-method-access]*
         types = [_protocol descriptionForInstanceMethod:aSelector]->types;
*                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~*
*/usr/include/objc/Protocol.h:45:12: note: *receiver is instance of class declared here
@interface Protocol : NSObject
*           ^*
*SRProxy.m:419:70: **error: **no member named 'types' in 'struct objc_object'*
*
*

With the 'Modern' Objective-C ABI (circa 2006) on Apple platforms, the only option on 64-bit and the default for a very long time on 32-bit, Protocol no longer has any methods exposed on it.  This means:

- descriptionForInstanceMethod: is gone.  Don't use it, use the runtime functions instead.  There is no point paying the overhead of an Objective-C message send for a function where all of the types are known at compile time.

- The compiler assumes that the nonexistent method -descriptionForInstanceMethod: returns id, which is a typedef for struct objc_object, which has no fields other than isa (probably not even isa, because direct access to isa is also deprecated).



reply via email to

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