Skip to content

Commit abb293d

Browse files
authored
Merge pull request #12702 from fowles/23.x
Cherry pick various portability fixes from mainline
2 parents d5a1b09 + b880933 commit abb293d

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

cmake/install.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ list(APPEND _pc_targets "utf8_range")
88

99
set(_protobuf_PC_REQUIRES "")
1010
set(_sep "")
11-
foreach (_target IN LISTS _pc_target_list)
11+
foreach (_target IN LISTS _pc_targets)
1212
string(CONCAT _protobuf_PC_REQUIRES "${_protobuf_PC_REQUIRES}" "${_sep}" "${_target}")
1313
set(_sep " ")
1414
endforeach ()
15+
set(_protobuf_PC_CFLAGS)
16+
if (protobuf_BUILD_SHARED_LIBS)
17+
set(_protobuf_PC_CFLAGS -DPROTOBUF_USE_DLLS)
18+
endif ()
1519

1620
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/protobuf.pc.cmake
1721
${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc @ONLY)

cmake/protobuf-lite.pc.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ Description: Google's Data Interchange Format
88
Version: @protobuf_VERSION@
99
Requires: @_protobuf_PC_REQUIRES@
1010
Libs: -L${libdir} -lprotobuf-lite @CMAKE_THREAD_LIBS_INIT@
11-
Cflags: -I${includedir}
11+
Cflags: -I${includedir} @_protobuf_PC_CFLAGS@
1212
Conflicts: protobuf

cmake/protobuf.pc.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ Description: Google's Data Interchange Format
88
Version: @protobuf_VERSION@
99
Requires: @_protobuf_PC_REQUIRES@
1010
Libs: -L${libdir} -lprotobuf @CMAKE_THREAD_LIBS_INIT@
11-
Cflags: -I${includedir}
11+
Cflags: -I${includedir} @_protobuf_PC_CFLAGS@
1212
Conflicts: protobuf-lite

src/google/protobuf/arena_align.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ struct ArenaAlignDefault {
9999
}
100100

101101
static inline PROTOBUF_ALWAYS_INLINE constexpr size_t Ceil(size_t n) {
102-
return (n + align - 1) & -align;
102+
return (n + align - 1) & ~(align - 1);
103103
}
104104
static inline PROTOBUF_ALWAYS_INLINE constexpr size_t Floor(size_t n) {
105105
return (n & ~(align - 1));
@@ -113,7 +113,7 @@ struct ArenaAlignDefault {
113113
template <typename T>
114114
static inline PROTOBUF_ALWAYS_INLINE T* Ceil(T* ptr) {
115115
uintptr_t intptr = reinterpret_cast<uintptr_t>(ptr);
116-
return reinterpret_cast<T*>((intptr + align - 1) & -align);
116+
return reinterpret_cast<T*>((intptr + align - 1) & ~(align - 1));
117117
}
118118

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

145-
constexpr size_t Ceil(size_t n) const { return (n + align - 1) & -align; }
145+
constexpr size_t Ceil(size_t n) const {
146+
return (n + align - 1) & ~(align - 1);
147+
}
146148
constexpr size_t Floor(size_t n) const { return (n & ~(align - 1)); }
147149

148150
constexpr size_t Padded(size_t n) const {
@@ -156,7 +158,7 @@ struct ArenaAlign {
156158
template <typename T>
157159
T* Ceil(T* ptr) const {
158160
uintptr_t intptr = reinterpret_cast<uintptr_t>(ptr);
159-
return reinterpret_cast<T*>((intptr + align - 1) & -align);
161+
return reinterpret_cast<T*>((intptr + align - 1) & ~(align - 1));
160162
}
161163

162164
template <typename T>

src/google/protobuf/repeated_field.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ template <typename Element>
494494
inline RepeatedField<Element>::RepeatedField(const RepeatedField& rhs)
495495
: current_size_(0), total_size_(0), arena_or_elements_(nullptr) {
496496
StaticValidityCheck();
497-
if (size_t size = rhs.current_size_) {
497+
if (auto size = rhs.current_size_) {
498498
Grow(0, size);
499499
ExchangeCurrentSize(size);
500500
UninitializedCopyN(rhs.elements(), size, unsafe_elements());
@@ -775,7 +775,7 @@ inline void RepeatedField<Element>::Clear() {
775775
template <typename Element>
776776
inline void RepeatedField<Element>::MergeFrom(const RepeatedField& rhs) {
777777
ABSL_DCHECK_NE(&rhs, this);
778-
if (size_t size = rhs.current_size_) {
778+
if (auto size = rhs.current_size_) {
779779
Reserve(current_size_ + size);
780780
Element* dst = elements() + ExchangeCurrentSize(current_size_ + size);
781781
UninitializedCopyN(rhs.elements(), size, dst);

0 commit comments

Comments
 (0)