diff --git a/core/src/ast/types.rs b/core/src/ast/types.rs index 689d639cb..1a6ca9c6d 100644 --- a/core/src/ast/types.rs +++ b/core/src/ast/types.rs @@ -1040,7 +1040,7 @@ lazy_static! { ("f32", PrimitiveType::f32), ("f64", PrimitiveType::f64), ("bool", PrimitiveType::bool), - ("char", PrimitiveType::char), + ("DiplomatChar", PrimitiveType::char), ]; static ref STRING_TO_PRIMITIVE: HashMap<&'static str, PrimitiveType> = PRIMITIVES_MAPPING.iter().cloned().collect(); diff --git a/core/src/ast/validity.rs b/core/src/ast/validity.rs index e8c68e225..26685e663 100644 --- a/core/src/ast/validity.rs +++ b/core/src/ast/validity.rs @@ -166,7 +166,7 @@ mod tests { } - pub fn do_thing2(opt: DiplomatResult, u8>) { + pub fn do_thing2(opt: DiplomatResult, u8>) { } pub fn do_thing2(opt: Option) { diff --git a/feature_tests/src/option.rs b/feature_tests/src/option.rs index f62c16609..8302ed5c6 100644 --- a/feature_tests/src/option.rs +++ b/feature_tests/src/option.rs @@ -51,8 +51,8 @@ pub mod ffi { } impl OptionOpaqueChar { - pub fn assert_char(&self, ch: char) { - assert_eq!(ch, self.0) + pub fn assert_char(&self, ch: DiplomatChar) { + assert_eq!(ch, self.0 as u32) } } } diff --git a/feature_tests/src/structs.rs b/feature_tests/src/structs.rs index 9c06a9ad4..0cdb53ef0 100644 --- a/feature_tests/src/structs.rs +++ b/feature_tests/src/structs.rs @@ -30,7 +30,7 @@ pub mod ffi { c: u8, d: u64, e: i32, - f: char, + f: DiplomatChar, g: MyEnum, } @@ -71,7 +71,7 @@ pub mod ffi { c: 209, d: 1234, e: 5991, - f: '餐', + f: '餐' as DiplomatChar, g: MyEnum::B, } } @@ -86,7 +86,7 @@ pub mod ffi { assert_eq!(self.c, 209); assert_eq!(self.d, 1234); assert_eq!(self.e, 5991); - assert_eq!(self.f, '餐'); + assert_eq!(self.f, '餐' as DiplomatChar); assert_eq!(self.g, MyEnum::B); } } diff --git a/macro/src/lib.rs b/macro/src/lib.rs index e54f005f4..795f381a6 100644 --- a/macro/src/lib.rs +++ b/macro/src/lib.rs @@ -63,14 +63,6 @@ fn gen_params_at_boundary(param: &ast::Param, expanded_params: &mut Vec) ), })); } - ast::TypeName::Primitive(ast::PrimitiveType::char) => gen_params_at_boundary( - &{ - let mut p = param.clone(); - p.ty = ast::TypeName::Primitive(ast::PrimitiveType::u32); - p - }, - expanded_params, - ), o => { expanded_params.push(FnArg::Typed(PatType { attrs: vec![], @@ -118,11 +110,6 @@ fn gen_params_invocation(param: &ast::Param, expanded_params: &mut Vec) { let param = ¶m.name; expanded_params.push(parse2(quote!(#param.into())).unwrap()); } - ast::TypeName::Primitive(ast::PrimitiveType::char) => { - let name = ¶m.name; - // TODO(#318): don't just unwrap? or should we assume that the other side gives us a good value? - expanded_params.push(parse2(quote! { char::from_u32(#name).unwrap() }).unwrap()); - } _ => { expanded_params.push(Expr::Path(ExprPath { attrs: vec![], @@ -279,6 +266,8 @@ fn gen_bridge(input: ItemMod) -> ItemMod { let module = ast::Module::from_syn(&input, true); let (brace, mut new_contents) = input.content.unwrap(); + new_contents.push(parse2(quote! { use diplomat_runtime::*; }).unwrap()); + new_contents.iter_mut().for_each(|c| match c { Item::Struct(s) => { let info = AttributeInfo::extract(&mut s.attrs); diff --git a/macro/src/snapshots/diplomat__tests__cfgd_struct.snap b/macro/src/snapshots/diplomat__tests__cfgd_struct.snap index 432830917..30d4e234d 100644 --- a/macro/src/snapshots/diplomat__tests__cfgd_struct.snap +++ b/macro/src/snapshots/diplomat__tests__cfgd_struct.snap @@ -11,6 +11,7 @@ mod ffi { unimplemented!() } } + use diplomat_runtime::*; #[no_mangle] #[cfg(feature = "foo")] extern "C" fn Foo_bar(s: u8) { diff --git a/macro/src/snapshots/diplomat__tests__cfged_method-2.snap b/macro/src/snapshots/diplomat__tests__cfged_method-2.snap index b026704b8..2234c4635 100644 --- a/macro/src/snapshots/diplomat__tests__cfged_method-2.snap +++ b/macro/src/snapshots/diplomat__tests__cfged_method-2.snap @@ -12,6 +12,7 @@ mod ffi { unimplemented!() } } + use diplomat_runtime::*; #[no_mangle] #[cfg(feature = "foo")] #[cfg(feature = "bar")] diff --git a/macro/src/snapshots/diplomat__tests__cfged_method.snap b/macro/src/snapshots/diplomat__tests__cfged_method.snap index bc4adbb73..e348162d0 100644 --- a/macro/src/snapshots/diplomat__tests__cfged_method.snap +++ b/macro/src/snapshots/diplomat__tests__cfged_method.snap @@ -11,6 +11,7 @@ mod ffi { unimplemented!() } } + use diplomat_runtime::*; #[no_mangle] #[cfg(feature = "foo")] extern "C" fn Foo_bar(s: u8) { diff --git a/macro/src/snapshots/diplomat__tests__method_taking_mutable_slice.snap b/macro/src/snapshots/diplomat__tests__method_taking_mutable_slice.snap index 01fea65c2..341f4b9b9 100644 --- a/macro/src/snapshots/diplomat__tests__method_taking_mutable_slice.snap +++ b/macro/src/snapshots/diplomat__tests__method_taking_mutable_slice.snap @@ -10,6 +10,7 @@ mod ffi { unimplemented!() } } + use diplomat_runtime::*; #[no_mangle] extern "C" fn Foo_fill_slice(s_diplomat_data: *mut f64, s_diplomat_len: usize) { Foo::fill_slice(unsafe { core::slice::from_raw_parts_mut(s_diplomat_data, s_diplomat_len) }) diff --git a/macro/src/snapshots/diplomat__tests__method_taking_slice.snap b/macro/src/snapshots/diplomat__tests__method_taking_slice.snap index 94daec2af..f88b027e4 100644 --- a/macro/src/snapshots/diplomat__tests__method_taking_slice.snap +++ b/macro/src/snapshots/diplomat__tests__method_taking_slice.snap @@ -10,6 +10,7 @@ mod ffi { unimplemented!() } } + use diplomat_runtime::*; #[no_mangle] extern "C" fn Foo_from_slice(s_diplomat_data: *const f64, s_diplomat_len: usize) { Foo::from_slice(unsafe { core::slice::from_raw_parts(s_diplomat_data, s_diplomat_len) }) diff --git a/macro/src/snapshots/diplomat__tests__method_taking_str.snap b/macro/src/snapshots/diplomat__tests__method_taking_str.snap index 76939905b..9cea29ea6 100644 --- a/macro/src/snapshots/diplomat__tests__method_taking_str.snap +++ b/macro/src/snapshots/diplomat__tests__method_taking_str.snap @@ -10,6 +10,7 @@ mod ffi { unimplemented!() } } + use diplomat_runtime::*; #[no_mangle] extern "C" fn Foo_from_str(s_diplomat_data: *const u8, s_diplomat_len: usize) { Foo::from_str( diff --git a/macro/src/snapshots/diplomat__tests__mod_with_enum.snap b/macro/src/snapshots/diplomat__tests__mod_with_enum.snap index 723e17d78..246569f54 100644 --- a/macro/src/snapshots/diplomat__tests__mod_with_enum.snap +++ b/macro/src/snapshots/diplomat__tests__mod_with_enum.snap @@ -13,6 +13,7 @@ mod ffi { unimplemented!() } } + use diplomat_runtime::*; #[no_mangle] extern "C" fn Abc_do_something(this: &Abc) { this.do_something() diff --git a/macro/src/snapshots/diplomat__tests__mod_with_rust_result.snap b/macro/src/snapshots/diplomat__tests__mod_with_rust_result.snap index 1eeb28808..2fc4a3ec0 100644 --- a/macro/src/snapshots/diplomat__tests__mod_with_rust_result.snap +++ b/macro/src/snapshots/diplomat__tests__mod_with_rust_result.snap @@ -10,6 +10,7 @@ mod ffi { unimplemented!() } } + use diplomat_runtime::*; #[no_mangle] extern "C" fn Foo_bar(this: &Foo) -> diplomat_runtime::DiplomatResult<(), ()> { this.bar().into() diff --git a/macro/src/snapshots/diplomat__tests__mod_with_writeable_result.snap b/macro/src/snapshots/diplomat__tests__mod_with_writeable_result.snap index 870193052..7bde4ff32 100644 --- a/macro/src/snapshots/diplomat__tests__mod_with_writeable_result.snap +++ b/macro/src/snapshots/diplomat__tests__mod_with_writeable_result.snap @@ -10,6 +10,7 @@ mod ffi { unimplemented!() } } + use diplomat_runtime::*; #[no_mangle] extern "C" fn Foo_to_string( this: &Foo, diff --git a/macro/src/snapshots/diplomat__tests__multilevel_borrows.snap b/macro/src/snapshots/diplomat__tests__multilevel_borrows.snap index b8158b001..7cd16f290 100644 --- a/macro/src/snapshots/diplomat__tests__multilevel_borrows.snap +++ b/macro/src/snapshots/diplomat__tests__multilevel_borrows.snap @@ -20,6 +20,7 @@ mod ffi { Bax { foo: self } } } + use diplomat_runtime::*; #[no_mangle] extern "C" fn Bar_destroy<'b, 'a: 'b>(this: Box>) {} #[no_mangle] diff --git a/macro/src/snapshots/diplomat__tests__self_params.snap b/macro/src/snapshots/diplomat__tests__self_params.snap index 6b931197a..52eaddd7c 100644 --- a/macro/src/snapshots/diplomat__tests__self_params.snap +++ b/macro/src/snapshots/diplomat__tests__self_params.snap @@ -12,6 +12,7 @@ mod ffi { unimplemented!() } } + use diplomat_runtime::*; #[no_mangle] extern "C" fn RefList_extend<'b>(this: &mut RefList<'b>, other: &RefList<'b>) -> RefList<'b> { this.extend(other) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index fa1c5d7dd..ebdb68077 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -14,6 +14,8 @@ pub use writeable::DiplomatWriteable; mod result; pub use result::DiplomatResult; +pub type DiplomatChar = u32; + /// Allocates a buffer of a given size in Rust's memory. /// /// # Safety diff --git a/tool/tests/dotnet_target.rs b/tool/tests/dotnet_target.rs index f03129295..a6024946f 100644 --- a/tool/tests/dotnet_target.rs +++ b/tool/tests/dotnet_target.rs @@ -552,7 +552,7 @@ fn error_handling() { unimplemented!() } - pub fn bar(&self) -> Result { + pub fn bar(&self) -> Result { unimplemented!() }