Skip to content

objc: use objc_runtime_name for class! lookups - #3547

Open
HawkForge wants to merge 1 commit into
rust-lang:mainfrom
HawkForge:fix/objc-runtime-name
Open

HawkForge wants to merge 1 commit into
rust-lang:mainfrom
HawkForge:fix/objc-runtime-name

Conversation

@HawkForge

Copy link
Copy Markdown

Fixes #3476

For an interface with __attribute__((objc_runtime_name("RuntimeFoo"))), bindgen generated class!(Foo) (the source name) for alloc(), class methods and the TryFrom downcast. At runtime the class is registered as RuntimeFoo, so the lookup fails.

libclang has no cursor kind for this attribute, so ObjCInterface::from_ty now reads it from the tokens of the CXCursor_UnexposedAttr child (objc_runtime_name ( "Name" )) and stores it as runtime_name. Codegen uses runtime_name() for every class!() call; the Rust struct and trait keep the source name. Without the attribute nothing changes.

Test: added objc_runtime_name.h with expectations (an interface with the attribute, one without). cargo test -p bindgen-tests passes except header_objc_template_h, which also fails on unmodified main. cargo +nightly fmt --check is clean.

class!() was given the source name, but a class declared with
objc_runtime_name("X") is registered as X at runtime, so alloc, class
methods and the TryFrom downcast looked up a class that doesn't exist.
libclang exposes the attribute only as an unexposed attr, so read it from
the attribute's tokens. The Rust type keeps the source name.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

objc_runtime_name is ignored: class!(SourceName) looks up a class that does not exist

1 participant