-
Notifications
You must be signed in to change notification settings - Fork 745
Bindgen converts char
to c_schar
instead of c_char
#603
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
Comments
From a short investigation, it seems that bindgen only knows about
|
Right, but LLVM takes care of figuring out signedness for us. See #559. |
Maybe so when bindgen is used as part of the build process for the target platform, but this doesn't work when generating one set of bindings that's meant to be used on all platforms, using the command line application. Or is this mode of operation now unsupported?
|
I guess that has only ever worked because of the platforms people generate bindings in happen to have signed chars. I guess this would need a bit of a hack to work, but I believe it can be done. In particular, we could try to check the type spelling to see if it doesn't contain neither |
The reason this "ever worked" is that it had only been broken for three weeks when reported (4f1e3da). I'm completely in agreement with what @crumblingstatue says about wanting to generate bindings offline. So "me too" on this one. |
The point is that before that change, we used char when libclang reported a signed char. |
Yes, I understand. But I guess that it's much more common for C APIs to use So I expect we've switched from "uncommon case is broken" to "common case is broken". |
It looks easy enough to 90% fix this, by which I mean convert types correctly from C to Rust. But there are still some places where bindgen asks whether a type is signed, and it's obviously impossible to give a universal definitive answer for Let me put together a pull request... |
Treat char as c_char Per #603. This still leaves `bindgen` having to make a call as to what to say when asked whether `Char` `is_signed()`. I've opted just to leave this as `true`, on the grounds that: * I don't currently understand an example where it matters * I suspect that if there are cases where it matters, then it shouldn't! * Because by definition, use of unadorned `char` in the original header says that it doesn't care about signedness * (signed is the common case, so that's a more sensible guess than unsigned)
@emilio @dimbleby @crumblingstatue Can this issue be closed now? |
I think so, yes. |
Input C/C++ Header
Bindgen Invokation
bindgen foo.h
Actual Results
Expected Results
The field should be
c_char
, notc_schar
.char
is not defined as always signed in the C standard. It can be unsigned.The text was updated successfully, but these errors were encountered: