Skip to content

Commit 429db76

Browse files
committed
GH-1441 Use span instead of vector
1 parent 5604b76 commit 429db76

File tree

6 files changed

+15
-25
lines changed

6 files changed

+15
-25
lines changed

libraries/chain/include/eosio/chain/webassembly/eos-vm-oc/code_cache.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class code_cache_async : public code_cache_base {
134134
void wait_on_compile_monitor_message();
135135
std::tuple<size_t, size_t> consume_compile_thread_queue();
136136
void process_queued_compiles();
137-
void write_message(const digest_type& code_id, const eosvmoc_message& message, const std::vector<wrapped_fd>& fds);
137+
void write_message(const digest_type& code_id, const eosvmoc_message& message, std::span<wrapped_fd> fds);
138138

139139
};
140140

libraries/chain/include/eosio/chain/webassembly/eos-vm-oc/ipc_helpers.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class wrapped_fd {
4747

4848
std::tuple<bool, eosvmoc_message, std::vector<wrapped_fd>> read_message_with_fds(boost::asio::local::datagram_protocol::socket& s);
4949
std::tuple<bool, eosvmoc_message, std::vector<wrapped_fd>> read_message_with_fds(int fd);
50-
bool write_message_with_fds(boost::asio::local::datagram_protocol::socket& s, const eosvmoc_message& message, const std::vector<wrapped_fd>& fds = std::vector<wrapped_fd>());
51-
bool write_message_with_fds(int fd_to_send_to, const eosvmoc_message& message, const std::vector<wrapped_fd>& fds = std::vector<wrapped_fd>());
50+
bool write_message_with_fds(boost::asio::local::datagram_protocol::socket& s, const eosvmoc_message& message, std::span<wrapped_fd> fds = {});
51+
bool write_message_with_fds(int fd_to_send_to, const eosvmoc_message& message, std::span<wrapped_fd> fds = {});
5252

5353
template<typename T>
5454
wrapped_fd memfd_for_bytearray(const T& bytes) {

libraries/chain/webassembly/runtimes/eos-vm-oc/code_cache.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void code_cache_async::wait_on_compile_monitor_message() {
8585
}
8686

8787
//call with _mtx locked
88-
void code_cache_async::write_message(const digest_type& code_id, const eosvmoc_message& message, const std::vector<wrapped_fd>& fds) {
88+
void code_cache_async::write_message(const digest_type& code_id, const eosvmoc_message& message, std::span<wrapped_fd> fds) {
8989
_outstanding_compiles_and_poison.emplace(code_id, false);
9090
++_outstanding_compiles;
9191
if (!write_message_with_fds(_compile_monitor_write_socket, message, fds)) {
@@ -99,9 +99,8 @@ void code_cache_async::process_queued_compiles() {
9999
while (_outstanding_compiles < _threads && !_queued_compiles.empty()) {
100100
auto nextup = _queued_compiles.begin();
101101

102-
std::vector<wrapped_fd> fds_to_pass;
103-
fds_to_pass.emplace_back(memfd_for_bytearray(nextup->code));
104-
write_message(nextup->code_id(), nextup->msg, fds_to_pass);
102+
auto fd = memfd_for_bytearray(nextup->code);
103+
write_message(nextup->code_id(), nextup->msg, std::span<wrapped_fd>{&fd, 1});
105104

106105
_queued_compiles.erase(nextup);
107106
}
@@ -215,9 +214,8 @@ code_cache_async::get_descriptor_for_code(mode m, const digest_type& code_id, co
215214
return nullptr;
216215
}
217216

218-
std::vector<wrapped_fd> fds_to_pass;
219-
fds_to_pass.emplace_back(memfd_for_bytearray(codeobject->code));
220-
write_message(code_id, msg, fds_to_pass);
217+
auto fd = memfd_for_bytearray(codeobject->code);
218+
write_message(code_id, msg, std::span<wrapped_fd>{&fd, 1});
221219
failure = get_cd_failure::temporary; // Compile might not be done yet
222220
return nullptr;
223221
}
@@ -246,15 +244,13 @@ const code_descriptor* const code_cache_sync::get_descriptor_for_code_sync(mode
246244
if(!codeobject) //should be impossible right?
247245
return nullptr;
248246

249-
std::vector<wrapped_fd> fds_to_pass;
250-
fds_to_pass.emplace_back(memfd_for_bytearray(codeobject->code));
251-
252247
auto msg = compile_wasm_message{
253248
.code = { code_id, vm_version },
254249
.queued_time = fc::time_point{}, // could use now() if compile time measurement desired
255250
.limits = !m.whitelisted ? _eosvmoc_config.non_whitelisted_limits : std::optional<subjective_compile_limits>{}
256251
};
257-
write_message_with_fds(_compile_monitor_write_socket, msg, fds_to_pass);
252+
auto fd = memfd_for_bytearray(codeobject->code);
253+
write_message_with_fds(_compile_monitor_write_socket, msg, std::span<wrapped_fd>{&fd, 1});
258254
auto [success, message, fds] = read_message_with_fds(_compile_monitor_read_socket);
259255
EOS_ASSERT(success, wasm_execution_error, "failed to read response from monitor process");
260256
EOS_ASSERT(std::holds_alternative<wasm_compilation_result_message>(message), wasm_execution_error, "unexpected response from monitor process");

libraries/chain/webassembly/runtimes/eos-vm-oc/compile_monitor.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ struct compile_monitor_session {
9696
socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, socks);
9797
local::datagram_protocol::socket response_socket(_ctx);
9898
response_socket.assign(local::datagram_protocol(), socks[0]);
99-
std::vector<wrapped_fd> fds_pass_to_trampoline;
100-
fds_pass_to_trampoline.emplace_back(socks[1]);
101-
fds_pass_to_trampoline.emplace_back(std::move(wasm_code));
99+
std::array<wrapped_fd, 2> fds_pass_to_trampoline { socks[1], std::move(wasm_code) };
102100

103101
eosvmoc_message trampoline_compile_request = msg;
104102
if(write_message_with_fds(_trampoline_socket, trampoline_compile_request, fds_pass_to_trampoline) == false) {
@@ -324,9 +322,7 @@ wrapped_fd get_connection_to_compile_monitor(int cache_fd) {
324322
FC_ASSERT(dup_of_cache_fd != -1, "failed to dup cache_fd");
325323
wrapped_fd dup_cache_fd(dup_of_cache_fd);
326324

327-
std::vector<wrapped_fd> fds_to_pass;
328-
fds_to_pass.emplace_back(std::move(socket_to_hand_to_monitor_session));
329-
fds_to_pass.emplace_back(std::move(dup_cache_fd));
325+
std::array<wrapped_fd, 2> fds_to_pass { std::move(socket_to_hand_to_monitor_session), std::move(dup_cache_fd) };
330326
write_message_with_fds(the_compile_monitor_trampoline.compile_manager_fd, initialize_message(), fds_to_pass);
331327

332328
auto [success, message, fds] = read_message_with_fds(the_compile_monitor_trampoline.compile_manager_fd);

libraries/chain/webassembly/runtimes/eos-vm-oc/compile_trampoline.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ void run_compile(wrapped_fd&& response_sock, wrapped_fd&& wasm_code, uint64_t st
133133
std::move(prologue_it, prologue.end(), std::back_inserter(initdata_prep));
134134
std::move(initial_mem.begin(), initial_mem.end(), std::back_inserter(initdata_prep));
135135

136-
std::vector<wrapped_fd> fds_to_send;
137-
fds_to_send.emplace_back(memfd_for_bytearray(code.code));
138-
fds_to_send.emplace_back(memfd_for_bytearray(initdata_prep));
136+
std::array<wrapped_fd, 2> fds_to_send{ memfd_for_bytearray(code.code), memfd_for_bytearray(initdata_prep) };
139137
write_message_with_fds(response_sock, result_message, fds_to_send);
140138
}
141139

libraries/chain/webassembly/runtimes/eos-vm-oc/ipc_helpers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ std::tuple<bool, eosvmoc_message, std::vector<wrapped_fd>> read_message_with_fds
7171
return {true, message, std::move(fds)};
7272
}
7373

74-
bool write_message_with_fds(boost::asio::local::datagram_protocol::socket& s, const eosvmoc_message& message, const std::vector<wrapped_fd>& fds) {
74+
bool write_message_with_fds(boost::asio::local::datagram_protocol::socket& s, const eosvmoc_message& message, std::span<wrapped_fd> fds) {
7575
return write_message_with_fds(s.native_handle(), message, fds);
7676
}
7777

78-
bool write_message_with_fds(int fd_to_send_to, const eosvmoc_message& message, const std::vector<wrapped_fd>& fds) {
78+
bool write_message_with_fds(int fd_to_send_to, const eosvmoc_message& message, std::span<wrapped_fd> fds) {
7979
struct msghdr msg = {};
8080
struct cmsghdr* cmsg;
8181

0 commit comments

Comments
 (0)