From 087a0f36366b76510b307a809583f641d9f06ba4 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 20 May 2020 18:41:59 -0700 Subject: [PATCH] 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*). --- NEWS | 8 ++++---- src/Discard.cc | 8 ++++---- src/EventHandler.cc | 2 +- src/Expr.cc | 2 +- src/Func.cc | 10 ++++------ src/Func.h | 17 +++++++++-------- src/RuleCondition.cc | 2 +- src/Val.cc | 6 +++--- src/broker/Manager.cc | 4 ++-- src/broker/messaging.bif | 4 ++-- src/file_analysis/analyzer/x509/X509.cc | 4 ++-- src/input/Manager.cc | 2 +- src/logging/Manager.cc | 12 ++++++------ src/option.bif | 2 +- src/zeek.bif | 4 ++-- 15 files changed, 43 insertions(+), 44 deletions(-) diff --git a/NEWS b/NEWS index ed465b2230..16569dbb8e 100644 --- a/NEWS +++ b/NEWS @@ -104,10 +104,10 @@ Removed Functionality Deprecated Functionality ------------------------ -- The ``Func::Call(val_list*, ...)`` method is now deprecated. The alternate - overload taking a ``zeek::Args`` (``std::vector>``) should - be used instead. There's also now a variadic template that forwards all - arguments. +- The ``Func::Call(val_list*, ...)`` method is now deprecated. Use operator() + instead which takes a ``zeek::Args`` (``std::vector>``). + There's also a variadic template for operator() that forwards all arguments + into a ``zeek::Args`` for you. - The ``EventMgr::QueueEvent()`` and EventMgr::QueueEventFast()`` methods are now deprecated, use ``EventMgr::Enqueue()`` instead. diff --git a/src/Discard.cc b/src/Discard.cc index 6e5aee9826..1984ced575 100644 --- a/src/Discard.cc +++ b/src/Discard.cc @@ -43,7 +43,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_ip->Call(args)->AsBool(); + discard_packet = check_ip->operator()(args)->AsBool(); } catch ( InterpreterException& e ) @@ -98,7 +98,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_tcp->Call(args)->AsBool(); + discard_packet = check_tcp->operator()(args)->AsBool(); } catch ( InterpreterException& e ) @@ -122,7 +122,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_udp->Call(args)->AsBool(); + discard_packet = check_udp->operator()(args)->AsBool(); } catch ( InterpreterException& e ) @@ -142,7 +142,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_icmp->Call(args)->AsBool(); + discard_packet = check_icmp->operator()(args)->AsBool(); } catch ( InterpreterException& e ) diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 45014bc73b..fe3472fbf5 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -115,7 +115,7 @@ void EventHandler::Call(const zeek::Args& vl, bool no_remote) if ( local ) // No try/catch here; we pass exceptions upstream. - local->Call(vl); + local->operator()(vl); } void EventHandler::NewEvent(const zeek::Args& vl) diff --git a/src/Expr.cc b/src/Expr.cc index 52f0dcfd29..fe32e54df8 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -4144,7 +4144,7 @@ IntrusivePtr CallExpr::Eval(Frame* f) const if ( f ) f->SetCall(this); - ret = funcv->Call(*v, f); + ret = funcv->operator()(*v, f); if ( f ) f->SetCall(current_call); diff --git a/src/Func.cc b/src/Func.cc index 3b1b5893fe..99ec67496c 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -294,12 +294,10 @@ bool BroFunc::IsPure() const [](const Body& b) { return b.stmts->IsPure(); }); } -IntrusivePtr Func::Call(val_list* args, Frame* parent) const - { - return Call(zeek::val_list_to_args(*args), parent); - } +Val* Func::Call(val_list* args, Frame* parent) const + { return operator()(zeek::val_list_to_args(*args), parent).release(); }; -IntrusivePtr BroFunc::Call(const zeek::Args& args, Frame* parent) const +IntrusivePtr BroFunc::operator()(const zeek::Args& args, Frame* parent) const { #ifdef PROFILE_BRO_FUNCTIONS DEBUG_MSG("Function: %s\n", Name()); @@ -605,7 +603,7 @@ bool BuiltinFunc::IsPure() const return is_pure; } -IntrusivePtr BuiltinFunc::Call(const zeek::Args& args, Frame* parent) const +IntrusivePtr BuiltinFunc::operator()(const zeek::Args& args, Frame* parent) const { #ifdef PROFILE_BRO_FUNCTIONS DEBUG_MSG("Function: %s\n", Name()); diff --git a/src/Func.h b/src/Func.h index 6bec0d259c..6b96373045 100644 --- a/src/Func.h +++ b/src/Func.h @@ -49,8 +49,8 @@ public: const std::vector& GetBodies() const { return bodies; } bool HasBodies() const { return bodies.size(); } - [[deprecated("Remove in v4.1. Use zeek::Args overload instead.")]] - virtual IntrusivePtr Call(val_list* args, Frame* parent = nullptr) const; + [[deprecated("Remove in v4.1. Use operator() instead.")]] + Val* Call(val_list* args, Frame* parent = nullptr) const; /** * Calls a Zeek function. @@ -58,18 +58,19 @@ public: * @param parent the frame from which the function is being called. * @return the return value of the function call. */ - virtual IntrusivePtr Call(const zeek::Args& args, Frame* parent = nullptr) const = 0; + virtual IntrusivePtr 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 std::enable_if_t< std::is_convertible_v>, IntrusivePtr>, IntrusivePtr> - Call(Args&&... args) const - { return Call(zeek::Args{std::forward(args)...}); } + operator()(Args&&... args) const + { return operator()(zeek::Args{std::forward(args)...}); } // Add a new event handler to an existing function (event). virtual void AddBody(IntrusivePtr new_body, id_list* new_inits, @@ -128,7 +129,7 @@ public: ~BroFunc() override; bool IsPure() const override; - IntrusivePtr Call(const zeek::Args& args, Frame* parent) const override; + IntrusivePtr operator()(const zeek::Args& args, Frame* parent) const override; /** * Adds adds a closure to the function. Closures are cloned and @@ -224,7 +225,7 @@ public: ~BuiltinFunc() override; bool IsPure() const override; - IntrusivePtr Call(const zeek::Args& args, Frame* parent) const override; + IntrusivePtr operator()(const zeek::Args& args, Frame* parent) const override; built_in_func TheFunc() const { return func; } void Describe(ODesc* d) const override; diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index 86c5bbdb63..ed179f1c85 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -181,7 +181,7 @@ bool RuleConditionEval::DoMatch(Rule* rule, RuleEndpointState* state, try { - auto val = id->GetVal()->AsFunc()->Call(args); + auto val = id->GetVal()->AsFunc()->operator()(args); result = val && val->AsBool(); } diff --git a/src/Val.cc b/src/Val.cc index f38cf5e788..a11c26b0f7 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1869,7 +1869,7 @@ IntrusivePtr TableVal::Default(const IntrusivePtr& index) try { - result = f->Call(vl); + result = f->operator()(vl); } catch ( InterpreterException& e ) @@ -2080,7 +2080,7 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe vl.emplace_back(NewRef{}, old_value); in_change_func = true; - f->Call(vl); + f->operator()(vl); } catch ( InterpreterException& e ) { @@ -2538,7 +2538,7 @@ double TableVal::CallExpireFunc(IntrusivePtr idx) vl.emplace_back(std::move(idx)); } - auto result = f->Call(vl); + auto result = f->operator()(vl); if ( result ) secs = result->AsInterval(); diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 3a1dc82906..6d185084e6 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -552,8 +552,8 @@ bool Manager::PublishLogWrite(EnumVal* stream, EnumVal* writer, string path, int std::string serial_data(data, len); free(data); - auto v = log_topic_func->Call(IntrusivePtr{NewRef{}, stream}, - make_intrusive(path)); + auto v = log_topic_func->operator()(IntrusivePtr{NewRef{}, stream}, + make_intrusive(path)); if ( ! v ) { diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index 0189c07c82..8125020ad3 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -188,7 +188,7 @@ function Cluster::publish_rr%(pool: Pool, key: string, ...%): bool topic_func = global_scope()->Find("Cluster::rr_topic")->GetVal()->AsFunc(); zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; - auto topic = topic_func->Call(vl); + auto topic = topic_func->operator()(vl); if ( ! topic->AsString()->Len() ) 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(); zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; - auto topic = topic_func->Call(vl); + auto topic = topic_func->operator()(vl); if ( ! topic->AsString()->Len() ) return val_mgr->False(); diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index edd0de10f8..6588153646 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -61,8 +61,8 @@ bool file_analysis::X509::EndOfFile() return false; // yup, let's call the callback. - cache_hit_callback->Call(IntrusivePtr{NewRef{}, GetFile()->GetVal()}, - entry, make_intrusive(cert_sha256)); + cache_hit_callback->operator()(IntrusivePtr{NewRef{}, GetFile()->GetVal()}, + entry, make_intrusive(cert_sha256)); return false; } } diff --git a/src/input/Manager.cc b/src/input/Manager.cc index c8c70801b5..9788fbd802 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1778,7 +1778,7 @@ bool Manager::CallPred(Func* pred_func, const int numvals, ...) const va_end(lP); - auto v = pred_func->Call(vl); + auto v = pred_func->operator()(vl); if ( v ) result = v->AsBool(); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 8991b134d0..5ae05cb2af 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -721,7 +721,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) // See whether the predicates indicates that we want // to log this record. int result = 1; - auto v = filter->pred->Call(columns); + auto v = filter->pred->operator()(columns); if ( v ) result = v->AsBool(); @@ -748,9 +748,9 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) // Can be TYPE_ANY here. rec_arg = columns; - auto v = filter->path_func->Call(IntrusivePtr{NewRef{}, id}, - std::move(path_arg), - std::move(rec_arg)); + auto v = filter->path_func->operator()(IntrusivePtr{NewRef{}, id}, + std::move(path_arg), + std::move(rec_arg)); if ( ! v ) return false; @@ -1054,7 +1054,7 @@ threading::Value** Manager::RecordToFilterVals(Stream* stream, Filter* filter, 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 ) ext_rec = {AdoptRef{}, res.release()->AsRecordVal()}; @@ -1531,7 +1531,7 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con // Call the postprocessor function. int result = 0; - auto v = func->Call(std::move(info)); + auto v = func->operator()(std::move(info)); if ( v ) result = v->AsBool(); diff --git a/src/option.bif b/src/option.bif index f6869b6dad..27fd236fc2 100644 --- a/src/option.bif +++ b/src/option.bif @@ -24,7 +24,7 @@ static bool call_option_handlers_and_set_value(StringVal* name, const IntrusiveP if ( add_loc ) 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 ) { diff --git a/src/zeek.bif b/src/zeek.bif index 5d2fc12f35..51a95cbaf3 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1338,8 +1338,8 @@ bool sort_function(Val* a, Val* b) if ( ! b ) return 1; - auto result = sort_function_comp->Call(IntrusivePtr{NewRef{}, a}, - IntrusivePtr{NewRef{}, b}); + auto result = sort_function_comp->operator()(IntrusivePtr{NewRef{}, a}, + IntrusivePtr{NewRef{}, b}); int int_result = result->CoerceToInt(); return int_result < 0;