Switch FuncType capture-list storage to optional<vector<Capture>>

May help clarify overall mem-mgmt/ownership semantics.
This commit is contained in:
Jon Siwek 2021-01-11 15:57:58 -08:00
parent ab15a98b28
commit b08112b2e7
8 changed files with 44 additions and 41 deletions

View file

@ -1315,7 +1315,24 @@ begin_lambda:
{
auto id = zeek::detail::current_scope()->GenerateTemporary("anonymous-function");
zeek::detail::begin_func(id, zeek::detail::current_module.c_str(), zeek::FUNC_FLAVOR_FUNCTION, false, {zeek::AdoptRef{}, $2});
$2->SetCaptures($1);
std::optional<zeek::FuncType::CaptureList> captures;
if ( $1 )
{
captures = zeek::FuncType::CaptureList{};
captures->reserve($1->size());
for ( auto c : *$1 )
{
captures->emplace_back(*c);
delete c;
}
delete $1;
}
$2->SetCaptures(std::move(captures));
$$ = id.release();
}
;