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

Side by Side Diff: third_party/protobuf/src/google/protobuf/stubs/structurally_valid.cc

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
OLDNEW
1 // Copyright 2005-2008 Google Inc. All Rights Reserved. 1 // Copyright 2005-2008 Google Inc. All Rights Reserved.
2 // Author: jrm@google.com (Jim Meehan) 2 // Author: jrm@google.com (Jim Meehan)
3 3
4 #include <google/protobuf/stubs/common.h> 4 #include <google/protobuf/stubs/common.h>
5 5
6 #include <google/protobuf/stubs/stringpiece.h> 6 #include <google/protobuf/stubs/stringpiece.h>
7 7
8 namespace google { 8 namespace google {
9 namespace protobuf { 9 namespace protobuf {
10 namespace internal { 10 namespace internal {
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 *bytes_consumed = src - isrc; 504 *bytes_consumed = src - isrc;
505 return exit_reason; 505 return exit_reason;
506 } 506 }
507 507
508 // Hack: On some compilers the static tables are initialized at startup. 508 // Hack: On some compilers the static tables are initialized at startup.
509 // We can't use them until they are initialized. However, some Protocol 509 // We can't use them until they are initialized. However, some Protocol
510 // Buffer parsing happens at static init time and may try to validate 510 // Buffer parsing happens at static init time and may try to validate
511 // UTF-8 strings. Since UTF-8 validation is only used for debugging 511 // UTF-8 strings. Since UTF-8 validation is only used for debugging
512 // anyway, we simply always return success if initialization hasn't 512 // anyway, we simply always return success if initialization hasn't
513 // occurred yet. 513 // occurred yet.
514 namespace { 514 extern bool cr_module_initialized_;
515
516 bool module_initialized_ = false;
517
518 struct InitDetector {
519 InitDetector() {
520 module_initialized_ = true;
521 }
522 };
523 InitDetector init_detector;
524
525 } // namespace
526 515
527 bool IsStructurallyValidUTF8(const char* buf, int len) { 516 bool IsStructurallyValidUTF8(const char* buf, int len) {
528 if (!module_initialized_) return true; 517 if (!cr_module_initialized_) return true;
529 518
530 int bytes_consumed = 0; 519 int bytes_consumed = 0;
531 UTF8GenericScanFastAscii(&utf8acceptnonsurrogates_obj, 520 UTF8GenericScanFastAscii(&utf8acceptnonsurrogates_obj,
532 buf, len, &bytes_consumed); 521 buf, len, &bytes_consumed);
533 return (bytes_consumed == len); 522 return (bytes_consumed == len);
534 } 523 }
535 524
536 int UTF8SpnStructurallyValid(const StringPiece& str) { 525 int UTF8SpnStructurallyValid(const StringPiece& str) {
537 if (!module_initialized_) return str.size(); 526 if (!cr_module_initialized_) return str.size();
538 527
539 int bytes_consumed = 0; 528 int bytes_consumed = 0;
540 UTF8GenericScanFastAscii(&utf8acceptnonsurrogates_obj, 529 UTF8GenericScanFastAscii(&utf8acceptnonsurrogates_obj,
541 str.data(), str.size(), &bytes_consumed); 530 str.data(), str.size(), &bytes_consumed);
542 return bytes_consumed; 531 return bytes_consumed;
543 } 532 }
544 533
545 // Coerce UTF-8 byte string in src_str to be 534 // Coerce UTF-8 byte string in src_str to be
546 // a structurally-valid equal-length string by selectively 535 // a structurally-valid equal-length string by selectively
547 // overwriting illegal bytes with replace_char (typically blank). 536 // overwriting illegal bytes with replace_char (typically blank).
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 src += n; 568 src += n;
580 dst += n; 569 dst += n;
581 } 570 }
582 } 571 }
583 return idst; 572 return idst;
584 } 573 }
585 574
586 } // namespace internal 575 } // namespace internal
587 } // namespace protobuf 576 } // namespace protobuf
588 } // namespace google 577 } // namespace google
OLDNEW
« no previous file with comments | « third_party/protobuf/src/google/protobuf/stubs/common.cc ('k') | third_party/protobuf/src/google/protobuf/stubs/strutil.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698