Skip to content

Commit

Permalink
fix a few missing includes and ::proxy_wasm namespace pollution with …
Browse files Browse the repository at this point in the history
…std {} (#365)

* include: add missing dependencies

Signed-off-by: Ivan Prisyazhnyy <[email protected]>

* 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 <[email protected]>

* include: add missing includes to pairs_util and the test

Signed-off-by: Ivan Prisyazhnyy <[email protected]>

* 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 <[email protected]>

---------

Signed-off-by: Ivan Prisyazhnyy <[email protected]>
  • Loading branch information
sitano authored Dec 19, 2023
1 parent b7e6907 commit e200fee
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 16 deletions.
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
4 changes: 1 addition & 3 deletions include/proxy-wasm/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@
#include <string_view>
#include <vector>

#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;
Expand Down
5 changes: 2 additions & 3 deletions include/proxy-wasm/context_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
#include <memory>
#include <vector>

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<std::pair<std::string_view, std::string_view>>;
using PairsWithStringValues = std::vector<std::pair<std::string_view, std::string>>;
Expand Down
1 change: 1 addition & 0 deletions include/proxy-wasm/pairs_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#pragma once

#include <cstddef>
#include <string>
#include <string_view>
#include <vector>
Expand Down
50 changes: 50 additions & 0 deletions include/proxy-wasm/sdk.h
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <cstdint>

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
4 changes: 3 additions & 1 deletion include/proxy-wasm/vm_id_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#pragma once

#include <functional>
#include <mutex>
#include <memory>
#include <mutex>
#include <string>
#include <string_view>
#include <unordered_map>

namespace proxy_wasm {
Expand Down
3 changes: 1 addition & 2 deletions include/proxy-wasm/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
#include <unordered_map>
#include <unordered_set>

#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"
#include "include/proxy-wasm/vm_id_handle.h"

namespace proxy_wasm {

#include "proxy_wasm_common.h"

class ContextBase;
class WasmHandleBase;

Expand Down
4 changes: 1 addition & 3 deletions include/proxy-wasm/wasm_api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@
#include <utility>
#include <vector>

#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<uint64_t>(_x))
#define WR(_x) Word(reinterpret_cast<uint64_t>(_x))

Expand Down
4 changes: 2 additions & 2 deletions include/proxy-wasm/wasm_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#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
Expand Down
4 changes: 2 additions & 2 deletions include/proxy-wasm/word.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

#include <iostream>

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__) && \
Expand Down
1 change: 1 addition & 0 deletions test/fuzz/pairs_util_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "include/proxy-wasm/pairs_util.h"

#include <cstdint>
#include <cstring>

namespace proxy_wasm {
Expand Down

0 comments on commit e200fee

Please sign in to comment.