Closed
Description
This was original encountered with Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1476252
Following is sample program which builds on https://github.com/alexcrichton/rust-ffi-examples
The issue is that on Sparc (tested on Solaris) the returing structure contains just zeros (on intel Solaris it works as expected).
git clone https://github.com/alexcrichton/rust-ffi-examples.git
cd rust-ffi-examples
gpatch -p1 <<EOF
index 78b6a46..0a4f23b 100644
--- a/cpp-to-rust/src/example.h
+++ b/cpp-to-rust/src/example.h
@@ -7,6 +7,12 @@ extern "C"{
int double_input(int input);
+struct MyStruct {
+ bool a;
+};
+
+const MyStruct GetMyStruct();
+
#ifdef __cplusplus
}
#endif
diff --git a/cpp-to-rust/src/lib.rs b/cpp-to-rust/src/lib.rs
index bf573d1..96270c2 100644
--- a/cpp-to-rust/src/lib.rs
+++ b/cpp-to-rust/src/lib.rs
@@ -2,3 +2,16 @@
pub extern fn double_input(input: i32) -> i32 {
input * 2
}
+
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct MyStruct {
+ pub a: bool,
+}
+
+#[no_mangle]
+pub extern fn GetMyStruct() -> MyStruct {
+ MyStruct {
+ a: true,
+ }
+}
diff --git a/cpp-to-rust/src/main.cpp b/cpp-to-rust/src/main.cpp
index e4c5ced..f66c298 100644
--- a/cpp-to-rust/src/main.cpp
+++ b/cpp-to-rust/src/main.cpp
@@ -7,6 +7,8 @@ int main() {
int input = 10;
int output = double_input(input);
cout<<input<<" * 2 = "<<output<<"\n";
+ const MyStruct mystruct = GetMyStruct();
+ cout<<"GetMyStruct returns "<<mystruct.a<<"\n";
return 0;
}
EOF
cd cpp-to-rust
gmake
10 * 2 = 20
GetMyStruct returns 0 <==== Should be 1!!!