You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are some C++ types where autocxx just says "nope, we can't pass it by value" - autocxx calls these non-POD types; cxx calls them Opaque (see #17 for the terminology difference).
For those, autocxx offers no means to access the fields.
Rust cannot and should not attempt to access those fields, because we can't know the correct offsets. It's my intention that we should autogenerate accessor methods. Specifically, here's what I think we need to do.
For any non-POD type, when we discover the fields as output by bindgen, add a new type of AdditionalNeed to add an accessor method - https://github.com/google/autocxx/blob/main/engine/src/additional_cpp_generator.rs#L101. (Possibly we just want to do this for public fields or similar; I haven't checked if that information is exposed by bindgen or if it can be configured using bindgen options).
Generate a getter method with some plausible name within additional_cpp_generator.rs.
This will automatically be picked up during the second invocation of bindgen within autocxx, and therefore we'll get Rust bindings to this method within our ffi::cxxbridge generated code.
Now, make it work for fields which we can't safely pass by value because those fields themselves are non-POD types, e.g. std::string. One option here is to do a third pass of bindgen, which would replace fn thingy_getter(thingy: &Thingy) -> CxxString automatically with fn thingy_getter(thingy: &Thingy) -> UniquePtr<CxxString> and all would be well. But we don't really want to run bindgen three times... it's slow. So it would probably be better to add knowledge of these cases into additional_cpp_generator.rs itself.
There are some C++ types where
autocxx
just says "nope, we can't pass it by value" -autocxx
calls these non-POD types;cxx
calls themOpaque
(see #17 for the terminology difference).For those,
autocxx
offers no means to access the fields.Rust cannot and should not attempt to access those fields, because we can't know the correct offsets. It's my intention that we should autogenerate accessor methods. Specifically, here's what I think we need to do.
AdditionalNeed
to add an accessor method - https://github.com/google/autocxx/blob/main/engine/src/additional_cpp_generator.rs#L101. (Possibly we just want to do this for public fields or similar; I haven't checked if that information is exposed by bindgen or if it can be configured using bindgen options).additional_cpp_generator.rs
.bindgen
within autocxx, and therefore we'll get Rust bindings to this method within ourffi::cxxbridge
generated code.std::string
. One option here is to do a third pass of bindgen, which would replacefn thingy_getter(thingy: &Thingy) -> CxxString
automatically withfn thingy_getter(thingy: &Thingy) -> UniquePtr<CxxString>
and all would be well. But we don't really want to run bindgen three times... it's slow. So it would probably be better to add knowledge of these cases intoadditional_cpp_generator.rs
itself.The text was updated successfully, but these errors were encountered: