Switch Func::Call(val_list*) back to returning Val*

And renamed the method returning IntrusivePtr to operator().
This corrects the deprecation process for Func::Call(val_list*).
This commit is contained in:
Jon Siwek 2020-05-20 18:41:59 -07:00
parent 85a0ddd62d
commit 087a0f3636
15 changed files with 43 additions and 44 deletions

8
NEWS
View file

@ -104,10 +104,10 @@ Removed Functionality
Deprecated Functionality Deprecated Functionality
------------------------ ------------------------
- The ``Func::Call(val_list*, ...)`` method is now deprecated. The alternate - The ``Func::Call(val_list*, ...)`` method is now deprecated. Use operator()
overload taking a ``zeek::Args`` (``std::vector<IntrusivePtr<Val>>``) should instead which takes a ``zeek::Args`` (``std::vector<IntrusivePtr<Val>>``).
be used instead. There's also now a variadic template that forwards all There's also a variadic template for operator() that forwards all arguments
arguments. into a ``zeek::Args`` for you.
- The ``EventMgr::QueueEvent()`` and EventMgr::QueueEventFast()`` methods - The ``EventMgr::QueueEvent()`` and EventMgr::QueueEventFast()`` methods
are now deprecated, use ``EventMgr::Enqueue()`` instead. are now deprecated, use ``EventMgr::Enqueue()`` instead.

View file

@ -43,7 +43,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen)
try try
{ {
discard_packet = check_ip->Call(args)->AsBool(); discard_packet = check_ip->operator()(args)->AsBool();
} }
catch ( InterpreterException& e ) catch ( InterpreterException& e )
@ -98,7 +98,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen)
try try
{ {
discard_packet = check_tcp->Call(args)->AsBool(); discard_packet = check_tcp->operator()(args)->AsBool();
} }
catch ( InterpreterException& e ) catch ( InterpreterException& e )
@ -122,7 +122,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen)
try try
{ {
discard_packet = check_udp->Call(args)->AsBool(); discard_packet = check_udp->operator()(args)->AsBool();
} }
catch ( InterpreterException& e ) catch ( InterpreterException& e )
@ -142,7 +142,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen)
try try
{ {
discard_packet = check_icmp->Call(args)->AsBool(); discard_packet = check_icmp->operator()(args)->AsBool();
} }
catch ( InterpreterException& e ) catch ( InterpreterException& e )

View file

@ -115,7 +115,7 @@ void EventHandler::Call(const zeek::Args& vl, bool no_remote)
if ( local ) if ( local )
// No try/catch here; we pass exceptions upstream. // No try/catch here; we pass exceptions upstream.
local->Call(vl); local->operator()(vl);
} }
void EventHandler::NewEvent(const zeek::Args& vl) void EventHandler::NewEvent(const zeek::Args& vl)

View file

@ -4144,7 +4144,7 @@ IntrusivePtr<Val> CallExpr::Eval(Frame* f) const
if ( f ) if ( f )
f->SetCall(this); f->SetCall(this);
ret = funcv->Call(*v, f); ret = funcv->operator()(*v, f);
if ( f ) if ( f )
f->SetCall(current_call); f->SetCall(current_call);

View file

@ -294,12 +294,10 @@ bool BroFunc::IsPure() const
[](const Body& b) { return b.stmts->IsPure(); }); [](const Body& b) { return b.stmts->IsPure(); });
} }
IntrusivePtr<Val> Func::Call(val_list* args, Frame* parent) const Val* Func::Call(val_list* args, Frame* parent) const
{ { return operator()(zeek::val_list_to_args(*args), parent).release(); };
return Call(zeek::val_list_to_args(*args), parent);
}
IntrusivePtr<Val> BroFunc::Call(const zeek::Args& args, Frame* parent) const IntrusivePtr<Val> BroFunc::operator()(const zeek::Args& args, Frame* parent) const
{ {
#ifdef PROFILE_BRO_FUNCTIONS #ifdef PROFILE_BRO_FUNCTIONS
DEBUG_MSG("Function: %s\n", Name()); DEBUG_MSG("Function: %s\n", Name());
@ -605,7 +603,7 @@ bool BuiltinFunc::IsPure() const
return is_pure; return is_pure;
} }
IntrusivePtr<Val> BuiltinFunc::Call(const zeek::Args& args, Frame* parent) const IntrusivePtr<Val> BuiltinFunc::operator()(const zeek::Args& args, Frame* parent) const
{ {
#ifdef PROFILE_BRO_FUNCTIONS #ifdef PROFILE_BRO_FUNCTIONS
DEBUG_MSG("Function: %s\n", Name()); DEBUG_MSG("Function: %s\n", Name());

View file

@ -49,8 +49,8 @@ public:
const std::vector<Body>& GetBodies() const { return bodies; } const std::vector<Body>& GetBodies() const { return bodies; }
bool HasBodies() const { return bodies.size(); } bool HasBodies() const { return bodies.size(); }
[[deprecated("Remove in v4.1. Use zeek::Args overload instead.")]] [[deprecated("Remove in v4.1. Use operator() instead.")]]
virtual IntrusivePtr<Val> Call(val_list* args, Frame* parent = nullptr) const; Val* Call(val_list* args, Frame* parent = nullptr) const;
/** /**
* Calls a Zeek function. * Calls a Zeek function.
@ -58,18 +58,19 @@ public:
* @param parent the frame from which the function is being called. * @param parent the frame from which the function is being called.
* @return the return value of the function call. * @return the return value of the function call.
*/ */
virtual IntrusivePtr<Val> Call(const zeek::Args& args, Frame* parent = nullptr) const = 0; virtual IntrusivePtr<Val> operator()(const zeek::Args& args,
Frame* parent = nullptr) const = 0;
/** /**
* A version of Call() taking a variable number of individual arguments. * A version of operator() taking a variable number of individual arguments.
*/ */
template <class... Args> template <class... Args>
std::enable_if_t< std::enable_if_t<
std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>, std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>,
IntrusivePtr<Val>>, IntrusivePtr<Val>>,
IntrusivePtr<Val>> IntrusivePtr<Val>>
Call(Args&&... args) const operator()(Args&&... args) const
{ return Call(zeek::Args{std::forward<Args>(args)...}); } { return operator()(zeek::Args{std::forward<Args>(args)...}); }
// Add a new event handler to an existing function (event). // Add a new event handler to an existing function (event).
virtual void AddBody(IntrusivePtr<Stmt> new_body, id_list* new_inits, virtual void AddBody(IntrusivePtr<Stmt> new_body, id_list* new_inits,
@ -128,7 +129,7 @@ public:
~BroFunc() override; ~BroFunc() override;
bool IsPure() const override; bool IsPure() const override;
IntrusivePtr<Val> Call(const zeek::Args& args, Frame* parent) const override; IntrusivePtr<Val> operator()(const zeek::Args& args, Frame* parent) const override;
/** /**
* Adds adds a closure to the function. Closures are cloned and * Adds adds a closure to the function. Closures are cloned and
@ -224,7 +225,7 @@ public:
~BuiltinFunc() override; ~BuiltinFunc() override;
bool IsPure() const override; bool IsPure() const override;
IntrusivePtr<Val> Call(const zeek::Args& args, Frame* parent) const override; IntrusivePtr<Val> operator()(const zeek::Args& args, Frame* parent) const override;
built_in_func TheFunc() const { return func; } built_in_func TheFunc() const { return func; }
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;

View file

@ -181,7 +181,7 @@ bool RuleConditionEval::DoMatch(Rule* rule, RuleEndpointState* state,
try try
{ {
auto val = id->GetVal()->AsFunc()->Call(args); auto val = id->GetVal()->AsFunc()->operator()(args);
result = val && val->AsBool(); result = val && val->AsBool();
} }

View file

@ -1869,7 +1869,7 @@ IntrusivePtr<Val> TableVal::Default(const IntrusivePtr<Val>& index)
try try
{ {
result = f->Call(vl); result = f->operator()(vl);
} }
catch ( InterpreterException& e ) catch ( InterpreterException& e )
@ -2080,7 +2080,7 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe
vl.emplace_back(NewRef{}, old_value); vl.emplace_back(NewRef{}, old_value);
in_change_func = true; in_change_func = true;
f->Call(vl); f->operator()(vl);
} }
catch ( InterpreterException& e ) catch ( InterpreterException& e )
{ {
@ -2538,7 +2538,7 @@ double TableVal::CallExpireFunc(IntrusivePtr<ListVal> idx)
vl.emplace_back(std::move(idx)); vl.emplace_back(std::move(idx));
} }
auto result = f->Call(vl); auto result = f->operator()(vl);
if ( result ) if ( result )
secs = result->AsInterval(); secs = result->AsInterval();

View file

@ -552,8 +552,8 @@ bool Manager::PublishLogWrite(EnumVal* stream, EnumVal* writer, string path, int
std::string serial_data(data, len); std::string serial_data(data, len);
free(data); free(data);
auto v = log_topic_func->Call(IntrusivePtr{NewRef{}, stream}, auto v = log_topic_func->operator()(IntrusivePtr{NewRef{}, stream},
make_intrusive<StringVal>(path)); make_intrusive<StringVal>(path));
if ( ! v ) if ( ! v )
{ {

View file

@ -188,7 +188,7 @@ function Cluster::publish_rr%(pool: Pool, key: string, ...%): bool
topic_func = global_scope()->Find("Cluster::rr_topic")->GetVal()->AsFunc(); topic_func = global_scope()->Find("Cluster::rr_topic")->GetVal()->AsFunc();
zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}};
auto topic = topic_func->Call(vl); auto topic = topic_func->operator()(vl);
if ( ! topic->AsString()->Len() ) if ( ! topic->AsString()->Len() )
return val_mgr->False(); return val_mgr->False();
@ -225,7 +225,7 @@ function Cluster::publish_hrw%(pool: Pool, key: any, ...%): bool
topic_func = global_scope()->Find("Cluster::hrw_topic")->GetVal()->AsFunc(); topic_func = global_scope()->Find("Cluster::hrw_topic")->GetVal()->AsFunc();
zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}};
auto topic = topic_func->Call(vl); auto topic = topic_func->operator()(vl);
if ( ! topic->AsString()->Len() ) if ( ! topic->AsString()->Len() )
return val_mgr->False(); return val_mgr->False();

View file

@ -61,8 +61,8 @@ bool file_analysis::X509::EndOfFile()
return false; return false;
// yup, let's call the callback. // yup, let's call the callback.
cache_hit_callback->Call(IntrusivePtr{NewRef{}, GetFile()->GetVal()}, cache_hit_callback->operator()(IntrusivePtr{NewRef{}, GetFile()->GetVal()},
entry, make_intrusive<StringVal>(cert_sha256)); entry, make_intrusive<StringVal>(cert_sha256));
return false; return false;
} }
} }

View file

@ -1778,7 +1778,7 @@ bool Manager::CallPred(Func* pred_func, const int numvals, ...) const
va_end(lP); va_end(lP);
auto v = pred_func->Call(vl); auto v = pred_func->operator()(vl);
if ( v ) if ( v )
result = v->AsBool(); result = v->AsBool();

View file

@ -721,7 +721,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg)
// See whether the predicates indicates that we want // See whether the predicates indicates that we want
// to log this record. // to log this record.
int result = 1; int result = 1;
auto v = filter->pred->Call(columns); auto v = filter->pred->operator()(columns);
if ( v ) if ( v )
result = v->AsBool(); result = v->AsBool();
@ -748,9 +748,9 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg)
// Can be TYPE_ANY here. // Can be TYPE_ANY here.
rec_arg = columns; rec_arg = columns;
auto v = filter->path_func->Call(IntrusivePtr{NewRef{}, id}, auto v = filter->path_func->operator()(IntrusivePtr{NewRef{}, id},
std::move(path_arg), std::move(path_arg),
std::move(rec_arg)); std::move(rec_arg));
if ( ! v ) if ( ! v )
return false; return false;
@ -1054,7 +1054,7 @@ threading::Value** Manager::RecordToFilterVals(Stream* stream, Filter* filter,
if ( filter->num_ext_fields > 0 ) if ( filter->num_ext_fields > 0 )
{ {
auto res = filter->ext_func->Call(IntrusivePtr{NewRef{}, filter->path_val}); auto res = filter->ext_func->operator()(IntrusivePtr{NewRef{}, filter->path_val});
if ( res ) if ( res )
ext_rec = {AdoptRef{}, res.release()->AsRecordVal()}; ext_rec = {AdoptRef{}, res.release()->AsRecordVal()};
@ -1531,7 +1531,7 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con
// Call the postprocessor function. // Call the postprocessor function.
int result = 0; int result = 0;
auto v = func->Call(std::move(info)); auto v = func->operator()(std::move(info));
if ( v ) if ( v )
result = v->AsBool(); result = v->AsBool();

View file

@ -24,7 +24,7 @@ static bool call_option_handlers_and_set_value(StringVal* name, const IntrusiveP
if ( add_loc ) if ( add_loc )
vl.emplace_back(NewRef{}, location); vl.emplace_back(NewRef{}, location);
val = handler_function->Call(vl); // consumed by next call. val = handler_function->operator()(vl); // consumed by next call.
if ( ! val ) if ( ! val )
{ {

View file

@ -1338,8 +1338,8 @@ bool sort_function(Val* a, Val* b)
if ( ! b ) if ( ! b )
return 1; return 1;
auto result = sort_function_comp->Call(IntrusivePtr{NewRef{}, a}, auto result = sort_function_comp->operator()(IntrusivePtr{NewRef{}, a},
IntrusivePtr{NewRef{}, b}); IntrusivePtr{NewRef{}, b});
int int_result = result->CoerceToInt(); int int_result = result->CoerceToInt();
return int_result < 0; return int_result < 0;