Skip to content

Commit

Permalink
Revert "Validate chars (rust-diplomat#365)"
Browse files Browse the repository at this point in the history
This reverts commit 3b174d8.
  • Loading branch information
robertbastian committed Nov 21, 2023
1 parent 3b174d8 commit b610a6b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
19 changes: 3 additions & 16 deletions macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ fn gen_params_at_boundary(param: &ast::Param, expanded_params: &mut Vec<FnArg>)
),
}));
}
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![],
Expand Down Expand Up @@ -107,9 +99,9 @@ fn gen_params_invocation(param: &ast::Param, expanded_params: &mut Vec<Expr>) {
} else {
// TODO(#57): don't just unwrap? or should we assume that the other side gives us a good value?
quote! {
core::str::from_utf8(unsafe {
core::slice::from_raw_parts(#data_ident, #len_ident)
}).unwrap()
unsafe {
core::str::from_utf8(core::slice::from_raw_parts(#data_ident, #len_ident)).unwrap()
}
}
};
expanded_params.push(parse2(tokens).unwrap());
Expand All @@ -118,11 +110,6 @@ fn gen_params_invocation(param: &ast::Param, expanded_params: &mut Vec<Expr>) {
let param = &param.name;
expanded_params.push(parse2(quote!(#param.into())).unwrap());
}
ast::TypeName::Primitive(ast::PrimitiveType::char) => {
let name = &param.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![],
Expand Down
10 changes: 4 additions & 6 deletions macro/src/snapshots/diplomat__tests__method_taking_str.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ mod ffi {
}
#[no_mangle]
extern "C" fn Foo_from_str(s_diplomat_data: *const u8, s_diplomat_len: usize) {
Foo::from_str(
core::str::from_utf8(unsafe {
core::slice::from_raw_parts(s_diplomat_data, s_diplomat_len)
})
.unwrap(),
)
Foo::from_str(unsafe {
core::str::from_utf8(core::slice::from_raw_parts(s_diplomat_data, s_diplomat_len))
.unwrap()
})
}
#[no_mangle]
extern "C" fn Foo_destroy(this: Box<Foo>) {}
Expand Down
10 changes: 4 additions & 6 deletions macro/src/snapshots/diplomat__tests__multilevel_borrows.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ mod ffi {
extern "C" fn Baz_destroy<'x: 'y, 'y>(this: Box<Baz<'x, 'y>>) {}
#[no_mangle]
extern "C" fn Foo_new<'a>(x_diplomat_data: *const u8, x_diplomat_len: usize) -> Box<Foo<'a>> {
Foo::new(
core::str::from_utf8(unsafe {
core::slice::from_raw_parts(x_diplomat_data, x_diplomat_len)
})
.unwrap(),
)
Foo::new(unsafe {
core::str::from_utf8(core::slice::from_raw_parts(x_diplomat_data, x_diplomat_len))
.unwrap()
})
}
#[no_mangle]
extern "C" fn Foo_get_bar<'a: 'b, 'b>(this: &'b Foo<'a>) -> Box<Bar<'b, 'a>> {
Expand Down

0 comments on commit b610a6b

Please sign in to comment.