From e200fee8af40918c41f3275cff090993e3b26940 Mon Sep 17 00:00:00 2001 From: Ivan Prisyazhnyy Date: Tue, 19 Dec 2023 16:26:47 +0100 Subject: [PATCH] fix a few missing includes and ::proxy_wasm namespace pollution with std {} (#365) * include: add missing dependencies Signed-off-by: Ivan Prisyazhnyy * fix: proxy_wasm namespace polution with std defs fixes: In file included from external/proxy_wasm_cpp_host/src/null/null.cc:17: In file included from external/proxy_wasm_cpp_host/include/proxy-wasm/null_vm.h:22: In file included from external/proxy_wasm_cpp_host/include/proxy-wasm/null_vm_plugin.h:18: In file included from external/proxy_wasm_cpp_host/include/proxy-wasm/wasm_vm.h:26: In file included from external/proxy_wasm_cpp_host/include/proxy-wasm/word.h:22: external/proxy_wasm_cpp_sdk/proxy_wasm_common.h:59:8: error: no type named 'string' in namespace 'proxy_wasm::std'; did you mean '::std::string'? inline std::string toString(WasmResult r) { ^~~~~~~~~~~ ::std::string The headers from https://github.com/proxy-wasm/proxy-wasm-cpp-sdk include C++ headers that pollute the current namespace with a partial definition of std{} namespace that then interferes with the names resolution inside of proxy_wasm as well as duplicates ::std defs. Signed-off-by: Ivan Prisyazhnyy * include: add missing includes to pairs_util and the test Signed-off-by: Ivan Prisyazhnyy * sdk.h/change: drop one redundant namespace hierarchy level to have +using WasmResult = internal::WasmResult; instead of -using WasmResult = internal::proxy_wasm::WasmResult; the patchset fixes: In file included from external/proxy_wasm_cpp_host/src/null/null.cc:17: In file included from external/proxy_wasm_cpp_host/include/proxy-wasm/null_vm.h:22: In file included from external/proxy_wasm_cpp_host/include/proxy-wasm/null_vm_plugin.h:18: In file included from external/proxy_wasm_cpp_host/include/proxy-wasm/wasm_vm.h:26: In file included from external/proxy_wasm_cpp_host/include/proxy-wasm/word.h:22: external/proxy_wasm_cpp_sdk/proxy_wasm_common.h:59:8: error: no type named 'string' in namespace 'proxy_wasm::std'; did you mean '::std::string'? inline std::string toString(WasmResult r) { ^~~~~~~~~~~ ::std::string The headers from https://github.com/proxy-wasm/proxy-wasm-cpp-sdk include C++ headers that pollute the current namespace with a partial definition of std{} namespace that then interferes with the names resolution inside of proxy_wasm as well as duplicates ::std defs. Signed-off-by: Ivan Prisyazhnyy --------- Signed-off-by: Ivan Prisyazhnyy --- BUILD | 1 + include/proxy-wasm/context.h | 4 +-- include/proxy-wasm/context_interface.h | 5 ++- include/proxy-wasm/pairs_util.h | 1 + include/proxy-wasm/sdk.h | 50 ++++++++++++++++++++++++++ include/proxy-wasm/vm_id_handle.h | 4 ++- include/proxy-wasm/wasm.h | 3 +- include/proxy-wasm/wasm_api_impl.h | 4 +-- include/proxy-wasm/wasm_vm.h | 4 +-- include/proxy-wasm/word.h | 4 +-- test/fuzz/pairs_util_fuzzer.cc | 1 + 11 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 include/proxy-wasm/sdk.h diff --git a/BUILD b/BUILD index 8b330199..66c3371d 100644 --- a/BUILD +++ b/BUILD @@ -38,6 +38,7 @@ cc_library( name = "wasm_vm_headers", hdrs = [ "include/proxy-wasm/limits.h", + "include/proxy-wasm/sdk.h", "include/proxy-wasm/wasm_vm.h", "include/proxy-wasm/word.h", ], diff --git a/include/proxy-wasm/context.h b/include/proxy-wasm/context.h index ab99cad7..12937041 100644 --- a/include/proxy-wasm/context.h +++ b/include/proxy-wasm/context.h @@ -26,13 +26,11 @@ #include #include +#include "include/proxy-wasm/sdk.h" #include "include/proxy-wasm/context_interface.h" namespace proxy_wasm { -#include "proxy_wasm_common.h" -#include "proxy_wasm_enums.h" - class PluginHandleBase; class WasmBase; class WasmVm; diff --git a/include/proxy-wasm/context_interface.h b/include/proxy-wasm/context_interface.h index 81973eed..48fce76d 100644 --- a/include/proxy-wasm/context_interface.h +++ b/include/proxy-wasm/context_interface.h @@ -25,10 +25,9 @@ #include #include -namespace proxy_wasm { +#include "include/proxy-wasm/sdk.h" -#include "proxy_wasm_common.h" -#include "proxy_wasm_enums.h" +namespace proxy_wasm { using Pairs = std::vector>; using PairsWithStringValues = std::vector>; diff --git a/include/proxy-wasm/pairs_util.h b/include/proxy-wasm/pairs_util.h index 54df2fd8..019c970b 100644 --- a/include/proxy-wasm/pairs_util.h +++ b/include/proxy-wasm/pairs_util.h @@ -15,6 +15,7 @@ #pragma once +#include #include #include #include diff --git a/include/proxy-wasm/sdk.h b/include/proxy-wasm/sdk.h new file mode 100644 index 00000000..10585437 --- /dev/null +++ b/include/proxy-wasm/sdk.h @@ -0,0 +1,50 @@ +// Copyright 2016-2019 Envoy Project Authors +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include +#include + +namespace proxy_wasm { + +namespace internal { + +// isolate those includes to prevent ::proxy_wasm namespace pollution with std +// namespace definitions. +#include "proxy_wasm_common.h" +#include "proxy_wasm_enums.h" + +} // namespace internal + +// proxy_wasm_common.h +using WasmResult = internal::WasmResult; +using WasmHeaderMapType = internal::WasmHeaderMapType; +using WasmBufferType = internal::WasmBufferType; +using WasmBufferFlags = internal::WasmBufferFlags; +using WasmStreamType = internal::WasmStreamType; + +// proxy_wasm_enums.h +using LogLevel = internal::LogLevel; +using FilterStatus = internal::FilterStatus; +using FilterHeadersStatus = internal::FilterHeadersStatus; +using FilterMetadataStatus = internal::FilterMetadataStatus; +using FilterTrailersStatus = internal::FilterTrailersStatus; +using FilterDataStatus = internal::FilterDataStatus; +using GrpcStatus = internal::GrpcStatus; +using MetricType = internal::MetricType; +using CloseType = internal::CloseType; + +} // namespace proxy_wasm diff --git a/include/proxy-wasm/vm_id_handle.h b/include/proxy-wasm/vm_id_handle.h index 547eca22..16ebb4bf 100644 --- a/include/proxy-wasm/vm_id_handle.h +++ b/include/proxy-wasm/vm_id_handle.h @@ -15,8 +15,10 @@ #pragma once #include -#include #include +#include +#include +#include #include namespace proxy_wasm { diff --git a/include/proxy-wasm/wasm.h b/include/proxy-wasm/wasm.h index 1a785a8f..9fa2bda1 100644 --- a/include/proxy-wasm/wasm.h +++ b/include/proxy-wasm/wasm.h @@ -24,6 +24,7 @@ #include #include +#include "include/proxy-wasm/sdk.h" #include "include/proxy-wasm/context.h" #include "include/proxy-wasm/exports.h" #include "include/proxy-wasm/wasm_vm.h" @@ -31,8 +32,6 @@ namespace proxy_wasm { -#include "proxy_wasm_common.h" - class ContextBase; class WasmHandleBase; diff --git a/include/proxy-wasm/wasm_api_impl.h b/include/proxy-wasm/wasm_api_impl.h index 8bd9626f..899af7e4 100644 --- a/include/proxy-wasm/wasm_api_impl.h +++ b/include/proxy-wasm/wasm_api_impl.h @@ -30,15 +30,13 @@ #include #include +#include "include/proxy-wasm/sdk.h" #include "include/proxy-wasm/exports.h" #include "include/proxy-wasm/word.h" namespace proxy_wasm { namespace null_plugin { -#include "proxy_wasm_enums.h" -#include "proxy_wasm_common.h" - #define WS(_x) Word(static_cast(_x)) #define WR(_x) Word(reinterpret_cast(_x)) diff --git a/include/proxy-wasm/wasm_vm.h b/include/proxy-wasm/wasm_vm.h index acf0ccf3..a573212e 100644 --- a/include/proxy-wasm/wasm_vm.h +++ b/include/proxy-wasm/wasm_vm.h @@ -19,16 +19,16 @@ #include #include #include +#include #include #include #include +#include "include/proxy-wasm/sdk.h" #include "include/proxy-wasm/word.h" namespace proxy_wasm { -#include "proxy_wasm_enums.h" - class ContextBase; // These are templates and its helper for constructing signatures of functions calling into Wasm diff --git a/include/proxy-wasm/word.h b/include/proxy-wasm/word.h index 90ea932d..bc0d23a8 100644 --- a/include/proxy-wasm/word.h +++ b/include/proxy-wasm/word.h @@ -17,9 +17,9 @@ #include -namespace proxy_wasm { +#include "include/proxy-wasm/sdk.h" -#include "proxy_wasm_common.h" +namespace proxy_wasm { // Use byteswap functions only when compiling for big-endian platforms. #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \ diff --git a/test/fuzz/pairs_util_fuzzer.cc b/test/fuzz/pairs_util_fuzzer.cc index aaef0d09..84e7ca0f 100644 --- a/test/fuzz/pairs_util_fuzzer.cc +++ b/test/fuzz/pairs_util_fuzzer.cc @@ -14,6 +14,7 @@ #include "include/proxy-wasm/pairs_util.h" +#include #include namespace proxy_wasm {