Code Monkey home page Code Monkey logo

Comments (2)

ronaldoussoren avatar ronaldoussoren commented on August 27, 2024

This issue is still present, and seems to fail unconditionally now instead of only intermittently (BigSur, M1).

I suspect that this is a bug in how PyObjC builds formal protocols.

from pyobjc.

ronaldoussoren avatar ronaldoussoren commented on August 27, 2024

The weird thing is that the "fake" implementation for protocol_getMethodDescription() calls protocol_copyMethodDescriptionList() to get information from the ObjC runtime and never seems to fail. This is the same runtime information that the real protocol_getMethodDescription() is supposed to use.

Some more checking: Added sanity check with protocol_getMethodDescription() both before and after objc_registerProtocol() (which finishes protocol creation). This sanity check always succeeds before the call to objc_registerProtocol() and sometimes fails after that call.

Registering all protocol selectors twice seems to fix the issue, but then those selectors end up twice in the protocol which causes other test failures.

This seems to be an ObjC runtime bug, although I haven't been able yet to reproduce it outside of PyObjC...

#import <objc/runtime.h>
#include <stdio.h>


int main(void)
{
    SEL sel1 = sel_registerName("protoMethod:");
    const char* sig1 = "I@:";

    SEL sel2 = sel_registerName("anotherProto:with:");
    const char* sig2 = "v@:ii";

    Protocol* p = objc_allocateProtocol("MyProtocol");
    struct objc_method_description descr;

    if (p == NULL) {
        printf("cannot create protocol\n");
        return 1;
    }

    protocol_addMethodDescription(p, sel1, sig1, YES, YES);

    descr = protocol_getMethodDescription(p, sel1, YES, YES);
    if (descr.name == NULL) {
        printf("added selector 1 not found protocol (build phase)\n");
        return 1;
    }

    protocol_addMethodDescription(p, sel2, sig2, YES, YES);

    descr = protocol_getMethodDescription(p, sel2, YES, YES);
    if (descr.name == NULL) {
        printf("added selector 2 not found protocol (build phase)\n");
        return 1;
    }

    objc_registerProtocol(p);        

    descr = protocol_getMethodDescription(p, sel1, YES, YES);
    if (descr.name == NULL) {
        printf("added selector 1 not found protocol (registered phase)\n");
        return 1;
    }

    descr = protocol_getMethodDescription(p, sel2, YES, YES);
    if (descr.name == NULL) {
        printf("added selector 2 not found protocol (registered phase)\n");
        return 1;
    }

    return 0;
}

That's it for now, although I might return to this issue later on.

from pyobjc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.