Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: third_party/protobuf/patches/0012-extract-globals.patch

Issue 2756543002: Statically link libprotobuf_lite on Linux component builds (Closed)
Patch Set: Extract all global data to globals.cc Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/protobuf/README.chromium ('k') | third_party/protobuf/src/google/protobuf/arena.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 diff -ru --new-file protobuf/src/google/protobuf/arena.cc protobuf2/src/google/p rotobuf/arena.cc
2 --- protobuf/src/google/protobuf/arena.cc 2017-03-17 22:40:59.379153132 -0 700
3 +++ protobuf2/src/google/protobuf/arena.cc 2017-03-17 22:40:52.667151339 -0 700
4 @@ -39,7 +39,6 @@
5 namespace protobuf {
6
7
8 -google::protobuf::internal::SequenceNumber Arena::lifecycle_id_generator_;
9 #if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL)
10 Arena::ThreadCache& Arena::thread_cache() {
11 static internal::ThreadLocalStorage<ThreadCache>* thread_cache_ =
12 @@ -56,7 +55,7 @@
13 #endif
14
15 void Arena::Init() {
16 - lifecycle_id_ = lifecycle_id_generator_.GetNext();
17 + lifecycle_id_ = internal::cr_lifecycle_id_generator_.GetNext();
18 blocks_ = 0;
19 hint_ = 0;
20 owns_first_block_ = true;
21 @@ -99,7 +98,7 @@
22
23 uint64 Arena::Reset() {
24 // Invalidate any ThreadCaches pointing to any blocks we just destroyed.
25 - lifecycle_id_ = lifecycle_id_generator_.GetNext();
26 + lifecycle_id_ = internal::cr_lifecycle_id_generator_.GetNext();
27 return ResetInternal();
28 }
29
30 diff -ru --new-file protobuf/src/google/protobuf/arena.h protobuf2/src/google/pr otobuf/arena.h
31 --- protobuf/src/google/protobuf/arena.h 2017-03-17 22:40:59.379153132 -0 700
32 +++ protobuf2/src/google/protobuf/arena.h 2017-03-17 22:40:52.667151339 -0 700
33 @@ -70,6 +70,9 @@
34 template<typename Type>
35 class GenericTypeHandler; // repeated_field.h
36
37 +LIBPROTOBUF_EXPORT extern google::protobuf::internal::SequenceNumber
38 + cr_lifecycle_id_generator_;
39 +
40 // Templated cleanup methods.
41 template<typename T> void arena_destruct_object(void* object) {
42 reinterpret_cast<T*>(object)->~T();
43 @@ -552,7 +555,6 @@
44 };
45
46 static const size_t kHeaderSize = sizeof(Block);
47 - static google::protobuf::internal::SequenceNumber lifecycle_id_generator_;
48 #if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL)
49 // Android ndk does not support GOOGLE_THREAD_LOCAL keyword so we use a custo m thread
50 // local storage class we implemented.
51 diff -ru --new-file protobuf/src/google/protobuf/extension_set.cc protobuf2/src/ google/protobuf/extension_set.cc
52 --- protobuf/src/google/protobuf/extension_set.cc 2017-03-17 22:40:59.3791 53132 -0700
53 +++ protobuf2/src/google/protobuf/extension_set.cc 2017-03-17 22:40:52.6671 51339 -0700
54 @@ -46,6 +46,12 @@
55 namespace protobuf {
56 namespace internal {
57
58 +// Registry stuff.
59 +typedef hash_map<pair<const MessageLite*, int>, ExtensionInfo>
60 + ExtensionRegistry;
61 +extern ExtensionRegistry* cr_registry_;
62 +extern ProtobufOnceType cr_registry_init_;
63 +
64 namespace {
65
66 inline WireFormatLite::FieldType real_type(FieldType type) {
67 @@ -75,19 +81,13 @@
68 return false;
69 }
70
71 -// Registry stuff.
72 -typedef hash_map<pair<const MessageLite*, int>,
73 - ExtensionInfo> ExtensionRegistry;
74 -ExtensionRegistry* registry_ = NULL;
75 -GOOGLE_PROTOBUF_DECLARE_ONCE(registry_init_);
76 -
77 void DeleteRegistry() {
78 - delete registry_;
79 - registry_ = NULL;
80 + delete cr_registry_;
81 + cr_registry_ = NULL;
82 }
83
84 void InitRegistry() {
85 - registry_ = new ExtensionRegistry;
86 + cr_registry_ = new ExtensionRegistry;
87 OnShutdown(&DeleteRegistry);
88 }
89
90 @@ -95,9 +95,9 @@
91 // safety.
92 void Register(const MessageLite* containing_type,
93 int number, ExtensionInfo info) {
94 - ::google::protobuf::GoogleOnceInit(&registry_init_, &InitRegistry);
95 + ::google::protobuf::GoogleOnceInit(&cr_registry_init_, &InitRegistry);
96
97 - if (!InsertIfNotPresent(registry_, std::make_pair(containing_type, number),
98 + if (!InsertIfNotPresent(cr_registry_, std::make_pair(containing_type, number) ,
99 info)) {
100 GOOGLE_LOG(FATAL) << "Multiple extension registrations for type \""
101 << containing_type->GetTypeName()
102 @@ -107,9 +107,10 @@
103
104 const ExtensionInfo* FindRegisteredExtension(
105 const MessageLite* containing_type, int number) {
106 - return (registry_ == NULL)
107 + return (cr_registry_ == NULL)
108 ? NULL
109 - : FindOrNull(*registry_, std::make_pair(containing_type, number));
110 + : FindOrNull(*cr_registry_,
111 + std::make_pair(containing_type, number));
112 }
113
114 } // namespace
115 @@ -1748,68 +1749,45 @@
116 // ==================================================================
117 // Default repeated field instances for iterator-compatible accessors
118
119 -GOOGLE_PROTOBUF_DECLARE_ONCE(repeated_primitive_generic_type_traits_once_init_) ;
120 -GOOGLE_PROTOBUF_DECLARE_ONCE(repeated_string_type_traits_once_init_);
121 -GOOGLE_PROTOBUF_DECLARE_ONCE(repeated_message_generic_type_traits_once_init_);
122 -
123 void RepeatedPrimitiveGenericTypeTraits::InitializeDefaultRepeatedFields() {
124 - default_repeated_field_int32_ = new RepeatedField<int32>;
125 - default_repeated_field_int64_ = new RepeatedField<int64>;
126 - default_repeated_field_uint32_ = new RepeatedField<uint32>;
127 - default_repeated_field_uint64_ = new RepeatedField<uint64>;
128 - default_repeated_field_double_ = new RepeatedField<double>;
129 - default_repeated_field_float_ = new RepeatedField<float>;
130 - default_repeated_field_bool_ = new RepeatedField<bool>;
131 + cr_default_repeated_field_int32_ = new RepeatedField<int32>;
132 + cr_default_repeated_field_int64_ = new RepeatedField<int64>;
133 + cr_default_repeated_field_uint32_ = new RepeatedField<uint32>;
134 + cr_default_repeated_field_uint64_ = new RepeatedField<uint64>;
135 + cr_default_repeated_field_double_ = new RepeatedField<double>;
136 + cr_default_repeated_field_float_ = new RepeatedField<float>;
137 + cr_default_repeated_field_bool_ = new RepeatedField<bool>;
138 OnShutdown(&DestroyDefaultRepeatedFields);
139 }
140
141 void RepeatedPrimitiveGenericTypeTraits::DestroyDefaultRepeatedFields() {
142 - delete default_repeated_field_int32_;
143 - delete default_repeated_field_int64_;
144 - delete default_repeated_field_uint32_;
145 - delete default_repeated_field_uint64_;
146 - delete default_repeated_field_double_;
147 - delete default_repeated_field_float_;
148 - delete default_repeated_field_bool_;
149 + delete cr_default_repeated_field_int32_;
150 + delete cr_default_repeated_field_int64_;
151 + delete cr_default_repeated_field_uint32_;
152 + delete cr_default_repeated_field_uint64_;
153 + delete cr_default_repeated_field_double_;
154 + delete cr_default_repeated_field_float_;
155 + delete cr_default_repeated_field_bool_;
156 }
157
158 void RepeatedStringTypeTraits::InitializeDefaultRepeatedFields() {
159 - default_repeated_field_ = new RepeatedFieldType;
160 + cr_default_repeated_field_ = new RepeatedFieldType;
161 OnShutdown(&DestroyDefaultRepeatedFields);
162 }
163
164 void RepeatedStringTypeTraits::DestroyDefaultRepeatedFields() {
165 - delete default_repeated_field_;
166 + delete cr_default_repeated_field_;
167 }
168
169 void RepeatedMessageGenericTypeTraits::InitializeDefaultRepeatedFields() {
170 - default_repeated_field_ = new RepeatedFieldType;
171 + cr_default_repeated_field_ = new RepeatedFieldType;
172 OnShutdown(&DestroyDefaultRepeatedFields);
173 }
174
175 void RepeatedMessageGenericTypeTraits::DestroyDefaultRepeatedFields() {
176 - delete default_repeated_field_;
177 + delete cr_default_repeated_field_;
178 }
179
180 -const RepeatedField<int32>*
181 -RepeatedPrimitiveGenericTypeTraits::default_repeated_field_int32_ = NULL;
182 -const RepeatedField<int64>*
183 -RepeatedPrimitiveGenericTypeTraits::default_repeated_field_int64_ = NULL;
184 -const RepeatedField<uint32>*
185 -RepeatedPrimitiveGenericTypeTraits::default_repeated_field_uint32_ = NULL;
186 -const RepeatedField<uint64>*
187 -RepeatedPrimitiveGenericTypeTraits::default_repeated_field_uint64_ = NULL;
188 -const RepeatedField<double>*
189 -RepeatedPrimitiveGenericTypeTraits::default_repeated_field_double_ = NULL;
190 -const RepeatedField<float>*
191 -RepeatedPrimitiveGenericTypeTraits::default_repeated_field_float_ = NULL;
192 -const RepeatedField<bool>*
193 -RepeatedPrimitiveGenericTypeTraits::default_repeated_field_bool_ = NULL;
194 -const RepeatedStringTypeTraits::RepeatedFieldType*
195 -RepeatedStringTypeTraits::default_repeated_field_ = NULL;
196 -const RepeatedMessageGenericTypeTraits::RepeatedFieldType*
197 -RepeatedMessageGenericTypeTraits::default_repeated_field_ = NULL;
198 -
199 } // namespace internal
200 } // namespace protobuf
201 } // namespace google
202 diff -ru --new-file protobuf/src/google/protobuf/extension_set.h protobuf2/src/g oogle/protobuf/extension_set.h
203 --- protobuf/src/google/protobuf/extension_set.h 2017-03-17 22:40:59.3791 53132 -0700
204 +++ protobuf2/src/google/protobuf/extension_set.h 2017-03-17 22:40:52.6751 51341 -0700
205 @@ -731,13 +731,13 @@
206 template<typename Type> friend class RepeatedPrimitiveTypeTraits;
207 static void InitializeDefaultRepeatedFields();
208 static void DestroyDefaultRepeatedFields();
209 - static const RepeatedField<int32>* default_repeated_field_int32_;
210 - static const RepeatedField<int64>* default_repeated_field_int64_;
211 - static const RepeatedField<uint32>* default_repeated_field_uint32_;
212 - static const RepeatedField<uint64>* default_repeated_field_uint64_;
213 - static const RepeatedField<double>* default_repeated_field_double_;
214 - static const RepeatedField<float>* default_repeated_field_float_;
215 - static const RepeatedField<bool>* default_repeated_field_bool_;
216 + static const RepeatedField<int32>* cr_default_repeated_field_int32_;
217 + static const RepeatedField<int64>* cr_default_repeated_field_int64_;
218 + static const RepeatedField<uint32>* cr_default_repeated_field_uint32_;
219 + static const RepeatedField<uint64>* cr_default_repeated_field_uint64_;
220 + static const RepeatedField<double>* cr_default_repeated_field_double_;
221 + static const RepeatedField<float>* cr_default_repeated_field_float_;
222 + static const RepeatedField<bool>* cr_default_repeated_field_bool_;
223 };
224
225 #define PROTOBUF_DEFINE_PRIMITIVE_TYPE(TYPE, METHOD) \
226 @@ -769,7 +769,7 @@
227 &repeated_primitive_generic_type_traits_once_init_, \
228 &RepeatedPrimitiveGenericTypeTraits::InitializeDefaultRepeatedFields); \
229 return RepeatedPrimitiveGenericTypeTraits:: \
230 - default_repeated_field_##TYPE##_; \
231 + cr_default_repeated_field_##TYPE##_; \
232 } \
233 template<> inline const RepeatedField<TYPE>& \
234 RepeatedPrimitiveTypeTraits<TYPE>::GetRepeated(int number, \
235 @@ -821,7 +821,8 @@
236 }
237 };
238
239 -LIBPROTOBUF_EXPORT extern ProtobufOnceType repeated_string_type_traits_once_ini t_;
240 +LIBPROTOBUF_EXPORT extern ProtobufOnceType
241 + cr_repeated_string_type_traits_once_init_;
242
243 class LIBPROTOBUF_EXPORT RepeatedStringTypeTraits {
244 public:
245 @@ -866,15 +867,16 @@
246 }
247
248 static const RepeatedFieldType* GetDefaultRepeatedField() {
249 - ::google::protobuf::GoogleOnceInit(&repeated_string_type_traits_once_init_,
250 - &InitializeDefaultRepeatedFields);
251 - return default_repeated_field_;
252 + ::google::protobuf::GoogleOnceInit(
253 + &cr_repeated_string_type_traits_once_init_,
254 + &InitializeDefaultRepeatedFields);
255 + return cr_default_repeated_field_;
256 }
257
258 private:
259 static void InitializeDefaultRepeatedFields();
260 static void DestroyDefaultRepeatedFields();
261 - static const RepeatedFieldType *default_repeated_field_;
262 + static const RepeatedFieldType* cr_default_repeated_field_;
263 };
264
265 // -------------------------------------------------------------------
266 @@ -1043,7 +1045,7 @@
267 template<typename Type> friend class RepeatedMessageTypeTraits;
268 static void InitializeDefaultRepeatedFields();
269 static void DestroyDefaultRepeatedFields();
270 - static const RepeatedFieldType* default_repeated_field_;
271 + static const RepeatedFieldType* cr_default_repeated_field_;
272 };
273
274 template<typename Type> inline
275 @@ -1053,7 +1055,7 @@
276 &repeated_message_generic_type_traits_once_init_,
277 &RepeatedMessageGenericTypeTraits::InitializeDefaultRepeatedFields);
278 return reinterpret_cast<const RepeatedFieldType*>(
279 - RepeatedMessageGenericTypeTraits::default_repeated_field_);
280 + RepeatedMessageGenericTypeTraits::cr_default_repeated_field_);
281 }
282
283 // -------------------------------------------------------------------
284 diff -ru --new-file protobuf/src/google/protobuf/generated_message_util.cc proto buf2/src/google/protobuf/generated_message_util.cc
285 --- protobuf/src/google/protobuf/generated_message_util.cc 2017-03-17 22:40 :59.379153132 -0700
286 +++ protobuf2/src/google/protobuf/generated_message_util.cc 2017-03-17 22:40 :52.691151345 -0700
287 @@ -48,20 +48,18 @@
288 return std::numeric_limits<double>::quiet_NaN();
289 }
290
291 -const ::std::string* empty_string_;
292 -GOOGLE_PROTOBUF_DECLARE_ONCE(empty_string_once_init_);
293 -
294 void DeleteEmptyString() {
295 - delete empty_string_;
296 + delete cr_empty_string_;
297 }
298
299 void InitEmptyString() {
300 - empty_string_ = new string;
301 + cr_empty_string_ = new string;
302 OnShutdown(&DeleteEmptyString);
303 }
304
305 const ::std::string& GetEmptyString() {
306 - ::google::protobuf::GoogleOnceInit(&empty_string_once_init_, &InitEmptyString );
307 + ::google::protobuf::GoogleOnceInit(&cr_empty_string_once_init_,
308 + &InitEmptyString);
309 return GetEmptyStringAlreadyInited();
310 }
311
312 diff -ru --new-file protobuf/src/google/protobuf/generated_message_util.h protob uf2/src/google/protobuf/generated_message_util.h
313 --- protobuf/src/google/protobuf/generated_message_util.h 2017-03-17 22:40 :59.379153132 -0700
314 +++ protobuf2/src/google/protobuf/generated_message_util.h 2017-03-17 22:40 :52.655151335 -0700
315 @@ -77,14 +77,14 @@
316
317 // Default empty string object. Don't use the pointer directly. Instead, call
318 // GetEmptyString() to get the reference.
319 -LIBPROTOBUF_EXPORT extern const ::std::string* empty_string_;
320 -LIBPROTOBUF_EXPORT extern ProtobufOnceType empty_string_once_init_;
321 +LIBPROTOBUF_EXPORT extern const ::std::string* cr_empty_string_;
322 +LIBPROTOBUF_EXPORT extern ProtobufOnceType cr_empty_string_once_init_;
323 LIBPROTOBUF_EXPORT void InitEmptyString();
324
325
326 LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyStringAlreadyInited() {
327 - assert(empty_string_ != NULL);
328 - return *empty_string_;
329 + assert(cr_empty_string_ != NULL);
330 + return *cr_empty_string_;
331 }
332
333 LIBPROTOBUF_EXPORT const ::std::string& GetEmptyString();
334 diff -ru --new-file protobuf/src/google/protobuf/globals.cc protobuf2/src/google /protobuf/globals.cc
335 --- protobuf/src/google/protobuf/globals.cc 1969-12-31 16:00:00.000000000 -0 800
336 +++ protobuf2/src/google/protobuf/globals.cc 2017-03-17 22:40:52.655151335 -0 700
337 @@ -0,0 +1,113 @@
338 +// Protocol Buffers - Google's data interchange format
339 +// Copyright 2017 Google Inc. All rights reserved.
340 +// https://developers.google.com/protocol-buffers/
341 +//
342 +// Redistribution and use in source and binary forms, with or without
343 +// modification, are permitted provided that the following conditions are
344 +// met:
345 +//
346 +// * Redistributions of source code must retain the above copyright
347 +// notice, this list of conditions and the following disclaimer.
348 +// * Redistributions in binary form must reproduce the above
349 +// copyright notice, this list of conditions and the following disclaimer
350 +// in the documentation and/or other materials provided with the
351 +// distribution.
352 +// * Neither the name of Google Inc. nor the names of its
353 +// contributors may be used to endorse or promote products derived from
354 +// this software without specific prior written permission.
355 +//
356 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
357 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
358 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
359 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
360 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
361 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
362 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
363 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
364 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
365 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
366 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
367 +
368 +#include <google/protobuf/extension_set.h>
369 +#include <google/protobuf/generated_message_util.h>
370 +#include <google/protobuf/stubs/atomicops.h>
371 +#include <google/protobuf/stubs/hash.h>
372 +
373 +namespace google {
374 +namespace protobuf {
375 +namespace internal {
376 +
377 +SequenceNumber cr_lifecycle_id_generator_;
378 +
379 +const ::std::string* cr_empty_string_;
380 +GOOGLE_PROTOBUF_DECLARE_ONCE(cr_empty_string_once_init_);
381 +
382 +const RepeatedField<int32>*
383 + RepeatedPrimitiveGenericTypeTraits::cr_default_repeated_field_int32_ = NULL ;
384 +const RepeatedField<int64>*
385 + RepeatedPrimitiveGenericTypeTraits::cr_default_repeated_field_int64_ = NULL ;
386 +const RepeatedField<uint32>*
387 + RepeatedPrimitiveGenericTypeTraits::cr_default_repeated_field_uint32_ =
388 + NULL;
389 +const RepeatedField<uint64>*
390 + RepeatedPrimitiveGenericTypeTraits::cr_default_repeated_field_uint64_ =
391 + NULL;
392 +const RepeatedField<double>*
393 + RepeatedPrimitiveGenericTypeTraits::cr_default_repeated_field_double_ =
394 + NULL;
395 +const RepeatedField<float>*
396 + RepeatedPrimitiveGenericTypeTraits::cr_default_repeated_field_float_ = NULL ;
397 +const RepeatedField<bool>*
398 + RepeatedPrimitiveGenericTypeTraits::cr_default_repeated_field_bool_ = NULL;
399 +const RepeatedStringTypeTraits::RepeatedFieldType*
400 + RepeatedStringTypeTraits::cr_default_repeated_field_ = NULL;
401 +const RepeatedMessageGenericTypeTraits::RepeatedFieldType*
402 + RepeatedMessageGenericTypeTraits::cr_default_repeated_field_ = NULL;
403 +
404 +LIBPROTOBUF_EXPORT vector<void (*)()>* cr_shutdown_functions = NULL;
405 +LIBPROTOBUF_EXPORT Mutex* cr_shutdown_functions_mutex = NULL;
406 +LIBPROTOBUF_EXPORT GOOGLE_PROTOBUF_DECLARE_ONCE(cr_shutdown_functions_init);
407 +
408 +LIBPROTOBUF_EXPORT LogHandler* cr_log_handler_ = NULL;
409 +LIBPROTOBUF_EXPORT int cr_log_silencer_count_ = 0;
410 +
411 +LIBPROTOBUF_EXPORT Mutex* cr_log_silencer_count_mutex_ = NULL;
412 +LIBPROTOBUF_EXPORT GOOGLE_PROTOBUF_DECLARE_ONCE(cr_log_silencer_count_init_);
413 +
414 +GOOGLE_PROTOBUF_DECLARE_ONCE(
415 + cr_repeated_primitive_generic_type_traits_once_init_);
416 +GOOGLE_PROTOBUF_DECLARE_ONCE(cr_repeated_string_type_traits_once_init_);
417 +GOOGLE_PROTOBUF_DECLARE_ONCE(
418 + cr_repeated_message_generic_type_traits_once_init_);
419 +
420 +LIBPROTOBUF_EXPORT hash_map<pair<const MessageLite*, int>, ExtensionInfo>*
421 + cr_registry_ = NULL;
422 +LIBPROTOBUF_EXPORT GOOGLE_PROTOBUF_DECLARE_ONCE(cr_registry_init_);
423 +
424 +LIBPROTOBUF_EXPORT bool cr_module_initialized_ = false;
425 +struct InitDetector {
426 + InitDetector() { cr_module_initialized_ = true; }
427 +};
428 +InitDetector cr_init_detector;
429 +
430 +#ifdef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_X86_GCC_H_
431 +// Set the flags so that code will run correctly and conservatively, so even
432 +// if we haven't been initialized yet, we're probably single threaded, and our
433 +// default values should hopefully be pretty safe.
434 +LIBPROTOBUF_EXPORT struct AtomicOps_x86CPUFeatureStruct
435 + cr_AtomicOps_Internalx86CPUFeatures = {
436 + false, // bug can't exist before process spawns multiple threads
437 + false, // no SSE2
438 +};
439 +
440 +class AtomicOpsx86Initializer {
441 + public:
442 + AtomicOpsx86Initializer() { AtomicOps_Internalx86CPUFeaturesInit(); }
443 +};
444 +
445 +AtomicOpsx86Initializer cr_g_initer;
446 +#endif
447 +
448 +} // namespace internal
449 +} // namespace protobuf
450 +} // namespace google
451 diff -ru --new-file protobuf/src/google/protobuf/io/coded_stream.cc protobuf2/sr c/google/protobuf/io/coded_stream.cc
452 --- protobuf/src/google/protobuf/io/coded_stream.cc 2017-03-17 22:40:59.3831 53133 -0700
453 +++ protobuf2/src/google/protobuf/io/coded_stream.cc 2017-03-17 22:40:52.6591 51336 -0700
454 @@ -83,7 +83,7 @@
455 }
456
457 // Static.
458 -int CodedInputStream::default_recursion_limit_ = 100;
459 +int const CodedInputStream::default_recursion_limit_ = 100;
460
461
462 void CodedOutputStream::EnableAliasing(bool enabled) {
463 diff -ru --new-file protobuf/src/google/protobuf/io/coded_stream.h protobuf2/src /google/protobuf/io/coded_stream.h
464 --- protobuf/src/google/protobuf/io/coded_stream.h 2017-03-17 22:40:59.3831 53133 -0700
465 +++ protobuf2/src/google/protobuf/io/coded_stream.h 2017-03-17 22:40:52.6591 51336 -0700
466 @@ -613,7 +613,7 @@
467
468 static const int kDefaultTotalBytesWarningThreshold = 32 << 20; // 32MB
469
470 - static int default_recursion_limit_; // 100 by default.
471 + static const int default_recursion_limit_; // 100 by default.
472 };
473
474 // Class which encodes and writes binary data which is composed of varint-
475 diff -ru --new-file protobuf/src/google/protobuf/stubs/atomicops_internals_x86_g cc.cc protobuf2/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc
476 --- protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc 2017-03- 17 22:40:59.383153133 -0700
477 +++ protobuf2/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc 2017-03- 17 22:40:52.671151340 -0700
478 @@ -58,23 +58,13 @@
479 : "=a" (a), "=D" (b), "=c" (c), "=d" (d) : "a" (inp))
480 #endif
481
482 -#if defined(cpuid) // initialize the struct only on x86
483 -
484 namespace google {
485 namespace protobuf {
486 namespace internal {
487
488 -// Set the flags so that code will run correctly and conservatively, so even
489 -// if we haven't been initialized yet, we're probably single threaded, and our
490 -// default values should hopefully be pretty safe.
491 -struct AtomicOps_x86CPUFeatureStruct AtomicOps_Internalx86CPUFeatures = {
492 - false, // bug can't exist before process spawns multiple threads
493 - false, // no SSE2
494 -};
495 -
496 -namespace {
497 +#if defined(cpuid) // initialize the struct only on x86
498
499 -// Initialize the AtomicOps_Internalx86CPUFeatures struct.
500 +// Initialize the cr_AtomicOps_Internalx86CPUFeatures struct.
501 void AtomicOps_Internalx86CPUFeaturesInit() {
502 uint32_t eax;
503 uint32_t ebx;
504 @@ -107,31 +97,20 @@
505 if (strcmp(vendor, "AuthenticAMD") == 0 && // AMD
506 family == 15 &&
507 32 <= model && model <= 63) {
508 - AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = true;
509 + cr_AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = true;
510 } else {
511 - AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = false;
512 + cr_AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug = false;
513 }
514
515 // edx bit 26 is SSE2 which we use to tell use whether we can use mfence
516 - AtomicOps_Internalx86CPUFeatures.has_sse2 = ((edx >> 26) & 1);
517 + cr_AtomicOps_Internalx86CPUFeatures.has_sse2 = ((edx >> 26) & 1);
518 }
519 -
520 -class AtomicOpsx86Initializer {
521 - public:
522 - AtomicOpsx86Initializer() {
523 - AtomicOps_Internalx86CPUFeaturesInit();
524 - }
525 -};
526 -
527 -// A global to get use initialized on startup via static initialization :/
528 -AtomicOpsx86Initializer g_initer;
529 -
530 -} // namespace
531 +#else
532 +void AtomicOps_Internalx86CPUFeaturesInit() {}
533 +#endif // __i386__
534
535 } // namespace internal
536 } // namespace protobuf
537 } // namespace google
538
539 -#endif // __i386__
540 -
541 #endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_X86_GCC_H_
542 diff -ru --new-file protobuf/src/google/protobuf/stubs/atomicops_internals_x86_g cc.h protobuf2/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h
543 --- protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h 2017-03- 17 22:40:59.383153133 -0700
544 +++ protobuf2/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h 2017-03- 17 22:40:52.671151340 -0700
545 @@ -46,7 +46,9 @@
546 // after acquire compare-and-swap.
547 bool has_sse2; // Processor has SSE2.
548 };
549 -extern struct AtomicOps_x86CPUFeatureStruct AtomicOps_Internalx86CPUFeatures;
550 +extern struct AtomicOps_x86CPUFeatureStruct cr_AtomicOps_Internalx86CPUFeatures ;
551 +
552 +void AtomicOps_Internalx86CPUFeaturesInit();
553
554 #define ATOMICOPS_COMPILER_BARRIER() __asm__ __volatile__("" : : : "memory")
555
556 @@ -89,7 +91,7 @@
557 : "+r" (temp), "+m" (*ptr)
558 : : "memory");
559 // temp now holds the old value of *ptr
560 - if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
561 + if (cr_AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
562 __asm__ __volatile__("lfence" : : : "memory");
563 }
564 return temp + increment;
565 @@ -99,7 +101,7 @@
566 Atomic32 old_value,
567 Atomic32 new_value) {
568 Atomic32 x = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
569 - if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
570 + if (cr_AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
571 __asm__ __volatile__("lfence" : : : "memory");
572 }
573 return x;
574 @@ -131,7 +133,7 @@
575 #else
576
577 inline void MemoryBarrier() {
578 - if (AtomicOps_Internalx86CPUFeatures.has_sse2) {
579 + if (cr_AtomicOps_Internalx86CPUFeatures.has_sse2) {
580 __asm__ __volatile__("mfence" : : : "memory");
581 } else { // mfence is faster but not present on PIII
582 Atomic32 x = 0;
583 @@ -140,7 +142,7 @@
584 }
585
586 inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
587 - if (AtomicOps_Internalx86CPUFeatures.has_sse2) {
588 + if (cr_AtomicOps_Internalx86CPUFeatures.has_sse2) {
589 *ptr = value;
590 __asm__ __volatile__("mfence" : : : "memory");
591 } else {
592 @@ -213,7 +215,7 @@
593 : "+r" (temp), "+m" (*ptr)
594 : : "memory");
595 // temp now contains the previous value of *ptr
596 - if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
597 + if (cr_AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
598 __asm__ __volatile__("lfence" : : : "memory");
599 }
600 return temp + increment;
601 @@ -270,7 +272,7 @@
602 Atomic64 old_value,
603 Atomic64 new_value) {
604 Atomic64 x = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
605 - if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
606 + if (cr_AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) {
607 __asm__ __volatile__("lfence" : : : "memory");
608 }
609 return x;
610 diff -ru --new-file protobuf/src/google/protobuf/stubs/common.cc protobuf2/src/g oogle/protobuf/stubs/common.cc
611 --- protobuf/src/google/protobuf/stubs/common.cc 2017-03-17 22:40:59.3831 53133 -0700
612 +++ protobuf2/src/google/protobuf/stubs/common.cc 2017-03-17 22:40:52.6711 51340 -0700
613 @@ -116,7 +116,8 @@
614 if (level < GOOGLE_PROTOBUF_MIN_LOG_LEVEL) {
615 return;
616 }
617 - static const char* level_names[] = {"INFO", "WARNING", "ERROR", "FATAL"};
618 + static const char* const level_names[] = {"INFO", "WARNING", "ERROR",
619 + "FATAL"};
620
621 static const int android_log_levels[] = {
622 ANDROID_LOG_INFO, // LOG(INFO),
623 @@ -148,7 +149,8 @@
624 #else
625 void DefaultLogHandler(LogLevel level, const char* filename, int line,
626 const string& message) {
627 - static const char* level_names[] = { "INFO", "WARNING", "ERROR", "FATAL" };
628 + static const char* const level_names[] = {"INFO", "WARNING", "ERROR",
629 + "FATAL"};
630
631 // We use fprintf() instead of cerr because we want this to work at static
632 // initialization time.
633 @@ -163,22 +165,22 @@
634 // Nothing.
635 }
636
637 -static LogHandler* log_handler_ = &DefaultLogHandler;
638 -static int log_silencer_count_ = 0;
639 +extern LogHandler* cr_log_handler_;
640 +extern int cr_log_silencer_count_;
641
642 -static Mutex* log_silencer_count_mutex_ = NULL;
643 -GOOGLE_PROTOBUF_DECLARE_ONCE(log_silencer_count_init_);
644 +extern Mutex* cr_log_silencer_count_mutex_;
645 +extern ProtobufOnceType cr_log_silencer_count_init_;
646
647 void DeleteLogSilencerCount() {
648 - delete log_silencer_count_mutex_;
649 - log_silencer_count_mutex_ = NULL;
650 + delete cr_log_silencer_count_mutex_;
651 + cr_log_silencer_count_mutex_ = NULL;
652 }
653 void InitLogSilencerCount() {
654 - log_silencer_count_mutex_ = new Mutex;
655 + cr_log_silencer_count_mutex_ = new Mutex;
656 OnShutdown(&DeleteLogSilencerCount);
657 }
658 void InitLogSilencerCountOnce() {
659 - GoogleOnceInit(&log_silencer_count_init_, &InitLogSilencerCount);
660 + GoogleOnceInit(&cr_log_silencer_count_init_, &InitLogSilencerCount);
661 }
662
663 LogMessage& LogMessage::operator<<(const string& value) {
664 @@ -246,12 +248,13 @@
665
666 if (level_ != LOGLEVEL_FATAL) {
667 InitLogSilencerCountOnce();
668 - MutexLock lock(log_silencer_count_mutex_);
669 - suppress = log_silencer_count_ > 0;
670 + MutexLock lock(cr_log_silencer_count_mutex_);
671 + suppress = cr_log_silencer_count_ > 0;
672 }
673
674 if (!suppress) {
675 - log_handler_(level_, filename_, line_, message_);
676 + (cr_log_handler_ ? cr_log_handler_ : DefaultLogHandler)(level_, filename_,
677 + line_, message_);
678 }
679
680 if (level_ == LOGLEVEL_FATAL) {
681 @@ -270,28 +273,29 @@
682 } // namespace internal
683
684 LogHandler* SetLogHandler(LogHandler* new_func) {
685 - LogHandler* old = internal::log_handler_;
686 + LogHandler* old = internal::cr_log_handler_ ? internal::cr_log_handler_
687 + : internal::DefaultLogHandler;
688 if (old == &internal::NullLogHandler) {
689 old = NULL;
690 }
691 if (new_func == NULL) {
692 - internal::log_handler_ = &internal::NullLogHandler;
693 + internal::cr_log_handler_ = &internal::NullLogHandler;
694 } else {
695 - internal::log_handler_ = new_func;
696 + internal::cr_log_handler_ = new_func;
697 }
698 return old;
699 }
700
701 LogSilencer::LogSilencer() {
702 internal::InitLogSilencerCountOnce();
703 - MutexLock lock(internal::log_silencer_count_mutex_);
704 - ++internal::log_silencer_count_;
705 + MutexLock lock(internal::cr_log_silencer_count_mutex_);
706 + ++internal::cr_log_silencer_count_;
707 };
708
709 LogSilencer::~LogSilencer() {
710 internal::InitLogSilencerCountOnce();
711 - MutexLock lock(internal::log_silencer_count_mutex_);
712 - --internal::log_silencer_count_;
713 + MutexLock lock(internal::cr_log_silencer_count_mutex_);
714 + --internal::cr_log_silencer_count_;
715 };
716
717 // ===================================================================
718 @@ -407,23 +411,23 @@
719 namespace internal {
720
721 typedef void OnShutdownFunc();
722 -vector<void (*)()>* shutdown_functions = NULL;
723 -Mutex* shutdown_functions_mutex = NULL;
724 -GOOGLE_PROTOBUF_DECLARE_ONCE(shutdown_functions_init);
725 +extern vector<void (*)()>* cr_shutdown_functions;
726 +extern Mutex* cr_shutdown_functions_mutex;
727 +extern ProtobufOnceType cr_shutdown_functions_init;
728
729 void InitShutdownFunctions() {
730 - shutdown_functions = new vector<void (*)()>;
731 - shutdown_functions_mutex = new Mutex;
732 + cr_shutdown_functions = new vector<void (*)()>;
733 + cr_shutdown_functions_mutex = new Mutex;
734 }
735
736 inline void InitShutdownFunctionsOnce() {
737 - GoogleOnceInit(&shutdown_functions_init, &InitShutdownFunctions);
738 + GoogleOnceInit(&cr_shutdown_functions_init, &InitShutdownFunctions);
739 }
740
741 void OnShutdown(void (*func)()) {
742 InitShutdownFunctionsOnce();
743 - MutexLock lock(shutdown_functions_mutex);
744 - shutdown_functions->push_back(func);
745 + MutexLock lock(cr_shutdown_functions_mutex);
746 + cr_shutdown_functions->push_back(func);
747 }
748
749 } // namespace internal
750 @@ -431,20 +435,20 @@
751 void ShutdownProtobufLibrary() {
752 internal::InitShutdownFunctionsOnce();
753
754 - // We don't need to lock shutdown_functions_mutex because it's up to the
755 + // We don't need to lock cr_shutdown_functions_mutex because it's up to the
756 // caller to make sure that no one is using the library before this is
757 // called.
758
759 // Make it safe to call this multiple times.
760 - if (internal::shutdown_functions == NULL) return;
761 + if (internal::cr_shutdown_functions == NULL) return;
762
763 - for (int i = 0; i < internal::shutdown_functions->size(); i++) {
764 - internal::shutdown_functions->at(i)();
765 + for (int i = 0; i < internal::cr_shutdown_functions->size(); i++) {
766 + internal::cr_shutdown_functions->at(i)();
767 }
768 - delete internal::shutdown_functions;
769 - internal::shutdown_functions = NULL;
770 - delete internal::shutdown_functions_mutex;
771 - internal::shutdown_functions_mutex = NULL;
772 + delete internal::cr_shutdown_functions;
773 + internal::cr_shutdown_functions = NULL;
774 + delete internal::cr_shutdown_functions_mutex;
775 + internal::cr_shutdown_functions_mutex = NULL;
776 }
777
778 #if PROTOBUF_USE_EXCEPTIONS
779 diff -ru --new-file protobuf/src/google/protobuf/stubs/structurally_valid.cc pro tobuf2/src/google/protobuf/stubs/structurally_valid.cc
780 --- protobuf/src/google/protobuf/stubs/structurally_valid.cc 2017-03-17 22:40 :59.383153133 -0700
781 +++ protobuf2/src/google/protobuf/stubs/structurally_valid.cc 2017-03-17 22:40 :52.675151341 -0700
782 @@ -511,21 +511,10 @@
783 // UTF-8 strings. Since UTF-8 validation is only used for debugging
784 // anyway, we simply always return success if initialization hasn't
785 // occurred yet.
786 -namespace {
787 -
788 -bool module_initialized_ = false;
789 -
790 -struct InitDetector {
791 - InitDetector() {
792 - module_initialized_ = true;
793 - }
794 -};
795 -InitDetector init_detector;
796 -
797 -} // namespace
798 +extern bool cr_module_initialized_;
799
800 bool IsStructurallyValidUTF8(const char* buf, int len) {
801 - if (!module_initialized_) return true;
802 + if (!cr_module_initialized_) return true;
803
804 int bytes_consumed = 0;
805 UTF8GenericScanFastAscii(&utf8acceptnonsurrogates_obj,
806 @@ -534,7 +523,7 @@
807 }
808
809 int UTF8SpnStructurallyValid(const StringPiece& str) {
810 - if (!module_initialized_) return str.size();
811 + if (!cr_module_initialized_) return str.size();
812
813 int bytes_consumed = 0;
814 UTF8GenericScanFastAscii(&utf8acceptnonsurrogates_obj,
815 diff -ru --new-file protobuf/src/google/protobuf/stubs/strutil.cc protobuf2/src/ google/protobuf/stubs/strutil.cc
816 --- protobuf/src/google/protobuf/stubs/strutil.cc 2017-03-17 22:40:59.3831 53133 -0700
817 +++ protobuf2/src/google/protobuf/stubs/strutil.cc 2017-03-17 22:40:52.6711 51340 -0700
818 @@ -528,7 +528,7 @@
819 // Assumes that non-printable characters are escaped using octal sequences, and
820 // that UTF-8 bytes are not handled specially.
821 static inline size_t CEscapedLength(StringPiece src) {
822 - static char c_escaped_len[256] = {
823 + static const char c_escaped_len[256] = {
824 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 4, 4, 2, 4, 4, // \t, \n, \r
825 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
826 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, // ", '
827 @@ -891,7 +891,7 @@
828 char *FastHexToBuffer(int i, char* buffer) {
829 GOOGLE_CHECK(i >= 0) << "FastHexToBuffer() wants non-negative integers, not " << i;
830
831 - static const char *hexdigits = "0123456789abcdef";
832 + static const char hexdigits[] = "0123456789abcdef";
833 char *p = buffer + 21;
834 *p-- = '\0';
835 do {
836 @@ -902,7 +902,7 @@
837 }
838
839 char *InternalFastHexToBuffer(uint64 value, char* buffer, int num_byte) {
840 - static const char *hexdigits = "0123456789abcdef";
841 + static const char hexdigits[] = "0123456789abcdef";
842 buffer[num_byte] = '\0';
843 for (int i = num_byte - 1; i >= 0; i--) {
844 #ifdef _M_X64
OLDNEW
« no previous file with comments | « third_party/protobuf/README.chromium ('k') | third_party/protobuf/src/google/protobuf/arena.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698