-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Struct passed by-value from C to Rust get's corrupted (using FFI and .dll from Visual Studio) #11343
Comments
Issue #11198 is also similar. |
Update: As @eddyb on IRC suggested I have created a more compact example and included LLVM IR: https://gist.github.com/Matthias247/8376787 I also switched the C side from a C++ project with extern C declarations to a pure C project, so that this issue can be ruled out. |
You can bypass the problem by using external LLVM to compile bitcode. I wrote small utility to do that: |
I'm interfacing an external DLL which I'm creating with Visual Studio 2012.
I've tried to pass a struct by-value from C to Rust in a callback.
The struct and the callback are defined as follows:
However the struct received in
on_notification
is corrupted and contains not the data which is sent in C++.I wrote a test program to isolate and reproduce the issue.
The gist therefore is here: https://gist.github.com/Matthias247/8283183
It can be cloned from https://gist.github.com/8283183.git
It includes the source code for the library with a visual studio project to built it and the rust test program.
I also included make.sh to build it on Linux. However in Linux I can't reproduct the issue. The struct get's copied correctly there.
This is the output from my test program:
The first line is the content of the notification in bytes in C++, the second the content in Rust.
You can see that the last bytes of the notification structure are different in C++ in Rust. Interesting hereby is also that the last field (notification.data == 9) gets copied into notification.value_id.d (verified this with using other values for notification.data) and the remaining notification fields are garbage.
The text was updated successfully, but these errors were encountered: