This is an automated email from the ASF dual-hosted git repository. avamingli pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 273b9a2ffebe775a6da5fd39e31dcf131fedb04e Author: Zhang Mingli <[email protected]> AuthorDate: Thu May 28 18:23:05 2026 +0800 macOS: PAX C++ portability Compile-time fixes to let PAX build with Apple clang against Homebrew's modern protobuf (v22+). * file_system.h: typedef off64_t = off_t on macOS. glibc exposes off64_t for 32-bit programs opting into 64-bit file offsets; macOS's off_t is already 64-bit so there is no separate symbol. * pax_encoding_utils.{h,cc}: change BuildHistogram/ZigZagBuffers signatures from int64_t* to PG's int64* (long). On macOS x86_64 int64_t is 'long long', distinct from 'long' for overload resolution even though both are 64-bit. Using PG's int64 (consistently 'long' on every supported port) keeps callers from PG-typed buffers (e.g. DataBuffer<int64>::StartT) working on both platforms. * pax_delta_encoding.cc: replace 'uint8_t bit_widths[var] = {0};' (a gcc VLA-with-initializer extension that clang rejects) with std::vector<uint8_t>. * proto_wrappers.h: PG's c.h defines Min/Max macros and xlog_internal.h defines IsPowerOf2; abseil (pulled in by modern protobuf headers) declares identifiers with the same names. #undef them around the protobuf include, then restore PG's definitions afterwards. * protobuf_stream.{h,cc}: protobuf v22 removed the google::protobuf::int64 typedef. Use int64_t directly (which is the type of the base ZeroCopy{Output,Input}Stream::ByteCount() override anyway). --- .../pax_storage/src/cpp/storage/columns/pax_delta_encoding.cc | 8 ++++++++ .../pax_storage/src/cpp/storage/columns/pax_encoding_utils.cc | 4 ++-- contrib/pax_storage/src/cpp/storage/columns/pax_encoding_utils.h | 8 ++++++-- contrib/pax_storage/src/cpp/storage/file_system.h | 7 +++++++ contrib/pax_storage/src/cpp/storage/proto/proto_wrappers.h | 9 +++++++++ contrib/pax_storage/src/cpp/storage/proto/protobuf_stream.cc | 8 ++++---- contrib/pax_storage/src/cpp/storage/proto/protobuf_stream.h | 4 ++-- 7 files changed, 38 insertions(+), 10 deletions(-) diff --git a/contrib/pax_storage/src/cpp/storage/columns/pax_delta_encoding.cc b/contrib/pax_storage/src/cpp/storage/columns/pax_delta_encoding.cc index 3f4b5341c4a..2c1ae3045f4 100644 --- a/contrib/pax_storage/src/cpp/storage/columns/pax_delta_encoding.cc +++ b/contrib/pax_storage/src/cpp/storage/columns/pax_delta_encoding.cc @@ -454,7 +454,15 @@ size_t PaxDeltaDecoder<T>::Decoding() { if (remaining < mini_blocks_per_block_) break; + // VLA-with-initializer is a GCC extension; clang rejects it. Keep + // the (zero-overhead) stack VLA on gcc and only fall back to a + // heap std::vector under clang so Linux gcc performance is + // unchanged. +#if defined(__clang__) + std::vector<uint8_t> bit_widths(mini_blocks_per_block_, 0); +#else uint8_t bit_widths[mini_blocks_per_block_] = {0}; +#endif for (uint32_t i = 0; i < mini_blocks_per_block_; ++i) { bit_widths[i] = *p++; --remaining; diff --git a/contrib/pax_storage/src/cpp/storage/columns/pax_encoding_utils.cc b/contrib/pax_storage/src/cpp/storage/columns/pax_encoding_utils.cc index 0b07d08ad19..f32e533c880 100644 --- a/contrib/pax_storage/src/cpp/storage/columns/pax_encoding_utils.cc +++ b/contrib/pax_storage/src/cpp/storage/columns/pax_encoding_utils.cc @@ -112,7 +112,7 @@ uint32 FindClosestBits(int64 value) { return GetClosestBits(count); } -void BuildHistogram(int32 *histogram, int64_t *data, size_t number) { +void BuildHistogram(int32 *histogram, int64 *data, size_t number) { // histogram that store the encoded bit requirement for each values. // maximum number of bits that can encoded is 32 (refer FixedBitSizes) memset(histogram, 0, FixedBitSizes::kSIZE * sizeof(int32_t)); @@ -141,7 +141,7 @@ uint32_t GetPercentileBits(const int32 *const histogram, size_t histogram_len, return 0; } -void ZigZagBuffers(int64_t *input, int64_t *output, size_t number) { +void ZigZagBuffers(int64 *input, int64 *output, size_t number) { Assert(input && output); for (size_t i = 0; i < number; i++) { output[i] = ZigZag(input[i]); diff --git a/contrib/pax_storage/src/cpp/storage/columns/pax_encoding_utils.h b/contrib/pax_storage/src/cpp/storage/columns/pax_encoding_utils.h index 596351a757a..0334939c528 100644 --- a/contrib/pax_storage/src/cpp/storage/columns/pax_encoding_utils.h +++ b/contrib/pax_storage/src/cpp/storage/columns/pax_encoding_utils.h @@ -114,7 +114,11 @@ uint32 GetClosestAlignedBits(uint32 n); uint32 FindClosestBits(int64 value); // histogram functions -void BuildHistogram(int32 *histogram, int64_t *data, size_t number); +// NB: use PG's int64 (typedef'd to `long int` on every supported port) +// rather than C99 int64_t — on macOS x86_64 int64_t is `long long`, which +// is a distinct type from `long` for overload resolution even though both +// are 64-bit. +void BuildHistogram(int32 *histogram, int64 *data, size_t number); uint32_t GetPercentileBits(const int32 *histogram, size_t histogram_len, double p); @@ -154,6 +158,6 @@ inline int64 UnZigZagWithUnsigned(T value) { CBDB_RAISE(cbdb::CException::ExType::kExTypeLogicError); } -void ZigZagBuffers(int64_t *input, int64_t *output, size_t number); +void ZigZagBuffers(int64 *input, int64 *output, size_t number); } // namespace pax diff --git a/contrib/pax_storage/src/cpp/storage/file_system.h b/contrib/pax_storage/src/cpp/storage/file_system.h index 6569ee3b858..09e13ed1245 100644 --- a/contrib/pax_storage/src/cpp/storage/file_system.h +++ b/contrib/pax_storage/src/cpp/storage/file_system.h @@ -28,11 +28,18 @@ #pragma once #include <fcntl.h> +#include <sys/types.h> #include <functional> #include <string> #include <vector> +// glibc exposes off64_t for 32-bit programs opting into 64-bit file +// offsets. macOS's off_t is already 64-bit and there is no off64_t. +#ifdef __APPLE__ +typedef off_t off64_t; +#endif + #include "comm/common_io.h" #include "comm/pax_memory.h" diff --git a/contrib/pax_storage/src/cpp/storage/proto/proto_wrappers.h b/contrib/pax_storage/src/cpp/storage/proto/proto_wrappers.h index d577353c40b..3e57167f334 100644 --- a/contrib/pax_storage/src/cpp/storage/proto/proto_wrappers.h +++ b/contrib/pax_storage/src/cpp/storage/proto/proto_wrappers.h @@ -29,7 +29,16 @@ // The libproto defined `FATAL` inside as a marco linker #undef FATAL +// PG defines several macros (Min/Max in c.h, IsPowerOf2 in xlog_internal.h) +// whose names collide with abseil identifiers reached through protobuf +// headers. Suppress while including, restore the PG definitions after. +#undef Min +#undef Max +#undef IsPowerOf2 #include "storage/proto/micro_partition_stats.pb.h" #include "storage/proto/orc_proto.pb.h" #include "storage/proto/pax.pb.h" #define FATAL 22 +#define Min(x, y) ((x) < (y) ? (x) : (y)) +#define Max(x, y) ((x) > (y) ? (x) : (y)) +#define IsPowerOf2(x) (x > 0 && ((x) & ((x)-1)) == 0) diff --git a/contrib/pax_storage/src/cpp/storage/proto/protobuf_stream.cc b/contrib/pax_storage/src/cpp/storage/proto/protobuf_stream.cc index d2aac0388f2..238ef5a9fc6 100644 --- a/contrib/pax_storage/src/cpp/storage/proto/protobuf_stream.cc +++ b/contrib/pax_storage/src/cpp/storage/proto/protobuf_stream.cc @@ -75,9 +75,9 @@ void BufferedOutputStream::BackUp(int count) { } } -google::protobuf::int64 BufferedOutputStream::ByteCount() const { +int64_t BufferedOutputStream::ByteCount() const { Assert(data_buffer_); - return static_cast<google::protobuf::int64>(data_buffer_->Used()); + return static_cast<int64_t>(data_buffer_->Used()); } bool BufferedOutputStream::WriteAliasedRaw(const void * /*data*/, @@ -151,8 +151,8 @@ bool SeekableInputStream::Skip(int count) { return false; } -google::protobuf::int64 SeekableInputStream::ByteCount() const { - return static_cast<google::protobuf::int64>(data_buffer_.Used()); +int64_t SeekableInputStream::ByteCount() const { + return static_cast<int64_t>(data_buffer_.Used()); } } // namespace pax diff --git a/contrib/pax_storage/src/cpp/storage/proto/protobuf_stream.h b/contrib/pax_storage/src/cpp/storage/proto/protobuf_stream.h index 81463ce6eb9..5769b3eeae3 100644 --- a/contrib/pax_storage/src/cpp/storage/proto/protobuf_stream.h +++ b/contrib/pax_storage/src/cpp/storage/proto/protobuf_stream.h @@ -44,7 +44,7 @@ class BufferedOutputStream : public google::protobuf::io::ZeroCopyOutputStream { void BackUp(int count) override; - google::protobuf::int64 ByteCount() const override; + int64_t ByteCount() const override; bool WriteAliasedRaw(const void *data, int size) override; @@ -76,7 +76,7 @@ class SeekableInputStream : public google::protobuf::io::ZeroCopyInputStream { bool Skip(int count) override; - google::protobuf::int64 ByteCount() const override; + int64_t ByteCount() const override; private: DataBuffer<char> data_buffer_; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
