diff --git a/src/script_opt/CPP/InitsInfo.cc b/src/script_opt/CPP/InitsInfo.cc index c965d2b045..b9a5551cd9 100644 --- a/src/script_opt/CPP/InitsInfo.cc +++ b/src/script_opt/CPP/InitsInfo.cc @@ -382,7 +382,8 @@ GlobalInitInfo::GlobalInitInfo(CPPCompile* c, const ID* g, string _CPP_name) else attrs = -1; - exported = g->IsExport(); + is_exported = g->IsExport(); + is_option = g->IsOption(); val = ValElem(c, nullptr); // empty because we initialize dynamically if ( gt->Tag() == TYPE_FUNC && (! g->GetVal() || g->GetVal()->AsFunc()->GetKind() == Func::BUILTIN_FUNC) ) @@ -398,7 +399,8 @@ void GlobalInitInfo::InitializerVals(std::vector& ivs) const { ivs.push_back(Fmt(type)); ivs.push_back(Fmt(attrs)); ivs.push_back(val); - ivs.push_back(Fmt(exported)); + ivs.push_back(Fmt(is_exported)); + ivs.push_back(Fmt(is_option)); ivs.push_back(Fmt(func_with_no_val)); } diff --git a/src/script_opt/CPP/InitsInfo.h b/src/script_opt/CPP/InitsInfo.h index a72f9146f0..f900b8273c 100644 --- a/src/script_opt/CPP/InitsInfo.h +++ b/src/script_opt/CPP/InitsInfo.h @@ -479,7 +479,8 @@ public: }; // A lightweight initializer for a Zeek global that will look it up at -// initialization time but not create it if missing. +// initialization time but not create it if missing. If do_init is true, +// then the global will be (re-)initialized to its value during compilation. class GlobalLookupInitInfo : public CPP_InitInfo { public: GlobalLookupInitInfo(CPPCompile* c, const ID* g, std::string CPP_name, bool do_init = false); @@ -505,7 +506,8 @@ protected: int type; int attrs; std::string val; - bool exported; + bool is_exported; + bool is_option; bool func_with_no_val = false; // needed to handle some error situations }; diff --git a/src/script_opt/CPP/RuntimeInits.cc b/src/script_opt/CPP/RuntimeInits.cc index 299872d3ca..37249be638 100644 --- a/src/script_opt/CPP/RuntimeInits.cc +++ b/src/script_opt/CPP/RuntimeInits.cc @@ -464,7 +464,10 @@ void CPP_GlobalLookupInit::Generate(InitsManager* im, std::vector& /* ini void CPP_GlobalInit::Generate(InitsManager* im, std::vector& /* inits_vec */, int /* offset */) const { auto& t = im->Types(type); - global = lookup_global__CPP(name, t, exported); + global = lookup_global__CPP(name, t, is_exported); + + if ( is_option ) + global->SetOption(); if ( ! global->HasVal() ) { if ( val >= 0 ) diff --git a/src/script_opt/CPP/RuntimeInits.h b/src/script_opt/CPP/RuntimeInits.h index 62577d4193..4ced70af63 100644 --- a/src/script_opt/CPP/RuntimeInits.h +++ b/src/script_opt/CPP/RuntimeInits.h @@ -396,15 +396,16 @@ protected: class CPP_GlobalInit : public CPP_Init { public: - CPP_GlobalInit(IDPtr& _global, const char* _name, int _type, int _attrs, int _val, bool _exported, - bool _func_with_no_val) + CPP_GlobalInit(IDPtr& _global, const char* _name, int _type, int _attrs, int _val, bool _is_exported, + bool _is_option, bool _func_with_no_val) : CPP_Init(), global(_global), name(_name), type(_type), attrs(_attrs), val(_val), - exported(_exported), + is_exported(_is_exported), + is_option(_is_option), func_with_no_val(_func_with_no_val) {} void Generate(InitsManager* im, std::vector& /* inits_vec */, int /* offset */) const override; @@ -415,7 +416,8 @@ protected: int type; int attrs; int val; - bool exported; + bool is_exported; + bool is_option; bool func_with_no_val; };