Skip to content

Commit

Permalink
Merge pull request #12702 from fowles/23.x
Browse files Browse the repository at this point in the history
Cherry pick various portability fixes from mainline
  • Loading branch information
fowles committed May 8, 2023
2 parents d5a1b09 + b880933 commit abb293d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
6 changes: 5 additions & 1 deletion cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ list(APPEND _pc_targets "utf8_range")

set(_protobuf_PC_REQUIRES "")
set(_sep "")
foreach (_target IN LISTS _pc_target_list)
foreach (_target IN LISTS _pc_targets)
string(CONCAT _protobuf_PC_REQUIRES "${_protobuf_PC_REQUIRES}" "${_sep}" "${_target}")
set(_sep " ")
endforeach ()
set(_protobuf_PC_CFLAGS)
if (protobuf_BUILD_SHARED_LIBS)
set(_protobuf_PC_CFLAGS -DPROTOBUF_USE_DLLS)
endif ()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/protobuf.pc.cmake
${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc @ONLY)
Expand Down
2 changes: 1 addition & 1 deletion cmake/protobuf-lite.pc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Description: Google's Data Interchange Format
Version: @protobuf_VERSION@
Requires: @_protobuf_PC_REQUIRES@
Libs: -L${libdir} -lprotobuf-lite @CMAKE_THREAD_LIBS_INIT@
Cflags: -I${includedir}
Cflags: -I${includedir} @_protobuf_PC_CFLAGS@
Conflicts: protobuf
2 changes: 1 addition & 1 deletion cmake/protobuf.pc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Description: Google's Data Interchange Format
Version: @protobuf_VERSION@
Requires: @_protobuf_PC_REQUIRES@
Libs: -L${libdir} -lprotobuf @CMAKE_THREAD_LIBS_INIT@
Cflags: -I${includedir}
Cflags: -I${includedir} @_protobuf_PC_CFLAGS@
Conflicts: protobuf-lite
10 changes: 6 additions & 4 deletions src/google/protobuf/arena_align.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct ArenaAlignDefault {
}

static inline PROTOBUF_ALWAYS_INLINE constexpr size_t Ceil(size_t n) {
return (n + align - 1) & -align;
return (n + align - 1) & ~(align - 1);
}
static inline PROTOBUF_ALWAYS_INLINE constexpr size_t Floor(size_t n) {
return (n & ~(align - 1));
Expand All @@ -113,7 +113,7 @@ struct ArenaAlignDefault {
template <typename T>
static inline PROTOBUF_ALWAYS_INLINE T* Ceil(T* ptr) {
uintptr_t intptr = reinterpret_cast<uintptr_t>(ptr);
return reinterpret_cast<T*>((intptr + align - 1) & -align);
return reinterpret_cast<T*>((intptr + align - 1) & ~(align - 1));
}

template <typename T>
Expand Down Expand Up @@ -142,7 +142,9 @@ struct ArenaAlign {
return (reinterpret_cast<uintptr_t>(ptr) & (align - 1)) == 0U;
}

constexpr size_t Ceil(size_t n) const { return (n + align - 1) & -align; }
constexpr size_t Ceil(size_t n) const {
return (n + align - 1) & ~(align - 1);
}
constexpr size_t Floor(size_t n) const { return (n & ~(align - 1)); }

constexpr size_t Padded(size_t n) const {
Expand All @@ -156,7 +158,7 @@ struct ArenaAlign {
template <typename T>
T* Ceil(T* ptr) const {
uintptr_t intptr = reinterpret_cast<uintptr_t>(ptr);
return reinterpret_cast<T*>((intptr + align - 1) & -align);
return reinterpret_cast<T*>((intptr + align - 1) & ~(align - 1));
}

template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/repeated_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ template <typename Element>
inline RepeatedField<Element>::RepeatedField(const RepeatedField& rhs)
: current_size_(0), total_size_(0), arena_or_elements_(nullptr) {
StaticValidityCheck();
if (size_t size = rhs.current_size_) {
if (auto size = rhs.current_size_) {
Grow(0, size);
ExchangeCurrentSize(size);
UninitializedCopyN(rhs.elements(), size, unsafe_elements());
Expand Down Expand Up @@ -775,7 +775,7 @@ inline void RepeatedField<Element>::Clear() {
template <typename Element>
inline void RepeatedField<Element>::MergeFrom(const RepeatedField& rhs) {
ABSL_DCHECK_NE(&rhs, this);
if (size_t size = rhs.current_size_) {
if (auto size = rhs.current_size_) {
Reserve(current_size_ + size);
Element* dst = elements() + ExchangeCurrentSize(current_size_ + size);
UninitializedCopyN(rhs.elements(), size, dst);
Expand Down

0 comments on commit abb293d

Please sign in to comment.