Fix read-access through C++ interpreter to models declared as arrays

Arrays declared in .60 are mapped to a SharedVectorModel<Value> in order
to permit for write access. They can also be turned intoValue::Array /
SharedVector<Value> very cheaply, when reading from C++.
This commit is contained in:
Simon Hausmann 2022-01-26 11:44:10 +01:00 committed by Simon Hausmann
parent 99644a741a
commit b6492b02e8
5 changed files with 132 additions and 14 deletions

View file

@ -419,8 +419,10 @@ inline Value::Value(const sixtyfps::SharedVector<Value> &array)
inline std::optional<sixtyfps::SharedVector<Value>> Value::to_array() const
{
if (auto *array = cbindgen_private::sixtyfps_interpreter_value_to_array(&inner)) {
return *reinterpret_cast<const sixtyfps::SharedVector<Value> *>(array);
sixtyfps::SharedVector<Value> array;
if (cbindgen_private::sixtyfps_interpreter_value_to_array(
&inner, &reinterpret_cast<sixtyfps::SharedVector<ValueOpaque> &>(array))) {
return array;
} else {
return {};
}