[bindings] Give Transaction objects a buffer-is-owned flag.
authorMatt Corallo <git@bluematt.me>
Thu, 24 Sep 2020 23:03:05 +0000 (19:03 -0400)
committerMatt Corallo <git@bluematt.me>
Wed, 21 Oct 2020 18:50:22 +0000 (14:50 -0400)
commitd9a38d1846ad64622706c3093c0bb3a405817899
tree75bb5f0a75dd7a61049545e29505c0eccb576621
parent0719f9af00d3669302cec07f67c8d6980e64ed0b
[bindings] Give Transaction objects a buffer-is-owned flag.

A lot of our container mapping depends on the `is_owned` flag
which we have for in-crate mapped objects to map references and
non-references into the same container type. Transaction was
mapped to two completely different types (a slice and a Vec type),
which led to a number of edge cases in the bindings generation.
Specifically, I spent a few days trying to map
`[(A, &Transaction)]` properly and came up empty - we map slices
into the same types as Vecs (and rely on the `is_owned` flag to
avoid double-free) and the lack of one for `Transaction` would have
required a special-case in numerous functions.

Instead, we just add a flag in `Transaction` to mirror what we do
for in-crate types and check it before free-ing any underlying
memory.

Note that, sadly, because the c_types objects aren't mapped as a
part of our C++ bindings generation, you have to manually call
`Transaction_free()` even in C++.
c-bindings-gen/src/types.rs
lightning-c-bindings/demo.c
lightning-c-bindings/demo.cpp
lightning-c-bindings/src/c_types/mod.rs