Clean up repeated field shared library exports.

This removes the built in "extern template" declarations because they continue to cause issues in shared library builds.  Users who need this optimization can define it themselves.  This also adds PROTOBUF_EXPORT to some symbols that were previously missing it.

PiperOrigin-RevId: 500223387
pull/11092/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent 570e12538c
commit 37a4656ad4
  1. 19
      src/google/protobuf/repeated_field.cc
  2. 50
      src/google/protobuf/repeated_field.h

@ -107,25 +107,6 @@ PROTOBUF_EXPORT_TEMPLATE_DEFINE void RepeatedField<absl::Cord>::CopyArray(
} }
} }
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField<bool>;
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField<int32_t>;
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField<uint32_t>;
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField<int64_t>;
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField<uint64_t>;
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField<float>;
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField<double>;
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField<absl::Cord>;
namespace internal {
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedIterator<bool>;
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedIterator<int32_t>;
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedIterator<uint32_t>;
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedIterator<int64_t>;
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedIterator<uint64_t>;
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedIterator<float>;
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedIterator<double>;
template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedIterator<absl::Cord>;
} // namespace internal
} // namespace protobuf } // namespace protobuf
} // namespace google } // namespace google

@ -1032,36 +1032,40 @@ struct ElementCopier<Element, true> {
// some specializations for them. Some definitions are in the .cc file. // some specializations for them. Some definitions are in the .cc file.
template <> template <>
inline void RepeatedField<absl::Cord>::RemoveLast() { PROTOBUF_EXPORT inline void RepeatedField<absl::Cord>::RemoveLast() {
GOOGLE_ABSL_DCHECK_GT(current_size_, 0); GOOGLE_ABSL_DCHECK_GT(current_size_, 0);
Mutable(size() - 1)->Clear(); Mutable(size() - 1)->Clear();
ExchangeCurrentSize(current_size_ - 1); ExchangeCurrentSize(current_size_ - 1);
} }
template <> template <>
void RepeatedField<absl::Cord>::Clear(); PROTOBUF_EXPORT void RepeatedField<absl::Cord>::Clear();
template <> template <>
inline void RepeatedField<absl::Cord>::SwapElements(int index1, int index2) { PROTOBUF_EXPORT inline void RepeatedField<absl::Cord>::SwapElements(
int index1, int index2) {
Mutable(index1)->swap(*Mutable(index2)); Mutable(index1)->swap(*Mutable(index2));
} }
template <> template <>
size_t RepeatedField<absl::Cord>::SpaceUsedExcludingSelfLong() const; PROTOBUF_EXPORT size_t
RepeatedField<absl::Cord>::SpaceUsedExcludingSelfLong() const;
template <> template <>
void RepeatedField<absl::Cord>::Truncate(int new_size); PROTOBUF_EXPORT void RepeatedField<absl::Cord>::Truncate(int new_size);
template <> template <>
void RepeatedField<absl::Cord>::Resize(int new_size, const absl::Cord& value); PROTOBUF_EXPORT void RepeatedField<absl::Cord>::Resize(int new_size,
const absl::Cord& value);
template <> template <>
void RepeatedField<absl::Cord>::MoveArray(absl::Cord* to, absl::Cord* from, PROTOBUF_EXPORT void RepeatedField<absl::Cord>::MoveArray(absl::Cord* to,
int size); absl::Cord* from,
int size);
template <> template <>
void RepeatedField<absl::Cord>::CopyArray(absl::Cord* to, PROTOBUF_EXPORT void RepeatedField<absl::Cord>::CopyArray(
const absl::Cord* from, int size); absl::Cord* to, const absl::Cord* from, int size);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@ -1236,32 +1240,6 @@ internal::RepeatedFieldBackInsertIterator<T> RepeatedFieldBackInserter(
return internal::RepeatedFieldBackInsertIterator<T>(mutable_field); return internal::RepeatedFieldBackInsertIterator<T>(mutable_field);
} }
// Extern declarations of common instantiations to reduce library bloat.
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField<bool>;
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField<int32_t>;
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField<uint32_t>;
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField<int64_t>;
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField<uint64_t>;
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField<float>;
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField<double>;
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE
RepeatedField<absl::Cord>;
namespace internal {
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedIterator<bool>;
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE
RepeatedIterator<int32_t>;
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE
RepeatedIterator<uint32_t>;
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE
RepeatedIterator<int64_t>;
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE
RepeatedIterator<uint64_t>;
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedIterator<float>;
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedIterator<double>;
extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE
RepeatedIterator<absl::Cord>;
} // namespace internal
} // namespace protobuf } // namespace protobuf
} // namespace google } // namespace google

Loading…
Cancel
Save