return;
}
}
- if let syn::Type::Reference(r) = &**rtype {
- // We can't return a reference, cause we allocate things on the stack.
- types.write_c_type(w, &*r.elem, generics, true);
- } else {
- types.write_c_type(w, &*rtype, generics, true);
- }
+ types.write_c_type(w, &*rtype, generics, true);
},
_ => {},
}
write!(w, "ret").unwrap();
types.write_from_c_conversion_suffix(w, &*rtype, generics);
} else {
- let ret_returned = if let syn::Type::Reference(_) = &**rtype { true } else { false };
let new_var = types.write_to_c_conversion_new_var(w, &format_ident!("ret"), &rtype, generics, true);
if new_var {
write!(w, "\n\t{}", extra_indent).unwrap();
}
types.write_to_c_conversion_inline_prefix(w, &rtype, generics, true);
- write!(w, "{}ret", if ret_returned && !new_var { "*" } else { "" }).unwrap();
+ write!(w, "ret").unwrap();
types.write_to_c_conversion_inline_suffix(w, &rtype, generics, true);
}
}
"Option" => Some("local_"),
"[u8; 32]" if !is_ref => Some("crate::c_types::ThirtyTwoBytes { data: "),
- "[u8; 32]" if is_ref => Some("&"),
+ "[u8; 32]" if is_ref => Some(""),
"[u8; 16]" if !is_ref => Some("crate::c_types::SixteenBytes { data: "),
"[u8; 10]" if !is_ref => Some("crate::c_types::TenBytes { data: "),
"[u8; 4]" if !is_ref => Some("crate::c_types::FourBytes { data: "),
- "[u8; 3]" if is_ref => Some("&"),
+ "[u8; 3]" if is_ref => Some(""),
"[u8]" if is_ref => Some("local_"),
"[usize]" if is_ref => Some("local_"),
let resolved_path = self.resolve_path(&p.path, generics);
if let Some(aliased_type) = self.crate_types.type_aliases.get(&resolved_path) {
return self.write_conversion_inline_intern(w, aliased_type, None, is_ref, is_mut, ptr_for_ref, tupleconv, prefix, sliceconv, path_lookup, decl_lookup);
+ } else if self.is_primitive(&resolved_path) {
+ if is_ref && prefix {
+ write!(w, "*").unwrap();
+ }
} else if let Some(c_type) = path_lookup(&resolved_path, is_ref, ptr_for_ref) {
write!(w, "{}", c_type).unwrap();
} else if self.crate_types.opaques.get(&resolved_path).is_some() {
|a, b, c| self.to_c_conversion_inline_prefix_from_path(a, b, c),
|w, decl_type, decl_path, is_ref, _is_mut| {
match decl_type {
- DeclType::MirroredEnum if is_ref && ptr_for_ref => write!(w, "crate::{}::from_native(&", decl_path).unwrap(),
- DeclType::MirroredEnum if is_ref => write!(w, "&crate::{}::from_native(&", decl_path).unwrap(),
+ DeclType::MirroredEnum if is_ref && ptr_for_ref => write!(w, "crate::{}::from_native(", decl_path).unwrap(),
+ DeclType::MirroredEnum if is_ref => write!(w, "&crate::{}::from_native(", decl_path).unwrap(),
DeclType::MirroredEnum => write!(w, "crate::{}::native_into(", decl_path).unwrap(),
DeclType::EnumIgnored|DeclType::StructImported if is_ref && ptr_for_ref && from_ptr =>
write!(w, "crate::{} {{ inner: unsafe {{ (", decl_path).unwrap(),
DeclType::EnumIgnored|DeclType::StructImported if is_ref && ptr_for_ref =>
- write!(w, "crate::{} {{ inner: unsafe {{ ( (&(", decl_path).unwrap(),
+ write!(w, "crate::{} {{ inner: unsafe {{ ( (&(*", decl_path).unwrap(),
DeclType::EnumIgnored|DeclType::StructImported if is_ref =>
write!(w, "&crate::{} {{ inner: unsafe {{ (", decl_path).unwrap(),
DeclType::EnumIgnored|DeclType::StructImported if !is_ref && from_ptr =>
write!(w, "crate::{} {{ inner: ", decl_path).unwrap(),
DeclType::EnumIgnored|DeclType::StructImported if !is_ref =>
write!(w, "crate::{} {{ inner: Box::into_raw(Box::new(", decl_path).unwrap(),
- DeclType::Trait(_) if is_ref => write!(w, "&").unwrap(),
+ DeclType::Trait(_) if is_ref => write!(w, "").unwrap(),
DeclType::Trait(_) if !is_ref => {},
_ => panic!("{:?}", decl_path),
}