From db125b8d3a3ceb8d2ed0938f6121858393078097 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Fri, 11 Aug 2017 11:32:22 -0700 Subject: Fixing io_win32 for MinGW32 --- src/google/protobuf/stubs/io_win32.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/google/protobuf/stubs/io_win32.cc b/src/google/protobuf/stubs/io_win32.cc index 6f0295e1..a6449751 100644 --- a/src/google/protobuf/stubs/io_win32.cc +++ b/src/google/protobuf/stubs/io_win32.cc @@ -44,7 +44,10 @@ // Comment this out to fall back to using the ANSI versions (open, mkdir, ...) // instead of the Unicode ones (_wopen, _wmkdir, ...). Doing so can be useful to // debug failing tests if that's caused by the long path support. +// Long path support is disabled in MinGW +#ifndef __MINGW32__ #define SUPPORT_LONGPATHS +#endif // !__MINGW32__ #include #include -- cgit v1.2.3 From 7afa796bb914c911cc3d40aeeba1ce63b2f83f99 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Fri, 11 Aug 2017 11:45:41 -0700 Subject: Fix the declaration order in ming32 --- src/google/protobuf/stubs/io_win32.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/google/protobuf/stubs/io_win32.cc b/src/google/protobuf/stubs/io_win32.cc index a6449751..25f672cc 100644 --- a/src/google/protobuf/stubs/io_win32.cc +++ b/src/google/protobuf/stubs/io_win32.cc @@ -108,15 +108,15 @@ bool has_longpath_prefix(const char_type* path) { path[3] == '\\'; } -// Returns true if the path starts with a drive specifier (e.g. "c:\"). template -bool is_path_absolute(const char_type* path) { - return has_drive_letter(path) && is_separator(path[2]); +bool is_separator(char_type c) { + return c == '/' || c == '\\'; } +// Returns true if the path starts with a drive specifier (e.g. "c:\"). template -bool is_separator(char_type c) { - return c == '/' || c == '\\'; +bool is_path_absolute(const char_type* path) { + return has_drive_letter(path) && is_separator(path[2]); } template -- cgit v1.2.3 From 564f02c91ec0e983806762de4b842a762e21bb47 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Fri, 11 Aug 2017 12:08:00 -0700 Subject: Make win32_io only for MSVC This excludes cygwin and mingw from using the self implemented functions. --- src/google/protobuf/compiler/command_line_interface.cc | 2 +- src/google/protobuf/compiler/command_line_interface_unittest.cc | 2 +- src/google/protobuf/compiler/importer.cc | 3 +++ src/google/protobuf/compiler/objectivec/objectivec_helpers.cc | 2 +- src/google/protobuf/compiler/plugin.cc | 2 +- src/google/protobuf/io/zero_copy_stream_impl.cc | 3 +++ src/google/protobuf/io/zero_copy_stream_unittest.cc | 3 +++ src/google/protobuf/message_unittest.cc | 2 +- src/google/protobuf/stubs/io_win32.cc | 6 ++---- src/google/protobuf/stubs/io_win32.h | 4 ++-- src/google/protobuf/testing/file.cc | 3 +++ src/google/protobuf/testing/googletest.cc | 2 +- 12 files changed, 22 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 5707d72c..5f864041 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -108,7 +108,7 @@ namespace compiler { #endif namespace { -#if defined(_WIN32) && !defined(__CYGWIN__) +#if defined(_MSC_VER) // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::access; diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 64cdbcd2..73d3e4c9 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -69,7 +69,7 @@ namespace google { namespace protobuf { namespace compiler { -#if defined(_WIN32) +#if defined(_MSC_VER) // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::access; diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc index 4e86d787..4c357aa0 100644 --- a/src/google/protobuf/compiler/importer.cc +++ b/src/google/protobuf/compiler/importer.cc @@ -59,6 +59,9 @@ #ifdef _WIN32 #include +#endif + +#ifdef _MSC_VER // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::access; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 72b5d5f5..54dc7455 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -50,7 +50,7 @@ #include #include -#if defined(_WIN32) +#if defined(_MSC_VER) // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::open; diff --git a/src/google/protobuf/compiler/plugin.cc b/src/google/protobuf/compiler/plugin.cc index fcb08551..cb5e37bb 100644 --- a/src/google/protobuf/compiler/plugin.cc +++ b/src/google/protobuf/compiler/plugin.cc @@ -49,7 +49,7 @@ #include #include -#if defined(_WIN32) +#if defined(_MSC_VER) // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::setmode; diff --git a/src/google/protobuf/io/zero_copy_stream_impl.cc b/src/google/protobuf/io/zero_copy_stream_impl.cc index f72add41..81fb5033 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl.cc +++ b/src/google/protobuf/io/zero_copy_stream_impl.cc @@ -56,6 +56,9 @@ namespace io { // Win32 lseek is broken: If invoked on a non-seekable file descriptor, its // return value is undefined. We re-define it to always produce an error. #define lseek(fd, offset, origin) ((off_t)-1) +#endif + +#ifdef _MSC_VER // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::access; diff --git a/src/google/protobuf/io/zero_copy_stream_unittest.cc b/src/google/protobuf/io/zero_copy_stream_unittest.cc index f3754087..2bca6a90 100644 --- a/src/google/protobuf/io/zero_copy_stream_unittest.cc +++ b/src/google/protobuf/io/zero_copy_stream_unittest.cc @@ -83,6 +83,9 @@ namespace { #ifdef _WIN32 #define pipe(fds) _pipe(fds, 4096, O_BINARY) +#endif + +#ifdef _MSC_VER // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::access; diff --git a/src/google/protobuf/message_unittest.cc b/src/google/protobuf/message_unittest.cc index 362000c7..fe456677 100644 --- a/src/google/protobuf/message_unittest.cc +++ b/src/google/protobuf/message_unittest.cc @@ -63,7 +63,7 @@ namespace google { namespace protobuf { -#if defined(_WIN32) +#if defined(_MSC_VER) // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::close; diff --git a/src/google/protobuf/stubs/io_win32.cc b/src/google/protobuf/stubs/io_win32.cc index 25f672cc..d1ad6761 100644 --- a/src/google/protobuf/stubs/io_win32.cc +++ b/src/google/protobuf/stubs/io_win32.cc @@ -39,15 +39,13 @@ // // This file is only used on Windows, it's empty on other platforms. -#if defined(_WIN32) +#if defined(_MSC_VER) // Comment this out to fall back to using the ANSI versions (open, mkdir, ...) // instead of the Unicode ones (_wopen, _wmkdir, ...). Doing so can be useful to // debug failing tests if that's caused by the long path support. // Long path support is disabled in MinGW -#ifndef __MINGW32__ #define SUPPORT_LONGPATHS -#endif // !__MINGW32__ #include #include @@ -361,5 +359,5 @@ wstring testonly_path_to_winpath(const string& path) { } // namespace protobuf } // namespace google -#endif // defined(_WIN32) +#endif // defined(_MSC_VER) diff --git a/src/google/protobuf/stubs/io_win32.h b/src/google/protobuf/stubs/io_win32.h index 3699945b..2cd53a5e 100644 --- a/src/google/protobuf/stubs/io_win32.h +++ b/src/google/protobuf/stubs/io_win32.h @@ -45,7 +45,7 @@ #ifndef GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__ #define GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__ -#if defined(_WIN32) +#if defined(_MSC_VER) #include #include @@ -91,7 +91,7 @@ LIBPROTOBUF_EXPORT std::wstring testonly_path_to_winpath( #define STDOUT_FILENO 1 #endif -#endif // defined(_WIN32) +#endif // defined(_MSC_VER) #endif // GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__ diff --git a/src/google/protobuf/testing/file.cc b/src/google/protobuf/testing/file.cc index a1850e44..f32222b7 100644 --- a/src/google/protobuf/testing/file.cc +++ b/src/google/protobuf/testing/file.cc @@ -55,6 +55,9 @@ namespace protobuf { #define lstat stat // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. +#endif + +#ifdef _MSC_VER using google::protobuf::internal::win32::access; using google::protobuf::internal::win32::chdir; using google::protobuf::internal::win32::fopen; diff --git a/src/google/protobuf/testing/googletest.cc b/src/google/protobuf/testing/googletest.cc index c6fb00d4..33a75ed6 100644 --- a/src/google/protobuf/testing/googletest.cc +++ b/src/google/protobuf/testing/googletest.cc @@ -52,7 +52,7 @@ namespace google { namespace protobuf { -#ifdef _WIN32 +#ifdef _MSC_VER // DO NOT include , instead create functions in io_win32.{h,cc} and import // them like we do below. using google::protobuf::internal::win32::close; -- cgit v1.2.3 From 40d1855fe9107af8bee87c5e0cdf5bd6c434c8ff Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Fri, 11 Aug 2017 12:52:45 -0700 Subject: Fix mkdir --- src/google/protobuf/stubs/io_win32.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/google/protobuf/stubs/io_win32.h b/src/google/protobuf/stubs/io_win32.h index 2cd53a5e..63a52cac 100644 --- a/src/google/protobuf/stubs/io_win32.h +++ b/src/google/protobuf/stubs/io_win32.h @@ -45,11 +45,12 @@ #ifndef GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__ #define GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__ -#if defined(_MSC_VER) +#if defined(_WIN32) #include #include +#ifdef _MSC_VER namespace google { namespace protobuf { namespace internal { @@ -74,6 +75,9 @@ LIBPROTOBUF_EXPORT std::wstring testonly_path_to_winpath( } // namespace internal } // namespace protobuf } // namespace google +#else // _MSC_VER +#define mkdir(name, mode) mkdir(name) +#endif // !_MSC_VER #ifndef W_OK #define W_OK 02 // not defined by MSVC for whatever reason @@ -91,7 +95,7 @@ LIBPROTOBUF_EXPORT std::wstring testonly_path_to_winpath( #define STDOUT_FILENO 1 #endif -#endif // defined(_MSC_VER) +#endif // defined(_WIN32) #endif // GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__ -- cgit v1.2.3 From 34ebca0ca8c925a58e70d204a06e3b69b078769b Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Fri, 11 Aug 2017 13:01:28 -0700 Subject: Adding missing imports for strdup --- src/google/protobuf/compiler/subprocess.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/google/protobuf/compiler/subprocess.cc b/src/google/protobuf/compiler/subprocess.cc index afe48774..df2aeb1c 100644 --- a/src/google/protobuf/compiler/subprocess.cc +++ b/src/google/protobuf/compiler/subprocess.cc @@ -33,6 +33,7 @@ #include #include +#include #include #ifndef _WIN32 -- cgit v1.2.3 From fd31899f01a5e486c0f457318a5f9b4fe0915271 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Fri, 11 Aug 2017 13:32:52 -0700 Subject: implement remove strdup usage and implement our own strdup is not part C or C++ standard but POXIS function. Several compilers failed to compile strdup or generate warnings. --- src/google/protobuf/compiler/subprocess.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/google/protobuf/compiler/subprocess.cc b/src/google/protobuf/compiler/subprocess.cc index df2aeb1c..2a8688d6 100644 --- a/src/google/protobuf/compiler/subprocess.cc +++ b/src/google/protobuf/compiler/subprocess.cc @@ -52,6 +52,16 @@ namespace google { namespace protobuf { namespace compiler { +namespace { +char* portable_strdup(const char* s) { + char* ns = malloc(strlen(s) + 1); + if (ns) { + strcpy(ns, s); + } + return ns; +} +} // namespace + #ifdef _WIN32 static void CloseHandleOrDie(HANDLE handle) { @@ -115,7 +125,7 @@ void Subprocess::Start(const string& program, SearchMode search_mode) { } // CreateProcess() mutates its second parameter. WTF? - char* name_copy = strdup(program.c_str()); + char* name_copy = portable_strdup(program.c_str()); // Create the process. PROCESS_INFORMATION process_info; @@ -299,7 +309,7 @@ void Subprocess::Start(const string& program, SearchMode search_mode) { GOOGLE_CHECK(pipe(stdin_pipe) != -1); GOOGLE_CHECK(pipe(stdout_pipe) != -1); - char* argv[2] = { strdup(program.c_str()), NULL }; + char* argv[2] = { portable_strdup(program.c_str()), NULL }; child_pid_ = fork(); if (child_pid_ == -1) { -- cgit v1.2.3 From b4c0cfe3a4cbc17148c0d1d728666d70136b7e93 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Fri, 11 Aug 2017 13:46:14 -0700 Subject: Add malloc cast --- src/google/protobuf/compiler/subprocess.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/google/protobuf/compiler/subprocess.cc b/src/google/protobuf/compiler/subprocess.cc index 2a8688d6..2e5a89ac 100644 --- a/src/google/protobuf/compiler/subprocess.cc +++ b/src/google/protobuf/compiler/subprocess.cc @@ -54,8 +54,8 @@ namespace compiler { namespace { char* portable_strdup(const char* s) { - char* ns = malloc(strlen(s) + 1); - if (ns) { + char* ns = (char*) malloc(strlen(s) + 1); + if (ns != NULL) { strcpy(ns, s); } return ns; -- cgit v1.2.3 From 651429b709cd83ca1c780a7c40c3953e638954a4 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Fri, 11 Aug 2017 14:01:41 -0700 Subject: Fix comments --- src/google/protobuf/stubs/io_win32.cc | 1 - src/google/protobuf/stubs/io_win32.h | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/google/protobuf/stubs/io_win32.cc b/src/google/protobuf/stubs/io_win32.cc index d1ad6761..b418986b 100644 --- a/src/google/protobuf/stubs/io_win32.cc +++ b/src/google/protobuf/stubs/io_win32.cc @@ -44,7 +44,6 @@ // Comment this out to fall back to using the ANSI versions (open, mkdir, ...) // instead of the Unicode ones (_wopen, _wmkdir, ...). Doing so can be useful to // debug failing tests if that's caused by the long path support. -// Long path support is disabled in MinGW #define SUPPORT_LONGPATHS #include diff --git a/src/google/protobuf/stubs/io_win32.h b/src/google/protobuf/stubs/io_win32.h index 63a52cac..a20e64c7 100644 --- a/src/google/protobuf/stubs/io_win32.h +++ b/src/google/protobuf/stubs/io_win32.h @@ -50,6 +50,8 @@ #include #include +// Compilers on Windows other than MSVC (e.g. Cygwin, MinGW32) define the +// following functions already, except for mkdir. #ifdef _MSC_VER namespace google { namespace protobuf { -- cgit v1.2.3