Extra type information in block signature causing problems for pyobjc

Issue #106 resolved
Ian McCullough
created an issue

I have a block parameter to a continuation-passing-style ObjC method that looks like: void (^)(NSString*) PyObjCBlock_GetSignature returns: "v@?@\"NSString\"" as the signature of the block. Eventually PyObjCFFI_CountArguments barfs on the extra type information (\"NSString\") in this signature. I'm not sure if this extra metadata is the product of a new compiler or what, but I've been able to get past the problem locally by crudely filtering out quoted strings from signatures in PyObjCMethodSignature_WithMetaData. Since this block signature retrieval is effectively dipping into undocumented runtime implementation details, I'm not sure there's necessarily any better approach.

FWIW, I'm on Yosemite 10.10 (14A389) with Xcode 6.1 (6A1052d) which uses clang-600.0.54.

Comments (7)

  1. Ian McCullough reporter

    I can also confirm that this pattern plays itself out when the blocks have more parameters, for instance, a block that looks like: void(^)(NSString*, NSError*) has a signature that looks like v@?@"NSString"@"NSError"

  2. Ian McCullough reporter

    I saw in your release notes that this issue kind of blew up on you. If you have a few minutes I'd love to hear more about the system/CPython bug you ran into.

  3. Ronald Oussoren repo owner

    I added a test case for this issue in PyObjCTest/test_blocks.py (testBlocksWithoutMetadata), and that test causes crashes on some test runs. But annoyingly never when using a debugger.

    The crash appears to be due to a block pointer with an invalid internal structure (the block descriptor and the actual C callable aren't valid pointers). The 3.0.4 release contains a workaround for this in PyObjCBlock_GetSignature (in Modules/objc/block_support.m).

    This could still be a bug in PyObjC itself, but could also be an OSX or CPython bug in the code that loads C extensions. Pinpointing the exact bug will likely be a lot of work, but will have to be done some time. Hopefully it will turn out to be a bug in PyObjC or CPython...

  4. Log in to comment