From `@_cdecl` to `@cdecl`

We had some experience with @_cdecl and there were a few issues we hit:

  1. @_cdecl cannot control the visibility of the symbol. If the function is made public, it appears in the swift interface and causes conflicts when it is also present in a C header in the same module.
  2. The return value is always autoreleased. E.g. @_cdecl func MyObjectCopyDescription(_ obj: MyObjectPointer?) -> CFString does not return a retained CFString.
  3. Compiler does not help with nil checking and it's an undefined behavior when NULL is passed to a non-Optional argument. We ended up making everything Optional and force unwrapping them to deterministically crash.

I think it's better to follow the pattern of @objc @implementation where the function needs to match the declaration in a C header. It would be easier than manually matching the arguments and coming up with new annotations in Swift.

6 Likes