Skip to content
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

Rust's char is not guaranteed to be ABI-compatible with C++'s uint32_t #814

Open
anforowicz opened this issue Feb 22, 2023 · 0 comments
Open
Labels

Comments

@anforowicz
Copy link

Today cbindgen translates Rust's char into C++'s uint32_t (see here). (It used to translate into char32_t, but this was changed in a PR a few years ago.) This seems to work, but AFAIU Rust makes no guarantees wrt ABI behavior of Rust's built-in char type. In particular, the ABI may ask to use different registers depending on whether the type is classified as an integer or not (and Rust doesn't guarantee any particular classification of Rust's char).

Other notes:

  • improper_ctypes warning fires for char (see example Rust playground)
  • System V ABI documentation can be found here, but a Stack Overflow answer here provides a shorter and possibly easier-to-understand summary.
  • AFAIK cxx doesn't support the char type
  • Other FFI tools that do support char may also have the same bug (e.g. Crubit and Diplomat)

/cc @Manishearth who has kindly brought this issue to my attention

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants