Open EarthyOrange opened 3 years ago
let c_string: *const u8 = CString::new(str)?.as_bytes_with_nul().as_ptr();
This is not related to the assertion, but this does not sounds correct, because CString::new() will allocate a copy of the string, and then it will go out of scope because the CString is just a temporary. You need to keep the CString alive.
I don't know what is causing this assert because the arguments seems alright. The assert should contain the name of the wrong argument. It happens when trying to pass an argument which we can detect is of the wrong size, for example a i16 as a "int" or a const dyn Foo as a "const void"
Excellent point with the illegal borrow there. Maybe the compilation didn't fail because it was just checking the Result's movability and ignored the pointer it contains.
I see these asserts fail for all three arguments. The integer arg should not be failing the asserts, correct?
What's your compiler and platform ?
Actually, the size assertion should in theory never be triggered because there is also a compile check just before. Could you debug and see what are the values of the alignment and size and why they don't match?
I am cross-compiling on windows for linux OS using the gcc-linaro-arm-linux-gnueabihf v4.7 toolchain.
rustc: 1.48.0
Ah, cross-compilation ... That is probably the reason. I never tried that.
Is the C++ compiler is also running in cross compilation mode? Normally the cc
crate should take care of that.
For the string "Hello World!!!", size_of
returns 15aö>Ln
and align_of
returns 1
. I am not sure why the unicode characters are getting appended to the size_of value.
I don't have to compile any c++ code. I am just dynamically linking the shared objects which I assume have been created using the same g++ compiler.
I have the above code snippet, where I am simply trying to call C++'s setenv method. For each of the argument passed to the macro, I see the assertion failure messages (from cpp_macros-0.5.5/src/lib.rs) of the following format.
Can some light be please shown on: