If you don't use the C++ low-level / wire C++ bindings there's nothing to see here...
Howdy,
As part of our work to stabilize the FIDL C++ Wire-style bindings (
née LLCPP) we did an API review. One of the big pain points that came up was the interaction of tables, arenas and memory management. It's been very easy to write code that looks perfectly good to both C++ developers and compilers but that would crash (or worse have mostly silent memory bugs) at runtime.
To address this we've changed the API of FIDL tables from being a mutable type that must be correctly initialized and then configured carefully to being immutable where the only way to create them is through a builder pattern. The machine code produced by the C++ compiler will be roughly equivalent but it will be able to catch many more mistakes at compile time.
Along the way we managed to squeeze in some ergonomic improvements, like automatically passing an arena along to member constructors that need them.
So for example code that was:
fidl::Arena arena;
fuchsia_examples::wire::User user;
user.Allocate(allocator);
user.set_age(30);
user.set_name(allocator, allocator, "jdoe");
becomes:
fidl::Arena arena;
auto user = fuchsia_examples::wire::User::Builder(arena)
.age(30)
.name("joe")
.Build();
If you need fine-grained control over table frame or member allocation you can still do that but for most users this will be a lot simpler and safer.
This change lands in
https://fxrev.dev/652348 and updates
some test code but the old API is available behind the config //build/cpp:fidl-wire-deprecated-mutable-tables but using that is allow-listed. New code should use the new API. I will update some of the code in-tree but I'm hoping code owners will take this chance to make their code simpler and safer.
Let us know if there are use cases we aren't catering for. We think it's in good shape but the old API was flexible enough that we might have missed something important.
Ian