Skip to content

Commit 8d5d7cc

Browse files
committed
Fix LIBPROTOBUF_PROTOBUF annotations for buliding protobuf as DLLs.
1 parent 496d47c commit 8d5d7cc

File tree

8 files changed

+33
-18
lines changed

8 files changed

+33
-18
lines changed

src/google/protobuf/arena.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ namespace google {
3838
namespace protobuf {
3939

4040
google::protobuf::internal::SequenceNumber Arena::lifecycle_id_generator_;
41+
#ifdef PROTOBUF_USE_DLLS
42+
Arena::ThreadCache& Arena::thread_cache() {
43+
static GOOGLE_THREAD_LOCAL ThreadCache thread_cache_ = { -1, NULL };
44+
return thread_cache_;
45+
}
46+
#else
4147
GOOGLE_THREAD_LOCAL Arena::ThreadCache Arena::thread_cache_ = { -1, NULL };
48+
#endif
4249

4350
void Arena::Init(const ArenaOptions& options) {
4451
lifecycle_id_ = lifecycle_id_generator_.GetNext();
@@ -130,18 +137,18 @@ void* Arena::AllocateAligned(size_t n) {
130137
// If this thread already owns a block in this arena then try to use that.
131138
// This fast path optimizes the case where multiple threads allocate from the
132139
// same arena.
133-
if (thread_cache_.last_lifecycle_id_seen == lifecycle_id_ &&
134-
thread_cache_.last_block_used_ != NULL) {
135-
if (thread_cache_.last_block_used_->avail() < n) {
140+
if (thread_cache().last_lifecycle_id_seen == lifecycle_id_ &&
141+
thread_cache().last_block_used_ != NULL) {
142+
if (thread_cache().last_block_used_->avail() < n) {
136143
return SlowAlloc(n);
137144
}
138-
return AllocFromBlock(thread_cache_.last_block_used_, n);
145+
return AllocFromBlock(thread_cache().last_block_used_, n);
139146
}
140147

141148
// Check whether we own the last accessed block on this arena.
142149
// This fast path optimizes the case where a single thread uses multiple
143150
// arenas.
144-
void* me = &thread_cache_;
151+
void* me = &thread_cache();
145152
Block* b = reinterpret_cast<Block*>(google::protobuf::internal::Acquire_Load(&hint_));
146153
if (!b || b->owner != me || b->avail() < n) {
147154
// If the next block to allocate from is the first block, try to claim it
@@ -169,7 +176,7 @@ void* Arena::AllocFromBlock(Block* b, size_t n) {
169176
}
170177

171178
void* Arena::SlowAlloc(size_t n) {
172-
void* me = &thread_cache_;
179+
void* me = &thread_cache();
173180
Block* b = FindBlock(me); // Find block owned by me.
174181
// See if allocation fits in my latest block.
175182
if (b != NULL && b->avail() >= n) {

src/google/protobuf/arena.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,12 @@ class LIBPROTOBUF_EXPORT Arena {
312312

313313
static const size_t kHeaderSize = sizeof(Block);
314314
static google::protobuf::internal::SequenceNumber lifecycle_id_generator_;
315+
#ifdef PROTOBUF_USE_DLLS
316+
static ThreadCache& thread_cache();
317+
#else
315318
static GOOGLE_THREAD_LOCAL ThreadCache thread_cache_;
319+
static ThreadCache& thread_cache() { return thread_cache_; }
320+
#endif
316321

317322
// SFINAE for skipping addition to delete list for a Type. This is mainly to
318323
// skip proto2/proto1 message objects with cc_enable_arenas=true from being
@@ -434,8 +439,8 @@ class LIBPROTOBUF_EXPORT Arena {
434439
void CleanupList();
435440

436441
inline void SetThreadCacheBlock(Block* block) {
437-
thread_cache_.last_block_used_ = block;
438-
thread_cache_.last_lifecycle_id_seen = lifecycle_id_;
442+
thread_cache().last_block_used_ = block;
443+
thread_cache().last_lifecycle_id_seen = lifecycle_id_;
439444
}
440445

441446
int64 lifecycle_id_; // Unique for each arena. Changes on Reset().

src/google/protobuf/arenastring.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace google {
5353
namespace protobuf {
5454
namespace internal {
5555

56-
struct ArenaStringPtr {
56+
struct LIBPROTOBUF_EXPORT ArenaStringPtr {
5757
inline void Set(const ::std::string* default_value,
5858
const ::std::string& value, ::google::protobuf::Arena* arena) {
5959
if (ptr_ == default_value) {

src/google/protobuf/compiler/cpp/cpp_unittest.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ TEST(GeneratedMessageTest, Defaults) {
153153
&message.optional_import_message());
154154
}
155155

156+
#ifndef PROTOBUF_USE_DLLS
156157
TEST(GeneratedMessageTest, Int32StringConversion) {
157158
EXPECT_EQ("971", Int32ToString(971));
158159
EXPECT_EQ("(~0x7fffffff)", Int32ToString(kint32min));
@@ -165,6 +166,7 @@ TEST(GeneratedMessageTest, Int64StringConversion) {
165166
EXPECT_EQ("GOOGLE_LONGLONG(~0x7fffffffffffffff)", Int64ToString(kint64min));
166167
EXPECT_EQ("GOOGLE_LONGLONG(9223372036854775807)", Int64ToString(kint64max));
167168
}
169+
#endif // !PROTOBUF_USE_DLLS
168170

169171
TEST(GeneratedMessageTest, FloatingPointDefaults) {
170172
const unittest::TestExtremeDefaultValues& extreme_default =

src/google/protobuf/map.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class Map {
110110
~Map() { clear(); }
111111

112112
// Iterators
113-
class LIBPROTOBUF_EXPORT const_iterator
113+
class const_iterator
114114
: public std::iterator<std::forward_iterator_tag, value_type, ptrdiff_t,
115115
const value_type*, const value_type&> {
116116
typedef typename hash_map<Key, value_type*>::const_iterator InnerIt;
@@ -139,7 +139,7 @@ class Map {
139139
InnerIt it_;
140140
};
141141

142-
class LIBPROTOBUF_EXPORT iterator : public std::iterator<std::forward_iterator_tag, value_type> {
142+
class iterator : public std::iterator<std::forward_iterator_tag, value_type> {
143143
typedef typename hash_map<Key, value_type*>::iterator InnerIt;
144144

145145
public:
@@ -302,7 +302,7 @@ class Map {
302302

303303
template <typename K, typename V, FieldDescriptor::Type KeyProto,
304304
FieldDescriptor::Type ValueProto, int default_enum>
305-
friend class LIBPROTOBUF_EXPORT internal::MapField;
305+
friend class internal::MapField;
306306
};
307307

308308
} // namespace protobuf

src/google/protobuf/map_entry.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace internal {
4545

4646
// Register all MapEntry default instances so we can delete them in
4747
// ShutdownProtobufLibrary().
48-
void RegisterMapEntryDefaultInstance(MessageLite* default_instance);
48+
void LIBPROTOBUF_EXPORT RegisterMapEntryDefaultInstance(MessageLite* default_instance);
4949

5050
// This is the common base class for MapEntry. It is used by MapFieldBase in
5151
// reflection api, in which the static type of key and value is unknown.
@@ -84,7 +84,7 @@ class LIBPROTOBUF_EXPORT MapEntryBase : public Message {
8484
// Moreover, default_enum_value is used to initialize enum field in proto2.
8585
template <typename Key, typename Value, FieldDescriptor::Type KeyProtoType,
8686
FieldDescriptor::Type ValueProtoType, int default_enum_value>
87-
class LIBPROTOBUF_EXPORT MapEntry : public MapEntryBase {
87+
class MapEntry : public MapEntryBase {
8888
// Handlers for key/value's proto field type. Used to infer internal layout
8989
// and provide parsing/serialization support.
9090
typedef MapProtoTypeHandler<KeyProtoType> KeyProtoHandler;
@@ -363,7 +363,7 @@ class LIBPROTOBUF_EXPORT MapEntry : public MapEntryBase {
363363
template <typename KeyNested, typename ValueNested,
364364
FieldDescriptor::Type KeyProtoNested,
365365
FieldDescriptor::Type ValueProtoNested, int default_enum>
366-
class LIBPROTOBUF_EXPORT MapEntryWrapper
366+
class MapEntryWrapper
367367
: public MapEntry<KeyNested, ValueNested, KeyProtoNested,
368368
ValueProtoNested, default_enum> {
369369
typedef MapEntry<KeyNested, ValueNested, KeyProtoNested, ValueProtoNested,
@@ -394,7 +394,7 @@ class LIBPROTOBUF_EXPORT MapEntry : public MapEntryBase {
394394
template <typename KeyNested, typename ValueNested,
395395
FieldDescriptor::Type KeyProtoNested,
396396
FieldDescriptor::Type ValueProtoNested, int default_enum>
397-
class LIBPROTOBUF_EXPORT MapEnumEntryWrapper
397+
class MapEnumEntryWrapper
398398
: public MapEntry<KeyNested, ValueNested, KeyProtoNested,
399399
ValueProtoNested, default_enum> {
400400
typedef MapEntry<KeyNested, ValueNested, KeyProtoNested, ValueProtoNested,
@@ -433,7 +433,7 @@ class LIBPROTOBUF_EXPORT MapEntry : public MapEntryBase {
433433
template <typename K, typename V,
434434
FieldDescriptor::Type KType,
435435
FieldDescriptor::Type VType, int default_enum>
436-
friend class LIBPROTOBUF_EXPORT internal::MapField;
436+
friend class internal::MapField;
437437
friend class LIBPROTOBUF_EXPORT internal::GeneratedMessageReflection;
438438

439439
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntry);

src/google/protobuf/map_field.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class LIBPROTOBUF_EXPORT MapFieldBase {
137137
template<typename Key, typename T,
138138
FieldDescriptor::Type KeyProto,
139139
FieldDescriptor::Type ValueProto, int default_enum_value = 0>
140-
class LIBPROTOBUF_EXPORT MapField : public MapFieldBase {
140+
class MapField : public MapFieldBase {
141141
// Handlers for key/value's proto field type.
142142
typedef MapProtoTypeHandler<KeyProto> KeyProtoHandler;
143143
typedef MapProtoTypeHandler<ValueProto> ValueProtoHandler;

src/google/protobuf/message.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ const RepeatedField<TYPE>& Reflection::GetRepeatedField<TYPE>( \
967967
const Message& message, const FieldDescriptor* field) const; \
968968
\
969969
template<> \
970+
LIBPROTOBUF_EXPORT \
970971
RepeatedField<TYPE>* Reflection::MutableRepeatedField<TYPE>( \
971972
Message* message, const FieldDescriptor* field) const;
972973

0 commit comments

Comments
 (0)