-
Notifications
You must be signed in to change notification settings - Fork 733
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
C Atomics are not converted to equivalent atomics in Rust #2151
Comments
Along the same lines, it appears that the volatile keyword is ignored.
gets generated as
I'm honestly not sure how it should get generated. read_volatile() and write_volatile() don't really work here, unless you somehow wrap all access to this variable in them. But I'm not even sure that would be correct. Here's a pretty good blog post explaining the issue: https://lokathor.github.io/volatile/ Apparently, volatile in C is not like volatile in Java, and in LLVM it's something different entirely. Also, in my particular app, we're accessing shared memory across processes, not threads. That might or might not make a difference. The |
Hmm, yeah, this is a bit tricky. Part of the issue here is that they're not quite the same, ABI wise. An But we should definitely not crash. |
#2153 deals with the crash. What to do with atomics more generally needs more nuance. |
According to rust-lang/unsafe-code-guidelines#208
Also notice that an AtomicBool with anything but a 1 or 0 would be unsound because of the safe On the other hand, the docs for atomics like AtomicU8 https://doc.rust-lang.org/std/sync/atomic/struct.AtomicU8.html specify
I'm not sure since I'm not very familiar with C atomics, but maybe those are fine, and for AtomicBool maybe AtomicU8 can be used. As long as C atomic _Bool is guaranteed to be layout and ABI compatible with uint8_t. |
Rust's bool is guaranteed to be the same as C's Seems what's missing is the guarantee in C that What do you think? |
Input C/C++ Header
Bindgen Invocation
Actual Results
In general, these get translated into
u8
e.g.However, while trying to make an even smaller reproduce case:
I got a panic:
Expected Results
I would expect something more like this:
Since
std::sync::atomic::AtomicBool
has the same in-memory representation as a bool does, I think that might be exactly what I would expect as output.The text was updated successfully, but these errors were encountered: