From db55fdf73fa40df4e89c4264117361d8d41d982a Mon Sep 17 00:00:00 2001 From: Desour Date: Sun, 6 Oct 2024 15:49:42 +0200 Subject: [PATCH] dont use string_view I don't like that it's implicitly constructible from a const char *, and assumes it's 0-terminated. so void * it is. --- src/benchmark/benchmark_ipc_channel.cpp | 4 ++-- src/threading/ipc_channel.cpp | 2 +- src/threading/ipc_channel.h | 2 -- src/unittest/test_threading.cpp | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/benchmark/benchmark_ipc_channel.cpp b/src/benchmark/benchmark_ipc_channel.cpp index e81f55cf4..b59ffe572 100644 --- a/src/benchmark/benchmark_ipc_channel.cpp +++ b/src/benchmark/benchmark_ipc_channel.cpp @@ -37,14 +37,14 @@ TEST_CASE("benchmark_ipc_channel") auto thread_b = std::move(end_a_thread_b_p.second); BENCHMARK("simple_call_1", i) { - char buf[16] = {}; + u8 buf[16] = {}; buf[i & 0xf] = i; end_a.exchange(buf, 16); return reinterpret_cast(end_a.getRecvData())[i & 0xf]; }; BENCHMARK("simple_call_1000", i) { - char buf[16] = {}; + u8 buf[16] = {}; buf[i & 0xf] = i; for (int k = 0; k < 1000; ++k) { buf[0] = k & 0xff; diff --git a/src/threading/ipc_channel.cpp b/src/threading/ipc_channel.cpp index 59b90c4f5..fbe65a3cb 100644 --- a/src/threading/ipc_channel.cpp +++ b/src/threading/ipc_channel.cpp @@ -302,7 +302,7 @@ bool IPCChannelEnd::sendLarge(const void *data, size_t size, int timeout_ms) noe return false; size -= IPC_CHANNEL_MSG_SIZE; - data = (u8 *)data + IPC_CHANNEL_MSG_SIZE; + data = reinterpret_cast(data) + IPC_CHANNEL_MSG_SIZE; } while (size > IPC_CHANNEL_MSG_SIZE); if (size != 0) diff --git a/src/threading/ipc_channel.h b/src/threading/ipc_channel.h index 0cd8b4962..3f8ae33bd 100644 --- a/src/threading/ipc_channel.h +++ b/src/threading/ipc_channel.h @@ -236,7 +236,6 @@ public: } // Get the content of the last received message - // TODO: u8 *, or string_view? const void *getRecvData() const noexcept { return m_large_recv.data(); } size_t getRecvSize() const noexcept { return m_recv_size; } @@ -245,7 +244,6 @@ private: m_resources(std::move(resources)), m_dir(dir) {} - // TODO: u8 *, or string_view? void sendSmall(const void *data, size_t size) noexcept; // returns false on timeout diff --git a/src/unittest/test_threading.cpp b/src/unittest/test_threading.cpp index 7db619b04..18b519838 100644 --- a/src/unittest/test_threading.cpp +++ b/src/unittest/test_threading.cpp @@ -243,12 +243,12 @@ void TestThreading::testIPCChannel() } }); - char buf[20000] = {}; + u8 buf[20000] = {}; for (int i = sizeof(buf); i > 0; i -= 100) { buf[i - 1] = 123; UASSERT(end_a.exchangeWithTimeout(buf, i, -1)); UASSERTEQ(int, end_a.getRecvSize(), i); - UASSERTEQ(int, ((const char *)end_a.getRecvData())[i - 1], 123); + UASSERTEQ(int, reinterpret_cast(end_a.getRecvData())[i - 1], 123); } // stop thread_b