diff --git a/NEWS b/NEWS index 840e687988..055a1a48a6 100644 --- a/NEWS +++ b/NEWS @@ -157,6 +157,8 @@ Deprecated Functionality - ``ID::Type()`` is deprecated, use ``ID::GetType()``. +- ``ID::ID_Val()`` is deprecated, use ``ID::GetVal()``. + Zeek 3.1.0 ========== diff --git a/src/Debug.cc b/src/Debug.cc index 7136daf3cb..b28d03a7e2 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -221,7 +221,7 @@ static void parse_function_name(vector& result, return; } - const Func* func = id->ID_Val()->AsFunc(); + const Func* func = id->GetVal()->AsFunc(); const vector& bodies = func->GetBodies(); if ( bodies.size() == 0 ) diff --git a/src/Expr.cc b/src/Expr.cc index 3ff94d3242..4848a6db73 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -236,7 +236,7 @@ IntrusivePtr NameExpr::Eval(Frame* f) const return make_intrusive(id->GetType(), true); if ( id->IsGlobal() ) - v = {NewRef{}, id->ID_Val()}; + v = id->GetVal(); else if ( f ) v = {NewRef{}, f->GetElement(id.get())}; diff --git a/src/ID.cc b/src/ID.cc index 0ddab99d92..20d4e1df85 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -25,7 +25,6 @@ ID::ID(const char* arg_name, IDScope arg_scope, bool arg_is_export) scope = arg_scope; is_export = arg_is_export; is_option = false; - val = nullptr; is_const = false; is_enum_const = false; is_type = false; @@ -41,8 +40,8 @@ ID::~ID() { delete [] name; - if ( ! weak_ref ) - Unref(val); + if ( weak_ref ) + val.release(); } std::string ID::ModuleName() const @@ -57,18 +56,16 @@ void ID::SetType(IntrusivePtr t) void ID::ClearVal() { - if ( ! weak_ref ) - Unref(val); - - val = nullptr; + if ( weak_ref ) + val.release(); } void ID::SetVal(IntrusivePtr v, bool arg_weak_ref) { - if ( ! weak_ref ) - Unref(val); + if ( weak_ref ) + val.release(); - val = v.release(); + val = std::move(v); weak_ref = arg_weak_ref; Modified(); @@ -124,12 +121,12 @@ void ID::SetVal(IntrusivePtr v, init_class c) return; } else - v->AddTo(val, false); + v->AddTo(val.get(), false); } else { if ( val ) - v->RemoveFrom(val); + v->RemoveFrom(val.get()); } } } @@ -267,7 +264,7 @@ void ID::SetOption() void ID::EvalFunc(IntrusivePtr ef, IntrusivePtr ev) { - auto arg1 = make_intrusive(IntrusivePtr{NewRef{}, val}); + auto arg1 = make_intrusive(val); auto args = make_intrusive(); args->Append(std::move(arg1)); args->Append(std::move(ev)); @@ -488,10 +485,8 @@ void ID::DescribeReST(ODesc* d, bool roles_only) const d->Add(":Default:"); auto ii = zeekygen_mgr->GetIdentifierInfo(Name()); auto redefs = ii->GetRedefs(); - auto iv = val; - - if ( ! redefs.empty() && ii->InitialVal() ) - iv = ii->InitialVal(); + const auto& iv = ! redefs.empty() && ii->InitialVal() ? ii->InitialVal() + : val; if ( type->InternalType() == TYPE_INTERNAL_OTHER ) { diff --git a/src/ID.h b/src/ID.h index 7324032c3c..0ec222f733 100644 --- a/src/ID.h +++ b/src/ID.h @@ -70,8 +70,15 @@ public: void SetVal(IntrusivePtr ev, init_class c); bool HasVal() const { return val != nullptr; } - Val* ID_Val() { return val; } - const Val* ID_Val() const { return val; } + + [[deprecated("Remove in v4.1. Use GetVal().")]] + Val* ID_Val() { return val.get(); } + [[deprecated("Remove in v4.1. Use GetVal().")]] + const Val* ID_Val() const { return val.get(); } + + const IntrusivePtr& GetVal() const + { return val; } + void ClearVal(); void SetConst() { is_const = true; } @@ -139,7 +146,7 @@ protected: IntrusivePtr type; bool is_const, is_enum_const, is_type, is_option; int offset; - Val* val; + IntrusivePtr val; IntrusivePtr attrs; // contains list of functions that are called when an option changes std::multimap> option_handlers; diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index ff43f0ecaf..315a40551f 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -164,7 +164,7 @@ bool RuleConditionEval::DoMatch(Rule* rule, RuleEndpointState* state, } if ( id->GetType()->Tag() != TYPE_FUNC ) - return id->ID_Val()->AsBool(); + return id->GetVal()->AsBool(); // Call function with a signature_state value as argument. zeek::Args args; @@ -180,7 +180,7 @@ bool RuleConditionEval::DoMatch(Rule* rule, RuleEndpointState* state, try { - auto val = id->ID_Val()->AsFunc()->Call(args); + auto val = id->GetVal()->AsFunc()->Call(args); result = val && val->AsBool(); } diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index b624008271..1137d0ee76 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -1278,7 +1278,7 @@ static Val* get_bro_val(const char* label) return nullptr; } - return id->ID_Val(); + return id->GetVal().get(); } diff --git a/src/Stats.cc b/src/Stats.cc index 3c2508c7f7..70427ebcf5 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -257,9 +257,9 @@ void ProfileLogger::Log() // contained in some other global user-visible container. if ( id->HasVal() ) { - Val* v = id->ID_Val(); + const auto& v = id->GetVal(); - size = id->ID_Val()->MemoryAllocation(); + size = v->MemoryAllocation(); mem += size; bool print = false; diff --git a/src/Trigger.cc b/src/Trigger.cc index f024cfbbe5..18fd850b64 100644 --- a/src/Trigger.cc +++ b/src/Trigger.cc @@ -50,7 +50,8 @@ TraversalCode TriggerTraversalCallback::PreExpr(const Expr* expr) if ( e->Id()->IsGlobal() ) trigger->Register(e->Id()); - Val* v = e->Id()->ID_Val(); + Val* v = e->Id()->GetVal().get(); + if ( v && v->Modifiable() ) trigger->Register(v); break; diff --git a/src/Type.cc b/src/Type.cc index 1c8176ddcf..be18f6d059 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1168,7 +1168,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, // cyclic dependencies. string fullname = make_full_var_name(module_name.c_str(), name); if ( id->Name() != fullname - || (id->HasVal() && val != id->ID_Val()->AsEnum()) + || (id->HasVal() && val != id->GetVal()->AsEnum()) || (names.find(fullname) != names.end() && names[fullname] != val) ) { reporter->Error("identifier or enumerator value in enumerated type definition already exists"); diff --git a/src/Var.cc b/src/Var.cc index cf79a6ba4d..7a5c9026d8 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -525,7 +525,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, if ( id->HasVal() ) { - function_flavor id_flavor = id->ID_Val()->AsFunc()->Flavor(); + function_flavor id_flavor = id->GetVal()->AsFunc()->Flavor(); if ( id_flavor != flavor ) id->Error("inconsistent function flavor", t.get()); @@ -630,7 +630,7 @@ void end_func(IntrusivePtr body) auto ingredients = std::make_unique(pop_scope(), std::move(body)); if ( ingredients->id->HasVal() ) - ingredients->id->ID_Val()->AsFunc()->AddBody( + ingredients->id->GetVal()->AsFunc()->AddBody( ingredients->body, ingredients->inits, ingredients->frame_size, @@ -648,7 +648,7 @@ void end_func(IntrusivePtr body) ingredients->id->SetConst(); } - ingredients->id->ID_Val()->AsFunc()->SetScope(ingredients->scope); + ingredients->id->GetVal()->AsFunc()->SetScope(ingredients->scope); // Note: ideally, something would take ownership of this memory until the // end of script execution, but that's essentially the same as the // lifetime of the process at the moment, so ok to "leak" it. @@ -662,7 +662,7 @@ Val* internal_val(const char* name) if ( ! id ) reporter->InternalError("internal variable %s missing", name); - return id->ID_Val(); + return id->GetVal().get(); } id_list gather_outer_ids(Scope* scope, Stmt* body) @@ -694,13 +694,13 @@ Val* internal_const_val(const char* name) if ( ! id->IsConst() ) reporter->InternalError("internal variable %s is not constant", name); - return id->ID_Val(); + return id->GetVal().get(); } Val* opt_internal_val(const char* name) { auto id = lookup_ID(name, GLOBAL_MODULE_NAME); - return id ? id->ID_Val() : nullptr; + return id ? id->GetVal().get() : nullptr; } double opt_internal_double(const char* name) @@ -739,7 +739,7 @@ ListVal* internal_list_val(const char* name) if ( ! id ) return nullptr; - Val* v = id->ID_Val(); + Val* v = id->GetVal().get(); if ( v ) { diff --git a/src/analyzer/Manager.cc b/src/analyzer/Manager.cc index 45f6b7792e..d605e04d0e 100644 --- a/src/analyzer/Manager.cc +++ b/src/analyzer/Manager.cc @@ -92,10 +92,10 @@ void Manager::InitPostScript() { auto id = global_scope()->Lookup("Tunnel::vxlan_ports"); - if ( ! (id && id->ID_Val()) ) + if ( ! (id && id->GetVal()) ) reporter->FatalError("Tunnel::vxlan_ports not defined"); - auto table_val = id->ID_Val()->AsTableVal(); + auto table_val = id->GetVal()->AsTableVal(); auto port_list = table_val->ToPureListVal(); for ( auto i = 0; i < port_list->Length(); ++i ) diff --git a/src/analyzer/protocol/mqtt/commands/publish.pac b/src/analyzer/protocol/mqtt/commands/publish.pac index a2ded3783d..029f52b899 100644 --- a/src/analyzer/protocol/mqtt/commands/publish.pac +++ b/src/analyzer/protocol/mqtt/commands/publish.pac @@ -31,7 +31,7 @@ refine flow MQTT_Flow += { reinterpret_cast(${msg.topic.str}.begin()))); auto len = ${msg.payload}.length(); - auto max = analyzer::MQTT::MQTT_Analyzer::max_payload_size->ID_Val()->AsCount(); + auto max = analyzer::MQTT::MQTT_Analyzer::max_payload_size->GetVal()->AsCount(); if ( len > static_cast(max) ) len = max; diff --git a/src/broker/Data.cc b/src/broker/Data.cc index cbed055db3..c653256a89 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -357,7 +357,7 @@ struct val_converter { if ( ! id ) return nullptr; - auto rval = id->ID_Val(); + const auto& rval = id->GetVal(); if ( ! rval ) return nullptr; @@ -701,7 +701,7 @@ struct type_checker { if ( ! id ) return false; - auto rval = id->ID_Val(); + const auto& rval = id->GetVal(); if ( ! rval ) return false; diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 9155dad4cd..c5be4b918b 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -31,10 +31,10 @@ static inline Val* get_option(const char* option) { auto id = global_scope()->Lookup(option); - if ( ! (id && id->ID_Val()) ) + if ( ! (id && id->GetVal()) ) reporter->FatalError("Unknown Broker option %s", option); - return id->ID_Val(); + return id->GetVal().get(); } class BrokerConfig : public broker::configuration { @@ -418,14 +418,14 @@ bool Manager::PublishIdentifier(std::string topic, std::string id) if ( ! i ) return false; - auto val = i->ID_Val(); + const auto& val = i->GetVal(); if ( ! val ) // Probably could have a special case to also unset the value on the // receiving side, but not sure what use that would be. return false; - auto data = val_to_data(val); + auto data = val_to_data(val.get()); if ( ! data ) { diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index c809b013ee..fd33464371 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -185,7 +185,7 @@ function Cluster::publish_rr%(pool: Pool, key: string, ...%): bool static Func* topic_func = 0; if ( ! topic_func ) - topic_func = global_scope()->Lookup("Cluster::rr_topic")->ID_Val()->AsFunc(); + topic_func = global_scope()->Lookup("Cluster::rr_topic")->GetVal()->AsFunc(); zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; auto topic = topic_func->Call(vl); @@ -222,7 +222,7 @@ function Cluster::publish_hrw%(pool: Pool, key: any, ...%): bool static Func* topic_func = 0; if ( ! topic_func ) - topic_func = global_scope()->Lookup("Cluster::hrw_topic")->ID_Val()->AsFunc(); + topic_func = global_scope()->Lookup("Cluster::hrw_topic")->GetVal()->AsFunc(); zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; auto topic = topic_func->Call(vl); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 2a190ba53a..5f0933d234 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -1184,7 +1184,7 @@ WriterFrontend* Manager::CreateWriter(EnumVal* id, EnumVal* writer, WriterBacken { ID* id = global_scope()->Lookup("Log::default_rotation_interval"); assert(id); - winfo->interval = id->ID_Val()->AsInterval(); + winfo->interval = id->GetVal()->AsInterval(); } stream->writers.insert( @@ -1527,7 +1527,7 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con { ID* id = global_scope()->Lookup("Log::__default_rotation_postprocessor"); assert(id); - func = id->ID_Val()->AsFunc(); + func = id->GetVal()->AsFunc(); } assert(func); diff --git a/src/option.bif b/src/option.bif index 016bcd993e..c898b725bf 100644 --- a/src/option.bif +++ b/src/option.bif @@ -104,7 +104,7 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool // Just coerce an empty/unspecified table to the right type. auto tv = make_intrusive( cast_intrusive(i->GetType()), - IntrusivePtr{NewRef{}, i->ID_Val()->AsTableVal()->Attrs()}); + IntrusivePtr{NewRef{}, i->GetVal()->AsTableVal()->Attrs()}); auto rval = call_option_handlers_and_set_value(ID, i, std::move(tv), location); return val_mgr->Bool(rval); } diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 4b04974245..0f063a3f76 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1195,7 +1195,7 @@ bool Supervisor::SupervisedNode::InitCluster() const auto cluster_node_type = global_scope()->Lookup("Cluster::Node")->GetType()->AsRecordType(); auto cluster_nodes_id = global_scope()->Lookup("Cluster::nodes"); auto cluster_manager_is_logger_id = global_scope()->Lookup("Cluster::manager_is_logger"); - auto cluster_nodes = cluster_nodes_id->ID_Val()->AsTableVal(); + auto cluster_nodes = cluster_nodes_id->GetVal()->AsTableVal(); auto has_logger = false; std::optional manager_name; diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index b8d65a01b4..cb5e3bd49c 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -631,11 +631,11 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, // initialization). binpac::FlowBuffer::Policy flowbuffer_policy; flowbuffer_policy.max_capacity = global_scope()->Lookup( - "BinPAC::flowbuffer_capacity_max")->ID_Val()->AsCount(); + "BinPAC::flowbuffer_capacity_max")->GetVal()->AsCount(); flowbuffer_policy.min_capacity = global_scope()->Lookup( - "BinPAC::flowbuffer_capacity_min")->ID_Val()->AsCount(); + "BinPAC::flowbuffer_capacity_min")->GetVal()->AsCount(); flowbuffer_policy.contract_threshold = global_scope()->Lookup( - "BinPAC::flowbuffer_contract_threshold")->ID_Val()->AsCount(); + "BinPAC::flowbuffer_contract_threshold")->GetVal()->AsCount(); binpac::init(&flowbuffer_policy); plugin_mgr->InitBifs(); diff --git a/src/zeek.bif b/src/zeek.bif index 93ffc5caed..91e7d82000 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1926,7 +1926,7 @@ function global_sizes%(%): var_sizes if ( id->HasVal() ) { auto id_name = make_intrusive(id->Name()); - auto id_size = val_mgr->Count(id->ID_Val()->MemoryAllocation()); + auto id_size = val_mgr->Count(id->GetVal()->MemoryAllocation()); sizes->Assign(id_name.get(), std::move(id_size)); } } @@ -1959,11 +1959,7 @@ function global_ids%(%): id_table rec->Assign(5, val_mgr->Bool(id->IsRedefinable())); if ( id->HasVal() ) - { - Val* val = id->ID_Val(); - Ref(val); - rec->Assign(6, val); - } + rec->Assign(6, id->GetVal()); auto id_name = make_intrusive(id->Name()); ids->Assign(id_name.get(), std::move(rec)); @@ -1984,10 +1980,10 @@ function lookup_ID%(id: string%) : any if ( ! i ) return make_intrusive(""); - if ( ! i->ID_Val() ) + if ( ! i->GetVal() ) return make_intrusive(""); - return IntrusivePtr{NewRef{}, i->ID_Val()}; + return i->GetVal(); %} ## Generates metadata about a record's fields. The returned information @@ -3908,7 +3904,7 @@ static Val* mmdb_getvalue(MMDB_entry_data_s* entry_data, int status, static bool mmdb_try_open_loc () { // City database is always preferred over Country database. - auto mmdb_dir_val = global_scope()->Lookup("mmdb_dir")->ID_Val(); + const auto& mmdb_dir_val = global_scope()->Lookup("mmdb_dir")->GetVal(); std::string mmdb_dir = mmdb_dir_val->AsString()->CheckString(); if ( ! mmdb_dir.empty() ) @@ -3936,7 +3932,7 @@ static bool mmdb_try_open_loc () static bool mmdb_try_open_asn () { - auto mmdb_dir_val = global_scope()->Lookup("mmdb_dir")->ID_Val(); + const auto& mmdb_dir_val = global_scope()->Lookup("mmdb_dir")->GetVal(); std::string mmdb_dir = mmdb_dir_val->AsString()->CheckString(); if ( ! mmdb_dir.empty() ) diff --git a/src/zeekygen/IdentifierInfo.cc b/src/zeekygen/IdentifierInfo.cc index 8372582f1c..744aab928b 100644 --- a/src/zeekygen/IdentifierInfo.cc +++ b/src/zeekygen/IdentifierInfo.cc @@ -16,8 +16,8 @@ IdentifierInfo::IdentifierInfo(IntrusivePtr arg_id, ScriptInfo* script) comments(), id(std::move(arg_id)), initial_val(), redefs(), fields(), last_field_seen(), declaring_script(script) { - if ( id->ID_Val() && (id->IsOption() || id->IsRedefinable()) ) - initial_val = id->ID_Val()->Clone(); + if ( id->GetVal() && (id->IsOption() || id->IsRedefinable()) ) + initial_val = id->GetVal()->Clone(); } IdentifierInfo::~IdentifierInfo() diff --git a/src/zeekygen/IdentifierInfo.h b/src/zeekygen/IdentifierInfo.h index e21912d8fb..a2292844d1 100644 --- a/src/zeekygen/IdentifierInfo.h +++ b/src/zeekygen/IdentifierInfo.h @@ -42,8 +42,8 @@ public: /** * Returns the initial value of the identifier. */ - Val* InitialVal() const - { return initial_val.get(); } + const IntrusivePtr& InitialVal() const + { return initial_val; } /** * Add a comment associated with the identifier. If the identifier is a