rust-lang / rust-bindgen

Automatically generates Rust FFI bindings to C (and some C++) libraries.
https://rust-lang.github.io/rust-bindgen/
BSD 3-Clause "New" or "Revised" License
4.37k stars 687 forks source link

Different results for tests/headers/objc_template.h in LLVM trunk. #695

Open emilio opened 7 years ago

emilio commented 7 years ago

Running the tests on LLVM trunk with (or without) #694 yields:

diff --git a/tests/expectations/tests/objc_template.rs b/tests/expectations/tests/objc_template.rs
index e5a874c6..95d12ff6 100644
--- a/tests/expectations/tests/objc_template.rs
+++ b/tests/expectations/tests/objc_template.rs
@@ -11,8 +11,8 @@ extern crate objc;
 pub type id = *mut objc::runtime::Object;
 pub trait Foo {
     unsafe fn get(self)
-    -> id;
+    -> *mut ObjectType;
 }
 impl Foo for id {
-    unsafe fn get(self) -> id { msg_send!(self , get) }
+    unsafe fn get(self) -> *mut ObjectType { msg_send!(self , get) }
 }

cc @scoopr

scoopr commented 7 years ago

Ah yes, I was kind of afraid of this :/

Suggestions are welcome how I should handle this, the template handling stuff is a bit harder to grok in bindgen.

So before the objc template params came up as an typedef, but now they seem to be TypeRefs, which I think aligns with, and are handled, as proper template params. And to keep things simple I'd just want the type to be replaced with the ‘id’.

I almost got it working hacking Item::named_type() to rewrite the name to "id" when location.referenced().typedef_type().kind() == CXType_ObjCId, but that made it also mut-pointer. Also I kind of feel that it should be done earlier in the parsing.

I suppose making it behave like a proper generic in rust land would also be an option, but so far I have not looked in to that.