-
Notifications
You must be signed in to change notification settings - Fork 717
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
PhantomData is not foreign-function safe #442
Comments
That is (unfortunately) known, see rust-lang/rust#34798. This is a lint problem though. This goes away in nightly rust if you use native unions, of course, but until that's fixed... We could only alter our union representation to use setters/getters instead of fields, but I implemented the current solution because people complained that getters/setters were too annoying :/ |
Also, we cannot workaround these warnings for things like: template <typename T>
struct Foo {
int bar;
}; |
Thanks for the follow up. I'm still confused about whether the lint is a real issue or not. If So maybe the lint should except this type? Or we could stabilize an |
It's a lint issue as far as I understand it.
Yeah, an exception for the lint is the best thing (I never looked into implementing it, but doesn't sound too difficult). Alternatively, |
I'll try to whitelist PhantomData, and see how it turns like. |
I am having this exact issue. Are the structs I am passing to C still represented correctly? The C library I am working with behaves differently when I call call it with Rust and C. Could there be a representation issue? |
Yes, we generate assertions so that the types and offsets are correct. With template parameters it's a bit harder, but it's not a problem of BTW, I landed a PR in rust to avoid the warning. I'm happy to take a look at the code if you hand me a link to see what can be going wrong :) |
PR: awesome ;) My code is at: Library works fine when using C (same repo) https://github.com/medium-endian/crisp/blob/master/cisp/parsing.c parsing.c and main.rs are supposed do the same thing :) |
Your code acts wrong because you made a typo, but the bindings work correctly. This code: if (mpc_parse(stdin_str.as_ptr(), input.as_ptr(), number, &mut r)) != 0 { Should read: if (mpc_parse(stdin_str.as_ptr(), input.as_ptr(), lispy, &mut r)) != 0 { With that both do the same :) |
Also, probably you want to know that you can use |
Oh my, thank you so much. Really can't thank enough. Sorry for accusing the bindings! |
This should be fixed now: rust-lang/rust#39462 |
Since PhantomData is a ZST, it wasn't considered safe to use in a repr(C) struct. In practice, however, since the C side doesn't care about the PhantomData, it's fine. Also this particular case no longer causes the warning on nightlies: rust-lang/rust-bindgen#442
On my system (Fedora Linux 25) bindgen generates a
PhantomData
-based union representation forfpos_t
from stdio. Rustc (1.14 or 1.15) complains about this:Here's a reduced example:
It would be good if the generated code compiled without warnings.
The text was updated successfully, but these errors were encountered: