mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 16:48:19 +00:00
Use IntrusivePtr in TableVal::CallExpireFunc
This commit is contained in:
parent
7a4ce9fb51
commit
0b5a18495d
2 changed files with 6 additions and 20 deletions
23
src/Val.cc
23
src/Val.cc
|
@ -2348,7 +2348,7 @@ void TableVal::DoExpire(double t)
|
||||||
if ( expire_func )
|
if ( expire_func )
|
||||||
{
|
{
|
||||||
idx = RecoverIndex(k);
|
idx = RecoverIndex(k);
|
||||||
double secs = CallExpireFunc(idx->Ref());
|
double secs = CallExpireFunc({NewRef{}, idx});
|
||||||
|
|
||||||
// It's possible that the user-provided
|
// It's possible that the user-provided
|
||||||
// function modified or deleted the table
|
// function modified or deleted the table
|
||||||
|
@ -2439,13 +2439,10 @@ double TableVal::GetExpireTime()
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
double TableVal::CallExpireFunc(Val* idx)
|
double TableVal::CallExpireFunc(IntrusivePtr<Val> idx)
|
||||||
{
|
{
|
||||||
if ( ! expire_func )
|
if ( ! expire_func )
|
||||||
{
|
|
||||||
Unref(idx);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
double secs = 0;
|
double secs = 0;
|
||||||
|
|
||||||
|
@ -2454,16 +2451,12 @@ double TableVal::CallExpireFunc(Val* idx)
|
||||||
auto vf = expire_func->Eval(nullptr);
|
auto vf = expire_func->Eval(nullptr);
|
||||||
|
|
||||||
if ( ! vf )
|
if ( ! vf )
|
||||||
{
|
|
||||||
// Will have been reported already.
|
// Will have been reported already.
|
||||||
Unref(idx);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if ( vf->Type()->Tag() != TYPE_FUNC )
|
if ( vf->Type()->Tag() != TYPE_FUNC )
|
||||||
{
|
{
|
||||||
vf->Error("not a function");
|
vf->Error("not a function");
|
||||||
Unref(idx);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2481,25 +2474,19 @@ double TableVal::CallExpireFunc(Val* idx)
|
||||||
{
|
{
|
||||||
for ( const auto& v : *idx->AsListVal()->Vals() )
|
for ( const auto& v : *idx->AsListVal()->Vals() )
|
||||||
vl.append(v->Ref());
|
vl.append(v->Ref());
|
||||||
|
|
||||||
Unref(idx);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ListVal* idx_list = idx->AsListVal();
|
ListVal* idx_list = idx->AsListVal();
|
||||||
// Flatten if only one element
|
// Flatten if only one element
|
||||||
if ( idx_list->Length() == 1 )
|
if ( idx_list->Length() == 1 )
|
||||||
{
|
idx = {NewRef{}, idx_list->Index(0)};
|
||||||
Val* old = idx;
|
|
||||||
idx = idx_list->Index(0)->Ref();
|
|
||||||
Unref(old);
|
|
||||||
}
|
|
||||||
|
|
||||||
vl.append(idx);
|
vl.append(idx.release());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
vl.append(idx);
|
vl.append(idx.release());
|
||||||
|
|
||||||
auto result = f->Call(&vl);
|
auto result = f->Call(&vl);
|
||||||
|
|
||||||
|
|
|
@ -851,8 +851,7 @@ protected:
|
||||||
double GetExpireTime();
|
double GetExpireTime();
|
||||||
|
|
||||||
// Calls &expire_func and returns its return interval;
|
// Calls &expire_func and returns its return interval;
|
||||||
// takes ownership of the reference.
|
double CallExpireFunc(IntrusivePtr<Val> idx);
|
||||||
double CallExpireFunc(Val *idx);
|
|
||||||
|
|
||||||
// Enum for the different kinds of changes an &on_change handler can see
|
// Enum for the different kinds of changes an &on_change handler can see
|
||||||
enum OnChangeType { ELEMENT_NEW, ELEMENT_CHANGED, ELEMENT_REMOVED, ELEMENT_EXPIRED };
|
enum OnChangeType { ELEMENT_NEW, ELEMENT_CHANGED, ELEMENT_REMOVED, ELEMENT_EXPIRED };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue