From fe71c632ce8563f890c6749f7bada9bfbe0eab72 Mon Sep 17 00:00:00 2001 From: John Plevyak Date: Thu, 30 Jul 2020 21:55:37 +0000 Subject: [PATCH 1/2] Remove c++14 support in proxy-wasm. Signed-off-by: John Plevyak --- BUILD | 39 ------ WORKSPACE | 2 +- context_test.cc | 7 +- include/proxy-wasm/compat.h | 46 ------- include/proxy-wasm/context.h | 75 ++++++----- include/proxy-wasm/context_interface.h | 68 +++++----- include/proxy-wasm/null_plugin.h | 14 +-- include/proxy-wasm/null_vm.h | 14 +-- include/proxy-wasm/null_vm_plugin.h | 4 +- include/proxy-wasm/wasm.h | 33 +++-- include/proxy-wasm/wasm_api_impl.h | 4 +- include/proxy-wasm/wasm_vm.h | 28 ++--- src/context.cc | 30 ++--- src/exports.cc | 12 +- src/foreign.cc | 4 +- src/null/null_plugin.cc | 22 ++-- src/null/null_vm.cc | 14 +-- src/v8/v8.cc | 49 ++++---- src/wasm.cc | 14 +-- src/wavm/wavm.cc | 166 +++++++++++++------------ wasm_vm_test.cc | 4 +- 21 files changed, 279 insertions(+), 370 deletions(-) delete mode 100644 include/proxy-wasm/compat.h diff --git a/BUILD b/BUILD index 7dc8fafd0..ce2ad35cb 100644 --- a/BUILD +++ b/BUILD @@ -27,30 +27,6 @@ cc_library( ], ) -# TODO: remove when dependent projects have been upgraded. -cc_library( - name = "lib14", - srcs = glob( - ["src/**/*.cc"], - exclude = [ - "src/**/wavm*", - "src/**/v8*", - ], - ) + glob(["src/**/*.h"]), - copts = [ - "-std=c++14", - "-DWITHOUT_ZLIB=1", - ], - deps = [ - ":include", - "@com_google_absl//absl/base", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/types:optional", - "@com_google_protobuf//:protobuf_lite", - "@proxy_wasm_cpp_sdk//:api_lib", - ], -) - cc_test( name = "wasm_vm_test", srcs = ["wasm_vm_test.cc"], @@ -70,18 +46,3 @@ cc_test( "@com_google_googletest//:gtest_main", ], ) - -# TODO: remove when dependent projects have been upgraded. -cc_test( - name = "context_14_test", - srcs = ["context_test.cc"], - copts = ["-std=c++14"], - deps = [ - ":include", - "@com_google_absl//absl/base", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/types:optional", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) diff --git a/WORKSPACE b/WORKSPACE index b1a37f15f..e932f250c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -5,7 +5,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") git_repository( name = "proxy_wasm_cpp_sdk", - commit = "35163bbf32fccfbde7b95d909a392dc1dc562596", + commit = "aea22d74befc1bb34d2b8c35f0558e53ba5d1cd5", remote = "https://github.com/proxy-wasm/proxy-wasm-cpp-sdk", ) diff --git a/context_test.cc b/context_test.cc index 73d83c5e5..bd4b3283b 100644 --- a/context_test.cc +++ b/context_test.cc @@ -21,11 +21,12 @@ namespace { class Context : public ContextBase { public: - Context(std::function error_function) : error_function_(error_function) {} - void error(string_view message) { error_function_(message); } + Context(std::function error_function) + : error_function_(error_function) {} + void error(std::string_view message) { error_function_(message); } private: - std::function error_function_; + std::function error_function_; }; TEST(Context, IncludeParses) {} diff --git a/include/proxy-wasm/compat.h b/include/proxy-wasm/compat.h deleted file mode 100644 index 87819ae86..000000000 --- a/include/proxy-wasm/compat.h +++ /dev/null @@ -1,46 +0,0 @@ -// 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 - -// Provide compatibiliby for projects which have not yet moved to C++17. -// TODO: remove this when all dependent projects have upgraded. - -#if __cplusplus >= 201703L -#include -#include -#else -#include "absl/types/optional.h" -#include "absl/strings/string_view.h" -#endif - -namespace proxy_wasm { -#if __cplusplus >= 201703L - -template using optional = std::optional; -// Only available in C++17 -// inline constexpr std::nullopt_t nullopt = std::nullopt; -#define PROXY_WASM_NULLOPT std::nullopt -using string_view = std::string_view; - -#else - -template using optional = absl::optional; -// Only available in C++17 -// inline constexpr absl::nullopt_t nullopt = absl::nullopt; -#define PROXY_WASM_NULLOPT absl::nullopt -using string_view = absl::string_view; - -#endif -} // namespace proxy_wasm diff --git a/include/proxy-wasm/context.h b/include/proxy-wasm/context.h index 9299e51dc..17dde4b39 100644 --- a/include/proxy-wasm/context.h +++ b/include/proxy-wasm/context.h @@ -25,7 +25,6 @@ #include #include -#include "include/proxy-wasm/compat.h" #include "include/proxy-wasm/context_interface.h" namespace proxy_wasm { @@ -47,8 +46,8 @@ class WasmVm; * @param fail_open if true the plugin will pass traffic as opposed to close all streams. */ struct PluginBase { - PluginBase(string_view name, string_view root_id, string_view vm_id, string_view runtime, - string_view plugin_configuration, bool fail_open) + PluginBase(std::string_view name, std::string_view root_id, std::string_view vm_id, std::string_view runtime, + std::string_view plugin_configuration, bool fail_open) : name_(std::string(name)), root_id_(std::string(root_id)), vm_id_(std::string(vm_id)), runtime_(std::string(runtime)), plugin_configuration_(plugin_configuration), fail_open_(fail_open) {} @@ -80,7 +79,7 @@ struct BufferBase : public BufferInterface { } WasmResult copyTo(WasmBase *wasm, size_t start, size_t length, uint64_t ptr_ptr, uint64_t size_ptr) const override; - WasmResult copyFrom(size_t /* start */, size_t /* length */, string_view /* data */) override { + WasmResult copyFrom(size_t /* start */, size_t /* length */, std::string_view /* data */) override { // Setting a string buffer not supported (no use case). return WasmResult::BadArgument; } @@ -89,7 +88,7 @@ struct BufferBase : public BufferInterface { data_ = ""; owned_data_ = nullptr; } - BufferBase *set(string_view data) { + BufferBase *set(std::string_view data) { clear(); data_ = data; return this; @@ -102,7 +101,7 @@ struct BufferBase : public BufferInterface { } protected: - string_view data_; + std::string_view data_; std::unique_ptr owned_data_; uint32_t owned_data_size_; }; @@ -158,8 +157,8 @@ class ContextBase : public RootInterface, } return parent; } - string_view root_id() const { return isRootContext() ? root_id_ : plugin_->root_id_; } - string_view log_prefix() const { + std::string_view root_id() const { return isRootContext() ? root_id_ : plugin_->root_id_; } + std::string_view log_prefix() const { return isRootContext() ? root_log_prefix_ : plugin_->log_prefix(); } WasmVm *wasmVm() const; @@ -212,7 +211,7 @@ class ContextBase : public RootInterface, void onGrpcReceiveTrailingMetadata(GrpcToken token, uint32_t trailers) override; void onGrpcClose(GrpcToken token, GrpcStatusCode status_code) override; - void error(string_view message) override { + void error(std::string_view message) override { std::cerr << message << "\n"; abort(); } @@ -226,7 +225,7 @@ class ContextBase : public RootInterface, // // General Callbacks. // - WasmResult log(uint32_t /* level */, string_view /* message */) override { + WasmResult log(uint32_t /* level */, std::string_view /* message */) override { return unimplemented(); } uint32_t getLogLevel() override { return static_cast(LogLevel::info); } @@ -238,7 +237,7 @@ class ContextBase : public RootInterface, t += tpe.tv_nsec; return t; } - std::pair getStatus() override { + std::pair getStatus() override { unimplemented(); return std::make_pair(1, "unimplmemented"); } @@ -255,21 +254,21 @@ class ContextBase : public RootInterface, } // HTTP - WasmResult httpCall(string_view /* target */, const Pairs & /*request_headers */, - string_view /* request_body */, const Pairs & /* request_trailers */, + WasmResult httpCall(std::string_view /* target */, const Pairs & /*request_headers */, + std::string_view /* request_body */, const Pairs & /* request_trailers */, int /* timeout_millisconds */, uint32_t * /* token_ptr */) override { return unimplemented(); } // gRPC - WasmResult grpcCall(string_view /* grpc_service */, string_view /* service_name */, - string_view /* method_name */, const Pairs & /* initial_metadata */, - string_view /* request */, std::chrono::milliseconds /* timeout */, + WasmResult grpcCall(std::string_view /* grpc_service */, std::string_view /* service_name */, + std::string_view /* method_name */, const Pairs & /* initial_metadata */, + std::string_view /* request */, std::chrono::milliseconds /* timeout */, GrpcToken * /* token_ptr */) override { return unimplemented(); } - WasmResult grpcStream(string_view /* grpc_service */, string_view /* service_name */, - string_view /* method_name */, const Pairs & /* initial_metadata */, + WasmResult grpcStream(std::string_view /* grpc_service */, std::string_view /* service_name */, + std::string_view /* method_name */, const Pairs & /* initial_metadata */, GrpcToken * /* token_ptr */) override { return unimplemented(); } @@ -279,13 +278,13 @@ class ContextBase : public RootInterface, WasmResult grpcCancel(uint32_t /* token */) override { // cancel on call, reset on stream. return unimplemented(); } - WasmResult grpcSend(uint32_t /* token */, string_view /* message */, + WasmResult grpcSend(uint32_t /* token */, std::string_view /* message */, bool /* end_stream */) override { // stream only return unimplemented(); } // Metrics - WasmResult defineMetric(uint32_t /* type */, string_view /* name */, + WasmResult defineMetric(uint32_t /* type */, std::string_view /* name */, uint32_t * /* metric_id_ptr */) override { return unimplemented(); } @@ -300,43 +299,43 @@ class ContextBase : public RootInterface, } // Properties - WasmResult getProperty(string_view /* path */, std::string * /* result */) override { + WasmResult getProperty(std::string_view /* path */, std::string * /* result */) override { return unimplemented(); } - WasmResult setProperty(string_view /* key */, string_view /* serialized_value */) override { + WasmResult setProperty(std::string_view /* key */, std::string_view /* serialized_value */) override { return unimplemented(); } // Continue WasmResult continueStream(WasmStreamType /* stream_type */) override { return unimplemented(); } WasmResult closeStream(WasmStreamType /* stream_type */) override { return unimplemented(); } - WasmResult sendLocalResponse(uint32_t /* response_code */, string_view /* body_text */, + WasmResult sendLocalResponse(uint32_t /* response_code */, std::string_view /* body_text */, Pairs /* additional_headers */, GrpcStatusCode /* grpc_status */, - string_view /* details */) override { + std::string_view /* details */) override { return unimplemented(); } void failStream(WasmStreamType stream_type) override { closeStream(stream_type); } // Shared Data - WasmResult getSharedData(string_view key, + WasmResult getSharedData(std::string_view key, std::pair *data) override; - WasmResult setSharedData(string_view key, string_view value, uint32_t cas) override; + WasmResult setSharedData(std::string_view key, std::string_view value, uint32_t cas) override; // Shared Queue - WasmResult registerSharedQueue(string_view queue_name, + WasmResult registerSharedQueue(std::string_view queue_name, SharedQueueDequeueToken *token_ptr) override; - WasmResult lookupSharedQueue(string_view vm_id, string_view queue_name, + WasmResult lookupSharedQueue(std::string_view vm_id, std::string_view queue_name, SharedQueueEnqueueToken *token) override; WasmResult dequeueSharedQueue(uint32_t token, std::string *data) override; - WasmResult enqueueSharedQueue(uint32_t token, string_view value) override; + WasmResult enqueueSharedQueue(uint32_t token, std::string_view value) override; // Header/Trailer/Metadata Maps - WasmResult addHeaderMapValue(WasmHeaderMapType /* type */, string_view /* key */, - string_view /* value */) override { + WasmResult addHeaderMapValue(WasmHeaderMapType /* type */, std::string_view /* key */, + std::string_view /* value */) override { return unimplemented(); } - WasmResult getHeaderMapValue(WasmHeaderMapType /* type */, string_view /* key */, - string_view * /*result */) override { + WasmResult getHeaderMapValue(WasmHeaderMapType /* type */, std::string_view /* key */, + std::string_view * /*result */) override { return unimplemented(); } WasmResult getHeaderMapPairs(WasmHeaderMapType /* type */, Pairs * /* result */) override { @@ -346,11 +345,11 @@ class ContextBase : public RootInterface, return unimplemented(); } - WasmResult removeHeaderMapValue(WasmHeaderMapType /* type */, string_view /* key */) override { + WasmResult removeHeaderMapValue(WasmHeaderMapType /* type */, std::string_view /* key */) override { return unimplemented(); } - WasmResult replaceHeaderMapValue(WasmHeaderMapType /* type */, string_view /* key */, - string_view /* value */) override { + WasmResult replaceHeaderMapValue(WasmHeaderMapType /* type */, std::string_view /* key */, + std::string_view /* value */) override { return unimplemented(); } @@ -362,7 +361,7 @@ class ContextBase : public RootInterface, friend class WasmBase; void initializeRootBase(WasmBase *wasm, std::shared_ptr plugin); - std::string makeRootLogPrefix(string_view vm_id) const; + std::string makeRootLogPrefix(std::string_view vm_id) const; WasmBase *wasm_{nullptr}; uint32_t id_{0}; @@ -384,6 +383,6 @@ class DeferAfterCallActions { WasmBase *const wasm_; }; -uint32_t resolveQueueForTest(string_view vm_id, string_view queue_name); +uint32_t resolveQueueForTest(std::string_view vm_id, std::string_view queue_name); } // namespace proxy_wasm diff --git a/include/proxy-wasm/context_interface.h b/include/proxy-wasm/context_interface.h index 558252eff..ac2b1648a 100644 --- a/include/proxy-wasm/context_interface.h +++ b/include/proxy-wasm/context_interface.h @@ -15,8 +15,6 @@ #pragma once -#include "include/proxy-wasm/compat.h" - #include #include #include @@ -31,8 +29,8 @@ namespace proxy_wasm { #include "proxy_wasm_common.h" #include "proxy_wasm_enums.h" -using Pairs = std::vector>; -using PairsWithStringValues = std::vector>; +using Pairs = std::vector>; +using PairsWithStringValues = std::vector>; using TimerToken = uint32_t; using HttpCallToken = uint32_t; using GrpcToken = uint32_t; @@ -80,7 +78,7 @@ struct BufferInterface { * @param data the data to copy over the replaced region. * @return a WasmResult with any error or WasmResult::Ok. */ - virtual WasmResult copyFrom(size_t start, size_t length, string_view data) = 0; + virtual WasmResult copyFrom(size_t start, size_t length, std::string_view data) = 0; }; /** @@ -175,7 +173,7 @@ struct RootInterface : public RootGrpcInterface { * shutting down. * @return true for stream contexts or for Root Context(s) if the VM can shutdown, false for Root * Context(s) if the VM should wait until the Root Context calls the proxy_done() ABI call. Note: - * the VM may (optionally) shutdown after some configured timeout even if the Root Context does + * the VM may (std::optionally) shutdown after some configured timeout even if the Root Context does * not call proxy_done(). */ virtual bool onDone() = 0; @@ -229,12 +227,12 @@ struct HttpInterface { * @param response_code is the response code to send. * @param body is the body of the response. * @param additional_headers are additional headers to send in the response. - * @param grpc_status is an optional gRPC status if the connection is a gRPC connection. + * @param grpc_status is an std::optional gRPC status if the connection is a gRPC connection. * @param details are details of any (gRPC) error. */ - virtual WasmResult sendLocalResponse(uint32_t response_code, string_view body, + virtual WasmResult sendLocalResponse(uint32_t response_code, std::string_view body, Pairs additional_headers, uint32_t grpc_status, - string_view details) = 0; + std::string_view details) = 0; // Call when the stream closes. See RootInterface. virtual bool onDone() = 0; @@ -341,8 +339,8 @@ struct HeaderInterface { * @param key is the key (header). * @param value is the value (header value). */ - virtual WasmResult addHeaderMapValue(WasmHeaderMapType type, string_view key, - string_view value) = 0; + virtual WasmResult addHeaderMapValue(WasmHeaderMapType type, std::string_view key, + std::string_view value) = 0; /** * Get a value from to a header map. @@ -350,8 +348,8 @@ struct HeaderInterface { * @param key is the key (header). * @param result is a pointer to the returned header value. */ - virtual WasmResult getHeaderMapValue(WasmHeaderMapType type, string_view key, - string_view *result) = 0; + virtual WasmResult getHeaderMapValue(WasmHeaderMapType type, std::string_view key, + std::string_view *result) = 0; /** * Get all the key-value pairs in a header map. @@ -372,7 +370,7 @@ struct HeaderInterface { * @param type of the header map. * @param key of the header map. */ - virtual WasmResult removeHeaderMapValue(WasmHeaderMapType type, string_view key) = 0; + virtual WasmResult removeHeaderMapValue(WasmHeaderMapType type, std::string_view key) = 0; /** * Replace (or set) a value in a header map. @@ -380,8 +378,8 @@ struct HeaderInterface { * @param key of the header map. * @param value to set in the header map. */ - virtual WasmResult replaceHeaderMapValue(WasmHeaderMapType type, string_view key, - string_view value) = 0; + virtual WasmResult replaceHeaderMapValue(WasmHeaderMapType type, std::string_view key, + std::string_view value) = 0; /** * Returns the number of entries in a header map. @@ -407,8 +405,8 @@ struct HttpCallInterface { * Note: the response arrives on the ancestor RootContext as this call may outlive any stream. * Plugin writers should use the VM SDK setEffectiveContext() to switch to any waiting streams. */ - virtual WasmResult httpCall(string_view target, const Pairs &request_headers, - string_view request_body, const Pairs &request_trailers, + virtual WasmResult httpCall(std::string_view target, const Pairs &request_headers, + std::string_view request_body, const Pairs &request_trailers, int timeout_milliseconds, HttpCallToken *token_ptr) = 0; }; @@ -425,9 +423,9 @@ struct GrpcCallInterface { * @param token_ptr contains a pointer to a location to store the token which will be used with * the corresponding onGrpc and grpc calls. */ - virtual WasmResult grpcCall(string_view /* grpc_service */, string_view /* service_name */, - string_view /* method_name */, const Pairs & /* initial_metadata */, - string_view /* request */, std::chrono::milliseconds /* timeout */, + virtual WasmResult grpcCall(std::string_view /* grpc_service */, std::string_view /* service_name */, + std::string_view /* method_name */, const Pairs & /* initial_metadata */, + std::string_view /* request */, std::chrono::milliseconds /* timeout */, GrpcToken * /* token_ptr */) = 0; /** @@ -456,8 +454,8 @@ struct GrpcStreamInterface { * @param token_ptr contains a pointer to a location to store the token which will be used with * the corresponding onGrpc and grpc calls. */ - virtual WasmResult grpcStream(string_view grpc_service, string_view service_name, - string_view method_name, const Pairs & /* initial_metadata */, + virtual WasmResult grpcStream(std::string_view grpc_service, std::string_view service_name, + std::string_view method_name, const Pairs & /* initial_metadata */, GrpcToken *token_ptr) = 0; /** @@ -467,7 +465,7 @@ struct GrpcStreamInterface { * @param end_stream indicates that the stream is now end_of_stream (e.g. WriteLast() or * WritesDone). */ - virtual WasmResult grpcSend(GrpcToken token, string_view message, bool end_stream) = 0; + virtual WasmResult grpcSend(GrpcToken token, std::string_view message, bool end_stream) = 0; // See GrpcCallInterface. virtual WasmResult grpcClose(GrpcToken token) = 0; @@ -490,7 +488,7 @@ struct MetricsInterface { * @param metric_id_ptr is a location to store a token used for subsequent operations on the * metric. */ - virtual WasmResult defineMetric(uint32_t /* type */, string_view /* name */, + virtual WasmResult defineMetric(uint32_t /* type */, std::string_view /* name */, uint32_t * /* metric_id_ptr */) = 0; /** @@ -521,7 +519,7 @@ struct GeneralInterface { * Will be called on severe Wasm errors. Callees may report and handle the error (e.g. via an * Exception) to prevent the proxy from crashing. */ - virtual void error(string_view message) = 0; + virtual void error(std::string_view message) = 0; /** * Called by all functions which are not overridden with a proxy-specific implementation. @@ -530,7 +528,7 @@ struct GeneralInterface { virtual WasmResult unimplemented() = 0; // Log a message. - virtual WasmResult log(uint32_t level, string_view message) = 0; + virtual WasmResult log(uint32_t level, std::string_view message) = 0; // Return the current log level in the host virtual uint32_t getLogLevel() = 0; @@ -554,7 +552,7 @@ struct GeneralInterface { * Provides the status of the last call into the VM or out of the VM, similar to errno. * @return the status code and a descriptive string. */ - virtual std::pair getStatus() = 0; + virtual std::pair getStatus() = 0; /** * Get the value of a property. Some properties are proxy-independent (e.g. ["plugin_root_id"]) @@ -562,7 +560,7 @@ struct GeneralInterface { * @param path is a sequence of strings describing a path to a property. * @param result is a location to write the value of the property. */ - virtual WasmResult getProperty(string_view path, std::string *result) = 0; + virtual WasmResult getProperty(std::string_view path, std::string *result) = 0; /** * Set the value of a property. @@ -570,7 +568,7 @@ struct GeneralInterface { * @param value the value to set. For non-string, non-integral types, the value may be * serialized.. */ - virtual WasmResult setProperty(string_view key, string_view value) = 0; + virtual WasmResult setProperty(std::string_view key, std::string_view value) = 0; /** * Custom extension call into the VM. Data is provided as WasmBufferType::CallData. @@ -597,7 +595,7 @@ struct SharedDataInterface { * compare-and-swap value which can be used with setSharedData for safe concurrent updates. */ virtual WasmResult - getSharedData(string_view key, std::pair *data) = 0; + getSharedData(std::string_view key, std::pair *data) = 0; /** * Set a key-value data shared between VMs. @@ -606,7 +604,7 @@ struct SharedDataInterface { * the cas associated with the value. * @param data is a location to store the returned value. */ - virtual WasmResult setSharedData(string_view key, string_view value, uint32_t cas) = 0; + virtual WasmResult setSharedData(std::string_view key, std::string_view value, uint32_t cas) = 0; }; // namespace proxy_wasm struct SharedQueueInterface { @@ -617,7 +615,7 @@ struct SharedQueueInterface { * to make a unique identifier for the queue. * @param token_ptr a location to store a token corresponding to the queue. */ - virtual WasmResult registerSharedQueue(string_view queue_name, + virtual WasmResult registerSharedQueue(std::string_view queue_name, SharedQueueDequeueToken *token_ptr) = 0; /** @@ -627,7 +625,7 @@ struct SharedQueueInterface { * to make a unique identifier for the queue. * @param token_ptr a location to store a token corresponding to the queue. */ - virtual WasmResult lookupSharedQueue(string_view vm_id, string_view queue_name, + virtual WasmResult lookupSharedQueue(std::string_view vm_id, std::string_view queue_name, SharedQueueEnqueueToken *token_ptr) = 0; /** @@ -642,7 +640,7 @@ struct SharedQueueInterface { * @param token is a token returned by resolveSharedQueue(); * @param data is the data to be queued. */ - virtual WasmResult enqueueSharedQueue(SharedQueueEnqueueToken token, string_view data) = 0; + virtual WasmResult enqueueSharedQueue(SharedQueueEnqueueToken token, std::string_view data) = 0; }; } // namespace proxy_wasm diff --git a/include/proxy-wasm/null_plugin.h b/include/proxy-wasm/null_plugin.h index 71eec3c50..136be6408 100644 --- a/include/proxy-wasm/null_plugin.h +++ b/include/proxy-wasm/null_plugin.h @@ -24,8 +24,6 @@ namespace proxy_wasm { namespace null_plugin { -template using Optional = optional; -using StringView = string_view; #include "proxy_wasm_enums.h" } // namespace null_plugin } // namespace proxy_wasm @@ -67,7 +65,7 @@ class NullPlugin : public NullVmPlugin { explicit NullPlugin(NullPluginRegistry *registry) : registry_(registry) {} NullPlugin(const NullPlugin &other) : registry_(other.registry_) {} -#define _DECLARE_OVERRIDE(_t) void getFunction(string_view function_name, _t *f) override; +#define _DECLARE_OVERRIDE(_t) void getFunction(std::string_view function_name, _t *f) override; FOR_ALL_WASM_VM_EXPORTS(_DECLARE_OVERRIDE) #undef _DECLARE_OVERRIDE @@ -109,10 +107,10 @@ class NullPlugin : public NullVmPlugin { uint64_t onDone(uint64_t context_id); void onDelete(uint64_t context_id); - null_plugin::RootContext *getRoot(string_view root_id); + null_plugin::RootContext *getRoot(std::string_view root_id); null_plugin::Context *getContext(uint64_t context_id); - void error(string_view message) { wasm_vm_->error(message); } + void error(std::string_view message) { wasm_vm_->error(message); } null_plugin::Context *ensureContext(uint64_t context_id, uint64_t root_context_id); null_plugin::RootContext *ensureRootContext(uint64_t context_id); @@ -130,7 +128,7 @@ class NullPlugin : public NullVmPlugin { struct RegisterContextFactory { \ explicit RegisterContextFactory(null_plugin::ContextFactory context_factory, \ null_plugin::RootFactory root_factory, \ - StringView root_id = "") { \ + std::string_view root_id = "") { \ if (!context_registry_) { \ context_registry_ = new NullPluginRegistry; \ } \ @@ -138,14 +136,14 @@ class NullPlugin : public NullVmPlugin { context_registry_->root_factories[std::string(root_id)] = root_factory; \ } \ explicit RegisterContextFactory(null_plugin::ContextFactory context_factory, \ - StringView root_id = "") { \ + std::string_view root_id = "") { \ if (!context_registry_) { \ context_registry_ = new NullPluginRegistry; \ } \ context_registry_->context_factories[std::string(root_id)] = context_factory; \ } \ explicit RegisterContextFactory(null_plugin::RootFactory root_factory, \ - StringView root_id = "") { \ + std::string_view root_id = "") { \ if (!context_registry_) { \ context_registry_ = new NullPluginRegistry; \ } \ diff --git a/include/proxy-wasm/null_vm.h b/include/proxy-wasm/null_vm.h index de75d2e6b..f86ba1038 100644 --- a/include/proxy-wasm/null_vm.h +++ b/include/proxy-wasm/null_vm.h @@ -32,21 +32,21 @@ struct NullVm : public WasmVm { NullVm(const NullVm &other) : plugin_name_(other.plugin_name_) {} // WasmVm - string_view runtime() override { return "null"; } + std::string_view runtime() override { return "null"; } Cloneable cloneable() override { return Cloneable::InstantiatedModule; }; std::unique_ptr clone() override; bool load(const std::string &code, bool allow_precompiled) override; - bool link(string_view debug_name) override; + bool link(std::string_view debug_name) override; uint64_t getMemorySize() override; - optional getMemory(uint64_t pointer, uint64_t size) override; + std::optional getMemory(uint64_t pointer, uint64_t size) override; bool setMemory(uint64_t pointer, uint64_t size, const void *data) override; bool setWord(uint64_t pointer, Word data) override; bool getWord(uint64_t pointer, Word *data) override; - string_view getCustomSection(string_view name) override; - string_view getPrecompiledSectionName() override; + std::string_view getCustomSection(std::string_view name) override; + std::string_view getPrecompiledSectionName() override; #define _FORWARD_GET_FUNCTION(_T) \ - void getFunction(string_view function_name, _T *f) override { \ + void getFunction(std::string_view function_name, _T *f) override { \ plugin_->getFunction(function_name, f); \ } FOR_ALL_WASM_VM_EXPORTS(_FORWARD_GET_FUNCTION) @@ -54,7 +54,7 @@ struct NullVm : public WasmVm { // These are not needed for NullVm which invokes the handlers directly. #define _REGISTER_CALLBACK(_T) \ - void registerCallback(string_view, string_view, _T, \ + void registerCallback(std::string_view, std::string_view, _T, \ typename ConvertFunctionTypeWordToUint32<_T>::type) override{}; FOR_ALL_WASM_VM_IMPORTS(_REGISTER_CALLBACK) #undef _REGISTER_CALLBACK diff --git a/include/proxy-wasm/null_vm_plugin.h b/include/proxy-wasm/null_vm_plugin.h index 02e8ebdd8..f01ddaaee 100644 --- a/include/proxy-wasm/null_vm_plugin.h +++ b/include/proxy-wasm/null_vm_plugin.h @@ -28,7 +28,7 @@ class NullVmPlugin { // NB: These are defined rather than declared PURE because gmock uses __LINE__ internally for // uniqueness, making it impossible to use FOR_ALL_WASM_VM_EXPORTS with MOCK_METHOD. #define _DEFINE_GET_FUNCTION(_T) \ - virtual void getFunction(string_view, _T *f) { *f = nullptr; } + virtual void getFunction(std::string_view, _T *f) { *f = nullptr; } FOR_ALL_WASM_VM_EXPORTS(_DEFINE_GET_FUNCTION) #undef _DEFIN_GET_FUNCTIONE @@ -38,7 +38,7 @@ class NullVmPlugin { using NullVmPluginFactory = std::function()>; struct RegisterNullVmPluginFactory { - RegisterNullVmPluginFactory(string_view name, NullVmPluginFactory factory); + RegisterNullVmPluginFactory(std::string_view name, NullVmPluginFactory factory); }; } // namespace proxy_wasm diff --git a/include/proxy-wasm/wasm.h b/include/proxy-wasm/wasm.h index e9454ea6a..1214a7d73 100644 --- a/include/proxy-wasm/wasm.h +++ b/include/proxy-wasm/wasm.h @@ -24,7 +24,6 @@ #include #include -#include "include/proxy-wasm/compat.h" #include "include/proxy-wasm/context.h" #include "include/proxy-wasm/exports.h" #include "include/proxy-wasm/wasm_vm.h" @@ -38,15 +37,15 @@ class WasmBase; class WasmHandleBase; using WasmForeignFunction = - std::function)>; + std::function)>; using WasmVmFactory = std::function()>; using CallOnThreadFunction = std::function)>; // Wasm execution instance. Manages the host side of the Wasm interface. class WasmBase : public std::enable_shared_from_this { public: - WasmBase(std::unique_ptr wasm_vm, string_view vm_id, string_view vm_configuration, - string_view vm_key); + WasmBase(std::unique_ptr wasm_vm, std::string_view vm_id, std::string_view vm_configuration, + std::string_view vm_key); WasmBase(const std::shared_ptr &other, WasmVmFactory factory); virtual ~WasmBase(); @@ -56,11 +55,11 @@ class WasmBase : public std::enable_shared_from_this { // Returns the root ContextBase or nullptr if onStart returns false. ContextBase *start(std::shared_ptr plugin); - string_view vm_id() const { return vm_id_; } - string_view vm_key() const { return vm_key_; } + std::string_view vm_id() const { return vm_id_; } + std::string_view vm_key() const { return vm_key_; } WasmVm *wasm_vm() const { return wasm_vm_.get(); } ContextBase *vm_context() const { return vm_context_.get(); } - ContextBase *getRootContext(string_view root_id) { + ContextBase *getRootContext(std::string_view root_id) { return root_contexts_[std::string(root_id)].get(); } ContextBase *getOrCreateRootContext(const std::shared_ptr &plugin); @@ -109,18 +108,18 @@ class WasmBase : public std::enable_shared_from_this { // void *allocMemory(uint64_t size, uint64_t *address); // Allocate a null-terminated string in the VM and return the pointer to use as a call arguments. - uint64_t copyString(string_view s); + uint64_t copyString(std::string_view s); // Copy the data in 's' into the VM along with the pointer-size pair. Returns true on success. - bool copyToPointerSize(string_view s, uint64_t ptr_ptr, uint64_t size_ptr); + bool copyToPointerSize(std::string_view s, uint64_t ptr_ptr, uint64_t size_ptr); template bool setDatatype(uint64_t ptr, const T &t); - WasmForeignFunction getForeignFunction(string_view function_name); + WasmForeignFunction getForeignFunction(std::string_view function_name); - void fail(FailState fail_state, string_view message) { + void fail(FailState fail_state, std::string_view message) { error(message); failed_ = fail_state; } - virtual void error(string_view message) { std::cerr << message << "\n"; } + virtual void error(std::string_view message) { std::cerr << message << "\n"; } virtual void unimplemented() { error("unimplemented proxy-wasm API"); } bool getEmscriptenVersion(uint32_t *emscripten_metadata_major_version, @@ -273,9 +272,9 @@ class WasmHandleBase : public std::enable_shared_from_this { std::shared_ptr wasm_base_; }; -std::string makeVmKey(string_view vm_id, string_view configuration, string_view code); +std::string makeVmKey(std::string_view vm_id, std::string_view configuration, std::string_view code); -using WasmHandleFactory = std::function(string_view vm_id)>; +using WasmHandleFactory = std::function(std::string_view vm_id)>; using WasmHandleCloneFactory = std::function(std::shared_ptr wasm)>; @@ -284,7 +283,7 @@ std::shared_ptr createWasm(std::string vm_key, std::string code, std::shared_ptr plugin, WasmHandleFactory factory, WasmHandleCloneFactory clone_factory, bool allow_precompiled); // Get an existing ThreadLocal VM matching 'vm_id' or nullptr if there isn't one. -std::shared_ptr getThreadLocalWasm(string_view vm_id); +std::shared_ptr getThreadLocalWasm(std::string_view vm_id); // Get an existing ThreadLocal VM matching 'vm_id' or create one using 'base_wavm' by cloning or by // using it it as a template. std::shared_ptr @@ -316,7 +315,7 @@ inline void *WasmBase::allocMemory(uint64_t size, uint64_t *address) { return const_cast(reinterpret_cast(memory.value().data())); } -inline uint64_t WasmBase::copyString(string_view s) { +inline uint64_t WasmBase::copyString(std::string_view s) { if (s.empty()) { return 0; // nullptr } @@ -327,7 +326,7 @@ inline uint64_t WasmBase::copyString(string_view s) { return pointer; } -inline bool WasmBase::copyToPointerSize(string_view s, uint64_t ptr_ptr, uint64_t size_ptr) { +inline bool WasmBase::copyToPointerSize(std::string_view s, uint64_t ptr_ptr, uint64_t size_ptr) { uint64_t pointer = 0; uint64_t size = s.size(); void *p = nullptr; diff --git a/include/proxy-wasm/wasm_api_impl.h b/include/proxy-wasm/wasm_api_impl.h index ab1486095..0e1f72844 100644 --- a/include/proxy-wasm/wasm_api_impl.h +++ b/include/proxy-wasm/wasm_api_impl.h @@ -15,8 +15,6 @@ #pragma once -#include "include/proxy-wasm/compat.h" - namespace proxy_wasm { namespace null_plugin { @@ -258,7 +256,7 @@ inline WasmResult proxy_call_foreign_function(const char *function_name, size_t #include "proxy_wasm_api.h" -RootContext *getRoot(string_view root_id); +RootContext *getRoot(std::string_view root_id); Context *getContext(uint32_t context_id); } // namespace null_plugin diff --git a/include/proxy-wasm/wasm_vm.h b/include/proxy-wasm/wasm_vm.h index 64d3865a1..5ae676346 100644 --- a/include/proxy-wasm/wasm_vm.h +++ b/include/proxy-wasm/wasm_vm.h @@ -15,8 +15,6 @@ #pragma once -#include "include/proxy-wasm/compat.h" - #include #include @@ -108,7 +106,7 @@ class NullPlugin; struct WasmVmIntegration { virtual ~WasmVmIntegration() {} virtual WasmVmIntegration *clone() = 0; - virtual void error(string_view message) = 0; + virtual void error(std::string_view message) = 0; // Get a NullVm implementation of a function. // @param function_name is the name of the function with the implementation specific prefix. // @param returns_word is true if the function returns a Word and false if it returns void. @@ -119,7 +117,7 @@ struct WasmVmIntegration { // @return true if the function was found. ptr_to_function_return could still be set to nullptr // (of the correct type) if the function has no implementation. Returning true will prevent a // "Missing getFunction" error. - virtual bool getNullVmFunction(string_view function_name, bool returns_word, + virtual bool getNullVmFunction(std::string_view function_name, bool returns_word, int number_of_arguments, NullPlugin *plugin, void *ptr_to_function_return) = 0; }; @@ -143,7 +141,7 @@ class WasmVm { * Return the runtime identifier. * @return one of WasmRuntimeValues from well_known_names.h (e.g. "v8"). */ - virtual string_view runtime() = 0; + virtual std::string_view runtime() = 0; /** * Whether or not the VM implementation supports cloning. Cloning is VM system dependent. @@ -184,7 +182,7 @@ class WasmVm { * @param debug_name user-provided name for use in log and error messages. * @return whether or not the link was successful. */ - virtual bool link(string_view debug_name) = 0; + virtual bool link(std::string_view debug_name) = 0; /** * Get size of the currently allocated memory in the VM. @@ -193,13 +191,13 @@ class WasmVm { virtual uint64_t getMemorySize() = 0; /** - * Convert a block of memory in the VM to a string_view. + * Convert a block of memory in the VM to a std::string_view. * @param pointer the offset into VM memory of the requested VM memory block. * @param size the size of the requested VM memory block. * @return if std::nullopt then the pointer/size pair were invalid, otherwise returns - * a host string_view pointing to the pointer/size pair in VM memory. + * a host std::string_view pointing to the pointer/size pair in VM memory. */ - virtual optional getMemory(uint64_t pointer, uint64_t size) = 0; + virtual std::optional getMemory(uint64_t pointer, uint64_t size) = 0; /** * Set a block of memory in the VM, returns true on success, false if the pointer/size is invalid. @@ -237,18 +235,18 @@ class WasmVm { * @return the contents of the custom section (if any). The result will be empty if there * is no such section. */ - virtual string_view getCustomSection(string_view name) = 0; + virtual std::string_view getCustomSection(std::string_view name) = 0; /** * Get the name of the custom section that contains precompiled module. * @return the name of the custom section that contains precompiled module. */ - virtual string_view getPrecompiledSectionName() = 0; + virtual std::string_view getPrecompiledSectionName() = 0; /** * Get typed function exported by the WASM module. */ -#define _GET_FUNCTION(_T) virtual void getFunction(string_view function_name, _T *f) = 0; +#define _GET_FUNCTION(_T) virtual void getFunction(std::string_view function_name, _T *f) = 0; FOR_ALL_WASM_VM_EXPORTS(_GET_FUNCTION) #undef _GET_FUNCTION @@ -256,13 +254,13 @@ class WasmVm { * Register typed callbacks exported by the host environment. */ #define _REGISTER_CALLBACK(_T) \ - virtual void registerCallback(string_view moduleName, string_view function_name, _T f, \ + virtual void registerCallback(std::string_view moduleName, std::string_view function_name, _T f, \ typename ConvertFunctionTypeWordToUint32<_T>::type) = 0; FOR_ALL_WASM_VM_IMPORTS(_REGISTER_CALLBACK) #undef _REGISTER_CALLBACK bool isFailed() { return failed_ != FailState::Ok; } - void fail(FailState fail_state, string_view message) { + void fail(FailState fail_state, std::string_view message) { error(message); failed_ = fail_state; if (fail_callback_) { @@ -275,7 +273,7 @@ class WasmVm { // Integrator operations. std::unique_ptr &integration() { return integration_; } - void error(string_view message) { integration()->error(message); } + void error(std::string_view message) { integration()->error(message); } protected: std::unique_ptr integration_; diff --git a/src/context.cc b/src/context.cc index 12d9b57be..4972a9301 100644 --- a/src/context.cc +++ b/src/context.cc @@ -50,7 +50,7 @@ using CallOnThreadFunction = std::function)>; class SharedData { public: - WasmResult get(string_view vm_id, const string_view key, + WasmResult get(std::string_view vm_id, const std::string_view key, std::pair *result) { std::lock_guard lock(mutex_); auto map = data_.find(std::string(vm_id)); @@ -65,7 +65,7 @@ class SharedData { return WasmResult::NotFound; } - WasmResult set(string_view vm_id, string_view key, string_view value, uint32_t cas) { + WasmResult set(std::string_view vm_id, std::string_view key, std::string_view value, uint32_t cas) { std::lock_guard lock(mutex_); std::unordered_map> *map; auto map_it = data_.find(std::string(vm_id)); @@ -86,8 +86,8 @@ class SharedData { return WasmResult::Ok; } - uint32_t registerQueue(string_view vm_id, string_view queue_name, uint32_t context_id, - CallOnThreadFunction call_on_thread, string_view vm_key) { + uint32_t registerQueue(std::string_view vm_id, std::string_view queue_name, uint32_t context_id, + CallOnThreadFunction call_on_thread, std::string_view vm_key) { std::lock_guard lock(mutex_); auto key = std::make_pair(std::string(vm_id), std::string(queue_name)); auto it = queue_tokens_.insert(std::make_pair(key, static_cast(0))); @@ -104,7 +104,7 @@ class SharedData { return token; } - uint32_t resolveQueue(string_view vm_id, string_view queue_name) { + uint32_t resolveQueue(std::string_view vm_id, std::string_view queue_name) { std::lock_guard lock(mutex_); auto key = std::make_pair(std::string(vm_id), std::string(queue_name)); auto it = queue_tokens_.find(key); @@ -128,7 +128,7 @@ class SharedData { return WasmResult::Ok; } - WasmResult enqueue(uint32_t token, string_view value) { + WasmResult enqueue(uint32_t token, std::string_view value) { std::string vm_key; uint32_t context_id; CallOnThreadFunction call_on_thread; @@ -213,13 +213,13 @@ DeferAfterCallActions::~DeferAfterCallActions() { wasm_->doAfterVmCallActions(); WasmResult BufferBase::copyTo(WasmBase *wasm, size_t start, size_t length, uint64_t ptr_ptr, uint64_t size_ptr) const { if (owned_data_) { - string_view s(owned_data_.get() + start, length); + std::string_view s(owned_data_.get() + start, length); if (!wasm->copyToPointerSize(s, ptr_ptr, size_ptr)) { return WasmResult::InvalidMemoryAccess; } return WasmResult::Ok; } - string_view s = data_.substr(start, length); + std::string_view s = data_.substr(start, length); if (!wasm->copyToPointerSize(s, ptr_ptr, size_ptr)) { return WasmResult::InvalidMemoryAccess; } @@ -228,7 +228,7 @@ WasmResult BufferBase::copyTo(WasmBase *wasm, size_t start, size_t length, uint6 // Test support. -uint32_t resolveQueueForTest(string_view vm_id, string_view queue_name) { +uint32_t resolveQueueForTest(std::string_view vm_id, std::string_view queue_name) { return global_shared_data.resolveQueue(vm_id, queue_name); } @@ -280,7 +280,7 @@ void ContextBase::initializeRootBase(WasmBase *wasm, std::shared_ptr wasm_->contexts_[id_] = this; } -std::string ContextBase::makeRootLogPrefix(string_view vm_id) const { +std::string ContextBase::makeRootLogPrefix(std::string_view vm_id) const { std::string prefix; if (!root_id_.empty()) { prefix = prefix + " " + std::string(root_id_); @@ -337,17 +337,17 @@ void ContextBase::onCreate() { } // Shared Data -WasmResult ContextBase::getSharedData(string_view key, std::pair *data) { +WasmResult ContextBase::getSharedData(std::string_view key, std::pair *data) { return global_shared_data.get(wasm_->vm_id(), key, data); } -WasmResult ContextBase::setSharedData(string_view key, string_view value, uint32_t cas) { +WasmResult ContextBase::setSharedData(std::string_view key, std::string_view value, uint32_t cas) { return global_shared_data.set(wasm_->vm_id(), key, value, cas); } // Shared Queue -WasmResult ContextBase::registerSharedQueue(string_view queue_name, +WasmResult ContextBase::registerSharedQueue(std::string_view queue_name, SharedQueueDequeueToken *result) { // Get the id of the root context if this is a stream context because onQueueReady is on the // root. @@ -357,7 +357,7 @@ WasmResult ContextBase::registerSharedQueue(string_view queue_name, return WasmResult::Ok; } -WasmResult ContextBase::lookupSharedQueue(string_view vm_id, string_view queue_name, +WasmResult ContextBase::lookupSharedQueue(std::string_view vm_id, std::string_view queue_name, uint32_t *token_ptr) { uint32_t token = global_shared_data.resolveQueue(vm_id, queue_name); if (isFailed() || !token) { @@ -371,7 +371,7 @@ WasmResult ContextBase::dequeueSharedQueue(uint32_t token, std::string *data) { return global_shared_data.dequeue(token, data); } -WasmResult ContextBase::enqueueSharedQueue(uint32_t token, string_view value) { +WasmResult ContextBase::enqueueSharedQueue(uint32_t token, std::string_view value) { return global_shared_data.enqueue(token, value); } void ContextBase::destroy() { diff --git a/src/exports.cc b/src/exports.cc index feb0c9205..7ad07b93e 100644 --- a/src/exports.cc +++ b/src/exports.cc @@ -40,7 +40,7 @@ ContextBase *ContextOrEffectiveContext(ContextBase *context) { namespace { -Pairs toPairs(string_view buffer) { +Pairs toPairs(std::string_view buffer) { Pairs result; const char *b = buffer.data(); if (buffer.size() < sizeof(uint32_t)) { @@ -53,15 +53,15 @@ Pairs toPairs(string_view buffer) { } result.resize(size); for (uint32_t i = 0; i < size; i++) { - result[i].first = string_view(nullptr, *reinterpret_cast(b)); + result[i].first = std::string_view(nullptr, *reinterpret_cast(b)); b += sizeof(uint32_t); - result[i].second = string_view(nullptr, *reinterpret_cast(b)); + result[i].second = std::string_view(nullptr, *reinterpret_cast(b)); b += sizeof(uint32_t); } for (auto &p : result) { - p.first = string_view(b, p.first.size()); + p.first = std::string_view(b, p.first.size()); b += p.first.size() + 1; - p.second = string_view(b, p.second.size()); + p.second = std::string_view(b, p.second.size()); b += p.second.size() + 1; } return result; @@ -374,7 +374,7 @@ Word get_header_map_value(void *raw_context, Word type, Word key_ptr, Word key_s if (!key) { return WasmResult::InvalidMemoryAccess; } - string_view value; + std::string_view value; auto result = context->getHeaderMapValue(static_cast(type.u64_), key.value(), &value); if (result != WasmResult::Ok) { diff --git a/src/foreign.cc b/src/foreign.cc index 759d577bf..34335697c 100644 --- a/src/foreign.cc +++ b/src/foreign.cc @@ -25,7 +25,7 @@ namespace { #ifndef WITHOUT_ZLIB RegisterForeignFunction compressFunction( "compress", - [](WasmBase &, string_view arguments, + [](WasmBase &, std::string_view arguments, std::function alloc_result) -> WasmResult { unsigned long dest_len = compressBound(arguments.size()); std::unique_ptr b(new unsigned char[dest_len]); @@ -40,7 +40,7 @@ RegisterForeignFunction compressFunction( RegisterForeignFunction uncompressFunction("uncompress", - [](WasmBase &, string_view arguments, + [](WasmBase &, std::string_view arguments, std::function alloc_result) -> WasmResult { unsigned long dest_len = arguments.size() * 2 + 2; // output estimate. while (1) { diff --git a/src/null/null_plugin.cc b/src/null/null_plugin.cc index 395852ba3..dbac0e9cf 100644 --- a/src/null/null_plugin.cc +++ b/src/null/null_plugin.cc @@ -32,7 +32,7 @@ namespace proxy_wasm { -void NullPlugin::getFunction(string_view function_name, WasmCallVoid<0> *f) { +void NullPlugin::getFunction(std::string_view function_name, WasmCallVoid<0> *f) { if (function_name == "proxy_abi_version_0_1_0") { *f = [](ContextBase *) { /* dummy function */ }; } else if (function_name == "_start") { @@ -45,7 +45,7 @@ void NullPlugin::getFunction(string_view function_name, WasmCallVoid<0> *f) { } } -void NullPlugin::getFunction(string_view function_name, WasmCallVoid<1> *f) { +void NullPlugin::getFunction(std::string_view function_name, WasmCallVoid<1> *f) { auto plugin = this; if (function_name == "proxy_on_tick") { *f = [plugin](ContextBase *context, Word context_id) { @@ -68,7 +68,7 @@ void NullPlugin::getFunction(string_view function_name, WasmCallVoid<1> *f) { } } -void NullPlugin::getFunction(string_view function_name, WasmCallVoid<2> *f) { +void NullPlugin::getFunction(std::string_view function_name, WasmCallVoid<2> *f) { auto plugin = this; if (function_name == "proxy_on_context_create") { *f = [plugin](ContextBase *context, Word context_id, Word parent_context_id) { @@ -96,7 +96,7 @@ void NullPlugin::getFunction(string_view function_name, WasmCallVoid<2> *f) { } } -void NullPlugin::getFunction(string_view function_name, WasmCallVoid<3> *f) { +void NullPlugin::getFunction(std::string_view function_name, WasmCallVoid<3> *f) { auto plugin = this; if (function_name == "proxy_on_grpc_close") { *f = [plugin](ContextBase *context, Word context_id, Word token, Word status_code) { @@ -129,7 +129,7 @@ void NullPlugin::getFunction(string_view function_name, WasmCallVoid<3> *f) { } } -void NullPlugin::getFunction(string_view function_name, WasmCallVoid<5> *f) { +void NullPlugin::getFunction(std::string_view function_name, WasmCallVoid<5> *f) { auto plugin = this; if (function_name == "proxy_on_http_call_response") { *f = [plugin](ContextBase *context, Word context_id, Word token, Word headers, Word body_size, @@ -143,7 +143,7 @@ void NullPlugin::getFunction(string_view function_name, WasmCallVoid<5> *f) { } } -void NullPlugin::getFunction(string_view function_name, WasmCallWord<1> *f) { +void NullPlugin::getFunction(std::string_view function_name, WasmCallWord<1> *f) { auto plugin = this; if (function_name == "malloc") { *f = [](ContextBase *, Word size) -> Word { @@ -165,7 +165,7 @@ void NullPlugin::getFunction(string_view function_name, WasmCallWord<1> *f) { } } -void NullPlugin::getFunction(string_view function_name, WasmCallWord<2> *f) { +void NullPlugin::getFunction(std::string_view function_name, WasmCallWord<2> *f) { auto plugin = this; if (function_name == "proxy_on_vm_start") { *f = [plugin](ContextBase *context, Word context_id, Word configuration_size) { @@ -208,7 +208,7 @@ void NullPlugin::getFunction(string_view function_name, WasmCallWord<2> *f) { } } -void NullPlugin::getFunction(string_view function_name, WasmCallWord<3> *f) { +void NullPlugin::getFunction(std::string_view function_name, WasmCallWord<3> *f) { auto plugin = this; if (function_name == "proxy_on_downstream_data") { *f = [plugin](ContextBase *context, Word context_id, Word body_buffer_length, @@ -321,7 +321,7 @@ null_plugin::RootContext *NullPlugin::getRootContext(uint64_t context_id) { return it->second->asRoot(); } -null_plugin::RootContext *NullPlugin::getRoot(string_view root_id) { +null_plugin::RootContext *NullPlugin::getRoot(std::string_view root_id) { auto it = root_context_map_.find(std::string(root_id)); if (it == root_context_map_.end()) { return nullptr; @@ -494,7 +494,7 @@ void NullPlugin::onDelete(uint64_t context_id) { namespace null_plugin { -RootContext *nullVmGetRoot(string_view root_id) { +RootContext *nullVmGetRoot(std::string_view root_id) { auto null_vm = static_cast(current_context_->wasmVm()); return static_cast(null_vm->plugin_.get())->getRoot(root_id); } @@ -504,7 +504,7 @@ Context *nullVmGetContext(uint32_t context_id) { return static_cast(null_vm->plugin_.get())->getContext(context_id); } -RootContext *getRoot(string_view root_id) { return nullVmGetRoot(root_id); } +RootContext *getRoot(std::string_view root_id) { return nullVmGetRoot(root_id); } Context *getContext(uint32_t context_id) { return nullVmGetContext(context_id); } diff --git a/src/null/null_vm.cc b/src/null/null_vm.cc index 8b732d867..c5d24ed27 100644 --- a/src/null/null_vm.cc +++ b/src/null/null_vm.cc @@ -28,7 +28,7 @@ namespace proxy_wasm { std::unordered_map *null_vm_plugin_factories_ = nullptr; -RegisterNullVmPluginFactory::RegisterNullVmPluginFactory(string_view name, +RegisterNullVmPluginFactory::RegisterNullVmPluginFactory(std::string_view name, NullVmPluginFactory factory) { if (!null_vm_plugin_factories_) null_vm_plugin_factories_ = @@ -57,16 +57,16 @@ bool NullVm::load(const std::string &name, bool /* allow_precompiled */) { return true; } -bool NullVm::link(string_view /* name */) { return true; } +bool NullVm::link(std::string_view /* name */) { return true; } uint64_t NullVm::getMemorySize() { return std::numeric_limits::max(); } // NulVm pointers are just native pointers. -optional NullVm::getMemory(uint64_t pointer, uint64_t size) { +std::optional NullVm::getMemory(uint64_t pointer, uint64_t size) { if (pointer == 0 && size != 0) { - return PROXY_WASM_NULLOPT; + return std::nullopt; } - return string_view(reinterpret_cast(pointer), static_cast(size)); + return std::string_view(reinterpret_cast(pointer), static_cast(size)); } bool NullVm::setMemory(uint64_t pointer, uint64_t size, const void *data) { @@ -100,12 +100,12 @@ bool NullVm::getWord(uint64_t pointer, Word *data) { return true; } -string_view NullVm::getCustomSection(string_view /* name */) { +std::string_view NullVm::getCustomSection(std::string_view /* name */) { // Return nothing: there is no WASM file. return {}; } -string_view NullVm::getPrecompiledSectionName() { +std::string_view NullVm::getPrecompiledSectionName() { // Return nothing: there is no WASM file. return {}; } diff --git a/src/v8/v8.cc b/src/v8/v8.cc index c4664f039..671c36ddc 100644 --- a/src/v8/v8.cc +++ b/src/v8/v8.cc @@ -13,7 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "include/proxy-wasm/compat.h" #include "include/proxy-wasm/v8.h" #include @@ -51,24 +50,24 @@ class V8 : public WasmVm { V8() {} // WasmVm - string_view runtime() override { return "v8"; } + std::string_view runtime() override { return "v8"; } bool load(const std::string &code, bool allow_precompiled) override; - string_view getCustomSection(string_view name) override; - string_view getPrecompiledSectionName() override; - bool link(string_view debug_name) override; + std::string_view getCustomSection(std::string_view name) override; + std::string_view getPrecompiledSectionName() override; + bool link(std::string_view debug_name) override; Cloneable cloneable() override { return Cloneable::CompiledBytecode; } std::unique_ptr clone() override; uint64_t getMemorySize() override; - optional getMemory(uint64_t pointer, uint64_t size) override; + std::optional getMemory(uint64_t pointer, uint64_t size) override; bool setMemory(uint64_t pointer, uint64_t size, const void *data) override; bool getWord(uint64_t pointer, Word *word) override; bool setWord(uint64_t pointer, Word word) override; #define _REGISTER_HOST_FUNCTION(T) \ - void registerCallback(string_view module_name, string_view function_name, T, \ + void registerCallback(std::string_view module_name, std::string_view function_name, T, \ typename ConvertFunctionTypeWordToUint32::type f) override { \ registerHostFunctionImpl(module_name, function_name, f); \ }; @@ -76,7 +75,7 @@ class V8 : public WasmVm { #undef _REGISTER_HOST_FUNCTION #define _GET_MODULE_FUNCTION(T) \ - void getFunction(string_view function_name, T *f) override { \ + void getFunction(std::string_view function_name, T *f) override { \ getModuleFunctionImpl(function_name, f); \ }; FOR_ALL_WASM_VM_EXPORTS(_GET_MODULE_FUNCTION) @@ -86,19 +85,19 @@ class V8 : public WasmVm { wasm::vec getStrippedSource(); template - void registerHostFunctionImpl(string_view module_name, string_view function_name, + void registerHostFunctionImpl(std::string_view module_name, std::string_view function_name, void (*function)(void *, Args...)); template - void registerHostFunctionImpl(string_view module_name, string_view function_name, + void registerHostFunctionImpl(std::string_view module_name, std::string_view function_name, R (*function)(void *, Args...)); template - void getModuleFunctionImpl(string_view function_name, + void getModuleFunctionImpl(std::string_view function_name, std::function *function); template - void getModuleFunctionImpl(string_view function_name, + void getModuleFunctionImpl(std::string_view function_name, std::function *function); wasm::vec source_ = wasm::vec::invalid(); @@ -315,7 +314,7 @@ wasm::vec V8::getStrippedSource() { return wasm::vec::make(stripped.size(), stripped.data()); } -string_view V8::getCustomSection(string_view name) { +std::string_view V8::getCustomSection(std::string_view name) { assert(source_.get() != nullptr); const byte_t *pos = source_.get() + 8 /* Wasm header */; @@ -356,7 +355,7 @@ string_view V8::getCustomSection(string_view name) { #define WEE8_PLATFORM "" #endif -string_view V8::getPrecompiledSectionName() { +std::string_view V8::getPrecompiledSectionName() { static const auto name = sizeof(WEE8_PLATFORM) - 1 > 0 ? ("precompiled_wee8_v" + std::to_string(V8_MAJOR_VERSION) + "." + @@ -366,15 +365,15 @@ string_view V8::getPrecompiledSectionName() { return name; } -bool V8::link(string_view debug_name) { +bool V8::link(std::string_view debug_name) { assert(module_ != nullptr); const auto import_types = module_.get()->imports(); std::vector imports; for (size_t i = 0; i < import_types.size(); i++) { - string_view module(import_types[i]->module().get(), import_types[i]->module().size()); - string_view name(import_types[i]->name().get(), import_types[i]->name().size()); + std::string_view module(import_types[i]->module().get(), import_types[i]->module().size()); + std::string_view name(import_types[i]->name().get(), import_types[i]->name().size()); auto import_type = import_types[i]->type(); switch (import_type->kind()) { @@ -438,7 +437,7 @@ bool V8::link(string_view debug_name) { assert(export_types.size() == exports.size()); for (size_t i = 0; i < export_types.size(); i++) { - string_view name(export_types[i]->name().get(), export_types[i]->name().size()); + std::string_view name(export_types[i]->name().get(), export_types[i]->name().size()); auto export_type = export_types[i]->type(); auto export_item = exports[i].get(); assert(export_type->kind() == export_item->kind()); @@ -470,12 +469,12 @@ bool V8::link(string_view debug_name) { uint64_t V8::getMemorySize() { return memory_->data_size(); } -optional V8::getMemory(uint64_t pointer, uint64_t size) { +std::optional V8::getMemory(uint64_t pointer, uint64_t size) { assert(memory_ != nullptr); if (pointer + size > memory_->data_size()) { - return PROXY_WASM_NULLOPT; + return std::nullopt; } - return string_view(memory_->data() + pointer, size); + return std::string_view(memory_->data() + pointer, size); } bool V8::setMemory(uint64_t pointer, uint64_t size, const void *data) { @@ -509,7 +508,7 @@ bool V8::setWord(uint64_t pointer, Word word) { } template -void V8::registerHostFunctionImpl(string_view module_name, string_view function_name, +void V8::registerHostFunctionImpl(std::string_view module_name, std::string_view function_name, void (*function)(void *, Args...)) { auto data = std::make_unique(std::string(module_name) + "." + std::string(function_name)); @@ -533,7 +532,7 @@ void V8::registerHostFunctionImpl(string_view module_name, string_view function_ } template -void V8::registerHostFunctionImpl(string_view module_name, string_view function_name, +void V8::registerHostFunctionImpl(std::string_view module_name, std::string_view function_name, R (*function)(void *, Args...)) { auto data = std::make_unique(std::string(module_name) + "." + std::string(function_name)); @@ -558,7 +557,7 @@ void V8::registerHostFunctionImpl(string_view module_name, string_view function_ } template -void V8::getModuleFunctionImpl(string_view function_name, +void V8::getModuleFunctionImpl(std::string_view function_name, std::function *function) { auto it = module_functions_.find(std::string(function_name)); if (it == module_functions_.end()) { @@ -585,7 +584,7 @@ void V8::getModuleFunctionImpl(string_view function_name, } template -void V8::getModuleFunctionImpl(string_view function_name, +void V8::getModuleFunctionImpl(std::string_view function_name, std::function *function) { auto it = module_functions_.find(std::string(function_name)); if (it == module_functions_.end()) { diff --git a/src/wasm.cc b/src/wasm.cc index e47bc1946..cf3191943 100644 --- a/src/wasm.cc +++ b/src/wasm.cc @@ -60,13 +60,13 @@ const uint8_t *decodeVarint(const uint8_t *pos, const uint8_t *end, uint32_t *ou return pos; } -std::string Sha256(string_view data) { +std::string Sha256(std::string_view data) { std::vector hash(picosha2::k_digest_size); picosha2::hash256(data.begin(), data.end(), hash.begin(), hash.end()); return std::string(reinterpret_cast(&hash[0]), hash.size()); } -std::string Xor(string_view a, string_view b) { +std::string Xor(std::string_view a, std::string_view b) { assert(a.size() == b.size()); std::string result; result.reserve(a.size()); @@ -78,7 +78,7 @@ std::string Xor(string_view a, string_view b) { } // namespace -std::string makeVmKey(string_view vm_id, string_view vm_configuration, string_view code) { +std::string makeVmKey(std::string_view vm_id, std::string_view vm_configuration, std::string_view code) { std::string vm_key = Sha256(vm_id); vm_key = Xor(vm_key, Sha256(vm_configuration)); vm_key = Xor(vm_key, Sha256(code)); @@ -257,8 +257,8 @@ WasmBase::WasmBase(const std::shared_ptr &base_wasm_handle, Wasm } } -WasmBase::WasmBase(std::unique_ptr wasm_vm, string_view vm_id, string_view vm_configuration, - string_view vm_key) +WasmBase::WasmBase(std::unique_ptr wasm_vm, std::string_view vm_id, std::string_view vm_configuration, + std::string_view vm_key) : vm_id_(std::string(vm_id)), vm_key_(std::string(vm_key)), wasm_vm_(std::move(wasm_vm)), vm_configuration_(std::string(vm_configuration)) { if (!wasm_vm_) { @@ -414,7 +414,7 @@ void WasmBase::finishShutdown() { } } -WasmForeignFunction WasmBase::getForeignFunction(string_view function_name) { +WasmForeignFunction WasmBase::getForeignFunction(std::string_view function_name) { auto it = foreign_functions->find(std::string(function_name)); if (it != foreign_functions->end()) { return it->second; @@ -504,7 +504,7 @@ createThreadLocalWasm(std::shared_ptr &base_wasm, return wasm_handle; } -std::shared_ptr getThreadLocalWasm(string_view vm_key) { +std::shared_ptr getThreadLocalWasm(std::string_view vm_key) { auto it = local_wasms.find(std::string(vm_key)); if (it == local_wasms.end()) { return nullptr; diff --git a/src/wavm/wavm.cc b/src/wavm/wavm.cc index 86ee52ba1..dc19c154a 100644 --- a/src/wavm/wavm.cc +++ b/src/wavm/wavm.cc @@ -58,14 +58,14 @@ namespace proxy_wasm { // Forward declarations. template -void getFunctionWavm(WasmVm *vm, string_view function_name, +void getFunctionWavm(WasmVm *vm, std::string_view function_name, std::function *function); template -void registerCallbackWavm(WasmVm *vm, string_view module_name, string_view function_name, +void registerCallbackWavm(WasmVm *vm, std::string_view module_name, std::string_view function_name, R (*)(Args...)); template -void registerCallbackWavm(WasmVm *vm, string_view module_name, string_view function_name, F, - R (*)(Args...)); +void registerCallbackWavm(WasmVm *vm, std::string_view module_name, std::string_view function_name, + F, R (*)(Args...)); namespace Wavm { @@ -177,28 +177,28 @@ struct Wavm : public WasmVmBase { ~Wavm() override; // WasmVm - string_view runtime() override { return WasmRuntimeNames::get().Wavm; } + std::string_view runtime() override { return WasmRuntimeNames::get().Wavm; } Cloneable cloneable() override { return Cloneable::InstantiatedModule; }; std::unique_ptr clone() override; bool load(const std::string &code, bool allow_precompiled) override; - void link(string_view debug_name) override; + void link(std::string_view debug_name) override; uint64_t getMemorySize() override; - optional getMemory(uint64_t pointer, uint64_t size) override; + std::optional getMemory(uint64_t pointer, uint64_t size) override; bool setMemory(uint64_t pointer, uint64_t size, const void *data) override; bool getWord(uint64_t pointer, Word *data) override; bool setWord(uint64_t pointer, Word data) override; - string_view getCustomSection(string_view name) override; - string_view getPrecompiledSectionName() override; + std::string_view getCustomSection(std::string_view name) override; + std::string_view getPrecompiledSectionName() override; #define _GET_FUNCTION(_T) \ - void getFunction(string_view function_name, _T *f) override { \ + void getFunction(std::string_view function_name, _T *f) override { \ getFunctionWavm(this, function_name, f); \ }; FOR_ALL_WASM_VM_EXPORTS(_GET_FUNCTION) #undef _GET_FUNCTION #define _REGISTER_CALLBACK(_T) \ - void registerCallback(string_view module_name, string_view function_name, _T, \ + void registerCallback(std::string_view module_name, std::string_view function_name, _T, \ typename ConvertFunctionTypeWordToUint32<_T>::type f) override { \ registerCallbackWavm(this, module_name, function_name, f); \ }; @@ -271,7 +271,7 @@ bool Wavm::load(const std::string &code, bool allow_precompiled) { return true; } -void Wavm::link(string_view debug_name) { +void Wavm::link(std::string_view debug_name) { RootResolver rootResolver(compartment_); for (auto &p : intrinsic_modules_) { auto instance = Intrinsics::instantiateModule(compartment_, {&intrinsic_modules_[p.first]}, @@ -288,12 +288,12 @@ void Wavm::link(string_view debug_name) { uint64_t Wavm::getMemorySize() { return WAVM::Runtime::getMemoryNumPages(memory_) * WasmPageSize; } -optional Wavm::getMemory(uint64_t pointer, uint64_t size) { +std::optional Wavm::getMemory(uint64_t pointer, uint64_t size) { auto memory_num_bytes = WAVM::Runtime::getMemoryNumPages(memory_) * WasmPageSize; if (pointer + size > memory_num_bytes) { - return PROXY_WASM_NULLOPT; + return std::nullopt; } - return string_view(reinterpret_cast(memory_base_ + pointer), size); + return std::string_view(reinterpret_cast(memory_base_ + pointer), size); } bool Wavm::setMemory(uint64_t pointer, uint64_t size, const void *data) { @@ -323,7 +323,7 @@ bool Wavm::setWord(uint64_t pointer, Word data) { return setMemory(pointer, sizeof(uint32_t), &data32); } -string_view Wavm::getCustomSection(string_view name) { +std::string_view Wavm::getCustomSection(string_view name) { for (auto §ion : ir_module_.customSections) { if (section.name == name) { return {reinterpret_cast(section.data.data()), section.data.size()}; @@ -332,7 +332,7 @@ string_view Wavm::getCustomSection(string_view name) { return {}; } -string_view Wavm::getPrecompiledSectionName() { return "wavm.precompiled_object"; } +std::string_view Wavm::getPrecompiledSectionName() { return "wavm.precompiled_object"; } std::unique_ptr createVm(Stats::ScopeSharedPtr scope) { return std::make_unique(scope); @@ -349,7 +349,7 @@ IR::FunctionType inferEnvoyFunctionType(R (*)(void *, Args...)) { using namespace Wavm; template -void registerCallbackWavm(WasmVm *vm, string_view module_name, string_view function_name, +void registerCallbackWavm(WasmVm *vm, std::string_view module_name, std::string_view function_name, R (*f)(Args...)) { auto wavm = static_cast(vm); wavm->envoyFunctions_.emplace_back( @@ -357,82 +357,84 @@ void registerCallbackWavm(WasmVm *vm, string_view module_name, string_view funct reinterpret_cast(f), inferEnvoyFunctionType(f))); } -template void registerCallbackWavm(WasmVm *vm, string_view module_name, - string_view function_name, void (*f)(void *)); -template void registerCallbackWavm(WasmVm *vm, string_view module_name, - string_view function_name, +template void registerCallbackWavm(WasmVm *vm, std::string_view module_name, + std::string_view function_name, void (*f)(void *)); +template void registerCallbackWavm(WasmVm *vm, std::string_view module_name, + std::string_view function_name, void (*f)(void *, U32)); -template void registerCallbackWavm(WasmVm *vm, string_view module_name, - string_view function_name, +template void registerCallbackWavm(WasmVm *vm, std::string_view module_name, + std::string_view function_name, void (*f)(void *, U32, U32)); -template void registerCallbackWavm(WasmVm *vm, string_view module_name, - string_view function_name, +template void registerCallbackWavm(WasmVm *vm, + std::string_view module_name, + std::string_view function_name, void (*f)(void *, U32, U32, U32)); template void -registerCallbackWavm(WasmVm *vm, string_view module_name, - string_view function_name, +registerCallbackWavm(WasmVm *vm, std::string_view module_name, + std::string_view function_name, void (*f)(void *, U32, U32, U32, U32)); template void registerCallbackWavm( - WasmVm *vm, string_view module_name, string_view function_name, + WasmVm *vm, std::string_view module_name, std::string_view function_name, void (*f)(void *, U32, U32, U32, U32, U32)); template void registerCallbackWavm( - WasmVm *vm, string_view module_name, string_view function_name, + WasmVm *vm, std::string_view module_name, std::string_view function_name, void (*f)(void *, U32, U32, U32, U32, U32, U32)); template void registerCallbackWavm( - WasmVm *vm, string_view module_name, string_view function_name, + WasmVm *vm, std::string_view module_name, std::string_view function_name, void (*f)(void *, U32, U32, U32, U32, U32, U32, U32)); template void registerCallbackWavm( - WasmVm *vm, string_view module_name, string_view function_name, + WasmVm *vm, std::string_view module_name, std::string_view function_name, void (*f)(void *, U32, U32, U32, U32, U32, U32, U32, U32)); template void registerCallbackWavm( - WasmVm *vm, string_view module_name, string_view function_name, + WasmVm *vm, std::string_view module_name, std::string_view function_name, void (*f)(void *, U32, U32, U32, U32, U32, U32, U32, U32, U32)); template void registerCallbackWavm( - WasmVm *vm, string_view module_name, string_view function_name, + WasmVm *vm, std::string_view module_name, std::string_view function_name, void (*f)(void *, U32, U32, U32, U32, U32, U32, U32, U32, U32, U32)); -template void registerCallbackWavm(WasmVm *vm, string_view module_name, - string_view function_name, U32 (*f)(void *)); -template void registerCallbackWavm(WasmVm *vm, string_view module_name, - string_view function_name, +template void registerCallbackWavm(WasmVm *vm, std::string_view module_name, + std::string_view function_name, U32 (*f)(void *)); +template void registerCallbackWavm(WasmVm *vm, std::string_view module_name, + std::string_view function_name, U32 (*f)(void *, U32)); -template void registerCallbackWavm(WasmVm *vm, string_view module_name, - string_view function_name, +template void registerCallbackWavm(WasmVm *vm, std::string_view module_name, + std::string_view function_name, U32 (*f)(void *, U32, U32)); -template void registerCallbackWavm(WasmVm *vm, string_view module_name, - string_view function_name, +template void registerCallbackWavm(WasmVm *vm, + std::string_view module_name, + std::string_view function_name, U32 (*f)(void *, U32, U32, U32)); template void -registerCallbackWavm(WasmVm *vm, string_view module_name, - string_view function_name, +registerCallbackWavm(WasmVm *vm, std::string_view module_name, + std::string_view function_name, U32 (*f)(void *, U32, U32, U32, U32)); template void registerCallbackWavm( - WasmVm *vm, string_view module_name, string_view function_name, + WasmVm *vm, std::string_view module_name, std::string_view function_name, U32 (*f)(void *, U32, U32, U32, U32, U32)); template void registerCallbackWavm( - WasmVm *vm, string_view module_name, string_view function_name, + WasmVm *vm, std::string_view module_name, std::string_view function_name, U32 (*f)(void *, U32, U32, U32, U32, U32, U32)); template void registerCallbackWavm( - WasmVm *vm, string_view module_name, string_view function_name, + WasmVm *vm, std::string_view module_name, std::string_view function_name, U32 (*f)(void *, U32, U32, U32, U32, U32, U32, U32)); template void registerCallbackWavm( - WasmVm *vm, string_view module_name, string_view function_name, + WasmVm *vm, std::string_view module_name, std::string_view function_name, U32 (*f)(void *, U32, U32, U32, U32, U32, U32, U32, U32)); template void registerCallbackWavm( - WasmVm *vm, string_view module_name, string_view function_name, + WasmVm *vm, std::string_view module_name, std::string_view function_name, U32 (*f)(void *, U32, U32, U32, U32, U32, U32, U32, U32, U32)); template void registerCallbackWavm( - WasmVm *vm, string_view module_name, string_view function_name, + WasmVm *vm, std::string_view module_name, std::string_view function_name, U32 (*f)(void *, U32, U32, U32, U32, U32, U32, U32, U32, U32, U32)); -template void registerCallbackWavm(WasmVm *vm, string_view module_name, - string_view function_name, +template void registerCallbackWavm(WasmVm *vm, std::string_view module_name, + std::string_view function_name, U64 (*f)(void *, U32)); -template void registerCallbackWavm(WasmVm *vm, string_view module_name, - string_view function_name, +template void registerCallbackWavm(WasmVm *vm, std::string_view module_name, + std::string_view function_name, void (*f)(void *, U32, I64)); -template void registerCallbackWavm(WasmVm *vm, string_view module_name, - string_view function_name, +template void registerCallbackWavm(WasmVm *vm, std::string_view module_name, + std::string_view function_name, void (*f)(void *, U32, U64)); template @@ -445,7 +447,7 @@ static bool checkFunctionType(WAVM::Runtime::Function *f, IR::FunctionType t) { } template -void getFunctionWavmReturn(WasmVm *vm, string_view function_name, +void getFunctionWavmReturn(WasmVm *vm, std::string_view function_name, std::function *function, uint32_t) { auto wavm = static_cast(vm); auto f = @@ -476,7 +478,7 @@ void getFunctionWavmReturn(WasmVm *vm, string_view function_name, struct Void {}; template -void getFunctionWavmReturn(WasmVm *vm, string_view function_name, +void getFunctionWavmReturn(WasmVm *vm, std::string_view function_name, std::function *function, Void) { auto wavm = static_cast(vm); auto f = @@ -505,80 +507,82 @@ void getFunctionWavmReturn(WasmVm *vm, string_view function_name, // we use 'Void' for template matching. Note that the template implementation above // which matchers on 'bool' does not use 'Void' in the implemenation. template -void getFunctionWavm(WasmVm *vm, string_view function_name, +void getFunctionWavm(WasmVm *vm, std::string_view function_name, std::function *function) { typename std::conditional::value, Void, uint32_t>::type x{}; getFunctionWavmReturn(vm, function_name, function, x); } -template void getFunctionWavm(WasmVm *, string_view, std::function *); -template void getFunctionWavm(WasmVm *, string_view, +template void getFunctionWavm(WasmVm *, std::string_view, + std::function *); +template void getFunctionWavm(WasmVm *, std::string_view, std::function *); template void -getFunctionWavm(WasmVm *, string_view, +getFunctionWavm(WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, std::function *); + WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, + WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, + WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, + WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, + WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, + WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, + WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, + WasmVm *, std::string_view, std::function *); -template void getFunctionWavm(WasmVm *, string_view, +template void getFunctionWavm(WasmVm *, std::string_view, std::function *); template void -getFunctionWavm(WasmVm *, string_view, +getFunctionWavm(WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, std::function *); + WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, std::function *); + WasmVm *, std::string_view, + std::function *); template void getFunctionWavm( - WasmVm *, string_view, + WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, + WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, + WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, + WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, + WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, + WasmVm *, std::string_view, std::function *); template void getFunctionWavm( - WasmVm *, string_view, + WasmVm *, std::string_view, std::function *); diff --git a/wasm_vm_test.cc b/wasm_vm_test.cc index 2f6293295..26d45473d 100644 --- a/wasm_vm_test.cc +++ b/wasm_vm_test.cc @@ -35,13 +35,13 @@ RegisterNullVmPluginFactory register_test_null_vm_plugin("test_null_vm_plugin", }); TEST(WasmVm, Compat) { - string_view foo = "foo"; + std::string_view foo = "foo"; std::string bar = "bar"; EXPECT_NE(foo, bar); EXPECT_EQ(foo, "foo"); - optional o = PROXY_WASM_NULLOPT; + std::optional o = std::nullopt; EXPECT_FALSE(o); o = 1; From 2d24da1ec8e8e5442570a131865f454194b4927a Mon Sep 17 00:00:00 2001 From: John Plevyak Date: Fri, 31 Jul 2020 01:42:54 +0000 Subject: [PATCH 2/2] Format. Signed-off-by: John Plevyak --- include/proxy-wasm/context.h | 13 ++++++++----- include/proxy-wasm/context_interface.h | 15 +++++++++------ include/proxy-wasm/null_plugin.h | 6 +++--- include/proxy-wasm/wasm.h | 7 ++++--- src/context.cc | 6 ++++-- src/wasm.cc | 7 ++++--- 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/include/proxy-wasm/context.h b/include/proxy-wasm/context.h index 17dde4b39..9c1189cbe 100644 --- a/include/proxy-wasm/context.h +++ b/include/proxy-wasm/context.h @@ -46,8 +46,8 @@ class WasmVm; * @param fail_open if true the plugin will pass traffic as opposed to close all streams. */ struct PluginBase { - PluginBase(std::string_view name, std::string_view root_id, std::string_view vm_id, std::string_view runtime, - std::string_view plugin_configuration, bool fail_open) + PluginBase(std::string_view name, std::string_view root_id, std::string_view vm_id, + std::string_view runtime, std::string_view plugin_configuration, bool fail_open) : name_(std::string(name)), root_id_(std::string(root_id)), vm_id_(std::string(vm_id)), runtime_(std::string(runtime)), plugin_configuration_(plugin_configuration), fail_open_(fail_open) {} @@ -79,7 +79,8 @@ struct BufferBase : public BufferInterface { } WasmResult copyTo(WasmBase *wasm, size_t start, size_t length, uint64_t ptr_ptr, uint64_t size_ptr) const override; - WasmResult copyFrom(size_t /* start */, size_t /* length */, std::string_view /* data */) override { + WasmResult copyFrom(size_t /* start */, size_t /* length */, + std::string_view /* data */) override { // Setting a string buffer not supported (no use case). return WasmResult::BadArgument; } @@ -302,7 +303,8 @@ class ContextBase : public RootInterface, WasmResult getProperty(std::string_view /* path */, std::string * /* result */) override { return unimplemented(); } - WasmResult setProperty(std::string_view /* key */, std::string_view /* serialized_value */) override { + WasmResult setProperty(std::string_view /* key */, + std::string_view /* serialized_value */) override { return unimplemented(); } @@ -345,7 +347,8 @@ class ContextBase : public RootInterface, return unimplemented(); } - WasmResult removeHeaderMapValue(WasmHeaderMapType /* type */, std::string_view /* key */) override { + WasmResult removeHeaderMapValue(WasmHeaderMapType /* type */, + std::string_view /* key */) override { return unimplemented(); } WasmResult replaceHeaderMapValue(WasmHeaderMapType /* type */, std::string_view /* key */, diff --git a/include/proxy-wasm/context_interface.h b/include/proxy-wasm/context_interface.h index ac2b1648a..9f6fd6ca3 100644 --- a/include/proxy-wasm/context_interface.h +++ b/include/proxy-wasm/context_interface.h @@ -173,8 +173,8 @@ struct RootInterface : public RootGrpcInterface { * shutting down. * @return true for stream contexts or for Root Context(s) if the VM can shutdown, false for Root * Context(s) if the VM should wait until the Root Context calls the proxy_done() ABI call. Note: - * the VM may (std::optionally) shutdown after some configured timeout even if the Root Context does - * not call proxy_done(). + * the VM may (std::optionally) shutdown after some configured timeout even if the Root Context + * does not call proxy_done(). */ virtual bool onDone() = 0; @@ -423,9 +423,11 @@ struct GrpcCallInterface { * @param token_ptr contains a pointer to a location to store the token which will be used with * the corresponding onGrpc and grpc calls. */ - virtual WasmResult grpcCall(std::string_view /* grpc_service */, std::string_view /* service_name */, - std::string_view /* method_name */, const Pairs & /* initial_metadata */, - std::string_view /* request */, std::chrono::milliseconds /* timeout */, + virtual WasmResult grpcCall(std::string_view /* grpc_service */, + std::string_view /* service_name */, + std::string_view /* method_name */, + const Pairs & /* initial_metadata */, std::string_view /* request */, + std::chrono::milliseconds /* timeout */, GrpcToken * /* token_ptr */) = 0; /** @@ -595,7 +597,8 @@ struct SharedDataInterface { * compare-and-swap value which can be used with setSharedData for safe concurrent updates. */ virtual WasmResult - getSharedData(std::string_view key, std::pair *data) = 0; + getSharedData(std::string_view key, + std::pair *data) = 0; /** * Set a key-value data shared between VMs. diff --git a/include/proxy-wasm/null_plugin.h b/include/proxy-wasm/null_plugin.h index 136be6408..9c8120892 100644 --- a/include/proxy-wasm/null_plugin.h +++ b/include/proxy-wasm/null_plugin.h @@ -128,7 +128,7 @@ class NullPlugin : public NullVmPlugin { struct RegisterContextFactory { \ explicit RegisterContextFactory(null_plugin::ContextFactory context_factory, \ null_plugin::RootFactory root_factory, \ - std::string_view root_id = "") { \ + std::string_view root_id = "") { \ if (!context_registry_) { \ context_registry_ = new NullPluginRegistry; \ } \ @@ -136,14 +136,14 @@ class NullPlugin : public NullVmPlugin { context_registry_->root_factories[std::string(root_id)] = root_factory; \ } \ explicit RegisterContextFactory(null_plugin::ContextFactory context_factory, \ - std::string_view root_id = "") { \ + std::string_view root_id = "") { \ if (!context_registry_) { \ context_registry_ = new NullPluginRegistry; \ } \ context_registry_->context_factories[std::string(root_id)] = context_factory; \ } \ explicit RegisterContextFactory(null_plugin::RootFactory root_factory, \ - std::string_view root_id = "") { \ + std::string_view root_id = "") { \ if (!context_registry_) { \ context_registry_ = new NullPluginRegistry; \ } \ diff --git a/include/proxy-wasm/wasm.h b/include/proxy-wasm/wasm.h index 1214a7d73..4b7bb7d76 100644 --- a/include/proxy-wasm/wasm.h +++ b/include/proxy-wasm/wasm.h @@ -44,8 +44,8 @@ using CallOnThreadFunction = std::function)>; // Wasm execution instance. Manages the host side of the Wasm interface. class WasmBase : public std::enable_shared_from_this { public: - WasmBase(std::unique_ptr wasm_vm, std::string_view vm_id, std::string_view vm_configuration, - std::string_view vm_key); + WasmBase(std::unique_ptr wasm_vm, std::string_view vm_id, + std::string_view vm_configuration, std::string_view vm_key); WasmBase(const std::shared_ptr &other, WasmVmFactory factory); virtual ~WasmBase(); @@ -272,7 +272,8 @@ class WasmHandleBase : public std::enable_shared_from_this { std::shared_ptr wasm_base_; }; -std::string makeVmKey(std::string_view vm_id, std::string_view configuration, std::string_view code); +std::string makeVmKey(std::string_view vm_id, std::string_view configuration, + std::string_view code); using WasmHandleFactory = std::function(std::string_view vm_id)>; using WasmHandleCloneFactory = diff --git a/src/context.cc b/src/context.cc index 4972a9301..b7b8d4d1f 100644 --- a/src/context.cc +++ b/src/context.cc @@ -65,7 +65,8 @@ class SharedData { return WasmResult::NotFound; } - WasmResult set(std::string_view vm_id, std::string_view key, std::string_view value, uint32_t cas) { + WasmResult set(std::string_view vm_id, std::string_view key, std::string_view value, + uint32_t cas) { std::lock_guard lock(mutex_); std::unordered_map> *map; auto map_it = data_.find(std::string(vm_id)); @@ -337,7 +338,8 @@ void ContextBase::onCreate() { } // Shared Data -WasmResult ContextBase::getSharedData(std::string_view key, std::pair *data) { +WasmResult ContextBase::getSharedData(std::string_view key, + std::pair *data) { return global_shared_data.get(wasm_->vm_id(), key, data); } diff --git a/src/wasm.cc b/src/wasm.cc index cf3191943..a874d1ace 100644 --- a/src/wasm.cc +++ b/src/wasm.cc @@ -78,7 +78,8 @@ std::string Xor(std::string_view a, std::string_view b) { } // namespace -std::string makeVmKey(std::string_view vm_id, std::string_view vm_configuration, std::string_view code) { +std::string makeVmKey(std::string_view vm_id, std::string_view vm_configuration, + std::string_view code) { std::string vm_key = Sha256(vm_id); vm_key = Xor(vm_key, Sha256(vm_configuration)); vm_key = Xor(vm_key, Sha256(code)); @@ -257,8 +258,8 @@ WasmBase::WasmBase(const std::shared_ptr &base_wasm_handle, Wasm } } -WasmBase::WasmBase(std::unique_ptr wasm_vm, std::string_view vm_id, std::string_view vm_configuration, - std::string_view vm_key) +WasmBase::WasmBase(std::unique_ptr wasm_vm, std::string_view vm_id, + std::string_view vm_configuration, std::string_view vm_key) : vm_id_(std::string(vm_id)), vm_key_(std::string(vm_key)), wasm_vm_(std::move(wasm_vm)), vm_configuration_(std::string(vm_configuration)) { if (!wasm_vm_) {