mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 08:38:20 +00:00
Add Val::AsFuncPtr() convenience method
Since it's not trivial to store IntrusivePtr in BroValUnion and also not satisfying to store IntrusivePtr*.
This commit is contained in:
parent
5af962e11f
commit
3b6f60a810
4 changed files with 10 additions and 3 deletions
|
@ -84,7 +84,7 @@ IntrusivePtr<Func> zeek::id::find_func(std::string_view name)
|
||||||
reporter->InternalError("Expected variable '%s' to be a function",
|
reporter->InternalError("Expected variable '%s' to be a function",
|
||||||
std::string(name).data());
|
std::string(name).data());
|
||||||
|
|
||||||
return {NewRef{}, v->AsFunc()};
|
return v->AsFuncPtr();
|
||||||
}
|
}
|
||||||
|
|
||||||
void zeek::id::detail::init()
|
void zeek::id::detail::init()
|
||||||
|
|
|
@ -153,6 +153,12 @@ IntrusivePtr<Val> Val::DoClone(CloneState* state)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IntrusivePtr<Func> Val::AsFuncPtr() const
|
||||||
|
{
|
||||||
|
CHECK_TAG(type->Tag(), TYPE_FUNC, "Val::Func", type_name)
|
||||||
|
return {NewRef{}, val.func_val};
|
||||||
|
}
|
||||||
|
|
||||||
bool Val::IsZero() const
|
bool Val::IsZero() const
|
||||||
{
|
{
|
||||||
switch ( type->InternalType() ) {
|
switch ( type->InternalType() ) {
|
||||||
|
|
|
@ -257,6 +257,8 @@ public:
|
||||||
ACCESSOR(TYPE_PATTERN, RE_Matcher*, re_val, AsPattern)
|
ACCESSOR(TYPE_PATTERN, RE_Matcher*, re_val, AsPattern)
|
||||||
ACCESSOR(TYPE_VECTOR, std::vector<Val*>*, vector_val, AsVector)
|
ACCESSOR(TYPE_VECTOR, std::vector<Val*>*, vector_val, AsVector)
|
||||||
|
|
||||||
|
IntrusivePtr<Func> AsFuncPtr() const;
|
||||||
|
|
||||||
const IPPrefix& AsSubNet()
|
const IPPrefix& AsSubNet()
|
||||||
{
|
{
|
||||||
CHECK_TAG(type->Tag(), TYPE_SUBNET, "Val::SubNet", type_name)
|
CHECK_TAG(type->Tag(), TYPE_SUBNET, "Val::SubNet", type_name)
|
||||||
|
|
|
@ -206,7 +206,6 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int &
|
||||||
return val_mgr->False();
|
return val_mgr->False();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* func = on_change->AsFunc();
|
i->AddOptionHandler(on_change->AsFuncPtr(), -priority);
|
||||||
i->AddOptionHandler({NewRef{}, func}, -priority);
|
|
||||||
return val_mgr->True();
|
return val_mgr->True();
|
||||||
%}
|
%}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue