-
Notifications
You must be signed in to change notification settings - Fork 707
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
Inconsistent opaque type representation #1194
Comments
So, this looks like something where libclang is lying at us, though I haven't actually checked much closer. First of all, I assume typedef Range<char*> MutableStringPiece; right? (otherwise the expected representation would be If I run a header that instantiates both types: template <class a> class Range { a b, c; };
typedef Range<const char *> StringPiece;
typedef Range<char*> MutableStringPiece;
struct Foo {
StringPiece foo;
MutableStringPiece bar;
}; I get the expected: /* automatically generated by rust-bindgen */
pub type StringPiece = [u64; 2usize];
pub type MutableStringPiece = [u64; 2usize]; |
In any case this is a bug of course, the type shouldn't change depending on whether it's instantiated or not... |
Err, I lie, and this is introduced by 28ae2a1, very obviously on retrospective. |
Hmm, not so obviously actually, I bet I messed up the bisect |
Yeah, the bisect is incorrect, this is not a new regression at all it seems... We're not getting the proper layout off libclang unless the type is actually instantiated, wtf. |
Yeah, 92c1a25 changed the output, but that was only from |
I think this is kind of expected, because based on the information clang has, the final size of the type is not known. Someone could do something like: template <class a> class Range { a b, c; };
typedef Range<const char *> StringPiece;
template<>
class Range<const char*> { }; Or what not... Probably could write a libclang patch to try to instantiate the type if not done before? Not sure if that's trivial, would need to dig a bit... |
Yes it should be that - I left the creduce run under-constrained. But it doesn't look like it makes any material difference to the real bug. |
OK, so I can work around this by adding struct _dummy_instantiate {
folly::MutableStringPiece a;
folly::MutableByteRange b;
};
to my header. I'm pleased to have a workaround, but this definitely seems like something I shouldn't have to do. I think this is probably a pervasive problem now that I think of it - I've seen a lot of inconsistencies between whether an opaque type is represented as |
Input C/C++ Header
Bindgen Invocation
Actual Results
Expected Results
StringPiece
has a Rust type which correctly reflects its representation:[u64; 2size]
, which allows the Rust version of the type to be moved around etc. TheMutableStringPiece
is misrepresented byu8
, which results in runtime errors because only the first byte is moved.It looks like the
d()
function is what makes the difference; if I remove this then bothStringPiece
andMutableStringPiece
get the same incorrectu8
representation.This seems to be a regression introduced about 0.31, but I haven't checked specifically.
cc @kulshrax
The text was updated successfully, but these errors were encountered: