From c60bddafc0c19a7b4b97e3651e938283c1fe5d2c Mon Sep 17 00:00:00 2001 From: Luke Metro Date: Fri, 15 Nov 2024 19:34:05 -0800 Subject: [PATCH] Inline CPP functions in inl files Missing these isn't a huge deal for smaller projects but causes issues with the address sanitizer or with linkers when this repo is a part of a library. --- cpp/mcap/include/mcap/reader.inl | 204 +++++++++++++++---------------- cpp/mcap/include/mcap/types.inl | 6 +- cpp/mcap/include/mcap/writer.inl | 174 +++++++++++++------------- 3 files changed, 192 insertions(+), 192 deletions(-) diff --git a/cpp/mcap/include/mcap/reader.inl b/cpp/mcap/include/mcap/reader.inl index ec1343de9a..a5dd74bc06 100644 --- a/cpp/mcap/include/mcap/reader.inl +++ b/cpp/mcap/include/mcap/reader.inl @@ -11,20 +11,20 @@ namespace mcap { -bool CompareChunkIndexes(const ChunkIndex& a, const ChunkIndex& b) { +inline bool CompareChunkIndexes(const ChunkIndex& a, const ChunkIndex& b) { return a.chunkStartOffset < b.chunkStartOffset; } // BufferReader //////////////////////////////////////////////////////////////// -void BufferReader::reset(const std::byte* data, uint64_t size, uint64_t uncompressedSize) { +inline void BufferReader::reset(const std::byte* data, uint64_t size, uint64_t uncompressedSize) { (void)uncompressedSize; assert(size == uncompressedSize); data_ = data; size_ = size; } -uint64_t BufferReader::read(std::byte** output, uint64_t offset, uint64_t size) { +inline uint64_t BufferReader::read(std::byte** output, uint64_t offset, uint64_t size) { if (!data_ || offset >= size_) { return 0; } @@ -34,17 +34,17 @@ uint64_t BufferReader::read(std::byte** output, uint64_t offset, uint64_t size) return std::min(size, available); } -uint64_t BufferReader::size() const { +inline uint64_t BufferReader::size() const { return size_; } -Status BufferReader::status() const { +inline Status BufferReader::status() const { return StatusCode::Success; } // FileReader ////////////////////////////////////////////////////////////////// -FileReader::FileReader(std::FILE* file) +inline FileReader::FileReader(std::FILE* file) : file_(file) , size_(0) , position_(0) { @@ -56,11 +56,11 @@ FileReader::FileReader(std::FILE* file) std::fseek(file_, 0, SEEK_SET); } -uint64_t FileReader::size() const { +inline uint64_t FileReader::size() const { return size_; } -uint64_t FileReader::read(std::byte** output, uint64_t offset, uint64_t size) { +inline uint64_t FileReader::read(std::byte** output, uint64_t offset, uint64_t size) { if (offset >= size_) { return 0; } @@ -84,7 +84,7 @@ uint64_t FileReader::read(std::byte** output, uint64_t offset, uint64_t size) { // FileStreamReader //////////////////////////////////////////////////////////// -FileStreamReader::FileStreamReader(std::ifstream& stream) +inline FileStreamReader::FileStreamReader(std::ifstream& stream) : stream_(stream) , position_(0) { assert(stream.is_open()); @@ -95,11 +95,11 @@ FileStreamReader::FileStreamReader(std::ifstream& stream) stream_.seekg(0, stream.beg); } -uint64_t FileStreamReader::size() const { +inline uint64_t FileStreamReader::size() const { return size_; } -uint64_t FileStreamReader::read(std::byte** output, uint64_t offset, uint64_t size) { +inline uint64_t FileStreamReader::read(std::byte** output, uint64_t offset, uint64_t size) { if (offset >= size_) { return 0; } @@ -124,7 +124,7 @@ uint64_t FileStreamReader::read(std::byte** output, uint64_t offset, uint64_t si // LZ4Reader /////////////////////////////////////////////////////////////////// #ifndef MCAP_COMPRESSION_NO_LZ4 -LZ4Reader::LZ4Reader() { +inline LZ4Reader::LZ4Reader() { const LZ4F_errorCode_t err = LZ4F_createDecompressionContext((LZ4F_dctx**)&decompressionContext_, LZ4F_VERSION); if (LZ4F_isError(err)) { @@ -135,13 +135,13 @@ LZ4Reader::LZ4Reader() { } } -LZ4Reader::~LZ4Reader() { +inline LZ4Reader::~LZ4Reader() { if (decompressionContext_) { LZ4F_freeDecompressionContext((LZ4F_dctx*)decompressionContext_); } } -void LZ4Reader::reset(const std::byte* data, uint64_t size, uint64_t uncompressedSize) { +inline void LZ4Reader::reset(const std::byte* data, uint64_t size, uint64_t uncompressedSize) { if (!decompressionContext_) { return; } @@ -151,7 +151,7 @@ void LZ4Reader::reset(const std::byte* data, uint64_t size, uint64_t uncompresse uncompressedSize_ = uncompressedData_.size(); } -uint64_t LZ4Reader::read(std::byte** output, uint64_t offset, uint64_t size) { +inline uint64_t LZ4Reader::read(std::byte** output, uint64_t offset, uint64_t size) { if (offset >= uncompressedSize_) { return 0; } @@ -161,14 +161,14 @@ uint64_t LZ4Reader::read(std::byte** output, uint64_t offset, uint64_t size) { return std::min(size, available); } -uint64_t LZ4Reader::size() const { +inline uint64_t LZ4Reader::size() const { return uncompressedSize_; } -Status LZ4Reader::status() const { +inline Status LZ4Reader::status() const { return status_; } -Status LZ4Reader::decompressAll(const std::byte* data, uint64_t compressedSize, +inline Status LZ4Reader::decompressAll(const std::byte* data, uint64_t compressedSize, uint64_t uncompressedSize, ByteArray* output) { if (!decompressionContext_) { return status_; @@ -216,11 +216,11 @@ Status LZ4Reader::decompressAll(const std::byte* data, uint64_t compressedSize, // ZStdReader ////////////////////////////////////////////////////////////////// #ifndef MCAP_COMPRESSION_NO_ZSTD -void ZStdReader::reset(const std::byte* data, uint64_t size, uint64_t uncompressedSize) { +inline void ZStdReader::reset(const std::byte* data, uint64_t size, uint64_t uncompressedSize) { status_ = DecompressAll(data, size, uncompressedSize, &uncompressedData_); } -uint64_t ZStdReader::read(std::byte** output, uint64_t offset, uint64_t size) { +inline uint64_t ZStdReader::read(std::byte** output, uint64_t offset, uint64_t size) { if (offset >= uncompressedData_.size()) { return 0; } @@ -230,15 +230,15 @@ uint64_t ZStdReader::read(std::byte** output, uint64_t offset, uint64_t size) { return std::min(size, available); } -uint64_t ZStdReader::size() const { +inline uint64_t ZStdReader::size() const { return uncompressedData_.size(); } -Status ZStdReader::status() const { +inline Status ZStdReader::status() const { return status_; } -Status ZStdReader::DecompressAll(const std::byte* data, uint64_t compressedSize, +inline Status ZStdReader::DecompressAll(const std::byte* data, uint64_t compressedSize, uint64_t uncompressedSize, ByteArray* output) { auto result = Status(); @@ -266,11 +266,11 @@ Status ZStdReader::DecompressAll(const std::byte* data, uint64_t compressedSize, // McapReader ////////////////////////////////////////////////////////////////// -McapReader::~McapReader() { +inline McapReader::~McapReader() { close(); } -Status McapReader::open(IReadable& reader) { +inline Status McapReader::open(IReadable& reader) { reset_(); const uint64_t fileSize = reader.size(); @@ -322,7 +322,7 @@ Status McapReader::open(IReadable& reader) { return StatusCode::Success; } -Status McapReader::open(std::string_view filename) { +inline Status McapReader::open(std::string_view filename) { if (file_) { std::fclose(file_); file_ = nullptr; @@ -337,12 +337,12 @@ Status McapReader::open(std::string_view filename) { return open(*fileInput_); } -Status McapReader::open(std::ifstream& stream) { +inline Status McapReader::open(std::ifstream& stream) { fileStreamInput_ = std::make_unique(stream); return open(*fileStreamInput_); } -void McapReader::close() { +inline void McapReader::close() { input_ = nullptr; if (file_) { std::fclose(file_); @@ -353,7 +353,7 @@ void McapReader::close() { reset_(); } -void McapReader::reset_() { +inline void McapReader::reset_() { header_ = std::nullopt; footer_ = std::nullopt; statistics_ = std::nullopt; @@ -366,7 +366,7 @@ void McapReader::reset_() { parsedSummary_ = false; } -Status McapReader::readSummary(ReadSummaryMethod method, const ProblemCallback& onProblem) { +inline Status McapReader::readSummary(ReadSummaryMethod method, const ProblemCallback& onProblem) { if (!input_) { const Status status{StatusCode::NotOpen}; onProblem(status); @@ -410,7 +410,7 @@ Status McapReader::readSummary(ReadSummaryMethod method, const ProblemCallback& return StatusCode::Success; } -Status McapReader::readSummarySection_(IReadable& reader) { +inline Status McapReader::readSummarySection_(IReadable& reader) { const uint64_t fileSize = reader.size(); // Read the footer @@ -484,7 +484,7 @@ Status McapReader::readSummarySection_(IReadable& reader) { return readStatistics ? StatusCode::Success : StatusCode::MissingStatistics; } -Status McapReader::readSummaryFromScan_(IReadable& reader) { +inline Status McapReader::readSummaryFromScan_(IReadable& reader) { bool done = false; Statistics statistics{}; statistics.messageStartTime = EndOffset; @@ -559,12 +559,12 @@ Status McapReader::readSummaryFromScan_(IReadable& reader) { return StatusCode::Success; } -LinearMessageView McapReader::readMessages(Timestamp startTime, Timestamp endTime) { +inline LinearMessageView McapReader::readMessages(Timestamp startTime, Timestamp endTime) { const auto onProblem = [](const Status&) {}; return readMessages(onProblem, startTime, endTime); } -LinearMessageView McapReader::readMessages(const ProblemCallback& onProblem, Timestamp startTime, +inline LinearMessageView McapReader::readMessages(const ProblemCallback& onProblem, Timestamp startTime, Timestamp endTime) { ReadMessageOptions options; options.startTime = startTime; @@ -572,7 +572,7 @@ LinearMessageView McapReader::readMessages(const ProblemCallback& onProblem, Tim return readMessages(onProblem, options); } -LinearMessageView McapReader::readMessages(const ProblemCallback& onProblem, +inline LinearMessageView McapReader::readMessages(const ProblemCallback& onProblem, const ReadMessageOptions& options) { // Check that open() has been successfully called if (!dataSource() || dataStart_ == 0) { @@ -584,7 +584,7 @@ LinearMessageView McapReader::readMessages(const ProblemCallback& onProblem, return LinearMessageView{*this, options, startOffset, endOffset, onProblem}; } -std::pair McapReader::byteRange(Timestamp startTime, +inline std::pair McapReader::byteRange(Timestamp startTime, Timestamp endTime) const { if (!parsedSummary_ || chunkRanges_.empty()) { return {dataStart_, dataEnd_}; @@ -605,53 +605,53 @@ std::pair McapReader::byteRange(Timestamp startTime, return {dataStart, dataEnd}; } -IReadable* McapReader::dataSource() { +inline IReadable* McapReader::dataSource() { return input_; } -const std::optional
& McapReader::header() const { +inline const std::optional
& McapReader::header() const { return header_; } -const std::optional