Enable using XPCInterface with protocols defined in Python

Issue #256 new
Ronald Oussoren
repo owner created an issue

Creating an NSXPCInterface using a protocol defined in python results in an ObjC exception:

    NSInvalidArgumentException - NSXPCInterface: Unable to get extended method signature from Protocol data (MyProtocol / runCommand:withReply:). Use of clang is required for NSXPCInterface.

Try to find a work around for this.

See also https://stackoverflow.com/questions/52284089/is-it-possible-to-use-pyobjc-with-a-privilved-xpc-helper-tool-and-xpcinterface-a

Comments (1)

  1. Ronald Oussoren reporter

    I haven't found a reference to extended signatures yet, but did find the private function "_protocol_getMethodTypeEncoding" which returns some more information:

    #include <objc/runtime.h>
    #import <Foundation/Foundation.h>
    @protocol MyProtocol
    -(void)runCommand:(NSString*)command withReply:(void(^)(int))callback;
    extern char* _protocol_getMethodTypeEncoding(Protocol*, SEL, BOOL, BOOL);
    int main(void)
            NSLog(@"%@", @protocol(MyProtocol));
            struct objc_method_description description = protocol_getMethodDescription(@protocol(MyProtocol), @selector(runCommand:withReply:), YES, YES);
            NSLog(@"name: %s", sel_getName(description.name));
            NSLog(@"types: %s", description.types);
            NSLog(@"encoding: %s", _protocol_getMethodTypeEncoding(@protocol(MyProtocol), @selector(runCommand:withReply:), YES, YES));

    This code prints the following output:

    2018-12-30 12:04:45.507 t[33524:14607107] <Protocol: 0x1061c80f8>
    2018-12-30 12:04:45.507 t[33524:14607107] name: runCommand:withReply:
    2018-12-30 12:04:45.507 t[33524:14607107] types: v32@0:8@16@?24
    2018-12-30 12:04:45.507 t[33524:14607107] encoding: v32@0:8@"NSString"16@?<v@?i>24

    Note the extra information in the last line. Using this with objc.selector currently fails because PyObjC doesn't know about the angled brackets in signatures.

  2. Log in to comment