Skip to content

Commit

Permalink
Generate impl UniquePtr for abstract types too
Browse files Browse the repository at this point in the history
Similarly to non-abstract types, if one `include_cpp!` section
`generate!`s an abstract type but never uses `unique_ptr` for that type,
but another one does, we need the explicit `impl UniquePtr` so that cxx
allows it.
  • Loading branch information
bsilver8192 committed Jul 26, 2022
1 parent b830b9d commit a50fc60
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
16 changes: 13 additions & 3 deletions engine/src/conversion/codegen_rs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,7 @@ impl<'a> RsCodeGenerator<'a> {
false,
)
}
Api::ForwardDeclaration { .. }
| Api::ConcreteType { .. }
| Api::OpaqueTypedef { .. } => self.generate_type(
Api::ConcreteType { .. } => self.generate_type(
&name,
id,
TypeKind::Abstract,
Expand All @@ -657,6 +655,17 @@ impl<'a> RsCodeGenerator<'a> {
None,
false,
),
Api::ForwardDeclaration { .. } | Api::OpaqueTypedef { .. } => self.generate_type(
&name,
id,
TypeKind::Abstract,
false, // these types can't be kept in a Vector
false, // these types can't be put in a smart pointer
|| None,
associated_methods,
None,
false,
),
Api::CType { .. } => RsCodegenResult {
extern_c_mod_items: vec![ForeignItem::Verbatim(quote! {
type #id = autocxx::#id;
Expand Down Expand Up @@ -1042,6 +1051,7 @@ impl<'a> RsCodeGenerator<'a> {
extern_c_mod_items: vec![
self.generate_cxxbridge_type(name, false, doc_attrs)
],
bridge_items: create_impl_items(&id, movable, destroyable, self.config),
bindgen_mod_items,
materializations,
..Default::default()
Expand Down
37 changes: 37 additions & 0 deletions integration-tests/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9429,6 +9429,43 @@ fn test_abstract_up() {
run_test("", hdr, rs, &["A", "get_a"], &[]);
}

#[test]
fn test_abstract_up_multiple_bridge() {
let hdr = indoc! {"
#include <memory>
class A {
public:
virtual void foo() const = 0;
virtual ~A() {}
};
class B : public A {
public:
void foo() const {}
};
inline std::unique_ptr<A> get_a() { return std::make_unique<B>(); }
"};
let hexathorpe = Token![#](Span::call_site());
let rs = quote! {
autocxx::include_cpp! {
#hexathorpe include "input.h"
safety!(unsafe_ffi)
generate!("A")
}
autocxx::include_cpp! {
#hexathorpe include "input.h"
safety!(unsafe_ffi)
name!(ffi2)
extern_cpp_type!("A", crate::ffi::A)
generate!("get_a")
}
fn main() {
let a = ffi2::get_a();
a.foo();
}
};
do_run_test_manual("", hdr, rs, None, None).unwrap();
}

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

0 comments on commit a50fc60

Please sign in to comment.