Skip to content

Commit

Permalink
Fix compilation error on some platform WRT hashing of enums. (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: John Plevyak <jplevyak@gmail.com>
  • Loading branch information
jplevyak authored Jun 6, 2019
1 parent 037a5ad commit 13bc9ab
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
18 changes: 9 additions & 9 deletions api/wasm/cpp/proxy_wasm_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ class Context {
friend class GrpcStreamHandlerBase;

uint32_t id_;
std::unordered_map<std::pair<MetadataType, std::string>, google::protobuf::Value, PairHash> value_cache_;
std::unordered_map<std::tuple<MetadataType, std::string, std::string>, google::protobuf::Value, Tuple3Hash> name_value_cache_;
std::unordered_map<std::pair<MetadataType, std::string>, google::protobuf::Struct, PairHash> struct_cache_;
std::unordered_map<std::pair<EnumType, std::string>, google::protobuf::Value, PairHash> value_cache_;
std::unordered_map<std::tuple<EnumType, std::string, std::string>, google::protobuf::Value, Tuple3Hash> name_value_cache_;
std::unordered_map<std::pair<EnumType, std::string>, google::protobuf::Struct, PairHash> struct_cache_;
std::unordered_map<uint32_t, HttpCallCallback> http_calls_;
std::unordered_map<uint32_t, GrpcSimpleCallCallback> simple_grpc_calls_;
std::unordered_map<uint32_t, std::unique_ptr<GrpcCallHandlerBase>> grpc_calls_;
Expand Down Expand Up @@ -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<EnumType>(type), std::string(key));
auto it = value_cache_.find(cache_key);
if (it != value_cache_.end()) {
return it->second;
Expand All @@ -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<EnumType>(type), std::string(p.first));
value_cache_[cache_key] = value;
}
}
Expand Down Expand Up @@ -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<EnumType>(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<EnumType>(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<EnumType>(type), n)] = std::move(s);
it = name_value_cache_.find(cache_key);
if (it != name_value_cache_.end()) {
return it->second;
Expand All @@ -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<EnumType>(type), std::string(name));
auto it = struct_cache_.find(cache_key);
if (it != struct_cache_.end()) {
return it->second;
Expand Down
1 change: 1 addition & 0 deletions source/extensions/common/wasm/null/null.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified test/extensions/filters/http/wasm/test_data/metadata_cpp.wasm
Binary file not shown.
30 changes: 15 additions & 15 deletions test/extensions/filters/http/wasm/test_data/metadata_cpp.wat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 13bc9ab

Please sign in to comment.