mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
Guarantee unique internal name for each lambda function
By dealing with hash collisions.
This commit is contained in:
parent
8575c9daed
commit
a1d8a21005
1 changed files with 18 additions and 3 deletions
21
src/Expr.cc
21
src/Expr.cc
|
@ -4339,10 +4339,25 @@ LambdaExpr::LambdaExpr(std::unique_ptr<function_ingredients> arg_ing,
|
||||||
// Get the body's "string" representation.
|
// Get the body's "string" representation.
|
||||||
ODesc d;
|
ODesc d;
|
||||||
dummy_func->Describe(&d);
|
dummy_func->Describe(&d);
|
||||||
uint64_t h[2];
|
|
||||||
internal_md5(d.Bytes(), d.Len(), reinterpret_cast<unsigned char*>(h));
|
|
||||||
|
|
||||||
my_name = "lambda_<" + std::to_string(h[0]) + ">";
|
for ( ; ; )
|
||||||
|
{
|
||||||
|
uint64_t h[2];
|
||||||
|
internal_md5(d.Bytes(), d.Len(), reinterpret_cast<unsigned char*>(h));
|
||||||
|
|
||||||
|
my_name = "lambda_<" + std::to_string(h[0]) + ">";
|
||||||
|
auto fullname = make_full_var_name(current_module.data(), my_name.data());
|
||||||
|
auto id = global_scope()->Lookup(fullname.data());
|
||||||
|
|
||||||
|
if ( id )
|
||||||
|
// Just try again to make a unique lambda name. If two peer
|
||||||
|
// processes need to agree on the same lambda name, this assumes
|
||||||
|
// they're loading the same scripts and thus have the same hash
|
||||||
|
// collisions.
|
||||||
|
d.Add(" ");
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Install that in the global_scope
|
// Install that in the global_scope
|
||||||
ID* id = install_ID(my_name.c_str(), current_module.c_str(), true, false);
|
ID* id = install_ID(my_name.c_str(), current_module.c_str(), true, false);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue