Skip to content

Commit

Permalink
fix from_unmanaged not being implemented for C++ types, and add corre…
Browse files Browse the repository at this point in the history
…sponding test
  • Loading branch information
russelltg committed Jan 26, 2022
1 parent 0af1133 commit a4747fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 12 additions & 0 deletions gen/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,18 @@ fn write_shared_ptr(out: &mut OutFile, key: NamedImplKey) {
writeln!(out, "}}");
}
begin_function_definition(out);
writeln!(
out,
"void cxxbridge1$shared_ptr${}$from_unmanaged(::std::shared_ptr<{}>* ptr, void* data) noexcept {{",
instance, inner,
);
writeln!(
out,
"new (ptr) std::shared_ptr<{}>(static_cast<{}*>(data));",
inner, inner
);
writeln!(out, "}}");
begin_function_definition(out);
writeln!(
out,
"void cxxbridge1$shared_ptr${}$clone(const ::std::shared_ptr<{}>& self, ::std::shared_ptr<{}> *ptr) noexcept {{",
Expand Down
10 changes: 9 additions & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,22 @@ fn test_shared_ptr_weak_ptr() {
}

#[test]
fn test_unique_to_shared_ptr() {
fn test_unique_to_shared_ptr_string() {
let unique = ffi::c_return_unique_ptr_string();
let ptr = &*unique as *const _;
let shared = unique.to_shared();
assert_eq!(&*shared as *const _, ptr);
assert_eq!(&*shared, "2020");
}

#[test]
fn test_unique_to_shared_ptr_cpp_type() {
let unique = ffi::c_return_unique_ptr();
let ptr = &*unique as *const _;
let shared = unique.to_shared();
assert_eq!(&*shared as *const _, ptr);
}

#[test]
fn test_c_ns_method_calls() {
let unique_ptr = ffi2::ns_c_return_unique_ptr_ns();
Expand Down

0 comments on commit a4747fa

Please sign in to comment.