From 13bc9ab2f52e6db2d84c1c75ea5097732007c1a3 Mon Sep 17 00:00:00 2001 From: John Plevyak Date: Thu, 6 Jun 2019 13:59:56 -0700 Subject: [PATCH] Fix compilation error on some platform WRT hashing of enums. (#36) Signed-off-by: John Plevyak --- api/wasm/cpp/proxy_wasm_impl.h | 18 +++++------ source/extensions/common/wasm/null/null.h | 1 + .../http/wasm/test_data/metadata_cpp.wasm | Bin 719007 -> 718942 bytes .../http/wasm/test_data/metadata_cpp.wat | 30 +++++++++--------- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/api/wasm/cpp/proxy_wasm_impl.h b/api/wasm/cpp/proxy_wasm_impl.h index d03c1c5b01ef..1f7b7d53d967 100644 --- a/api/wasm/cpp/proxy_wasm_impl.h +++ b/api/wasm/cpp/proxy_wasm_impl.h @@ -326,9 +326,9 @@ class Context { friend class GrpcStreamHandlerBase; uint32_t id_; - std::unordered_map, google::protobuf::Value, PairHash> value_cache_; - std::unordered_map, google::protobuf::Value, Tuple3Hash> name_value_cache_; - std::unordered_map, google::protobuf::Struct, PairHash> struct_cache_; + std::unordered_map, google::protobuf::Value, PairHash> value_cache_; + std::unordered_map, google::protobuf::Value, Tuple3Hash> name_value_cache_; + std::unordered_map, google::protobuf::Struct, PairHash> struct_cache_; std::unordered_map http_calls_; std::unordered_map simple_grpc_calls_; std::unordered_map> grpc_calls_; @@ -439,7 +439,7 @@ inline void setMetadataStruct(MetadataType type, StringView name, } inline google::protobuf::Value Context::metadataValue(MetadataType type, StringView key) { - auto cache_key = std::make_pair(type, std::string(key)); + auto cache_key = std::make_pair(static_cast(type), std::string(key)); auto it = value_cache_.find(cache_key); if (it != value_cache_.end()) { return it->second; @@ -449,7 +449,7 @@ inline google::protobuf::Value Context::metadataValue(MetadataType type, StringV for (auto &p : values->pairs()) { google::protobuf::Value value; if (value.ParseFromArray(p.second.data(), p.second.size())) { - auto k = std::make_pair(type, std::string(p.first)); + auto k = std::make_pair(static_cast(type), std::string(p.first)); value_cache_[cache_key] = value; } } @@ -491,17 +491,17 @@ inline google::protobuf::Value Context::nodeMetadataValue(StringView key) { inline google::protobuf::Value Context::namedMetadataValue(MetadataType type, StringView name, StringView key) { auto n = std::string(name); - auto cache_key = std::make_tuple(type, n, std::string(key)); + auto cache_key = std::make_tuple(static_cast(type), n, std::string(key)); auto it = name_value_cache_.find(cache_key); if (it != name_value_cache_.end()) { return it->second; } auto s = metadataStruct(type, name); for (auto &f : s.fields()) { - auto k = std::make_tuple(type, n, f.first); + auto k = std::make_tuple(static_cast(type), n, f.first); name_value_cache_[k] = f.second; } - struct_cache_[std::make_pair(type, n)] = std::move(s); + struct_cache_[std::make_pair(static_cast(type), n)] = std::move(s); it = name_value_cache_.find(cache_key); if (it != name_value_cache_.end()) { return it->second; @@ -518,7 +518,7 @@ inline google::protobuf::Value Context::responseMetadataValue(StringView name, S } inline google::protobuf::Struct Context::metadataStruct(MetadataType type, StringView name) { - auto cache_key = std::make_pair(type, std::string(name)); + auto cache_key = std::make_pair(static_cast(type), std::string(name)); auto it = struct_cache_.find(cache_key); if (it != struct_cache_.end()) { return it->second; diff --git a/source/extensions/common/wasm/null/null.h b/source/extensions/common/wasm/null/null.h index cff681f40a85..2a0031ca1303 100644 --- a/source/extensions/common/wasm/null/null.h +++ b/source/extensions/common/wasm/null/null.h @@ -18,6 +18,7 @@ using FilterDataStatus = Http::FilterDataStatus; using GrpcStatus = ProtobufUtil::error::Code; using MetricType = Envoy::Extensions::Common::Wasm::Context::MetricType; using StringView = absl::string_view; +using EnumType = uint32_t; } // namespace Plugin } // namespace Null } // namespace Wasm diff --git a/test/extensions/filters/http/wasm/test_data/metadata_cpp.wasm b/test/extensions/filters/http/wasm/test_data/metadata_cpp.wasm index 21a8d130a7f31b364948ded7a72afb20f991d7ea..8e27db3445af9b1a0aac82aba40be3e38e9f8e49 100644 GIT binary patch delta 452 zcmbRLQTyHp?S>Y{ElevcxvzIHvE(J@rZS%E*uL44shopx!*p#YCKbl4>FYN$Sxq-^ zWs;h{(TPc1*&^Q6)i2mI-qSDGFy7NU*djjI2`B^vnH8=K+FupEI`Z(#B4y!4#XTl%(;EK2N%Z%0GD=^5C8xG delta 542 zcmccjL3{p3?S>Y{Elevcxo31TvE(J@rZV<-Zr^OlRL;S;cY2{alM0`qk#A~AVoG93 zVn}5{>U76KCadWe+?j-@Ur1zPo4(kINkZ8&-qqDF*eu@DFW4~N(>vHQKG+#31O%BC zu0g@>@eUWK&u?ckoX+pe#7V%w9A_p47RUHt*Xa|SnRE<5ta!iRc#G7+(!`wjl6=o# zN1)L@Nrphv{esQoJ%RE-rb$|6UJ6id`Wt5^ZARDW5-v>DjI+tK)tFdY&5BYp5{olj zbDigsX_X2wR!v{-#&nW#AKv&dA{-0ulfjN`5A$FGVrC#_0b*7lW&>h&Am#vK&h23y HTpSw!M5?gB diff --git a/test/extensions/filters/http/wasm/test_data/metadata_cpp.wat b/test/extensions/filters/http/wasm/test_data/metadata_cpp.wat index 635cc01c48a9..0a5870cc40bb 100644 --- a/test/extensions/filters/http/wasm/test_data/metadata_cpp.wat +++ b/test/extensions/filters/http/wasm/test_data/metadata_cpp.wat @@ -4889,7 +4889,7 @@ i32.add local.tee $16 local.get $10 - call $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairI12MetadataTypeNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherISA_SE_8PairHashLb1EEENS_21__unordered_map_equalISA_SE_NS_8equal_toISA_EELb1EEENS7_ISE_EEE4findISA_EENS_15__hash_iteratorIPNS_11__hash_nodeISE_PvEEEERKT_ + call $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairIjNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherIS9_SD_8PairHashLb1EEENS_21__unordered_map_equalIS9_SD_NS_8equal_toIS9_EELb1EEENS6_ISD_EEE4findIS9_EENS_15__hash_iteratorIPNS_11__hash_nodeISD_PvEEEERKT_ local.tee $4 if $if_2 local.get $0 @@ -4925,7 +4925,7 @@ call $__Z16getMetadataValue12MetadataTypeNSt3__217basic_string_viewIcNS0_11char_traitsIcEEEE local.get $16 local.get $10 - call $__ZNSt3__213unordered_mapINS_4pairI12MetadataTypeNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueE8PairHashNS_8equal_toIS9_EENS6_INS1_IKS9_SC_EEEEEixERSG_ + call $__ZNSt3__213unordered_mapINS_4pairIjNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueE8PairHashNS_8equal_toIS8_EENS5_INS1_IKS8_SB_EEEEEixERSF_ local.get $0 call $__ZN6google8protobuf5Value8CopyFromERKS1_ br $block_1 @@ -5187,7 +5187,7 @@ local.set $2 local.get $16 local.get $10 - call $__ZNSt3__213unordered_mapINS_4pairI12MetadataTypeNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueE8PairHashNS_8equal_toIS9_EENS6_INS1_IKS9_SC_EEEEEixERSG_ + call $__ZNSt3__213unordered_mapINS_4pairIjNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueE8PairHashNS_8equal_toIS8_EENS5_INS1_IKS8_SB_EEEEEixERSF_ local.get $9 call $__ZN6google8protobuf5Value8CopyFromERKS1_ local.get $2 @@ -5226,7 +5226,7 @@ end ;; $if_12 local.get $16 local.get $10 - call $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairI12MetadataTypeNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherISA_SE_8PairHashLb1EEENS_21__unordered_map_equalISA_SE_NS_8equal_toISA_EELb1EEENS7_ISE_EEE4findISA_EENS_15__hash_iteratorIPNS_11__hash_nodeISE_PvEEEERKT_ + call $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairIjNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherIS9_SD_8PairHashLb1EEENS_21__unordered_map_equalIS9_SD_NS_8equal_toIS9_EELb1EEENS6_ISD_EEE4findIS9_EENS_15__hash_iteratorIPNS_11__hash_nodeISD_PvEEEERKT_ local.tee $1 if $if_13 local.get $0 @@ -5289,7 +5289,7 @@ end ;; $if ) - (func $__ZNSt3__213unordered_mapINS_4pairI12MetadataTypeNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueE8PairHashNS_8equal_toIS9_EENS6_INS1_IKS9_SC_EEEEEixERSG_ (type $4) + (func $__ZNSt3__213unordered_mapINS_4pairIjNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueE8PairHashNS_8equal_toIS8_EENS5_INS1_IKS8_SB_EEEEEixERSF_ (type $4) (param $0 i32) (param $1 i32) (result i32) @@ -5880,7 +5880,7 @@ local.get $2 i32.lt_u select - call $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairI12MetadataTypeNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherISA_SE_8PairHashLb1EEENS_21__unordered_map_equalISA_SE_NS_8equal_toISA_EELb1EEENS7_ISE_EEE6rehashEm + call $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairIjNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherIS9_SD_8PairHashLb1EEENS_21__unordered_map_equalIS9_SD_NS_8equal_toIS9_EELb1EEENS6_ISD_EEE6rehashEm local.get $14 i32.load local.tee $2 @@ -6004,7 +6004,7 @@ i32.add ) - (func $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairI12MetadataTypeNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherISA_SE_8PairHashLb1EEENS_21__unordered_map_equalISA_SE_NS_8equal_toISA_EELb1EEENS7_ISE_EEE4findISA_EENS_15__hash_iteratorIPNS_11__hash_nodeISE_PvEEEERKT_ (type $4) + (func $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairIjNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherIS9_SD_8PairHashLb1EEENS_21__unordered_map_equalIS9_SD_NS_8equal_toIS9_EELb1EEENS6_ISD_EEE4findIS9_EENS_15__hash_iteratorIPNS_11__hash_nodeISD_PvEEEERKT_ (type $4) (param $0 i32) (param $1 i32) (result i32) @@ -6609,7 +6609,7 @@ call $__ZdlPv ) - (func $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairI12MetadataTypeNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherISA_SE_8PairHashLb1EEENS_21__unordered_map_equalISA_SE_NS_8equal_toISA_EELb1EEENS7_ISE_EEE6rehashEm (type $3) + (func $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairIjNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherIS9_SD_8PairHashLb1EEENS_21__unordered_map_equalIS9_SD_NS_8equal_toIS9_EELb1EEENS6_ISD_EEE6rehashEm (type $3) (param $0 i32) (param $1 i32) (local $2 i32) @@ -6641,7 +6641,7 @@ if $if_1 local.get $0 local.get $1 - call $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairI12MetadataTypeNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherISA_SE_8PairHashLb1EEENS_21__unordered_map_equalISA_SE_NS_8equal_toISA_EELb1EEENS7_ISE_EEE8__rehashEm + call $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairIjNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherIS9_SD_8PairHashLb1EEENS_21__unordered_map_equalIS9_SD_NS_8equal_toIS9_EELb1EEENS6_ISD_EEE8__rehashEm return end ;; $if_1 local.get $1 @@ -6703,10 +6703,10 @@ end ;; $if_4 local.get $0 local.get $1 - call $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairI12MetadataTypeNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherISA_SE_8PairHashLb1EEENS_21__unordered_map_equalISA_SE_NS_8equal_toISA_EELb1EEENS7_ISE_EEE8__rehashEm + call $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairIjNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherIS9_SD_8PairHashLb1EEENS_21__unordered_map_equalIS9_SD_NS_8equal_toIS9_EELb1EEENS6_ISD_EEE8__rehashEm ) - (func $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairI12MetadataTypeNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherISA_SE_8PairHashLb1EEENS_21__unordered_map_equalISA_SE_NS_8equal_toISA_EELb1EEENS7_ISE_EEE8__rehashEm (type $3) + (func $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairIjNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherIS9_SD_8PairHashLb1EEENS_21__unordered_map_equalIS9_SD_NS_8equal_toIS9_EELb1EEENS6_ISD_EEE8__rehashEm (type $3) (param $0 i32) (param $1 i32) (local $2 i32) @@ -7425,7 +7425,7 @@ i32.add local.tee $5 local.get $9 - call $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairI12MetadataTypeNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherISA_SE_8PairHashLb1EEENS_21__unordered_map_equalISA_SE_NS_8equal_toISA_EELb1EEENS7_ISE_EEE4findISA_EENS_15__hash_iteratorIPNS_11__hash_nodeISE_PvEEEERKT_ + call $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairIjNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherIS9_SD_8PairHashLb1EEENS_21__unordered_map_equalIS9_SD_NS_8equal_toIS9_EELb1EEENS6_ISD_EEE4findIS9_EENS_15__hash_iteratorIPNS_11__hash_nodeISD_PvEEEERKT_ local.tee $1 if $if_2 local.get $0 @@ -7447,7 +7447,7 @@ call $__Z17getMetadataStruct12MetadataTypeNSt3__217basic_string_viewIcNS0_11char_traitsIcEEEE local.get $5 local.get $9 - call $__ZNSt3__213unordered_mapINS_4pairI12MetadataTypeNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf6StructE8PairHashNS_8equal_toIS9_EENS6_INS1_IKS9_SC_EEEEEixERSG_ + call $__ZNSt3__213unordered_mapINS_4pairIjNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf6StructE8PairHashNS_8equal_toIS8_EENS5_INS1_IKS8_SB_EEEEEixERSF_ local.get $8 call $__ZN6google8protobuf6Struct8CopyFromERKS1_ local.get $0 @@ -7625,7 +7625,7 @@ global.set $36 ) - (func $__ZNSt3__213unordered_mapINS_4pairI12MetadataTypeNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf6StructE8PairHashNS_8equal_toIS9_EENS6_INS1_IKS9_SC_EEEEEixERSG_ (type $4) + (func $__ZNSt3__213unordered_mapINS_4pairIjNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf6StructE8PairHashNS_8equal_toIS8_EENS5_INS1_IKS8_SB_EEEEEixERSF_ (type $4) (param $0 i32) (param $1 i32) (result i32) @@ -8216,7 +8216,7 @@ local.get $2 i32.lt_u select - call $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairI12MetadataTypeNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherISA_SE_8PairHashLb1EEENS_21__unordered_map_equalISA_SE_NS_8equal_toISA_EELb1EEENS7_ISE_EEE6rehashEm + call $__ZNSt3__212__hash_tableINS_17__hash_value_typeINS_4pairIjNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEN6google8protobuf5ValueEEENS_22__unordered_map_hasherIS9_SD_8PairHashLb1EEENS_21__unordered_map_equalIS9_SD_NS_8equal_toIS9_EELb1EEENS6_ISD_EEE6rehashEm local.get $14 i32.load local.tee $2