This is an automated email from the ASF dual-hosted git repository.
wangdan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git
The following commit(s) were added to refs/heads/master by this push:
new 7c0fd2574 fix(build): replace variable-length arrays with proper
structures to fix compilation errors on macOS (#2290)
7c0fd2574 is described below
commit 7c0fd2574848aae7acb64f48c7718ea3e89dfb31
Author: Dan Wang <[email protected]>
AuthorDate: Fri Sep 5 11:31:18 2025 +0800
fix(build): replace variable-length arrays with proper structures to fix
compilation errors on macOS (#2290)
Fix https://github.com/apache/incubator-pegasus/issues/2291.
Variable-length arrays are used somewhere in our codes. However, as a Clang
extension, currently they are considered as errors while building on macOS.
Therefore, we will replace them with some structures such as `std::vector`
or
`std::unique_ptr` to eliminate the compilation errors.
---
src/aio/test/aio.cpp | 30 ++++++++++++++-------------
src/server/test/pegasus_server_write_test.cpp | 8 +++----
src/shell/commands/local_partition_split.cpp | 2 +-
3 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/src/aio/test/aio.cpp b/src/aio/test/aio.cpp
index 7dbff2d7d..71f762404 100644
--- a/src/aio/test/aio.cpp
+++ b/src/aio/test/aio.cpp
@@ -24,11 +24,12 @@
* THE SOFTWARE.
*/
+// IWYU pragma: no_include <ext/alloc_traits.h>
#include <fmt/core.h>
#include <rocksdb/status.h>
-#include <string.h>
#include <algorithm>
#include <cstdint>
+#include <cstring>
#include <list>
#include <memory>
#include <random>
@@ -38,8 +39,8 @@
#include "aio/aio_task.h"
#include "aio/file_io.h"
#include "gtest/gtest.h"
-#include "task/task_code.h"
#include "runtime/tool_api.h"
+#include "task/task_code.h"
#include "test_util/test_util.h"
#include "utils/autoref_ptr.h"
#include "utils/env.h"
@@ -109,12 +110,12 @@ TEST_P(aio_test, basic)
pegasus::stop_watch sw;
uint64_t offset = 0;
std::list<aio_task_ptr> tasks;
- for (int i = 0; i < kTotalBufferCount; i++) {
- char read_buffer[kUnitBufferLength + 1];
- read_buffer[kUnitBufferLength] = 0;
+ for (int i = 0; i < kTotalBufferCount; ++i) {
+ auto read_buffer = std::make_unique<char[]>(kUnitBufferLength
+ 1);
+ read_buffer[kUnitBufferLength] = '\0';
auto t = ::dsn::file::read(rfile,
- read_buffer,
- kUnitBufferLength,
+ read_buffer.get(),
+ static_cast<int>(kUnitBufferLength),
offset,
LPC_AIO_TEST,
nullptr,
@@ -123,7 +124,7 @@ TEST_P(aio_test, basic)
t->wait();
ASSERT_EQ(kUnitBufferLength, t->get_transferred_size());
- ASSERT_STREQ(kUnitBuffer.c_str(), read_buffer);
+ ASSERT_STREQ(kUnitBuffer.c_str(), read_buffer.get());
}
sw.stop_and_output(fmt::format("sequential read"));
}
@@ -133,12 +134,13 @@ TEST_P(aio_test, basic)
pegasus::stop_watch sw;
uint64_t offset = 0;
std::list<aio_task_ptr> tasks;
- char read_buffers[kTotalBufferCount][kUnitBufferLength + 1];
- for (int i = 0; i < kTotalBufferCount; i++) {
- read_buffers[i][kUnitBufferLength] = 0;
+ std::vector<std::unique_ptr<char[]>>
read_buffers(kTotalBufferCount);
+ for (int i = 0; i < kTotalBufferCount; ++i) {
+ read_buffers[i] = std::make_unique<char[]>(kUnitBufferLength +
1);
+ read_buffers[i][kUnitBufferLength] = '\0';
auto t = ::dsn::file::read(rfile,
- read_buffers[i],
- kUnitBufferLength,
+ read_buffers[i].get(),
+ static_cast<int>(kUnitBufferLength),
offset,
LPC_AIO_TEST,
nullptr,
@@ -151,7 +153,7 @@ TEST_P(aio_test, basic)
ASSERT_EQ(kUnitBufferLength, t->get_transferred_size());
}
for (int i = 0; i < kTotalBufferCount; i++) {
- ASSERT_STREQ(kUnitBuffer.c_str(), read_buffers[i]);
+ ASSERT_STREQ(kUnitBuffer.c_str(), read_buffers[i].get());
}
sw.stop_and_output(fmt::format("concurrent read"));
}
diff --git a/src/server/test/pegasus_server_write_test.cpp
b/src/server/test/pegasus_server_write_test.cpp
index cfb1a0ebd..2bc91c0a8 100644
--- a/src/server/test/pegasus_server_write_test.cpp
+++ b/src/server/test/pegasus_server_write_test.cpp
@@ -83,16 +83,16 @@ public:
* rpc_holders, which created in on_batched_write_requests. So
we don't need to
* release them here
**/
- dsn::message_ex *writes[total_rpc_cnt];
- for (uint32_t i = 0; i < put_rpc_cnt; i++) {
+ auto writes = std::make_unique<dsn::message_ex
*[]>(total_rpc_cnt);
+ for (uint32_t i = 0; i < put_rpc_cnt; ++i) {
writes[i] = pegasus::create_put_request(req);
}
- for (uint32_t i = put_rpc_cnt; i < total_rpc_cnt; i++) {
+ for (uint32_t i = put_rpc_cnt; i < total_rpc_cnt; ++i) {
writes[i] = pegasus::create_remove_request(key);
}
const int err = _server_write->on_batched_write_requests(
- writes, total_rpc_cnt, decree, 0, nullptr);
+ writes.get(), total_rpc_cnt, decree, 0, nullptr);
switch (err) {
case FAIL_DB_WRITE_BATCH_PUT:
case FAIL_DB_WRITE_BATCH_DELETE:
diff --git a/src/shell/commands/local_partition_split.cpp
b/src/shell/commands/local_partition_split.cpp
index f880f4246..24ac53192 100644
--- a/src/shell/commands/local_partition_split.cpp
+++ b/src/shell/commands/local_partition_split.cpp
@@ -233,7 +233,7 @@ bool split_file(const LocalPartitionSplitContext &lpsc,
// 4. Iterate the sst file though sst reader, then split it to multiple
sst files
// though sst writers.
- std::shared_ptr<rocksdb::SstFileWriter> writers[lpsc.split_count];
+ std::vector<std::shared_ptr<rocksdb::SstFileWriter>>
writers(lpsc.split_count);
std::unique_ptr<rocksdb::Iterator> iter(reader->NewIterator({}));
for (iter->SeekToFirst(); iter->Valid(); iter->Next()) {
const auto &skey = iter->key();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]