Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problem using copy constructor of Box #1241

Merged
merged 6 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions engine/src/conversion/codegen_rs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,22 @@ impl<'a> RsCodeGenerator<'a> {
})],
..Default::default()
},
Api::RustType { path, .. } => RsCodegenResult {
global_items: vec![parse_quote! {
use super::#path;
}],
extern_rust_mod_items: vec![parse_quote! {
type #id;
}],
..Default::default()
},
Api::RustType { path, .. } => {
let id = path.get_final_ident();
RsCodegenResult {
global_items: vec![parse_quote! {
use super::#path;
}],
extern_rust_mod_items: vec![parse_quote! {
type #id;
}],
bindgen_mod_items: vec![parse_quote! {
#[allow(unused_imports)]
use super::super::#id;
}],
..Default::default()
}
}
Api::RustFn {
details:
RustFun {
Expand Down
4 changes: 3 additions & 1 deletion engine/src/known_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ impl TypeDatabase {
.map(|td| {
matches!(
td.behavior,
Behavior::CxxContainerPtr | Behavior::CxxContainerVector
Behavior::CxxContainerPtr
| Behavior::CxxContainerVector
| Behavior::RustContainerByValueSafe
)
})
.unwrap_or(false)
Expand Down
43 changes: 42 additions & 1 deletion integration-tests/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7193,7 +7193,7 @@ fn test_cpp17() {
}

#[test]
fn test_box() {
fn test_box_extern_rust_type() {
let hdr = indoc! {"
#include <cxx.h>
struct Foo;
Expand All @@ -7220,6 +7220,47 @@ fn test_box() {
);
}

#[test]
fn test_box_return_placement_new() {
let hdr = indoc! {"
#include <cxx.h>
struct Foo;
struct Foo2;
struct Ret {};
inline Ret take_box(rust::Box<Foo>, rust::Box<Foo2>) {
return Ret{};
}
"};
run_test_ex(
"",
hdr,
quote! {
let _ = ffi::take_box(
Box::new(Foo { a: "Hello".into() }),
Box::new(bar::Foo2 { a: "Goodbye".into() })
);
},
quote! {
generate!("take_box")
extern_rust_type!(Foo)
generate!("Ret")
},
None,
None,
Some(quote! {
pub struct Foo {
a: String,
}
mod bar {
#[autocxx::extern_rust::extern_rust_type]
pub struct Foo2 {
pub a: String,
}
}
}),
);
}

#[test]
fn test_box_via_extern_rust() {
let hdr = indoc! {"
Expand Down