summaryrefslogtreecommitdiffstats
path: root/tests/rust/swift_name.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:39:07 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:39:07 +0000
commitaf6b8ed095f88f1df2116cdc7a9d44872cfa6074 (patch)
tree1f2df671c1f8033d5ed83f056167a0911f8d2a57 /tests/rust/swift_name.rs
parentInitial commit. (diff)
downloadrust-cbindgen-af6b8ed095f88f1df2116cdc7a9d44872cfa6074.tar.xz
rust-cbindgen-af6b8ed095f88f1df2116cdc7a9d44872cfa6074.zip
Adding upstream version 0.26.0.upstream/0.26.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/rust/swift_name.rs')
-rw-r--r--tests/rust/swift_name.rs133
1 files changed, 133 insertions, 0 deletions
diff --git a/tests/rust/swift_name.rs b/tests/rust/swift_name.rs
new file mode 100644
index 0000000..01cfdbe
--- /dev/null
+++ b/tests/rust/swift_name.rs
@@ -0,0 +1,133 @@
+#[export_name="rust_print_hello_world"]
+pub extern fn say_hello() {
+ println!("Hello, World!");
+}
+
+#[repr(C)]
+pub struct SelfTypeTestStruct {
+ times: u8,
+}
+
+impl SelfTypeTestStruct {
+ #[export_name="SelfTypeTestStruct_should_exist_ref"]
+ #[no_mangle]
+ pub extern fn should_exist_ref(&self) {
+ println!("should_exist_ref");
+ }
+
+ #[export_name="SelfTypeTestStruct_should_exist_ref_mut"]
+ #[no_mangle]
+ pub extern fn should_exist_ref_mut(&mut self) {
+ println!("should_exist_ref_mut");
+ }
+
+ #[export_name="SelfTypeTestStruct_should_not_exist_box"]
+ #[no_mangle]
+ pub extern fn should_not_exist_box(self: Box<SelfTypeTestStruct>) {
+ println!("should_not_exist_box");
+ }
+
+ #[export_name="SelfTypeTestStruct_should_not_exist_return_box"]
+ #[no_mangle]
+ pub extern fn should_not_exist_box() -> Box<Self> {
+ println!("should_not_exist_box");
+ }
+
+ #[export_name="SelfTypeTestStruct_should_exist_annotated_self"]
+ #[no_mangle]
+ pub extern fn should_exist_annotated_self(self: Self) {
+ println!("should_exist_annotated_self");
+ }
+
+ #[export_name="SelfTypeTestStruct_should_exist_annotated_mut_self"]
+ #[no_mangle]
+ #[allow(unused_mut)]
+ pub extern fn should_exist_annotated_mut_self(mut self: Self) {
+ println!("should_exist_annotated_mut_self");
+ }
+
+ #[export_name="SelfTypeTestStruct_should_exist_annotated_by_name"]
+ #[no_mangle]
+ pub extern fn should_exist_annotated_by_name(self: SelfTypeTestStruct) {
+ println!("should_exist_annotated_by_name");
+ }
+
+ #[export_name="SelfTypeTestStruct_should_exist_annotated_mut_by_name"]
+ #[no_mangle]
+ #[allow(unused_mut)]
+ pub extern fn should_exist_annotated_mut_by_name(mut self: SelfTypeTestStruct) {
+ println!("should_exist_annotated_mut_by_name");
+ }
+
+ #[export_name="SelfTypeTestStruct_should_exist_unannotated"]
+ #[no_mangle]
+ pub extern fn should_exist_unannotated(self) {
+ println!("should_exist_unannotated");
+ }
+
+ #[export_name="SelfTypeTestStruct_should_exist_mut_unannotated"]
+ #[no_mangle]
+ #[allow(unused_mut)]
+ pub extern fn should_exist_mut_unannotated(mut self) {
+ println!("should_exist_mut_unannotated");
+ }
+}
+
+#[no_mangle]
+#[allow(unused_variables)]
+pub extern fn free_function_should_exist_ref(test_struct: &SelfTypeTestStruct) {
+ println!("free_function_should_exist_ref");
+}
+
+#[no_mangle]
+#[allow(unused_variables)]
+pub extern fn free_function_should_exist_ref_mut(test_struct: &mut SelfTypeTestStruct) {
+ println!("free_function_should_exist_ref_mut");
+}
+
+#[no_mangle]
+pub extern fn unnamed_argument(_: &mut SelfTypeTestStruct) {
+ println!("unnamed_argument");
+}
+
+#[no_mangle]
+#[allow(unused_variables)]
+pub extern fn free_function_should_not_exist_box(boxed: Box<SelfTypeTestStruct>) {
+ println!("free_function_should_not_exist_box");
+}
+
+#[no_mangle]
+#[allow(unused_variables)]
+pub extern fn free_function_should_exist_annotated_by_name(test_struct: SelfTypeTestStruct) {
+ println!("free_function_should_exist_annotated_by_name");
+}
+
+#[no_mangle]
+#[allow(unused_mut)]
+#[allow(unused_variables)]
+pub extern fn free_function_should_exist_annotated_mut_by_name(mut test_struct: SelfTypeTestStruct) {
+ println!("free_function_should_exist_annotated_mut_by_name");
+}
+
+struct Opaque {
+ times: u8
+}
+
+#[repr(C)]
+pub struct PointerToOpaque { ptr: *mut Opaque }
+
+impl PointerToOpaque {
+ #[export_name="PointerToOpaque_create"]
+ pub extern fn create(times: u8) -> PointerToOpaque {
+ PointerToOpaque { ptr: Box::into_raw(Box::new(Opaque { times })) }
+ }
+
+ #[export_name="PointerToOpaque_sayHello"]
+ pub extern fn say_hello(self: PointerToOpaque) {
+ if let Some(nonnull) = std::ptr::NonNull::new(self.ptr) {
+ for _ in 0 .. unsafe { nonnull.as_ref().times } {
+ println!("Hello!")
+ }
+ }
+ }
+}