aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message.cc10
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_field_base.cc10
-rw-r--r--src/google/protobuf/compiler/subprocess.cc2
-rw-r--r--src/google/protobuf/stubs/common.h16
-rw-r--r--src/google/protobuf/stubs/strutil.cc10
-rw-r--r--src/google/protobuf/text_format_unittest.cc10
-rw-r--r--src/google/protobuf/unknown_field_set.cc5
-rw-r--r--src/google/protobuf/util/internal/datapiece.cc3
-rw-r--r--src/google/protobuf/util/internal/utility.cc3
-rw-r--r--src/google/protobuf/wire_format.h2
-rw-r--r--src/google/protobuf/wire_format_unittest.cc144
11 files changed, 121 insertions, 94 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc
index 17f67a7b..b0e38755 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_message.cc
@@ -2932,7 +2932,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
"commontag", SimpleItoa(WireFormat::MakeTag(field)));
if (need_label ||
- (field->is_repeated() && !field->options().packed() && !loops)) {
+ (field->is_repeated() && !field->is_packed() && !loops)) {
printer->Print(
" parse_$name$:\n",
"name", field->name());
@@ -2945,7 +2945,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
}
printer->Indent();
- if (field->options().packed()) {
+ if (field->is_packed()) {
field_generator.GenerateMergeFromCodedStreamWithPacking(printer);
} else {
field_generator.GenerateMergeFromCodedStream(printer);
@@ -2953,7 +2953,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
printer->Outdent();
// Emit code to parse unexpectedly packed or unpacked values.
- if (field->is_packable() && field->options().packed()) {
+ if (field->is_packed()) {
internal::WireFormatLite::WireType wiretype =
WireFormat::WireTypeForFieldType(field->type());
printer->Print("} else if (tag == $uncommontag$) {\n",
@@ -2963,7 +2963,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
printer->Indent();
field_generator.GenerateMergeFromCodedStream(printer);
printer->Outdent();
- } else if (field->is_packable() && !field->options().packed()) {
+ } else if (field->is_packable() && !field->is_packed()) {
internal::WireFormatLite::WireType wiretype =
internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED;
printer->Print("} else if (tag == $uncommontag$) {\n",
@@ -2988,7 +2988,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
"if (input->ExpectTag($tag$)) goto parse_loop_$name$;\n",
"tag", SimpleItoa(WireFormat::MakeTag(field)),
"name", field->name());
- } else if (field->is_repeated() && !field->options().packed()) {
+ } else if (field->is_repeated() && !field->is_packed()) {
printer->Print(
"if (input->ExpectTag($tag$)) goto parse_$name$;\n",
"tag", SimpleItoa(WireFormat::MakeTag(field)),
diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc
index c3ce426b..4c6a3d72 100644
--- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc
@@ -38,6 +38,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/stubs/strutil.h>
+#include <google/protobuf/stubs/mathlimits.h>
#include <google/protobuf/compiler/csharp/csharp_field_base.h>
#include <google/protobuf/compiler/csharp/csharp_helpers.h>
@@ -248,11 +249,6 @@ bool FieldGeneratorBase::is_nullable_type() {
}
}
-inline bool IsNaN(double value) {
- // NaN is never equal to anything, even itself.
- return value != value;
-}
-
bool AllPrintableAscii(const std::string& text) {
for(int i = 0; i < text.size(); i++) {
if (text[i] < 0x20 || text[i] > 0x7e) {
@@ -309,7 +305,7 @@ std::string FieldGeneratorBase::default_value() {
return "double.PositiveInfinity";
} else if (value == -numeric_limits<double>::infinity()) {
return "double.NegativeInfinity";
- } else if (IsNaN(value)) {
+ } else if (MathLimits<double>::IsNaN(value)) {
return "double.NaN";
}
return SimpleDtoa(value) + "D";
@@ -320,7 +316,7 @@ std::string FieldGeneratorBase::default_value() {
return "float.PositiveInfinity";
} else if (value == -numeric_limits<float>::infinity()) {
return "float.NegativeInfinity";
- } else if (IsNaN(value)) {
+ } else if (MathLimits<float>::IsNaN(value)) {
return "float.NaN";
}
return SimpleFtoa(value) + "F";
diff --git a/src/google/protobuf/compiler/subprocess.cc b/src/google/protobuf/compiler/subprocess.cc
index 61ae4381..a3cff1f8 100644
--- a/src/google/protobuf/compiler/subprocess.cc
+++ b/src/google/protobuf/compiler/subprocess.cc
@@ -171,7 +171,7 @@ bool Subprocess::Communicate(const Message& input, Message* output,
DWORD wait_result =
WaitForMultipleObjects(handle_count, handles, FALSE, INFINITE);
- HANDLE signaled_handle;
+ HANDLE signaled_handle = NULL;
if (wait_result >= WAIT_OBJECT_0 &&
wait_result < WAIT_OBJECT_0 + handle_count) {
signaled_handle = handles[wait_result - WAIT_OBJECT_0];
diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h
index c3620146..3eb57a9b 100644
--- a/src/google/protobuf/stubs/common.h
+++ b/src/google/protobuf/stubs/common.h
@@ -1459,14 +1459,14 @@ static inline uint32 bswap_32(uint32 x) {
}
#define bswap_32(x) bswap_32(x)
static inline uint64 bswap_64(uint64 x) {
- return (((x & GG_ULONGLONG(0xFF)) << 56) |
- ((x & GG_ULONGLONG(0xFF00)) << 40) |
- ((x & GG_ULONGLONG(0xFF0000)) << 24) |
- ((x & GG_ULONGLONG(0xFF000000)) << 8) |
- ((x & GG_ULONGLONG(0xFF00000000)) >> 8) |
- ((x & GG_ULONGLONG(0xFF0000000000)) >> 24) |
- ((x & GG_ULONGLONG(0xFF000000000000)) >> 40) |
- ((x & GG_ULONGLONG(0xFF00000000000000)) >> 56));
+ return (((x & GOOGLE_ULONGLONG(0xFF)) << 56) |
+ ((x & GOOGLE_ULONGLONG(0xFF00)) << 40) |
+ ((x & GOOGLE_ULONGLONG(0xFF0000)) << 24) |
+ ((x & GOOGLE_ULONGLONG(0xFF000000)) << 8) |
+ ((x & GOOGLE_ULONGLONG(0xFF00000000)) >> 8) |
+ ((x & GOOGLE_ULONGLONG(0xFF0000000000)) >> 24) |
+ ((x & GOOGLE_ULONGLONG(0xFF000000000000)) >> 40) |
+ ((x & GOOGLE_ULONGLONG(0xFF00000000000000)) >> 56));
}
#define bswap_64(x) bswap_64(x)
diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc
index 99e8bf1d..2ec62b42 100644
--- a/src/google/protobuf/stubs/strutil.cc
+++ b/src/google/protobuf/stubs/strutil.cc
@@ -31,6 +31,7 @@
// from google3/strings/strutil.cc
#include <google/protobuf/stubs/strutil.h>
+#include <google/protobuf/stubs/mathlimits.h>
#include <errno.h>
#include <float.h> // FLT_DIG and DBL_DIG
@@ -58,11 +59,6 @@
namespace google {
namespace protobuf {
-inline bool IsNaN(double value) {
- // NaN is never equal to anything, even itself.
- return value != value;
-}
-
// These are defined as macros on some platforms. #undef them so that we can
// redefine them.
#undef isxdigit
@@ -1210,7 +1206,7 @@ char* DoubleToBuffer(double value, char* buffer) {
} else if (value == -numeric_limits<double>::infinity()) {
strcpy(buffer, "-inf");
return buffer;
- } else if (IsNaN(value)) {
+ } else if (MathLimits<double>::IsNaN(value)) {
strcpy(buffer, "nan");
return buffer;
}
@@ -1328,7 +1324,7 @@ char* FloatToBuffer(float value, char* buffer) {
} else if (value == -numeric_limits<double>::infinity()) {
strcpy(buffer, "-inf");
return buffer;
- } else if (IsNaN(value)) {
+ } else if (MathLimits<float>::IsNaN(value)) {
strcpy(buffer, "nan");
return buffer;
}
diff --git a/src/google/protobuf/text_format_unittest.cc b/src/google/protobuf/text_format_unittest.cc
index 1b18c5ed..76ce9875 100644
--- a/src/google/protobuf/text_format_unittest.cc
+++ b/src/google/protobuf/text_format_unittest.cc
@@ -46,6 +46,7 @@
#include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/stubs/strutil.h>
+#include <google/protobuf/stubs/mathlimits.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
@@ -57,11 +58,6 @@ namespace protobuf {
// Can't use an anonymous namespace here due to brokenness of Tru64 compiler.
namespace text_format_unittest {
-inline bool IsNaN(double value) {
- // NaN is never equal to anything, even itself.
- return value != value;
-}
-
// A basic string with different escapable characters for testing.
const string kEscapeTestString =
"\"A string with ' characters \n and \r newlines and \t tabs and \001 "
@@ -898,8 +894,8 @@ TEST_F(TextFormatTest, ParseExotic) {
EXPECT_EQ(message.repeated_double(8), numeric_limits<double>::infinity());
EXPECT_EQ(message.repeated_double(9), -numeric_limits<double>::infinity());
EXPECT_EQ(message.repeated_double(10), -numeric_limits<double>::infinity());
- EXPECT_TRUE(IsNaN(message.repeated_double(11)));
- EXPECT_TRUE(IsNaN(message.repeated_double(12)));
+ EXPECT_TRUE(MathLimits<double>::IsNaN(message.repeated_double(11)));
+ EXPECT_TRUE(MathLimits<double>::IsNaN(message.repeated_double(12)));
// Note: Since these string literals have \0's in them, we must explicitly
// pass their sizes to string's constructor.
diff --git a/src/google/protobuf/unknown_field_set.cc b/src/google/protobuf/unknown_field_set.cc
index 76644900..93f0f206 100644
--- a/src/google/protobuf/unknown_field_set.cc
+++ b/src/google/protobuf/unknown_field_set.cc
@@ -50,8 +50,13 @@ namespace {
// instantiate the UnknownFieldSet dynamically only when required.
UnknownFieldSet* default_unknown_field_set_instance_ = NULL;
+void DeleteDefaultUnknownFieldSet() {
+ delete default_unknown_field_set_instance_;
+}
+
void InitDefaultUnknownFieldSet() {
default_unknown_field_set_instance_ = new UnknownFieldSet();
+ internal::OnShutdown(&DeleteDefaultUnknownFieldSet);
}
GOOGLE_PROTOBUF_DECLARE_ONCE(default_unknown_field_set_once_init_);
diff --git a/src/google/protobuf/util/internal/datapiece.cc b/src/google/protobuf/util/internal/datapiece.cc
index 72b737e9..944fb2e3 100644
--- a/src/google/protobuf/util/internal/datapiece.cc
+++ b/src/google/protobuf/util/internal/datapiece.cc
@@ -36,6 +36,7 @@
#include <google/protobuf/util/internal/utility.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/mathutil.h>
+#include <google/protobuf/stubs/mathlimits.h>
namespace google {
namespace protobuf {
@@ -78,7 +79,7 @@ StatusOr<To> NumberConvertAndCheck(From before) {
// For conversion between double and float only.
template <typename To, typename From>
StatusOr<To> FloatingPointConvertAndCheck(From before) {
- if (isnan(before)) return std::numeric_limits<To>::quiet_NaN();
+ if (MathLimits<From>::IsNaN(before)) return std::numeric_limits<To>::quiet_NaN();
To after = static_cast<To>(before);
if (MathUtil::AlmostEquals<To>(after, before)) {
diff --git a/src/google/protobuf/util/internal/utility.cc b/src/google/protobuf/util/internal/utility.cc
index f550f43b..794777d4 100644
--- a/src/google/protobuf/util/internal/utility.cc
+++ b/src/google/protobuf/util/internal/utility.cc
@@ -41,6 +41,7 @@
#include <google/protobuf/util/internal/constants.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/map_util.h>
+#include <google/protobuf/stubs/mathlimits.h>
namespace google {
namespace protobuf {
@@ -302,7 +303,7 @@ bool IsMap(const google::protobuf::Field& field,
string DoubleAsString(double value) {
if (value == std::numeric_limits<double>::infinity()) return "Infinity";
if (value == -std::numeric_limits<double>::infinity()) return "-Infinity";
- if (::isnan(value)) return "NaN";
+ if (google::protobuf::MathLimits<double>::IsNaN(value)) return "NaN";
return SimpleDtoa(value);
}
diff --git a/src/google/protobuf/wire_format.h b/src/google/protobuf/wire_format.h
index 8de491a6..84270fee 100644
--- a/src/google/protobuf/wire_format.h
+++ b/src/google/protobuf/wire_format.h
@@ -290,7 +290,7 @@ class LIBPROTOBUF_EXPORT UnknownFieldSetFieldSkipper : public FieldSkipper {
inline WireFormatLite::WireType WireFormat::WireTypeForField(
const FieldDescriptor* field) {
- if (field->options().packed()) {
+ if (field->is_packed()) {
return WireFormatLite::WIRETYPE_LENGTH_DELIMITED;
} else {
return WireTypeForFieldType(field->type());
diff --git a/src/google/protobuf/wire_format_unittest.cc b/src/google/protobuf/wire_format_unittest.cc
index 4b151f97..aef22b29 100644
--- a/src/google/protobuf/wire_format_unittest.cc
+++ b/src/google/protobuf/wire_format_unittest.cc
@@ -795,9 +795,73 @@ TEST(WireFormatTest, CompatibleTypes) {
ASSERT_EQ(static_cast<uint32>(data), msg5.data());
}
-class Proto3PrimitiveRepeatedWireFormatTest
- : public ::testing::TestWithParam<bool> {
+class Proto3PrimitiveRepeatedWireFormatTest : public ::testing::Test {
protected:
+ Proto3PrimitiveRepeatedWireFormatTest()
+ : packedTestAllTypes_(
+ "\xFA\x01\x01\x01"
+ "\x82\x02\x01\x01"
+ "\x8A\x02\x01\x01"
+ "\x92\x02\x01\x01"
+ "\x9A\x02\x01\x02"
+ "\xA2\x02\x01\x02"
+ "\xAA\x02\x04\x01\x00\x00\x00"
+ "\xB2\x02\x08\x01\x00\x00\x00\x00\x00\x00\x00"
+ "\xBA\x02\x04\x01\x00\x00\x00"
+ "\xC2\x02\x08\x01\x00\x00\x00\x00\x00\x00\x00"
+ "\xCA\x02\x04\x00\x00\x80\x3f"
+ "\xD2\x02\x08\x00\x00\x00\x00\x00\x00\xf0\x3f"
+ "\xDA\x02\x01\x01"
+ "\x9A\x03\x01\x01",
+ 86),
+ packedTestUnpackedTypes_(
+ "\x0A\x01\x01"
+ "\x12\x01\x01"
+ "\x1A\x01\x01"
+ "\x22\x01\x01"
+ "\x2A\x01\x02"
+ "\x32\x01\x02"
+ "\x3A\x04\x01\x00\x00\x00"
+ "\x42\x08\x01\x00\x00\x00\x00\x00\x00\x00"
+ "\x4A\x04\x01\x00\x00\x00"
+ "\x52\x08\x01\x00\x00\x00\x00\x00\x00\x00"
+ "\x5A\x04\x00\x00\x80\x3f"
+ "\x62\x08\x00\x00\x00\x00\x00\x00\xf0\x3f"
+ "\x6A\x01\x01"
+ "\x72\x01\x01",
+ 72),
+ unpackedTestAllTypes_(
+ "\xF8\x01\x01"
+ "\x80\x02\x01"
+ "\x88\x02\x01"
+ "\x90\x02\x01"
+ "\x98\x02\x02"
+ "\xA0\x02\x02"
+ "\xAD\x02\x01\x00\x00\x00"
+ "\xB1\x02\x01\x00\x00\x00\x00\x00\x00\x00"
+ "\xBD\x02\x01\x00\x00\x00"
+ "\xC1\x02\x01\x00\x00\x00\x00\x00\x00\x00"
+ "\xCD\x02\x00\x00\x80\x3f"
+ "\xD1\x02\x00\x00\x00\x00\x00\x00\xf0\x3f"
+ "\xD8\x02\x01"
+ "\x98\x03\x01",
+ 72),
+ unpackedTestUnpackedTypes_(
+ "\x08\x01"
+ "\x10\x01"
+ "\x18\x01"
+ "\x20\x01"
+ "\x28\x02"
+ "\x30\x02"
+ "\x3D\x01\x00\x00\x00"
+ "\x41\x01\x00\x00\x00\x00\x00\x00\x00"
+ "\x4D\x01\x00\x00\x00"
+ "\x51\x01\x00\x00\x00\x00\x00\x00\x00"
+ "\x5D\x00\x00\x80\x3f"
+ "\x61\x00\x00\x00\x00\x00\x00\xf0\x3f"
+ "\x68\x01"
+ "\x70\x01",
+ 58) {}
template <class Proto>
void SetProto3PrimitiveRepeatedFields(Proto* message) {
message->add_repeated_int32(1);
@@ -837,8 +901,7 @@ class Proto3PrimitiveRepeatedWireFormatTest
}
template <class Proto>
- void TestProto3PrimitiveRepeatedFields(Proto* message,
- const string& expected) {
+ void TestSerialization(Proto* message, const string& expected) {
SetProto3PrimitiveRepeatedFields(message);
int size = message->ByteSize();
@@ -851,13 +914,8 @@ class Proto3PrimitiveRepeatedWireFormatTest
message->SerializeWithCachedSizes(&output);
ASSERT_FALSE(output.HadError());
}
-
EXPECT_TRUE(expected == generated_data);
- message->Clear();
- message->ParseFromString(generated_data);
- ExpectProto3PrimitiveRepeatedFieldsSet(*message);
-
// Serialize using the dynamic code.
string dynamic_data;
{
@@ -866,64 +924,38 @@ class Proto3PrimitiveRepeatedWireFormatTest
WireFormat::SerializeWithCachedSizes(*message, size, &output);
ASSERT_FALSE(output.HadError());
}
-
EXPECT_TRUE(expected == dynamic_data);
+ }
+
+ template <class Proto>
+ void TestParsing(Proto* message, const string& compatible_data) {
+ message->Clear();
+ message->ParseFromString(compatible_data);
+ ExpectProto3PrimitiveRepeatedFieldsSet(*message);
message->Clear();
io::CodedInputStream input(
- reinterpret_cast<const uint8*>(dynamic_data.data()),
- dynamic_data.size());
+ reinterpret_cast<const uint8*>(compatible_data.data()),
+ compatible_data.size());
WireFormat::ParseAndMergePartial(&input, message);
ExpectProto3PrimitiveRepeatedFieldsSet(*message);
}
+
+ const string packedTestAllTypes_;
+ const string packedTestUnpackedTypes_;
+ const string unpackedTestAllTypes_;
+ const string unpackedTestUnpackedTypes_;
};
-INSTANTIATE_TEST_CASE_P(SetPacked,
- Proto3PrimitiveRepeatedWireFormatTest,
- ::testing::Values(false, true));
-TEST_P(Proto3PrimitiveRepeatedWireFormatTest, Proto3PrimitiveRepeated) {
+TEST_F(Proto3PrimitiveRepeatedWireFormatTest, Proto3PrimitiveRepeated) {
proto3_arena_unittest::TestAllTypes packed_message;
proto3_arena_unittest::TestUnpackedTypes unpacked_message;
-
- const string packedExpected(
- "\xFA\x01\x01\x01"
- "\x82\x02\x01\x01"
- "\x8A\x02\x01\x01"
- "\x92\x02\x01\x01"
- "\x9A\x02\x01\x02"
- "\xA2\x02\x01\x02"
- "\xAA\x02\x04\x01\x00\x00\x00"
- "\xB2\x02\x08\x01\x00\x00\x00\x00\x00\x00\x00"
- "\xBA\x02\x04\x01\x00\x00\x00"
- "\xC2\x02\x08\x01\x00\x00\x00\x00\x00\x00\x00"
- "\xCA\x02\x04\x00\x00\x80\x3f"
- "\xD2\x02\x08\x00\x00\x00\x00\x00\x00\xf0\x3f"
- "\xDA\x02\x01\x01"
- "\x9A\x03\x01\x01",
- 86);
-
- const string unpackedExpected(
- "\x08\x01"
- "\x10\x01"
- "\x18\x01"
- "\x20\x01"
- "\x28\x02"
- "\x30\x02"
- "\x3D\x01\x00\x00\x00"
- "\x41\x01\x00\x00\x00\x00\x00\x00\x00"
- "\x4D\x01\x00\x00\x00"
- "\x51\x01\x00\x00\x00\x00\x00\x00\x00"
- "\x5D\x00\x00\x80\x3f"
- "\x61\x00\x00\x00\x00\x00\x00\xf0\x3f"
- "\x68\x01"
- "\x70\x01",
- 58);
-
- if (GetParam()) {
- TestProto3PrimitiveRepeatedFields(&packed_message, packedExpected);
- } else {
- TestProto3PrimitiveRepeatedFields(&unpacked_message, unpackedExpected);
- }
+ TestSerialization(&packed_message, packedTestAllTypes_);
+ TestParsing(&packed_message, packedTestAllTypes_);
+ TestParsing(&packed_message, unpackedTestAllTypes_);
+ TestSerialization(&unpacked_message, unpackedTestUnpackedTypes_);
+ TestParsing(&unpacked_message, packedTestUnpackedTypes_);
+ TestParsing(&unpacked_message, unpackedTestUnpackedTypes_);
}
class WireFormatInvalidInputTest : public testing::Test {