From 4aadcd3c7bf69c5c2c904ef73fef14a723dc4866 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Mon, 21 Aug 2017 13:15:00 -0700 Subject: Remove C++11 features in io_win32.cc - Use scoped_array instead of unique_ptr. - Do not use string::front() and string::back() --- src/google/protobuf/stubs/io_win32.cc | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/google/protobuf/stubs/io_win32.cc b/src/google/protobuf/stubs/io_win32.cc index b418986b..0eda8409 100644 --- a/src/google/protobuf/stubs/io_win32.cc +++ b/src/google/protobuf/stubs/io_win32.cc @@ -57,6 +57,7 @@ #include #include +#include #include #include @@ -71,7 +72,6 @@ namespace win32 { namespace { using std::string; -using std::unique_ptr; using std::wstring; template @@ -139,11 +139,11 @@ string join_paths(const string& path1, const string& path2) { return path1; } - if (is_separator(path1.back())) { - return is_separator(path2.front()) ? (path1 + path2.substr(1)) + if (is_separator(path1[path1.size() - 1])) { + return is_separator(path2[0]) ? (path1 + path2.substr(1)) : (path1 + path2); } else { - return is_separator(path2.front()) ? (path1 + path2) + return is_separator(path2[0]) ? (path1 + path2) : (path1 + '\\' + path2); } } @@ -203,24 +203,24 @@ string normalize(string path) { result << s; } // Preserve trailing separator if the input contained it. - if (is_separator(path.back())) { + if (!path.empty() && is_separator(path[path.size() - 1])) { result << '\\'; } return result.str(); } -std::unique_ptr as_wstring(const string& s) { +WCHAR* as_wstring(const string& s) { int len = ::MultiByteToWideChar(CP_UTF8, 0, s.c_str(), s.size(), NULL, 0); - std::unique_ptr result(new WCHAR[len + 1]); + WCHAR* result = new WCHAR[len + 1]; ::MultiByteToWideChar(CP_UTF8, 0, s.c_str(), s.size(), result.get(), len + 1); - result.get()[len] = 0; - return std::move(result); + result[len] = 0; + return result; } -wstring as_wchar_path(const string& path) { - std::unique_ptr wbuf(as_wstring(path)); - replace_directory_separators(wbuf.get()); - return wstring(wbuf.get()); +void as_wchar_path(const string& path, wstring* wchar_path) { + scoped_array wbuf(as_wstring(path)); + replace_directory_separators(wbuf); + wchar_path->assign(wbuf); } bool as_windows_path(const string& path, wstring* result) { @@ -239,7 +239,7 @@ bool as_windows_path(const string& path, wstring* result) { ::GetCurrentDirectoryA(MAX_PATH, cwd); mutable_path = join_paths(cwd, mutable_path); } - *result = as_wchar_path(normalize(mutable_path)); + as_wchar_path(normalize(mutable_path), result); if (!has_longpath_prefix(result->c_str())) { // Add the "\\?\" prefix unconditionally. This way we prevent the Win32 API // from processing the path and "helpfully" removing trailing dots from the @@ -324,7 +324,7 @@ FILE* fopen(const char* path, const char* mode) { errno = ENOENT; return NULL; } - std::unique_ptr wmode(as_wstring(mode)); + scoped_array wmode(as_wstring(mode)); return ::_wfopen(wpath.c_str(), wmode.get()); #else return ::fopen(path, mode); -- cgit v1.2.3 From dd5190980b8a9205eaf292f0cd947c3657daaeb1 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Mon, 21 Aug 2017 13:39:15 -0700 Subject: Use message name as defined in php runtime. --- php/src/Google/Protobuf/Internal/GPBUtil.php | 2 +- php/src/Google/Protobuf/Internal/Message.php | 3 +++ php/tests/generated_class_test.php | 12 ++++++++++++ php/tests/memory_leak_test.php | 2 ++ php/tests/proto/test.proto | 7 +++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php index 6fe36068..84e8ecf0 100644 --- a/php/src/Google/Protobuf/Internal/GPBUtil.php +++ b/php/src/Google/Protobuf/Internal/GPBUtil.php @@ -270,7 +270,7 @@ class GPBUtil $name, $file_proto) { - $classname = implode('_', array_map('ucwords', explode('.', $name))); + $classname = implode('_', explode('.', $name)); return static::getClassNamePrefix($classname, $file_proto) . $classname; } diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index e1009f2f..8886e61a 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -76,6 +76,9 @@ class Message } $pool = DescriptorPool::getGeneratedPool(); $this->desc = $pool->getDescriptorByClassName(get_class($this)); + if (is_null($this->desc)) { + user_error(get_class($this) . "is not found in descriptor pool."); + } foreach ($this->desc->getField() as $field) { $setter = $field->getSetter(); if ($field->isMap()) { diff --git a/php/tests/generated_class_test.php b/php/tests/generated_class_test.php index 86e68683..98918bce 100644 --- a/php/tests/generated_class_test.php +++ b/php/tests/generated_class_test.php @@ -14,6 +14,8 @@ use Foo\TestIncludePrefixMessage; use Foo\TestMessage; use Foo\TestMessage_Sub; use Foo\TestReverseFieldOrder; +use Foo\testLowerCaseMessage; +use Foo\testLowerCaseEnum; use Php\Test\TestNamespace; class GeneratedClassTest extends TestBase @@ -715,4 +717,14 @@ class GeneratedClassTest extends TestBase $this->assertSame("abc", $m->getB()); $this->assertNotSame("abc", $m->getA()); } + + ######################################################### + # Test Reverse Field Order. + ######################################################### + + public function testLowerCase() + { + $m = new testLowerCaseMessage(); + $n = testLowerCaseEnum::VALUE; + } } diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php index a92694d0..7c3a1801 100644 --- a/php/tests/memory_leak_test.php +++ b/php/tests/memory_leak_test.php @@ -23,6 +23,8 @@ require_once('generated/Foo/TestPhpDoc.php'); require_once('generated/Foo/TestRandomFieldOrder.php'); require_once('generated/Foo/TestReverseFieldOrder.php'); require_once('generated/Foo/TestUnpackedMessage.php'); +require_once('generated/Foo/testLowerCaseMessage.php'); +require_once('generated/Foo/testLowerCaseEnum.php'); require_once('generated/GPBMetadata/Proto/Test.php'); require_once('generated/GPBMetadata/Proto/TestEmptyPhpNamespace.php'); require_once('generated/GPBMetadata/Proto/TestInclude.php'); diff --git a/php/tests/proto/test.proto b/php/tests/proto/test.proto index a90f3d1d..56cba446 100644 --- a/php/tests/proto/test.proto +++ b/php/tests/proto/test.proto @@ -192,3 +192,10 @@ message TestReverseFieldOrder { repeated int32 a = 2; string b = 1; } + +message testLowerCaseMessage { +} + +enum testLowerCaseEnum { + VALUE = 0; +} -- cgit v1.2.3 From 77a453a57f065bfd059f2d039ec3883f8ce726a6 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Mon, 21 Aug 2017 14:21:00 -0700 Subject: Fix compile errors --- src/google/protobuf/stubs/io_win32.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/google/protobuf/stubs/io_win32.cc b/src/google/protobuf/stubs/io_win32.cc index 0eda8409..51656a78 100644 --- a/src/google/protobuf/stubs/io_win32.cc +++ b/src/google/protobuf/stubs/io_win32.cc @@ -212,15 +212,15 @@ string normalize(string path) { WCHAR* as_wstring(const string& s) { int len = ::MultiByteToWideChar(CP_UTF8, 0, s.c_str(), s.size(), NULL, 0); WCHAR* result = new WCHAR[len + 1]; - ::MultiByteToWideChar(CP_UTF8, 0, s.c_str(), s.size(), result.get(), len + 1); + ::MultiByteToWideChar(CP_UTF8, 0, s.c_str(), s.size(), result, len + 1); result[len] = 0; return result; } void as_wchar_path(const string& path, wstring* wchar_path) { scoped_array wbuf(as_wstring(path)); - replace_directory_separators(wbuf); - wchar_path->assign(wbuf); + replace_directory_separators(wbuf.get()); + wchar_path->assign(wbuf.get()); } bool as_windows_path(const string& path, wstring* result) { -- cgit v1.2.3 From 36ac06fdc76ea9fd2cea5195a9685756b5bd4179 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Mon, 21 Aug 2017 15:45:59 -0700 Subject: Merge pull request #3535 from drivehappy/clang_warn_cleanup Fixing unused parameter warnings under Clang. --- src/google/protobuf/map.h | 3 +- src/google/protobuf/map_type_handler.h | 59 ++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index 6514a0cc..883556a7 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -181,7 +181,7 @@ class Map { MapAllocator(const MapAllocator& allocator) : arena_(allocator.arena()) {} - pointer allocate(size_type n, const void* hint = 0) { + pointer allocate(size_type n, const void* /* hint */ = 0) { // If arena is not given, malloc needs to be called which doesn't // construct element object. if (arena_ == NULL) { @@ -197,6 +197,7 @@ class Map { #if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation) ::operator delete(p, n * sizeof(value_type)); #else + (void)n; ::operator delete(p); #endif } diff --git a/src/google/protobuf/map_type_handler.h b/src/google/protobuf/map_type_handler.h index 423c98f1..7f7b1e0e 100644 --- a/src/google/protobuf/map_type_handler.h +++ b/src/google/protobuf/map_type_handler.h @@ -72,7 +72,7 @@ class MapValueInitializer { template class MapValueInitializer { public: - static inline void Initialize(Type& value, int default_enum_value) {} + static inline void Initialize(Type& /* value */, int /* default_enum_value */) {} }; template @@ -301,7 +301,7 @@ GOOGLE_PROTOBUF_BYTE_SIZE(ENUM , Enum) #define FIXED_BYTE_SIZE(FieldType, DeclaredType) \ template \ inline int MapTypeHandler::ByteSize( \ - const MapEntryAccessorType& value) { \ + const MapEntryAccessorType& /* value */) { \ return WireFormatLite::k##DeclaredType##Size; \ } @@ -348,7 +348,7 @@ GET_CACHED_SIZE(ENUM , Enum) template \ inline int \ MapTypeHandler::GetCachedSize( \ - const MapEntryAccessorType& value) { \ + const MapEntryAccessorType& /* value */) { \ return WireFormatLite::k##DeclaredType##Size; \ } @@ -479,20 +479,20 @@ size_t MapTypeHandler::SpaceUsedInMapLong( template inline void MapTypeHandler::Clear( - Type** value, Arena* arena) { + Type** value, Arena* /* arena */) { if (*value != NULL) (*value)->Clear(); } template inline void MapTypeHandler::ClearMaybeByDefaultEnum(Type** value, - Arena* arena, - int default_enum_value) { + Arena* /* arena */, + int /* default_enum_value */) { if (*value != NULL) (*value)->Clear(); } template inline void MapTypeHandler::Merge( - const Type& from, Type** to, Arena* arena) { + const Type& from, Type** to, Arena* /* arena */) { (*to)->MergeFrom(from); } @@ -511,14 +511,14 @@ inline void MapTypeHandler inline void MapTypeHandler::Initialize(Type** x, - Arena* arena) { + Arena* /* arena */) { *x = NULL; } template inline void MapTypeHandler:: - InitializeMaybeByDefaultEnum(Type** x, int default_enum_value, - Arena* arena) { + InitializeMaybeByDefaultEnum(Type** x, int /* default_enum_value */, + Arena* /* arena */) { *x = NULL; } @@ -583,7 +583,7 @@ inline bool MapTypeHandler \ inline void MapTypeHandler:: \ ClearMaybeByDefaultEnum(TypeOnMemory* value, Arena* arena, \ - int default_enum) { \ + int /* default_enum */) { \ Clear(value, arena); \ } \ template \ @@ -598,18 +598,19 @@ inline bool MapTypeHandler \ inline void MapTypeHandler::AssignDefaultValue(TypeOnMemory* value) {} \ + Type>::AssignDefaultValue(TypeOnMemory* /* value */) {} \ template \ inline void \ MapTypeHandler::Initialize( \ - TypeOnMemory* value, Arena* arena) { \ + TypeOnMemory* value, Arena* /* arena */) { \ value->UnsafeSetDefault( \ &::google::protobuf::internal::GetEmptyStringAlreadyInited()); \ } \ template \ inline void MapTypeHandler:: \ InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ - int default_enum_value, Arena* arena) { \ + int /* default_enum_value */, \ + Arena* arena) { \ Initialize(value, arena); \ } \ template \ @@ -626,12 +627,12 @@ inline bool MapTypeHandler::DefaultIfNotInitialized(const TypeOnMemory& value, \ const TypeOnMemory& \ - default_value) { \ + /* default_value */) { \ return value.Get(); \ } \ template \ inline bool MapTypeHandler::IsInitialized(const TypeOnMemory& value) { \ + Type>::IsInitialized(const TypeOnMemory& /* value */) { \ return true; \ } STRING_OR_BYTES_HANDLER_FUNCTIONS(STRING) @@ -649,54 +650,56 @@ STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES) template \ inline size_t \ MapTypeHandler::SpaceUsedInMapEntryLong(const TypeOnMemory& value) { \ + Type>::SpaceUsedInMapEntryLong(const TypeOnMemory& /* value */) { \ return 0; \ } \ template \ inline size_t \ MapTypeHandler::SpaceUsedInMapLong( \ - const TypeOnMemory& value) { \ + const TypeOnMemory& /* value */) { \ return sizeof(Type); \ } \ template \ inline void MapTypeHandler::Clear( \ - TypeOnMemory* value, Arena* arena) { \ + TypeOnMemory* value, Arena* /* arena */) { \ *value = 0; \ } \ template \ inline void MapTypeHandler:: \ - ClearMaybeByDefaultEnum(TypeOnMemory* value, Arena* arena, \ + ClearMaybeByDefaultEnum(TypeOnMemory* value, Arena* /* arena */, \ int default_enum_value) { \ *value = static_cast(default_enum_value); \ } \ template \ inline void MapTypeHandler::Merge( \ - const MapEntryAccessorType& from, TypeOnMemory* to, Arena* arena) { \ + const MapEntryAccessorType& from, TypeOnMemory* to, \ + Arena* /* arena */) { \ *to = from; \ } \ template \ inline void MapTypeHandler::DeleteNoArena(TypeOnMemory& x) {} \ + Type>::DeleteNoArena(TypeOnMemory& /* x */) {} \ template \ inline void MapTypeHandler::AssignDefaultValue(TypeOnMemory* value) {} \ + Type>::AssignDefaultValue(TypeOnMemory* /* value */) {} \ template \ inline void \ MapTypeHandler::Initialize( \ - TypeOnMemory* value, Arena* arena) { \ + TypeOnMemory* value, Arena* /* arena */) { \ *value = 0; \ } \ template \ inline void MapTypeHandler:: \ InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ - int default_enum_value, Arena* arena) { \ + int default_enum_value, \ + Arena* /* arena */) { \ *value = static_cast(default_enum_value); \ } \ template \ inline typename MapTypeHandler::MapEntryAccessorType* \ MapTypeHandler::EnsureMutable( \ - TypeOnMemory* value, Arena* arena) { \ + TypeOnMemory* value, Arena* /* arena */) { \ return value; \ } \ template \ @@ -705,12 +708,12 @@ STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES) MapTypeHandler::DefaultIfNotInitialized(const TypeOnMemory& value, \ const TypeOnMemory& \ - default_value) { \ + /* default_value */) { \ return value; \ } \ template \ inline bool MapTypeHandler::IsInitialized(const TypeOnMemory& value) { \ + Type>::IsInitialized(const TypeOnMemory& /* value */) { \ return true; \ } PRIMITIVE_HANDLER_FUNCTIONS(INT64) -- cgit v1.2.3 From c27b56c6927642157f0c392faca6c9fcba9750d0 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Tue, 15 Aug 2017 14:58:38 -0700 Subject: Merge pull request #3494 from drivehappy/clang_warning_macro Fixing -Wexpansion-to-defined Clang warning --- src/google/protobuf/stubs/port.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h index dbc29861..0f304c6b 100644 --- a/src/google/protobuf/stubs/port.h +++ b/src/google/protobuf/stubs/port.h @@ -256,8 +256,11 @@ static const uint64 kuint64max = GOOGLE_ULONGLONG(0xFFFFFFFFFFFFFFFF); # define GOOGLE_PROTOBUF_USE_UNALIGNED 0 #else // x86 and x86-64 can perform unaligned loads/stores directly. -# define GOOGLE_PROTOBUF_USE_UNALIGNED defined(_M_X64) || \ - defined(__x86_64__) || defined(_M_IX86) || defined(__i386__) +# if defined(_M_X64) || defined(__x86_64__) || defined(_M_IX86) || defined(__i386__) +# define GOOGLE_PROTOBUF_USE_UNALIGNED 1 +# else +# define GOOGLE_PROTOBUF_USE_UNALIGNED 0 +# endif #endif #if GOOGLE_PROTOBUF_USE_UNALIGNED -- cgit v1.2.3 From 6609e521245ab788bbd9b773a9f668bfc15f6c29 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Tue, 22 Aug 2017 12:59:32 -0700 Subject: Disable death tests on windows Also remove cord related code --- src/google/protobuf/message_unittest.cc | 38 -------------------------------- src/google/protobuf/testing/googletest.h | 3 ++- 2 files changed, 2 insertions(+), 39 deletions(-) diff --git a/src/google/protobuf/message_unittest.cc b/src/google/protobuf/message_unittest.cc index fe456677..06a7f65c 100644 --- a/src/google/protobuf/message_unittest.cc +++ b/src/google/protobuf/message_unittest.cc @@ -257,44 +257,6 @@ TEST(MessageTest, CheckInitialized) { "fields: a, b, c"); } -TEST(MessageTest, CheckOverflow) { - unittest::TestAllTypes message; - // Create a message with size just over 2GB. This triggers integer overflow - // when computing message size. - const string data(1024, 'x'); - Cord one_megabyte; - for (int i = 0; i < 1024; i++) { - one_megabyte.Append(data); - } - - for (int i = 0; i < 2 * 1024 + 1; ++i) { - message.add_repeated_cord()->CopyFrom(one_megabyte); - } - - Cord serialized; - EXPECT_FALSE(message.AppendToCord(&serialized)); -} - -TEST(MessageTest, CheckBigOverflow) { - // Checking for 4GB buffers on 32 bit systems is problematic. - if (sizeof(void*) < 8) return; - unittest::TestAllTypes message; - // Create a message with size just over 4GB. We should be able to detect this - // too, even though it will make a plain "int" wrap back to a positive number. - const string data(1024, 'x'); - Cord one_megabyte; - for (int i = 0; i < 1024; i++) { - one_megabyte.Append(data); - } - - for (int i = 0; i < 4 * 1024 + 1; ++i) { - message.add_repeated_cord()->CopyFrom(one_megabyte); - } - - Cord serialized; - EXPECT_FALSE(message.AppendToCord(&serialized)); -} - #endif // PROTOBUF_HAS_DEATH_TEST namespace { diff --git a/src/google/protobuf/testing/googletest.h b/src/google/protobuf/testing/googletest.h index dc4401d0..2db3bfee 100644 --- a/src/google/protobuf/testing/googletest.h +++ b/src/google/protobuf/testing/googletest.h @@ -39,7 +39,8 @@ #include #include // Disable death tests if we use exceptions in CHECK(). -#if !PROTOBUF_USE_EXCEPTIONS && defined(GTEST_HAS_DEATH_TEST) +#if !PROTOBUF_USE_EXCEPTIONS && defined(GTEST_HAS_DEATH_TEST) && \ + !GTEST_OS_WINDOWS #define PROTOBUF_HAS_DEATH_TEST #endif -- cgit v1.2.3