mirror of
https://github.com/topjohnwu/cxx.git
synced 2024-11-24 04:20:02 +00:00
Make passing String by value to C++ const
This commit is contained in:
parent
d1e2efc847
commit
a46a237fe7
@ -169,6 +169,9 @@ fn write_cxx_function_shim(out: &mut OutFile, efn: &ExternFn, types: &Types) {
|
||||
if i > 0 {
|
||||
write!(out, ", ");
|
||||
}
|
||||
if arg.ty == RustString {
|
||||
write!(out, "const ");
|
||||
}
|
||||
write_extern_arg(out, arg, types);
|
||||
}
|
||||
if indirect_return {
|
||||
@ -213,6 +216,8 @@ fn write_cxx_function_shim(out: &mut OutFile, efn: &ExternFn, types: &Types) {
|
||||
} else if let Type::UniquePtr(_) = &arg.ty {
|
||||
write_type(out, &arg.ty);
|
||||
write!(out, "({})", arg.ident);
|
||||
} else if arg.ty == RustString {
|
||||
write!(out, "::rust::String(::rust::unsafe_bitcopy, *{})", arg.ident);
|
||||
} else if types.needs_indirect_abi(&arg.ty) {
|
||||
write!(out, "::std::move(*{})", arg.ident);
|
||||
} else {
|
||||
|
@ -126,7 +126,9 @@ fn expand_cxx_function_decl(namespace: &Namespace, efn: &ExternFn, types: &Types
|
||||
let args = efn.args.iter().map(|arg| {
|
||||
let ident = &arg.ident;
|
||||
let ty = expand_extern_type(&arg.ty);
|
||||
if types.needs_indirect_abi(&arg.ty) {
|
||||
if arg.ty == RustString {
|
||||
quote!(#ident: *const #ty)
|
||||
} else if types.needs_indirect_abi(&arg.ty) {
|
||||
quote!(#ident: *mut #ty)
|
||||
} else {
|
||||
quote!(#ident: #ty)
|
||||
@ -157,7 +159,7 @@ fn expand_cxx_function_shim(namespace: &Namespace, efn: &ExternFn, types: &Types
|
||||
let var = &arg.ident;
|
||||
match &arg.ty {
|
||||
Type::Ident(ident) if ident == RustString => {
|
||||
quote!(#var.as_mut_ptr() as *mut ::cxx::private::RustString)
|
||||
quote!(#var.as_mut_ptr() as *const ::cxx::private::RustString)
|
||||
}
|
||||
Type::RustBox(_) => quote!(::std::boxed::Box::into_raw(#var)),
|
||||
Type::UniquePtr(_) => quote!(::cxx::UniquePtr::into_raw(#var)),
|
||||
|
Loading…
Reference in New Issue
Block a user