Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions score/datarouter/src/daemon/persistentlogging_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ PersistentLoggingConfig ReadPersistentLoggingConfig(const std::string& file_path
using ReadResult = PersistentLoggingConfig::ReadResult;

PersistentLoggingConfig config;
using UniqueFileT = std::unique_ptr<std::FILE, decltype(&fclose)>;
UniqueFileT fp(std::fopen(file_path.c_str(), "r"), &fclose);
auto file_deleter = [](std::FILE* f) { if (f) fclose(f); };
using UniqueFileT = std::unique_ptr<std::FILE, decltype(file_deleter)>;
UniqueFileT fp(std::fopen(file_path.c_str(), "r"), file_deleter);
if (nullptr == fp)
{
config.read_result = ReadResult::kErrorOpen;
Expand Down
3 changes: 3 additions & 0 deletions score/datarouter/test/ut/ut_logging/test_dltprotocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ TEST(DltProtocolTest, DISABLED_PackageFileDataShallReturnsNulloptIfItWorkedOnAlr
ASSERT_TRUE(file != nullptr) << "The file used in the unit test is missed! The file: " << kFileName;
fclose(file); // Close the file immediately.

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuse-after-free"
auto result = PackageFileData(data_span, file, serial_number, pkg_number);
#pragma GCC diagnostic pop
EXPECT_EQ(result, std::nullopt);
}

Expand Down
11 changes: 11 additions & 0 deletions score/mw/log/rust/score_log_bridge/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@ config_setting(
],
)

config_setting(
name = "aarch64-linux",
constraint_values = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
],
)

cc_library(
name = "adapter",
srcs = ["src/adapter.cpp"],
# C++/Rust interface objects must share layout.
defines = select({
":x86_64-linux": ["x86_64_linux"],
":aarch64-linux": ["aarch64_linux"],
":arm64-qnx": ["arm64_qnx"],
":x86_64-qnx": ["x86_64_qnx"],
"//conditions:default": [],
Expand All @@ -65,6 +74,7 @@ rust_library(
# C++/Rust interface objects must share layout.
crate_features = select({
":x86_64-linux": ["x86_64_linux"],
":aarch64-linux": ["aarch64_linux"],
":arm64-qnx": ["arm64_qnx"],
":x86_64-qnx": ["x86_64_qnx"],
"//conditions:default": [],
Expand Down Expand Up @@ -94,6 +104,7 @@ rust_test(
crate = "score_log_bridge",
crate_features = select({
":x86_64-linux": ["x86_64_linux"],
":aarch64-linux": ["aarch64_linux"],
":arm64-qnx": ["arm64_qnx"],
":x86_64-qnx": ["x86_64_qnx"],
"//conditions:default": [],
Expand Down
2 changes: 1 addition & 1 deletion score/mw/log/rust/score_log_bridge/src/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using namespace score::mw::log::detail;
// Those parameters must be:
// - managed by build system (using defines and features)
// - cross-checked between `ffi.rs` and `adapter.cpp`
#if defined(x86_64_linux) || defined(arm64_qnx) || defined(x86_64_qnx)
#if defined(x86_64_linux) || defined(aarch64_linux) || defined(arm64_qnx) || defined(x86_64_qnx)
// Expected size and alignment of `SlotHandle`.
static_assert(sizeof(SlotHandle) == 24);
static_assert(alignof(SlotHandle) == 8);
Expand Down
20 changes: 15 additions & 5 deletions score/mw/log/rust/score_log_bridge/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl From<&str> for Context {
let size = min(value.len(), 4);

// Copy data into array.
let mut data = [0; _];
let mut data = [0; 4];
// SAFETY:
// Copying is safe:
// - source is a `&str`.
Expand Down Expand Up @@ -127,7 +127,7 @@ impl From<&Context> for &str {
// Create a slice from pointer and size.
let slice = from_raw_parts(data, size);
// Create a UTF-8 string from a slice.
str::from_utf8_unchecked(slice)
core::str::from_utf8_unchecked(slice)
}
}
}
Expand Down Expand Up @@ -180,13 +180,23 @@ unsafe impl Sync for Recorder {}
/// Those parameters must be:
/// - managed by build system (using defines and features)
/// - cross-checked between `ffi.rs` and `adapter.cpp`
#[cfg(any(feature = "x86_64_linux", feature = "arm64_qnx", feature = "x86_64_qnx"))]
#[cfg(any(
feature = "x86_64_linux",
feature = "aarch64_linux",
feature = "arm64_qnx",
feature = "x86_64_qnx"
))]
#[repr(C, align(8))]
pub struct SlotHandleStorage {
_private: [u8; 24],
}

#[cfg(not(any(feature = "x86_64_linux", feature = "arm64_qnx", feature = "x86_64_qnx")))]
#[cfg(not(any(
feature = "x86_64_linux",
feature = "aarch64_linux",
feature = "arm64_qnx",
feature = "x86_64_qnx"
)))]
compile_error!("Unknown configuration, unable to check layout");

impl SlotHandleStorage {
Expand All @@ -212,7 +222,7 @@ impl SlotHandleStorage {
impl Default for SlotHandleStorage {
/// Create storage for `SlotHandle`.
fn default() -> Self {
Self { _private: [0; _] }
Self { _private: [0; 24] }
}
}

Expand Down
2 changes: 1 addition & 1 deletion score/mw/log/rust/score_log_bridge_cpp_init/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C" fn set_default_logger(
if !context_ptr.is_null() {
let context = unsafe {
let slice = from_raw_parts(context_ptr.cast(), context_size);
str::from_utf8(slice).expect("provided context is not a valid UTF-8 string")
core::str::from_utf8(slice).expect("provided context is not a valid UTF-8 string")
};
builder = builder.context(context);
}
Expand Down
Loading