From 3f25ed10e63490f0845edf2ccdced1274bc0e5be Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Sun, 17 Dec 2023 14:42:19 -0800 Subject: [PATCH] Migrate C++ type name getters from `intXX` to standard integer types `intXX_t` PiperOrigin-RevId: 591730569 --- .../protobuf/compiler/php/php_generator.cc | 6 ++-- src/google/protobuf/descriptor.cc | 20 ++++++------- src/google/protobuf/descriptor_unittest.cc | 28 +++++++++---------- src/google/protobuf/map_test.inc | 4 +-- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 62498abc6f1d..aed817757af7 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -734,9 +734,9 @@ void GenerateFieldAccessor(const FieldDescriptor* field, const Options& options, "utf8", field->type() == FieldDescriptor::TYPE_STRING ? "True": "False"); } else { - printer->Print( - "GPBUtil::check^type^($var);\n", - "type", UnderscoresToCamelCase(field->cpp_type_name(), true)); + printer->Print("GPBUtil::check^type^($var);\n", "type", + UnderscoresToCamelCase( + absl::StripSuffix(field->cpp_type_name(), "_t"), true)); } if (oneof != NULL) { diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 004be51c3bdc..ee697254576a 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -790,16 +790,16 @@ const char* const FieldDescriptor::kTypeToName[MAX_TYPE + 1] = { const char* const FieldDescriptor::kCppTypeToName[MAX_CPPTYPE + 1] = { "ERROR", // 0 is reserved for errors - "int32", // CPPTYPE_INT32 - "int64", // CPPTYPE_INT64 - "uint32", // CPPTYPE_UINT32 - "uint64", // CPPTYPE_UINT64 - "double", // CPPTYPE_DOUBLE - "float", // CPPTYPE_FLOAT - "bool", // CPPTYPE_BOOL - "enum", // CPPTYPE_ENUM - "string", // CPPTYPE_STRING - "message", // CPPTYPE_MESSAGE + "int32_t", // CPPTYPE_INT32 + "int64_t", // CPPTYPE_INT64 + "uint32_t", // CPPTYPE_UINT32 + "uint64_t", // CPPTYPE_UINT64 + "double", // CPPTYPE_DOUBLE + "float", // CPPTYPE_FLOAT + "bool", // CPPTYPE_BOOL + "enum", // CPPTYPE_ENUM + "string", // CPPTYPE_STRING + "message", // CPPTYPE_MESSAGE }; const char* const FieldDescriptor::kLabelToName[MAX_LABEL + 1] = { diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index 703fb77861f5..30038b9f52cd 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -2729,22 +2729,22 @@ TEST_F(MiscTest, CppTypeNames) { EXPECT_STREQ("double", GetCppTypeNameForFieldType(FD::TYPE_DOUBLE)); EXPECT_STREQ("float", GetCppTypeNameForFieldType(FD::TYPE_FLOAT)); - EXPECT_STREQ("int64", GetCppTypeNameForFieldType(FD::TYPE_INT64)); - EXPECT_STREQ("uint64", GetCppTypeNameForFieldType(FD::TYPE_UINT64)); - EXPECT_STREQ("int32", GetCppTypeNameForFieldType(FD::TYPE_INT32)); - EXPECT_STREQ("uint64", GetCppTypeNameForFieldType(FD::TYPE_FIXED64)); - EXPECT_STREQ("uint32", GetCppTypeNameForFieldType(FD::TYPE_FIXED32)); + EXPECT_STREQ("int64_t", GetCppTypeNameForFieldType(FD::TYPE_INT64)); + EXPECT_STREQ("uint64_t", GetCppTypeNameForFieldType(FD::TYPE_UINT64)); + EXPECT_STREQ("int32_t", GetCppTypeNameForFieldType(FD::TYPE_INT32)); + EXPECT_STREQ("uint64_t", GetCppTypeNameForFieldType(FD::TYPE_FIXED64)); + EXPECT_STREQ("uint32_t", GetCppTypeNameForFieldType(FD::TYPE_FIXED32)); EXPECT_STREQ("bool", GetCppTypeNameForFieldType(FD::TYPE_BOOL)); EXPECT_STREQ("string", GetCppTypeNameForFieldType(FD::TYPE_STRING)); EXPECT_STREQ("message", GetCppTypeNameForFieldType(FD::TYPE_GROUP)); EXPECT_STREQ("message", GetCppTypeNameForFieldType(FD::TYPE_MESSAGE)); EXPECT_STREQ("string", GetCppTypeNameForFieldType(FD::TYPE_BYTES)); - EXPECT_STREQ("uint32", GetCppTypeNameForFieldType(FD::TYPE_UINT32)); + EXPECT_STREQ("uint32_t", GetCppTypeNameForFieldType(FD::TYPE_UINT32)); EXPECT_STREQ("enum", GetCppTypeNameForFieldType(FD::TYPE_ENUM)); - EXPECT_STREQ("int32", GetCppTypeNameForFieldType(FD::TYPE_SFIXED32)); - EXPECT_STREQ("int64", GetCppTypeNameForFieldType(FD::TYPE_SFIXED64)); - EXPECT_STREQ("int32", GetCppTypeNameForFieldType(FD::TYPE_SINT32)); - EXPECT_STREQ("int64", GetCppTypeNameForFieldType(FD::TYPE_SINT64)); + EXPECT_STREQ("int32_t", GetCppTypeNameForFieldType(FD::TYPE_SFIXED32)); + EXPECT_STREQ("int64_t", GetCppTypeNameForFieldType(FD::TYPE_SFIXED64)); + EXPECT_STREQ("int32_t", GetCppTypeNameForFieldType(FD::TYPE_SINT32)); + EXPECT_STREQ("int64_t", GetCppTypeNameForFieldType(FD::TYPE_SINT64)); } TEST_F(MiscTest, StaticCppTypeNames) { @@ -2752,10 +2752,10 @@ TEST_F(MiscTest, StaticCppTypeNames) { typedef FieldDescriptor FD; // avoid ugly line wrapping - EXPECT_STREQ("int32", FD::CppTypeName(FD::CPPTYPE_INT32)); - EXPECT_STREQ("int64", FD::CppTypeName(FD::CPPTYPE_INT64)); - EXPECT_STREQ("uint32", FD::CppTypeName(FD::CPPTYPE_UINT32)); - EXPECT_STREQ("uint64", FD::CppTypeName(FD::CPPTYPE_UINT64)); + EXPECT_STREQ("int32_t", FD::CppTypeName(FD::CPPTYPE_INT32)); + EXPECT_STREQ("int64_t", FD::CppTypeName(FD::CPPTYPE_INT64)); + EXPECT_STREQ("uint32_t", FD::CppTypeName(FD::CPPTYPE_UINT32)); + EXPECT_STREQ("uint64_t", FD::CppTypeName(FD::CPPTYPE_UINT64)); EXPECT_STREQ("double", FD::CppTypeName(FD::CPPTYPE_DOUBLE)); EXPECT_STREQ("float", FD::CppTypeName(FD::CPPTYPE_FLOAT)); EXPECT_STREQ("bool", FD::CppTypeName(FD::CPPTYPE_BOOL)); diff --git a/src/google/protobuf/map_test.inc b/src/google/protobuf/map_test.inc index cbd0f4461893..d710f8821036 100644 --- a/src/google/protobuf/map_test.inc +++ b/src/google/protobuf/map_test.inc @@ -386,8 +386,8 @@ TEST_F(MapImplTest, UsageErrors) { EXPECT_DEATH(key.GetUInt64Value(), "Protocol Buffer map usage error:\n" "MapKey::GetUInt64Value type does not match\n" - " Expected : uint64\n" - " Actual : int64"); + " Expected : uint64_t\n" + " Actual : int64_t"); MapValueRef value; EXPECT_DEATH(