From b7f7d32bf71f33e176b33afabe09adfb9223bfda Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Wed, 8 Mar 2023 09:49:59 +0100 Subject: [PATCH] Fix for EnumVal's returning their underlying value Change EnumVal()->AsEnum() to zeek_int_t. --- src/Val.h | 6 +++--- src/broker/Manager.cc | 12 ++++++++---- src/script_opt/CPP/Exprs.cc | 2 +- src/script_opt/CPP/RuntimeInitSupport.cc | 2 +- src/script_opt/CPP/RuntimeInitSupport.h | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Val.h b/src/Val.h index 5db5368b66..034919f813 100644 --- a/src/Val.h +++ b/src/Val.h @@ -155,7 +155,7 @@ public: UNDERLYING_ACCESSOR_DECL(detail::IntValImplementation, zeek_int_t, AsInt) UNDERLYING_ACCESSOR_DECL(BoolVal, bool, AsBool) - UNDERLYING_ACCESSOR_DECL(EnumVal, int, AsEnum) + UNDERLYING_ACCESSOR_DECL(EnumVal, zeek_int_t, AsEnum) UNDERLYING_ACCESSOR_DECL(detail::UnsignedValImplementation, zeek_uint_t, AsCount) UNDERLYING_ACCESSOR_DECL(detail::DoubleValImplementation, double, AsDouble) UNDERLYING_ACCESSOR_DECL(TimeVal, double, AsTime) @@ -1476,7 +1476,7 @@ protected: friend class Val; friend class EnumType; - friend EnumValPtr make_enum__CPP(TypePtr t, int i); + friend EnumValPtr make_enum__CPP(TypePtr t, zeek_int_t i); template friend IntrusivePtr make_intrusive(Ts&&... args); @@ -1700,7 +1700,7 @@ private: UNDERLYING_ACCESSOR_DEF(detail::IntValImplementation, zeek_int_t, AsInt) UNDERLYING_ACCESSOR_DEF(BoolVal, bool, AsBool) -UNDERLYING_ACCESSOR_DEF(EnumVal, int, AsEnum) +UNDERLYING_ACCESSOR_DEF(EnumVal, zeek_int_t, AsEnum) UNDERLYING_ACCESSOR_DEF(detail::UnsignedValImplementation, zeek_uint_t, AsCount) UNDERLYING_ACCESSOR_DEF(detail::DoubleValImplementation, double, AsDouble) UNDERLYING_ACCESSOR_DEF(TimeVal, double, AsTime) diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 59b614dcf3..e35ece26e2 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -729,7 +729,8 @@ bool Manager::PublishLogCreate(EnumVal* stream, EnumVal* writer, if ( ! stream_id ) { - reporter->Error("Failed to remotely log: stream %d doesn't have name", stream->AsEnum()); + reporter->Error("Failed to remotely log: stream %" PRId64 " doesn't have name", + stream->AsEnum()); return false; } @@ -737,7 +738,8 @@ bool Manager::PublishLogCreate(EnumVal* stream, EnumVal* writer, if ( ! writer_id ) { - reporter->Error("Failed to remotely log: writer %d doesn't have name", writer->AsEnum()); + reporter->Error("Failed to remotely log: writer %" PRId64 " doesn't have name", + writer->AsEnum()); return false; } @@ -784,7 +786,8 @@ bool Manager::PublishLogWrite(EnumVal* stream, EnumVal* writer, string path, int if ( ! stream_id ) { - reporter->Error("Failed to remotely log: stream %d doesn't have name", stream->AsEnum()); + reporter->Error("Failed to remotely log: stream %" PRId64 " doesn't have name", + stream->AsEnum()); return false; } @@ -792,7 +795,8 @@ bool Manager::PublishLogWrite(EnumVal* stream, EnumVal* writer, string path, int if ( ! writer_id ) { - reporter->Error("Failed to remotely log: writer %d doesn't have name", writer->AsEnum()); + reporter->Error("Failed to remotely log: writer %" PRId64 " doesn't have name", + writer->AsEnum()); return false; } diff --git a/src/script_opt/CPP/Exprs.cc b/src/script_opt/CPP/Exprs.cc index e464c9b8d3..1c105a21ab 100644 --- a/src/script_opt/CPP/Exprs.cc +++ b/src/script_opt/CPP/Exprs.cc @@ -1336,7 +1336,7 @@ string CPPCompile::GenEnum(const TypePtr& t, const ValPtr& ev) if ( ! et->HasRedefs() ) // Can use direct access. - return Fmt(v); + return std::to_string(v); // Need to dynamically map the access. int mapping_slot; diff --git a/src/script_opt/CPP/RuntimeInitSupport.cc b/src/script_opt/CPP/RuntimeInitSupport.cc index 62130f49df..8837204ae9 100644 --- a/src/script_opt/CPP/RuntimeInitSupport.cc +++ b/src/script_opt/CPP/RuntimeInitSupport.cc @@ -257,7 +257,7 @@ EnumTypePtr get_enum_type__CPP(const string& enum_type_name) return make_intrusive(enum_type_name); } -EnumValPtr make_enum__CPP(TypePtr t, int i) +EnumValPtr make_enum__CPP(TypePtr t, zeek_int_t i) { auto et = cast_intrusive(move(t)); return make_intrusive(et, i); diff --git a/src/script_opt/CPP/RuntimeInitSupport.h b/src/script_opt/CPP/RuntimeInitSupport.h index 06e5132edd..37a8782bf7 100644 --- a/src/script_opt/CPP/RuntimeInitSupport.h +++ b/src/script_opt/CPP/RuntimeInitSupport.h @@ -84,7 +84,7 @@ extern EnumTypePtr get_enum_type__CPP(const std::string& enum_type_name); // Returns an enum value corresponding to the given low-level value 'i' // in the context of the given enum type 't'. -extern EnumValPtr make_enum__CPP(TypePtr t, int i); +extern EnumValPtr make_enum__CPP(TypePtr t, zeek_int_t i); } // namespace zeek::detail } // namespace zeek