mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
GH-734: Improve handling of lambdas that escape enclosing frame
This commit is contained in:
parent
fd8db24daf
commit
eb826bd337
5 changed files with 62 additions and 0 deletions
14
src/Frame.cc
14
src/Frame.cc
|
@ -128,6 +128,20 @@ const zeek::ValPtr& Frame::GetElementByID(const zeek::detail::ID* id) const
|
|||
|
||||
void Frame::Reset(int startIdx)
|
||||
{
|
||||
if ( functions_with_closure_frame_reference )
|
||||
{
|
||||
for ( auto& func : *functions_with_closure_frame_reference )
|
||||
{
|
||||
// A lambda could be escaping its enclosing Frame at this point so
|
||||
// it needs to claim some ownership (or copy) of the Frame in
|
||||
// order to be of any further use.
|
||||
func->StrengthenClosureReference(this);
|
||||
Unref(func);
|
||||
}
|
||||
|
||||
functions_with_closure_frame_reference.reset();
|
||||
}
|
||||
|
||||
for ( int i = startIdx; i < size; ++i )
|
||||
ClearElement(i);
|
||||
}
|
||||
|
|
4
testing/btest/Baseline/language.lambda-escaping/out
Normal file
4
testing/btest/Baseline/language.lambda-escaping/out
Normal file
|
@ -0,0 +1,4 @@
|
|||
101
|
||||
101
|
||||
101
|
||||
101
|
1
testing/btest/Baseline/language.lambda-zeek-init/out
Normal file
1
testing/btest/Baseline/language.lambda-zeek-init/out
Normal file
|
@ -0,0 +1 @@
|
|||
103
|
31
testing/btest/language/lambda-escaping.zeek
Normal file
31
testing/btest/language/lambda-escaping.zeek
Normal file
|
@ -0,0 +1,31 @@
|
|||
# @TEST-EXEC: zeek -b %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
global my_func: function();
|
||||
|
||||
event other_event()
|
||||
{
|
||||
local baz = 42;
|
||||
my_func();
|
||||
}
|
||||
|
||||
event zeek_init() &priority=+10
|
||||
{
|
||||
local outer = 101;
|
||||
|
||||
local lambda = function()
|
||||
{ print outer; };
|
||||
|
||||
lambda();
|
||||
|
||||
my_func = lambda;
|
||||
my_func();
|
||||
|
||||
event other_event();
|
||||
}
|
||||
|
||||
event zeek_init() &priority=-10
|
||||
{
|
||||
local qux = 13;
|
||||
my_func();
|
||||
}
|
12
testing/btest/language/lambda-zeek-init.zeek
Normal file
12
testing/btest/language/lambda-zeek-init.zeek
Normal file
|
@ -0,0 +1,12 @@
|
|||
# @TEST-EXEC: zeek -b %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event zeek_init() &priority=+10
|
||||
{
|
||||
local outer = 101;
|
||||
|
||||
local lambda = function()
|
||||
{ print outer + 2; };
|
||||
|
||||
lambda();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue