mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 17:18:20 +00:00
&expire_func(table, arg1, arg2, ...) + type checking.
This commit is contained in:
parent
c22edc28a5
commit
0ca6b3e013
5 changed files with 110 additions and 25 deletions
46
src/Val.cc
46
src/Val.cc
|
@ -2306,24 +2306,46 @@ double TableVal::CallExpireFunc(Val* idx)
|
|||
return 0;
|
||||
}
|
||||
|
||||
const Func* f = vf->AsFunc();
|
||||
val_list vl { Ref() };
|
||||
|
||||
// Flatten lists of a single element.
|
||||
if ( idx->Type()->Tag() == TYPE_LIST &&
|
||||
idx->AsListVal()->Length() == 1 )
|
||||
const auto func_args = f->FType()->ArgTypes()->Types();
|
||||
|
||||
// backwards compatability with idx: any idiom
|
||||
bool any_idiom = func_args->length() == 2 && func_args->back()->Tag() == TYPE_ANY;
|
||||
|
||||
if ( idx->Type()->Tag() == TYPE_LIST )
|
||||
{
|
||||
Val* old = idx;
|
||||
idx = idx->AsListVal()->Index(0);
|
||||
idx->Ref();
|
||||
Unref(old);
|
||||
if ( ! any_idiom )
|
||||
{
|
||||
const val_list* vl0 = idx->AsListVal()->Vals();
|
||||
for ( const auto& v : *idx->AsListVal()->Vals() )
|
||||
vl.append(v->Ref());
|
||||
}
|
||||
else
|
||||
{
|
||||
ListVal* idx_list = idx->AsListVal();
|
||||
// Flatten if only one element
|
||||
if (idx_list->Length() == 1)
|
||||
{
|
||||
idx = idx_list->Index(0);
|
||||
}
|
||||
vl.append(idx->Ref());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vl.append(idx->Ref());
|
||||
}
|
||||
|
||||
val_list vl{Ref(), idx};
|
||||
Val* vs = vf->AsFunc()->Call(&vl);
|
||||
Val* result = 0;
|
||||
|
||||
if ( vs )
|
||||
result = f->Call(&vl);
|
||||
|
||||
if ( result )
|
||||
{
|
||||
secs = vs->AsInterval();
|
||||
Unref(vs);
|
||||
secs = result->AsInterval();
|
||||
Unref(result);
|
||||
}
|
||||
|
||||
Unref(vf);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue