rust-bindgen
rust-bindgen copied to clipboard
Invalid char array bindings generation
Input C/C++ Header
const char BUFFER[] = "Hello" "\0" "World" "\0";
Bindgen Invocation
bindgen::Builder::default()
.header("input.h")
.generate()
.unwrap()
Actual Results
pub const BUFFER: &[u8; 6] = b"Hello\0";
Expected Results
pub const BUFFER: &[u8; 13] = b"Hello\0World\0\0";
Did a bit of digging and it looks like clang_EvalResult_getAsStr
is the culprit, as it only returns a pointer and no size, and expects that literals contain no zeros.
I do not know if there's another way to get the full literal, but I tried my luck opening an issue on the LLVM project.
Sounds good, thank you
I linked it above, but then I realized this currently only applies to C++. For C, a static const
gets transformed into an extern "C" pub static
instead.
But that is strange, because the variable will not be exported from C. I assume the C++ const
is transformed into a Rust const
so that there is a chance to have the value, since it has internal linkage and some C++ headers may be written like that, especially before C++17. If that is the intention, then should the same apply to C, and thus a static const
be transformed into a const
too?
Taking an extra look, it seems that, for C++, all "global" variables (static
or not, const
or not) are mapped into Rust const
s (with the bug mentioned here). And for C, all are mapped into extern "C" pub static
s (with or without mut
).