Skip to content

Commit 17347e3

Browse files
committed
Fix for Visual Studio 2008.
1 parent 283c40c commit 17347e3

File tree

4 files changed

+27
-35
lines changed

4 files changed

+27
-35
lines changed

src/google/protobuf/compiler/js/js_generator.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ string JSOneofIndex(const OneofDescriptor* oneof) {
447447

448448
// Decodes a codepoint in \x0000 -- \xFFFF. Since JS strings are UTF-16, we only
449449
// need to handle the BMP (16-bit range) here.
450-
uint16_t DecodeUTF8Codepoint(uint8_t* bytes, size_t* length) {
450+
uint16 DecodeUTF8Codepoint(uint8* bytes, size_t* length) {
451451
if (*length == 0) {
452452
return 0;
453453
}
@@ -491,22 +491,22 @@ string EscapeJSString(const string& in, bool is_utf8) {
491491
string result;
492492
size_t decoded = 0;
493493
for (size_t i = 0; i < in.size(); i += decoded) {
494-
uint16_t codepoint = 0;
494+
uint16 codepoint = 0;
495495
if (is_utf8) {
496496
// Decode the next UTF-8 codepoint.
497497
size_t have_bytes = in.size() - i;
498-
uint8_t bytes[3] = {
499-
static_cast<uint8_t>(in[i]),
500-
static_cast<uint8_t>(((i + 1) < in.size()) ? in[i + 1] : 0),
501-
static_cast<uint8_t>(((i + 2) < in.size()) ? in[i + 2] : 0),
498+
uint8 bytes[3] = {
499+
static_cast<uint8>(in[i]),
500+
static_cast<uint8>(((i + 1) < in.size()) ? in[i + 1] : 0),
501+
static_cast<uint8>(((i + 2) < in.size()) ? in[i + 2] : 0),
502502
};
503503
codepoint = DecodeUTF8Codepoint(bytes, &have_bytes);
504504
if (have_bytes == 0) {
505505
break;
506506
}
507507
decoded = have_bytes;
508508
} else {
509-
codepoint = static_cast<uint16_t>(static_cast<uint8_t>(in[i]));
509+
codepoint = static_cast<uint16>(static_cast<uint8>(in[i]));
510510
decoded = 1;
511511
}
512512

src/google/protobuf/stubs/stringpiece_unittest.cc

-17
Original file line numberDiff line numberDiff line change
@@ -746,23 +746,6 @@ TEST(StringPiece, Comparisons2) {
746746
EXPECT_TRUE(abc.ends_with("nopqrstuvwxyz"));
747747
}
748748

749-
TEST(StringPiece, HashFunction) {
750-
hash_set<StringPiece> set;
751-
752-
set.insert(StringPiece("hello"));
753-
EXPECT_EQ(1, set.size());
754-
755-
// Insert a StringPiece of the same value again and should NOT increment
756-
// size of the set.
757-
set.insert(StringPiece("hello"));
758-
EXPECT_EQ(1, set.size());
759-
760-
// Insert a StringPiece with different value and check that size of the set
761-
// has been increment by one.
762-
set.insert(StringPiece("world"));
763-
EXPECT_EQ(2, set.size());
764-
}
765-
766749
TEST(ComparisonOpsTest, StringCompareNotAmbiguous) {
767750
EXPECT_EQ("hello", string("hello"));
768751
EXPECT_LT("hello", string("world"));

src/google/protobuf/util/internal/protostream_objectwriter_test.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -1685,13 +1685,17 @@ TEST_P(ProtoStreamObjectWriterFieldMaskTest, MapKeyMustBeEscapedCorrectly) {
16851685
TEST_P(ProtoStreamObjectWriterFieldMaskTest, MapKeyCanContainAnyChars) {
16861686
FieldMaskTest expected;
16871687
expected.mutable_single_mask()->add_paths(
1688-
"path.to.map[\"(),[],\\\"'!@#$%^&*123_|War孙天涌,./?><\\\\\"]");
1688+
// \xE5\xAD\x99 is the UTF-8 byte sequence for chinese character 孙.
1689+
// We cannot embed non-ASCII characters in the code directly because
1690+
// some windows compilers will try to interpret them using the system's
1691+
// current encoding and end up with invalid UTF-8 byte sequence.
1692+
"path.to.map[\"(),[],\\\"'!@#$%^&*123_|War\xE5\xAD\x99,./?><\\\\\"]");
16891693
expected.mutable_single_mask()->add_paths("path.to.map[\"key2\"]");
16901694

16911695
ow_->StartObject("");
16921696
ow_->RenderString(
16931697
"single_mask",
1694-
"path.to.map[\"(),[],\\\"'!@#$%^&*123_|War孙天涌,./?><\\\\\"],"
1698+
"path.to.map[\"(),[],\\\"'!@#$%^&*123_|War\xE5\xAD\x99,./?><\\\\\"],"
16951699
"path.to.map[\"key2\"]");
16961700
ow_->EndObject();
16971701

src/google/protobuf/util/message_differencer_unittest.cc

+14-9
Original file line numberDiff line numberDiff line change
@@ -2816,15 +2816,20 @@ class MatchingTest : public testing::Test {
28162816
const Message& msg1, const Message& msg2,
28172817
bool result) {
28182818
string output;
2819-
io::StringOutputStream output_stream(&output);
2820-
MessageDifferencer::StreamReporter reporter(&output_stream);
2821-
reporter.set_report_modified_aggregates(true);
2822-
differencer->set_report_matches(true);
2823-
differencer->ReportDifferencesTo(&reporter);
2824-
if (result) {
2825-
EXPECT_TRUE(differencer->Compare(msg1, msg2));
2826-
} else {
2827-
EXPECT_FALSE(differencer->Compare(msg1, msg2));
2819+
{
2820+
// Before we return the "output" string, we must make sure the
2821+
// StreamReporter is destructored because its destructor will
2822+
// flush the stream.
2823+
io::StringOutputStream output_stream(&output);
2824+
MessageDifferencer::StreamReporter reporter(&output_stream);
2825+
reporter.set_report_modified_aggregates(true);
2826+
differencer->set_report_matches(true);
2827+
differencer->ReportDifferencesTo(&reporter);
2828+
if (result) {
2829+
EXPECT_TRUE(differencer->Compare(msg1, msg2));
2830+
} else {
2831+
EXPECT_FALSE(differencer->Compare(msg1, msg2));
2832+
}
28282833
}
28292834
return output;
28302835
}

0 commit comments

Comments
 (0)