Skip to content

[ffigen] Improve handling of ObjC method families and retention annotations #1446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
liamappelbe opened this issue Aug 23, 2024 · 3 comments · Fixed by #1491
Closed

[ffigen] Improve handling of ObjC method families and retention annotations #1446

liamappelbe opened this issue Aug 23, 2024 · 3 comments · Fixed by #1491
Assignees
Milestone

Comments

@liamappelbe
Copy link
Contributor

To deduce whether an ObjC method returns a retained reference or not, we use a combination of method family detection and annotations. But our support for this is incomplete, and misses a few edge cases. The full docs are here.

Specifically, the method family detection rules are slightly more complicated than what we've implemented, we're not handling the annotations that can alter the method family, and we're only handling the NS_RETURNS_RETAINED annotation (the other annotations can opt-out a method that is supposed to return retained due to its method family).

We're also not handling the argument consumption annotations, or the consumes self annotation.

Finally, all these rules (except method families) should also apply to blocks.

Follow up to #1441

@dcharkes
Copy link
Collaborator

https://clang.llvm.org/docs/AutomaticReferenceCounting.html

That was an interesting read! I was rather surprised that method names automatically apply families. Lot's of magic in the name or conciseness.

@liamappelbe
Copy link
Contributor Author

The objc_method_family annotation is not exposed in libclang, so I'll ignore it for now. It seems pretty obscure anyway.

@liamappelbe
Copy link
Contributor Author

Finally, all these rules (except method families) should also apply to blocks.

Unfortunately libclang doesn't seem to have a way of accessing __attribute__((ns_returns_retained)) and __attribute__((ns_consumed)) annotations on blocks.

For methods and top level functions, these annotations are on the CXCursor of the declaration, but for blocks I only have a CXType with no declaration cursor. If I annotate a block with NS_RETURNS_RETAINED, the CXType's kind changes from FunctionProto to Unexposed. If I annotate it with __attribute__((ns_returns_retained)) the kind changes to Attributed, which is a bit more promising, but I can't find a way of getting the attribute. If I annotate one of the args with __attribute__((ns_consumed)), nothing happens at all.

I'll fix what bugs I can, and leave parsing these attributes as follow up work: #1490

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants