From 25720efec5173dc2a6b70841edcc0e56962567e9 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Tue, 12 Apr 2016 19:30:19 +0200 Subject: [PATCH 01/15] Sanitizing repository. --- src/proto/grpc/binary_log/v1alpha/log.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto/grpc/binary_log/v1alpha/log.proto b/src/proto/grpc/binary_log/v1alpha/log.proto index 6cc473be74e..83166cd4104 100644 --- a/src/proto/grpc/binary_log/v1alpha/log.proto +++ b/src/proto/grpc/binary_log/v1alpha/log.proto @@ -105,4 +105,4 @@ message Message { // The contents of the message. May be a prefix instead of the complete // message. bytes data = 5; -} \ No newline at end of file +} From c4b18a50de3ab04b189c9f0e2b56cb08a9f15542 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 15 Apr 2016 04:53:54 +0200 Subject: [PATCH 02/15] Adding support for msys. --- BUILD | 4 + Makefile | 2 + binding.gyp | 2 + build.yaml | 2 + config.m4 | 2 + gRPC.podspec | 2 + grpc.gemspec | 2 + include/grpc/impl/codegen/port_platform.h | 44 +++++----- package.xml | 2 + src/core/lib/iomgr/tcp_server_windows.c | 27 ++---- src/core/lib/iomgr/tcp_windows.c | 14 +++- src/core/lib/support/env_win32.c | 44 +++++----- src/core/lib/support/log_linux.c | 4 +- src/core/lib/support/log_win32.c | 18 +--- src/core/lib/support/string_util_win32.c | 91 +++++++++++++++++++++ src/core/lib/support/string_win32.c | 41 +++------- src/core/lib/support/time_win32.c | 4 +- src/core/lib/support/tmpfile_msys.c | 75 +++++++++++++++++ src/core/lib/support/tmpfile_posix.c | 4 +- src/core/lib/support/tmpfile_win32.c | 4 +- src/python/grpcio/grpc_core_dependencies.py | 2 + test/core/util/port_windows.c | 9 +- test/core/util/test_config.c | 2 +- tools/doxygen/Doxyfile.core.internal | 2 + tools/run_tests/sources_and_headers.json | 2 + vsprojects/vcxproj/gpr/gpr.vcxproj | 4 + vsprojects/vcxproj/gpr/gpr.vcxproj.filters | 6 ++ 27 files changed, 296 insertions(+), 119 deletions(-) create mode 100644 src/core/lib/support/string_util_win32.c create mode 100644 src/core/lib/support/tmpfile_msys.c diff --git a/BUILD b/BUILD index fa9a1209899..237322a5e10 100644 --- a/BUILD +++ b/BUILD @@ -84,6 +84,7 @@ cc_library( "src/core/lib/support/stack_lockfree.c", "src/core/lib/support/string.c", "src/core/lib/support/string_posix.c", + "src/core/lib/support/string_util_win32.c", "src/core/lib/support/string_win32.c", "src/core/lib/support/subprocess_posix.c", "src/core/lib/support/subprocess_windows.c", @@ -98,6 +99,7 @@ cc_library( "src/core/lib/support/time_precise.c", "src/core/lib/support/time_win32.c", "src/core/lib/support/tls_pthread.c", + "src/core/lib/support/tmpfile_msys.c", "src/core/lib/support/tmpfile_posix.c", "src/core/lib/support/tmpfile_win32.c", "src/core/lib/support/wrap_memcpy.c", @@ -1211,6 +1213,7 @@ objc_library( "src/core/lib/support/stack_lockfree.c", "src/core/lib/support/string.c", "src/core/lib/support/string_posix.c", + "src/core/lib/support/string_util_win32.c", "src/core/lib/support/string_win32.c", "src/core/lib/support/subprocess_posix.c", "src/core/lib/support/subprocess_windows.c", @@ -1225,6 +1228,7 @@ objc_library( "src/core/lib/support/time_precise.c", "src/core/lib/support/time_win32.c", "src/core/lib/support/tls_pthread.c", + "src/core/lib/support/tmpfile_msys.c", "src/core/lib/support/tmpfile_posix.c", "src/core/lib/support/tmpfile_win32.c", "src/core/lib/support/wrap_memcpy.c", diff --git a/Makefile b/Makefile index 488d6f4dcec..fdc523907d3 100644 --- a/Makefile +++ b/Makefile @@ -2322,6 +2322,7 @@ LIBGPR_SRC = \ src/core/lib/support/stack_lockfree.c \ src/core/lib/support/string.c \ src/core/lib/support/string_posix.c \ + src/core/lib/support/string_util_win32.c \ src/core/lib/support/string_win32.c \ src/core/lib/support/subprocess_posix.c \ src/core/lib/support/subprocess_windows.c \ @@ -2336,6 +2337,7 @@ LIBGPR_SRC = \ src/core/lib/support/time_precise.c \ src/core/lib/support/time_win32.c \ src/core/lib/support/tls_pthread.c \ + src/core/lib/support/tmpfile_msys.c \ src/core/lib/support/tmpfile_posix.c \ src/core/lib/support/tmpfile_win32.c \ src/core/lib/support/wrap_memcpy.c \ diff --git a/binding.gyp b/binding.gyp index 8efc8a2b8e6..492b75f8fd4 100644 --- a/binding.gyp +++ b/binding.gyp @@ -519,6 +519,7 @@ 'src/core/lib/support/stack_lockfree.c', 'src/core/lib/support/string.c', 'src/core/lib/support/string_posix.c', + 'src/core/lib/support/string_util_win32.c', 'src/core/lib/support/string_win32.c', 'src/core/lib/support/subprocess_posix.c', 'src/core/lib/support/subprocess_windows.c', @@ -533,6 +534,7 @@ 'src/core/lib/support/time_precise.c', 'src/core/lib/support/time_win32.c', 'src/core/lib/support/tls_pthread.c', + 'src/core/lib/support/tmpfile_msys.c', 'src/core/lib/support/tmpfile_posix.c', 'src/core/lib/support/tmpfile_win32.c', 'src/core/lib/support/wrap_memcpy.c', diff --git a/build.yaml b/build.yaml index a6feea50746..4a0663452d8 100644 --- a/build.yaml +++ b/build.yaml @@ -103,6 +103,7 @@ filegroups: - src/core/lib/support/stack_lockfree.c - src/core/lib/support/string.c - src/core/lib/support/string_posix.c + - src/core/lib/support/string_util_win32.c - src/core/lib/support/string_win32.c - src/core/lib/support/subprocess_posix.c - src/core/lib/support/subprocess_windows.c @@ -117,6 +118,7 @@ filegroups: - src/core/lib/support/time_precise.c - src/core/lib/support/time_win32.c - src/core/lib/support/tls_pthread.c + - src/core/lib/support/tmpfile_msys.c - src/core/lib/support/tmpfile_posix.c - src/core/lib/support/tmpfile_win32.c - src/core/lib/support/wrap_memcpy.c diff --git a/config.m4 b/config.m4 index 7d3d899a405..acd798741fb 100644 --- a/config.m4 +++ b/config.m4 @@ -63,6 +63,7 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/support/stack_lockfree.c \ src/core/lib/support/string.c \ src/core/lib/support/string_posix.c \ + src/core/lib/support/string_util_win32.c \ src/core/lib/support/string_win32.c \ src/core/lib/support/subprocess_posix.c \ src/core/lib/support/subprocess_windows.c \ @@ -77,6 +78,7 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/support/time_precise.c \ src/core/lib/support/time_win32.c \ src/core/lib/support/tls_pthread.c \ + src/core/lib/support/tmpfile_msys.c \ src/core/lib/support/tmpfile_posix.c \ src/core/lib/support/tmpfile_win32.c \ src/core/lib/support/wrap_memcpy.c \ diff --git a/gRPC.podspec b/gRPC.podspec index 82c5eaac411..b3122dd272e 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -144,6 +144,7 @@ Pod::Spec.new do |s| 'src/core/lib/support/stack_lockfree.c', 'src/core/lib/support/string.c', 'src/core/lib/support/string_posix.c', + 'src/core/lib/support/string_util_win32.c', 'src/core/lib/support/string_win32.c', 'src/core/lib/support/subprocess_posix.c', 'src/core/lib/support/subprocess_windows.c', @@ -158,6 +159,7 @@ Pod::Spec.new do |s| 'src/core/lib/support/time_precise.c', 'src/core/lib/support/time_win32.c', 'src/core/lib/support/tls_pthread.c', + 'src/core/lib/support/tmpfile_msys.c', 'src/core/lib/support/tmpfile_posix.c', 'src/core/lib/support/tmpfile_win32.c', 'src/core/lib/support/wrap_memcpy.c', diff --git a/grpc.gemspec b/grpc.gemspec index b8cfc4e6c4e..3e0677ebdcb 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -128,6 +128,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/support/stack_lockfree.c ) s.files += %w( src/core/lib/support/string.c ) s.files += %w( src/core/lib/support/string_posix.c ) + s.files += %w( src/core/lib/support/string_util_win32.c ) s.files += %w( src/core/lib/support/string_win32.c ) s.files += %w( src/core/lib/support/subprocess_posix.c ) s.files += %w( src/core/lib/support/subprocess_windows.c ) @@ -142,6 +143,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/support/time_precise.c ) s.files += %w( src/core/lib/support/time_win32.c ) s.files += %w( src/core/lib/support/tls_pthread.c ) + s.files += %w( src/core/lib/support/tmpfile_msys.c ) s.files += %w( src/core/lib/support/tmpfile_posix.c ) s.files += %w( src/core/lib/support/tmpfile_win32.c ) s.files += %w( src/core/lib/support/wrap_memcpy.c ) diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index 3242f07599b..bbcb4098e3a 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -82,28 +82,31 @@ things. */ #if !defined(GPR_NO_AUTODETECT_PLATFORM) +#if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32) #if defined(_WIN64) || defined(WIN64) -#define GPR_PLATFORM_STRING "windows" -#define GPR_WIN32 1 #define GPR_ARCH_64 1 -#define GPR_GETPID_IN_PROCESS_H 1 -#define GPR_WINSOCK_SOCKET 1 -#define GPR_WINDOWS_SUBPROCESS 1 -#ifdef __GNUC__ -#define GPR_GCC_ATOMIC 1 -#define GPR_GCC_TLS 1 #else -#define GPR_WIN32_ATOMIC 1 -#define GPR_MSVC_TLS 1 +#define GPR_ARCH_32 1 #endif -#define GPR_WINDOWS_CRASH_HANDLER 1 -#elif defined(_WIN32) || defined(WIN32) #define GPR_PLATFORM_STRING "windows" -#define GPR_ARCH_32 1 #define GPR_WIN32 1 -#define GPR_GETPID_IN_PROCESS_H 1 #define GPR_WINSOCK_SOCKET 1 #define GPR_WINDOWS_SUBPROCESS 1 +#define GPR_WIN32_ENV +#ifdef __MSYS__ +#define GPR_GETPID_IN_UNISTD_H 1 +#define GPR_MSYS_TMPFILE +#define GPR_POSIX_LOG +#define GPR_POSIX_STRING +#define GPR_POSIX_TIME +#else +#define GPR_GETPID_IN_PROCESS_H 1 +#define GPR_WIN32_TMPFILE +#define GPR_WIN32_LOG +#define GPR_WINDOWS_CRASH_HANDLER 1 +#define GPR_WIN32_STRING +#define GPR_WIN32_TIME +#endif #ifdef __GNUC__ #define GPR_GCC_ATOMIC 1 #define GPR_GCC_TLS 1 @@ -111,7 +114,6 @@ #define GPR_WIN32_ATOMIC 1 #define GPR_MSVC_TLS 1 #endif -#define GPR_WINDOWS_CRASH_HANDLER 1 #elif defined(ANDROID) || defined(__ANDROID__) #define GPR_PLATFORM_STRING "android" #define GPR_ANDROID 1 @@ -126,7 +128,8 @@ #define GPR_POSIX_SOCKETADDR 1 #define GPR_POSIX_SOCKETUTILS 1 #define GPR_POSIX_ENV 1 -#define GPR_POSIX_FILE 1 +#define GPR_POSIX_TMPFILE 1 +#define GPR_POSIX_LOG #define GPR_POSIX_STRING 1 #define GPR_POSIX_SUBPROCESS 1 #define GPR_POSIX_SYNC 1 @@ -153,6 +156,7 @@ #define GPR_GCC_ATOMIC 1 #define GPR_GCC_TLS 1 #define GPR_LINUX 1 +#define GPR_LINUX_LOG #define GPR_LINUX_MULTIPOLL_WITH_EPOLL 1 #define GPR_POSIX_WAKEUP_FD 1 #define GPR_POSIX_SOCKET 1 @@ -175,7 +179,7 @@ #ifndef GPR_LINUX_SOCKETUTILS #define GPR_POSIX_SOCKETUTILS #endif -#define GPR_POSIX_FILE 1 +#define GPR_POSIX_TMPFILE 1 #define GPR_POSIX_STRING 1 #define GPR_POSIX_SUBPROCESS 1 #define GPR_POSIX_SYNC 1 @@ -213,7 +217,7 @@ #define GPR_POSIX_SOCKETADDR 1 #define GPR_POSIX_SOCKETUTILS 1 #define GPR_POSIX_ENV 1 -#define GPR_POSIX_FILE 1 +#define GPR_POSIX_TMPFILE 1 #define GPR_POSIX_STRING 1 #define GPR_POSIX_SUBPROCESS 1 #define GPR_POSIX_SYNC 1 @@ -243,7 +247,7 @@ #define GPR_POSIX_SOCKETADDR 1 #define GPR_POSIX_SOCKETUTILS 1 #define GPR_POSIX_ENV 1 -#define GPR_POSIX_FILE 1 +#define GPR_POSIX_TMPFILE 1 #define GPR_POSIX_STRING 1 #define GPR_POSIX_SUBPROCESS 1 #define GPR_POSIX_SYNC 1 @@ -280,7 +284,7 @@ #define GPR_POSIX_SOCKETADDR 1 #define GPR_POSIX_SOCKETUTILS 1 #define GPR_POSIX_ENV 1 -#define GPR_POSIX_FILE 1 +#define GPR_POSIX_TMPFILE 1 #define GPR_POSIX_STRING 1 #define GPR_POSIX_SUBPROCESS 1 #define GPR_POSIX_SYNC 1 diff --git a/package.xml b/package.xml index 2f4c6255394..b21e974c8ef 100644 --- a/package.xml +++ b/package.xml @@ -131,6 +131,7 @@ + @@ -145,6 +146,7 @@ + diff --git a/src/core/lib/iomgr/tcp_server_windows.c b/src/core/lib/iomgr/tcp_server_windows.c index 6940dec7b02..53f58477a4a 100644 --- a/src/core/lib/iomgr/tcp_server_windows.c +++ b/src/core/lib/iomgr/tcp_server_windows.c @@ -510,30 +510,17 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr, unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server *s, unsigned port_index) { - grpc_tcp_listener *sp; - for (sp = s->head; sp && port_index != 0; sp = sp->next, --port_index) - ; - if (sp) { - return 1; - } else { - return 0; - } + (void)s; + (void)port_index; + abort(); } int grpc_tcp_server_port_fd(grpc_tcp_server *s, unsigned port_index, unsigned fd_index) { - grpc_tcp_listener *sp; - if (fd_index != 0) { - /* Windows implementation has only one fd per port_index. */ - return -1; - } - for (sp = s->head; sp && port_index != 0; sp = sp->next, --port_index) - ; - if (sp) { - return _open_osfhandle((intptr_t)sp->socket->socket, 0); - } else { - return -1; - } + (void)s; + (void)port_index; + (void)fd_index; + abort(); } void grpc_tcp_server_start(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s, diff --git a/src/core/lib/iomgr/tcp_windows.c b/src/core/lib/iomgr/tcp_windows.c index 7ee689a7e46..39968239334 100644 --- a/src/core/lib/iomgr/tcp_windows.c +++ b/src/core/lib/iomgr/tcp_windows.c @@ -35,6 +35,8 @@ #ifdef GPR_WINSOCK_SOCKET +#include + #include "src/core/lib/iomgr/sockaddr_win32.h" #include @@ -51,12 +53,20 @@ #include "src/core/lib/iomgr/tcp_client.h" #include "src/core/lib/iomgr/timer.h" +#if defined(__MSYS__) && defined(GPR_ARCH_64) +/* Nasty workaround for nasty bug when using the 64 bits msys compiler + in conjunction with Microsoft Windows headers. */ +#define GRPC_FIONBIO _IOW('f', 126, uint32_t) +#else +#define GRPC_FIONBIO FIONBIO +#endif + static int set_non_block(SOCKET sock) { int status; - unsigned long param = 1; + uint32_t param = 1; DWORD ret; status = - WSAIoctl(sock, FIONBIO, ¶m, sizeof(param), NULL, 0, &ret, NULL, NULL); + WSAIoctl(sock, GRPC_FIONBIO, ¶m, sizeof(param), NULL, 0, &ret, NULL, NULL); return status == 0; } diff --git a/src/core/lib/support/env_win32.c b/src/core/lib/support/env_win32.c index ef84c941df6..e670e1e8d03 100644 --- a/src/core/lib/support/env_win32.c +++ b/src/core/lib/support/env_win32.c @@ -33,41 +33,47 @@ #include -#ifdef GPR_WIN32 +#ifdef GPR_WIN32_ENV + +#include #include "src/core/lib/support/env.h" #include "src/core/lib/support/string.h" - -#ifdef __MINGW32__ -errno_t getenv_s(size_t *size_needed, char *buffer, size_t size, - const char *varname); -#else -#include -#endif +#include "src/core/lib/support/string_win32.h" #include #include #include char *gpr_getenv(const char *name) { - size_t size; char *result = NULL; - errno_t err; + DWORD size; + LPTSTR tresult = NULL; + LPTSTR tname = gpr_char_to_tchar(name); + DWORD ret; - err = getenv_s(&size, NULL, 0, name); - if (err || (size == 0)) return NULL; - result = gpr_malloc(size); - err = getenv_s(&size, result, size, name); - if (err) { - gpr_free(result); + ret = GetEnvironmentVariable(tname, NULL, 0); + if (ret == 0) return NULL; + size = ret * (DWORD)sizeof(TCHAR); + tresult = gpr_malloc(size); + ret = GetEnvironmentVariable(tname, tresult, size); + gpr_free(tname); + if (ret == 0) { + gpr_free(tresult); return NULL; } + result = gpr_tchar_to_char(tresult); + gpr_free(tresult); return result; } void gpr_setenv(const char *name, const char *value) { - errno_t res = _putenv_s(name, value); - GPR_ASSERT(res == 0); + LPTSTR tname = gpr_char_to_tchar(name); + LPTSTR tvalue = gpr_char_to_tchar(value); + BOOL res = SetEnvironmentVariable(tname, tvalue); + gpr_free(tname); + gpr_free(tvalue); + GPR_ASSERT(res); } -#endif /* GPR_WIN32 */ +#endif /* GPR_WIN32_ENV */ diff --git a/src/core/lib/support/log_linux.c b/src/core/lib/support/log_linux.c index ff3febb38eb..ca04c022e3f 100644 --- a/src/core/lib/support/log_linux.c +++ b/src/core/lib/support/log_linux.c @@ -41,7 +41,7 @@ #include -#ifdef GPR_LINUX +#ifdef GPR_LINUX_LOG #include #include @@ -103,4 +103,4 @@ void gpr_default_log(gpr_log_func_args *args) { gpr_free(prefix); } -#endif +#endif /* GPR_LINUX_LOG */ diff --git a/src/core/lib/support/log_win32.c b/src/core/lib/support/log_win32.c index ba78497a0a4..29735bd18c7 100644 --- a/src/core/lib/support/log_win32.c +++ b/src/core/lib/support/log_win32.c @@ -33,7 +33,7 @@ #include -#ifdef GPR_WIN32 +#ifdef GPR_WIN32_LOG #include #include @@ -109,18 +109,4 @@ void gpr_default_log(gpr_log_func_args *args) { fflush(stderr); } -char *gpr_format_message(int messageid) { - LPTSTR tmessage; - char *message; - DWORD status = FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, (DWORD)messageid, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)(&tmessage), 0, NULL); - if (status == 0) return gpr_strdup("Unable to retrieve error string"); - message = gpr_tchar_to_char(tmessage); - LocalFree(tmessage); - return message; -} - -#endif /* GPR_WIN32 */ +#endif /* GPR_WIN32_LOG */ diff --git a/src/core/lib/support/string_util_win32.c b/src/core/lib/support/string_util_win32.c new file mode 100644 index 00000000000..fd14ce54e43 --- /dev/null +++ b/src/core/lib/support/string_util_win32.c @@ -0,0 +1,91 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Posix code for gpr snprintf support. */ + +#include + +#ifdef GPR_WIN32 + +#include +#include +#include +#include +#include + +#include +#include + +#include "src/core/lib/support/string.h" + +#if defined UNICODE || defined _UNICODE +LPTSTR +gpr_char_to_tchar(LPCSTR input) { + LPTSTR ret; + int needed = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0); + if (needed <= 0) return NULL; + ret = gpr_malloc((unsigned)needed * sizeof(TCHAR)); + MultiByteToWideChar(CP_UTF8, 0, input, -1, ret, needed); + return ret; +} + +LPSTR +gpr_tchar_to_char(LPCTSTR input) { + LPSTR ret; + int needed = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL); + if (needed <= 0) return NULL; + ret = gpr_malloc((unsigned)needed); + WideCharToMultiByte(CP_UTF8, 0, input, -1, ret, needed, NULL, NULL); + return ret; +} +#else +char *gpr_tchar_to_char(LPTSTR input) { return gpr_strdup(input); } + +char *gpr_char_to_tchar(LPTSTR input) { return gpr_strdup(input); } +#endif + +char *gpr_format_message(int messageid) { + LPTSTR tmessage; + char *message; + DWORD status = FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, (DWORD)messageid, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)(&tmessage), 0, NULL); + if (status == 0) return gpr_strdup("Unable to retrieve error string"); + message = gpr_tchar_to_char(tmessage); + LocalFree(tmessage); + return message; +} + +#endif /* GPR_WIN32 */ diff --git a/src/core/lib/support/string_win32.c b/src/core/lib/support/string_win32.c index a2f9857356a..8382cde15a4 100644 --- a/src/core/lib/support/string_win32.c +++ b/src/core/lib/support/string_win32.c @@ -31,23 +31,28 @@ * */ -/* Posix code for gpr snprintf support. */ +/* Windows code for gpr snprintf support. */ #include -#ifdef GPR_WIN32 +#ifdef GPR_WIN32_STRING #include #include #include +#include +#include #include +#include #include "src/core/lib/support/string.h" int gpr_asprintf(char **strp, const char *format, ...) { va_list args; int ret; + + HRESULT success; size_t strp_buflen; /* Determine the length. */ @@ -68,9 +73,9 @@ int gpr_asprintf(char **strp, const char *format, ...) { /* Print to the buffer. */ va_start(args, format); - ret = vsnprintf_s(*strp, strp_buflen, _TRUNCATE, format, args); + success = StringCbVPrintfA(*strp, strp_buflen, format, args); va_end(args); - if ((size_t)ret == strp_buflen - 1) { + if (success == S_OK) { return ret; } @@ -80,30 +85,4 @@ int gpr_asprintf(char **strp, const char *format, ...) { return -1; } -#if defined UNICODE || defined _UNICODE -LPTSTR -gpr_char_to_tchar(LPCSTR input) { - LPTSTR ret; - int needed = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0); - if (needed <= 0) return NULL; - ret = gpr_malloc((unsigned)needed * sizeof(TCHAR)); - MultiByteToWideChar(CP_UTF8, 0, input, -1, ret, needed); - return ret; -} - -LPSTR -gpr_tchar_to_char(LPCTSTR input) { - LPSTR ret; - int needed = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL); - if (needed <= 0) return NULL; - ret = gpr_malloc((unsigned)needed); - WideCharToMultiByte(CP_UTF8, 0, input, -1, ret, needed, NULL, NULL); - return ret; -} -#else -char *gpr_tchar_to_char(LPTSTR input) { return gpr_strdup(input); } - -char *gpr_char_to_tchar(LPTSTR input) { return gpr_strdup(input); } -#endif - -#endif /* GPR_WIN32 */ +#endif /* GPR_WIN32_STRING */ diff --git a/src/core/lib/support/time_win32.c b/src/core/lib/support/time_win32.c index f7acbd14a67..9e924ab3f4a 100644 --- a/src/core/lib/support/time_win32.c +++ b/src/core/lib/support/time_win32.c @@ -35,7 +35,7 @@ #include -#ifdef GPR_WIN32 +#ifdef GPR_WIN32_TIME #include #include @@ -107,4 +107,4 @@ void gpr_sleep_until(gpr_timespec until) { } } -#endif /* GPR_WIN32 */ +#endif /* GPR_WIN32_TIME */ diff --git a/src/core/lib/support/tmpfile_msys.c b/src/core/lib/support/tmpfile_msys.c new file mode 100644 index 00000000000..f0f803aa754 --- /dev/null +++ b/src/core/lib/support/tmpfile_msys.c @@ -0,0 +1,75 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +#ifdef GPR_MSYS_TMPFILE + +#include +#include +#include +#include + +#include +#include +#include + +#include "src/core/lib/support/string_win32.h" +#include "src/core/lib/support/tmpfile.h" + +FILE *gpr_tmpfile(const char *prefix, char **tmp_filename_out) { + FILE *result = NULL; + char tmp_filename[MAX_PATH]; + UINT success; + + if (tmp_filename_out != NULL) *tmp_filename_out = NULL; + + /* Generate a unique filename with our template + temporary path. */ + success = GetTempFileNameA(".", prefix, 0, tmp_filename); + fprintf(stderr, "success = %d\n", success); + if (!success) goto end; + + /* Open a file there. */ + result = fopen(tmp_filename, "wb+"); + fprintf(stderr, "result = %p\n", result); + if (result == NULL) goto end; + +end: + if (result && tmp_filename_out) { + *tmp_filename_out = gpr_strdup(tmp_filename); + } + + return result; +} + +#endif /* GPR_MSYS_TMPFILE */ diff --git a/src/core/lib/support/tmpfile_posix.c b/src/core/lib/support/tmpfile_posix.c index 9e0e7ad8080..0cd4bb6fc3c 100644 --- a/src/core/lib/support/tmpfile_posix.c +++ b/src/core/lib/support/tmpfile_posix.c @@ -33,7 +33,7 @@ #include -#ifdef GPR_POSIX_FILE +#ifdef GPR_POSIX_TMPFILE #include "src/core/lib/support/tmpfile.h" @@ -82,4 +82,4 @@ end: return result; } -#endif /* GPR_POSIX_FILE */ +#endif /* GPR_POSIX_TMPFILE */ diff --git a/src/core/lib/support/tmpfile_win32.c b/src/core/lib/support/tmpfile_win32.c index 0cb2904f8de..9ac73128c39 100644 --- a/src/core/lib/support/tmpfile_win32.c +++ b/src/core/lib/support/tmpfile_win32.c @@ -33,7 +33,7 @@ #include -#ifdef GPR_WIN32 +#ifdef GPR_WIN32_TMPFILE #include #include @@ -81,4 +81,4 @@ end: return result; } -#endif /* GPR_WIN32 */ +#endif /* GPR_WIN32_TMPFILE */ diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 1f7f2a196be..e389782b47f 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -57,6 +57,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/support/stack_lockfree.c', 'src/core/lib/support/string.c', 'src/core/lib/support/string_posix.c', + 'src/core/lib/support/string_util_win32.c', 'src/core/lib/support/string_win32.c', 'src/core/lib/support/subprocess_posix.c', 'src/core/lib/support/subprocess_windows.c', @@ -71,6 +72,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/support/time_precise.c', 'src/core/lib/support/time_win32.c', 'src/core/lib/support/tls_pthread.c', + 'src/core/lib/support/tmpfile_msys.c', 'src/core/lib/support/tmpfile_posix.c', 'src/core/lib/support/tmpfile_win32.c', 'src/core/lib/support/wrap_memcpy.c', diff --git a/test/core/util/port_windows.c b/test/core/util/port_windows.c index 2b6d3dd223c..154d607ec7c 100644 --- a/test/core/util/port_windows.c +++ b/test/core/util/port_windows.c @@ -51,6 +51,11 @@ #include "src/core/lib/support/env.h" #include "test/core/util/port_server_client.h" +#if GPR_GETPID_IN_UNISTD_H +#include +static int _getpid() { return getpid(); } +#endif + #define NUM_RANDOM_PORTS_TO_PICK 100 static int *chosen_ports = NULL; @@ -114,7 +119,7 @@ static int is_port_available(int *port, int is_tcp) { /* Try binding to port */ addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY; - addr.sin_port = htons(*port); + addr.sin_port = htons((u_short)*port); if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { gpr_log(GPR_DEBUG, "bind(port=%d) failed: %s", *port, strerror(errno)); closesocket(fd); @@ -127,7 +132,7 @@ static int is_port_available(int *port, int is_tcp) { closesocket(fd); return 0; } - GPR_ASSERT(alen <= sizeof(addr)); + GPR_ASSERT(alen <= (socklen_t)sizeof(addr)); actual_port = ntohs(addr.sin_port); GPR_ASSERT(actual_port > 0); if (*port == 0) { diff --git a/test/core/util/test_config.c b/test/core/util/test_config.c index 3155a4ece6a..62468a5a61a 100644 --- a/test/core/util/test_config.c +++ b/test/core/util/test_config.c @@ -50,7 +50,7 @@ static unsigned seed(void) { return (unsigned)getpid(); } #if GPR_GETPID_IN_PROCESS_H #include -static unsigned seed(void) { return _getpid(); } +static unsigned seed(void) { return (unsigned)_getpid(); } #endif #if GPR_WINDOWS_CRASH_HANDLER diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index b131a55b592..e0d97148281 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1167,6 +1167,7 @@ src/core/lib/support/slice_buffer.c \ src/core/lib/support/stack_lockfree.c \ src/core/lib/support/string.c \ src/core/lib/support/string_posix.c \ +src/core/lib/support/string_util_win32.c \ src/core/lib/support/string_win32.c \ src/core/lib/support/subprocess_posix.c \ src/core/lib/support/subprocess_windows.c \ @@ -1181,6 +1182,7 @@ src/core/lib/support/time_posix.c \ src/core/lib/support/time_precise.c \ src/core/lib/support/time_win32.c \ src/core/lib/support/tls_pthread.c \ +src/core/lib/support/tmpfile_msys.c \ src/core/lib/support/tmpfile_posix.c \ src/core/lib/support/tmpfile_win32.c \ src/core/lib/support/wrap_memcpy.c diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 0b68315c82a..b9a004423cb 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -5429,6 +5429,7 @@ "src/core/lib/support/string.c", "src/core/lib/support/string.h", "src/core/lib/support/string_posix.c", + "src/core/lib/support/string_util_win32.c", "src/core/lib/support/string_win32.c", "src/core/lib/support/string_win32.h", "src/core/lib/support/subprocess_posix.c", @@ -5447,6 +5448,7 @@ "src/core/lib/support/time_win32.c", "src/core/lib/support/tls_pthread.c", "src/core/lib/support/tmpfile.h", + "src/core/lib/support/tmpfile_msys.c", "src/core/lib/support/tmpfile_posix.c", "src/core/lib/support/tmpfile_win32.c", "src/core/lib/support/wrap_memcpy.c" diff --git a/vsprojects/vcxproj/gpr/gpr.vcxproj b/vsprojects/vcxproj/gpr/gpr.vcxproj index cdb128e48ef..26195bb5417 100644 --- a/vsprojects/vcxproj/gpr/gpr.vcxproj +++ b/vsprojects/vcxproj/gpr/gpr.vcxproj @@ -259,6 +259,8 @@ + + @@ -287,6 +289,8 @@ + + diff --git a/vsprojects/vcxproj/gpr/gpr.vcxproj.filters b/vsprojects/vcxproj/gpr/gpr.vcxproj.filters index 8af6fdd44cb..be15391b092 100644 --- a/vsprojects/vcxproj/gpr/gpr.vcxproj.filters +++ b/vsprojects/vcxproj/gpr/gpr.vcxproj.filters @@ -82,6 +82,9 @@ src\core\lib\support + + src\core\lib\support + src\core\lib\support @@ -124,6 +127,9 @@ src\core\lib\support + + src\core\lib\support + src\core\lib\support From b7c34a50f1e0e529e7446158f6e6eb54e37b3fa8 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 15 Apr 2016 07:40:44 +0200 Subject: [PATCH 03/15] Removing grpc_tcp_server_port_fd* from the Windows implementation. --- src/core/lib/iomgr/tcp_server_windows.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/core/lib/iomgr/tcp_server_windows.c b/src/core/lib/iomgr/tcp_server_windows.c index 53f58477a4a..125f521d87e 100644 --- a/src/core/lib/iomgr/tcp_server_windows.c +++ b/src/core/lib/iomgr/tcp_server_windows.c @@ -508,21 +508,6 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr, } } -unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server *s, - unsigned port_index) { - (void)s; - (void)port_index; - abort(); -} - -int grpc_tcp_server_port_fd(grpc_tcp_server *s, unsigned port_index, - unsigned fd_index) { - (void)s; - (void)port_index; - (void)fd_index; - abort(); -} - void grpc_tcp_server_start(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s, grpc_pollset **pollset, size_t pollset_count, grpc_tcp_server_cb on_accept_cb, From a0091cba8957591be6a41c8e381a674874f6bc63 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 15 Apr 2016 07:47:50 +0200 Subject: [PATCH 04/15] Re-adding GPR_POSIX_FILE. --- include/grpc/impl/codegen/port_platform.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index bbcb4098e3a..1229d488edb 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -128,6 +128,7 @@ #define GPR_POSIX_SOCKETADDR 1 #define GPR_POSIX_SOCKETUTILS 1 #define GPR_POSIX_ENV 1 +#define GPR_POSIX_FILE 1 #define GPR_POSIX_TMPFILE 1 #define GPR_POSIX_LOG #define GPR_POSIX_STRING 1 @@ -179,6 +180,7 @@ #ifndef GPR_LINUX_SOCKETUTILS #define GPR_POSIX_SOCKETUTILS #endif +#define GPR_POSIX_FILE 1 #define GPR_POSIX_TMPFILE 1 #define GPR_POSIX_STRING 1 #define GPR_POSIX_SUBPROCESS 1 @@ -217,6 +219,7 @@ #define GPR_POSIX_SOCKETADDR 1 #define GPR_POSIX_SOCKETUTILS 1 #define GPR_POSIX_ENV 1 +#define GPR_POSIX_FILE 1 #define GPR_POSIX_TMPFILE 1 #define GPR_POSIX_STRING 1 #define GPR_POSIX_SUBPROCESS 1 @@ -247,6 +250,7 @@ #define GPR_POSIX_SOCKETADDR 1 #define GPR_POSIX_SOCKETUTILS 1 #define GPR_POSIX_ENV 1 +#define GPR_POSIX_FILE 1 #define GPR_POSIX_TMPFILE 1 #define GPR_POSIX_STRING 1 #define GPR_POSIX_SUBPROCESS 1 @@ -284,6 +288,7 @@ #define GPR_POSIX_SOCKETADDR 1 #define GPR_POSIX_SOCKETUTILS 1 #define GPR_POSIX_ENV 1 +#define GPR_POSIX_FILE 1 #define GPR_POSIX_TMPFILE 1 #define GPR_POSIX_STRING 1 #define GPR_POSIX_SUBPROCESS 1 From 344f55b7baad4fce6be0d5c7007b43f5f270e359 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 15 Apr 2016 07:52:25 +0200 Subject: [PATCH 05/15] clang-format. --- src/core/lib/iomgr/tcp_windows.c | 4 ++-- src/core/lib/support/string_util_win32.c | 2 +- src/core/lib/support/string_win32.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/lib/iomgr/tcp_windows.c b/src/core/lib/iomgr/tcp_windows.c index 39968239334..551149e1a62 100644 --- a/src/core/lib/iomgr/tcp_windows.c +++ b/src/core/lib/iomgr/tcp_windows.c @@ -65,8 +65,8 @@ static int set_non_block(SOCKET sock) { int status; uint32_t param = 1; DWORD ret; - status = - WSAIoctl(sock, GRPC_FIONBIO, ¶m, sizeof(param), NULL, 0, &ret, NULL, NULL); + status = WSAIoctl(sock, GRPC_FIONBIO, ¶m, sizeof(param), NULL, 0, &ret, + NULL, NULL); return status == 0; } diff --git a/src/core/lib/support/string_util_win32.c b/src/core/lib/support/string_util_win32.c index fd14ce54e43..c0586a3fbbf 100644 --- a/src/core/lib/support/string_util_win32.c +++ b/src/core/lib/support/string_util_win32.c @@ -40,8 +40,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/src/core/lib/support/string_win32.c b/src/core/lib/support/string_win32.c index 8382cde15a4..eabd9c6883e 100644 --- a/src/core/lib/support/string_win32.c +++ b/src/core/lib/support/string_win32.c @@ -40,8 +40,8 @@ #include #include #include -#include #include +#include #include #include From 95953bfd7f71c1555aaf7d9a158295c4720fa9da Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 15 Apr 2016 07:58:22 +0200 Subject: [PATCH 06/15] Moving headers around. --- src/core/lib/support/string_util_win32.c | 5 ++++- src/core/lib/support/string_win32.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/lib/support/string_util_win32.c b/src/core/lib/support/string_util_win32.c index c0586a3fbbf..f3cb0c050f9 100644 --- a/src/core/lib/support/string_util_win32.c +++ b/src/core/lib/support/string_util_win32.c @@ -37,11 +37,14 @@ #ifdef GPR_WIN32 +/* Some platforms (namely msys) need wchar to be included BEFORE + anything else, especially strsafe.h. */ +#include + #include #include #include #include -#include #include #include diff --git a/src/core/lib/support/string_win32.c b/src/core/lib/support/string_win32.c index eabd9c6883e..9b398b89c56 100644 --- a/src/core/lib/support/string_win32.c +++ b/src/core/lib/support/string_win32.c @@ -37,11 +37,14 @@ #ifdef GPR_WIN32_STRING +/* Some platforms (namely msys) need wchar to be included BEFORE + anything else, especially strsafe.h. */ +#include + #include #include #include #include -#include #include #include From 94a353aa460e618071572cd42f2106353fda6abe Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 16 Apr 2016 01:21:05 +0200 Subject: [PATCH 07/15] Reverting changes in string_win32.c, as we're going to use posix strings for msys. --- src/core/lib/support/string_win32.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/core/lib/support/string_win32.c b/src/core/lib/support/string_win32.c index 9b398b89c56..6b92f792534 100644 --- a/src/core/lib/support/string_win32.c +++ b/src/core/lib/support/string_win32.c @@ -37,25 +37,17 @@ #ifdef GPR_WIN32_STRING -/* Some platforms (namely msys) need wchar to be included BEFORE - anything else, especially strsafe.h. */ -#include - #include #include #include -#include #include -#include #include "src/core/lib/support/string.h" int gpr_asprintf(char **strp, const char *format, ...) { va_list args; int ret; - - HRESULT success; size_t strp_buflen; /* Determine the length. */ @@ -76,9 +68,9 @@ int gpr_asprintf(char **strp, const char *format, ...) { /* Print to the buffer. */ va_start(args, format); - success = StringCbVPrintfA(*strp, strp_buflen, format, args); + ret = vsnprintf_s(*strp, strp_buflen, _TRUNCATE, format, args); va_end(args); - if (success == S_OK) { + if ((size_t)ret == strp_buflen - 1) { return ret; } From 79a75e25c450d0f86c268578d81014dafd173ed2 Mon Sep 17 00:00:00 2001 From: Dmitry Kovalev Date: Thu, 21 Apr 2016 23:32:30 -0700 Subject: [PATCH 08/15] Fixing invalid usage of getProtobufServiceAttrs() function. getProtobufServiceAttrs(service, options) must be called with 2 arguments. --- src/node/src/client.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/node/src/client.js b/src/node/src/client.js index 5e07046fc61..f75f951eb8d 100644 --- a/src/node/src/client.js +++ b/src/node/src/client.js @@ -815,8 +815,7 @@ exports.waitForClientReady = function(client, deadline, callback) { * @return {function(string, Object)} New client constructor */ exports.makeProtobufClientConstructor = function(service, options) { - var method_attrs = common.getProtobufServiceAttrs(service, service.name, - options); + var method_attrs = common.getProtobufServiceAttrs(service, options); var deprecatedArgumentOrder = false; if (options) { deprecatedArgumentOrder = options.deprecatedArgumentOrder; From f5df6472b4028166ea1d51f15bb8ed1455fde472 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 23 Apr 2016 01:53:46 +0200 Subject: [PATCH 09/15] Refactor. --- src/core/lib/support/tmpfile_msys.c | 14 ++++++-------- third_party/boringssl | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/core/lib/support/tmpfile_msys.c b/src/core/lib/support/tmpfile_msys.c index f0f803aa754..2fdc89a64f2 100644 --- a/src/core/lib/support/tmpfile_msys.c +++ b/src/core/lib/support/tmpfile_msys.c @@ -57,15 +57,13 @@ FILE *gpr_tmpfile(const char *prefix, char **tmp_filename_out) { /* Generate a unique filename with our template + temporary path. */ success = GetTempFileNameA(".", prefix, 0, tmp_filename); fprintf(stderr, "success = %d\n", success); - if (!success) goto end; - /* Open a file there. */ - result = fopen(tmp_filename, "wb+"); - fprintf(stderr, "result = %p\n", result); - if (result == NULL) goto end; - -end: - if (result && tmp_filename_out) { + if (success) { + /* Open a file there. */ + result = fopen(tmp_filename, "wb+"); + fprintf(stderr, "result = %p\n", result); + } + if (result != NULL && tmp_filename_out) { *tmp_filename_out = gpr_strdup(tmp_filename); } diff --git a/third_party/boringssl b/third_party/boringssl index 907ae62b9d8..c880e42ba1c 160000 --- a/third_party/boringssl +++ b/third_party/boringssl @@ -1 +1 @@ -Subproject commit 907ae62b9d81121cb86b604f83e6b811a43f7a87 +Subproject commit c880e42ba1c8032d4cdde2aba0541d8a9d9fa2e9 From c5b1eef8b1e6d56a9f3c25962d815ae6579c78ee Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 26 Apr 2016 14:16:20 -0700 Subject: [PATCH 10/15] Change C implementation to not log an "Unexpected content-type" message when the header includes a semicolon. --- src/core/lib/channel/http_server_filter.c | 9 ++++---- .../tests/server_registered_method.headers | 2 +- test/core/bad_client/tests/simple_request.c | 22 +++++++++++++++++++ .../tests/simple_request_unusual2.headers | 13 +++++++++++ 4 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 test/core/bad_client/tests/simple_request_unusual2.headers diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index c140c61b8f3..ad3462bff4f 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -92,8 +92,10 @@ static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) { require */ return NULL; } else if (md->key == GRPC_MDSTR_CONTENT_TYPE) { - if (strncmp(grpc_mdstr_as_c_string(md->value), "application/grpc+", 17) == - 0) { + const char* value_str = grpc_mdstr_as_c_string(md->value); + if (strncmp(value_str, "application/grpc", 16) == 0 && + (strlen(value_str) == 16 || + value_str[16] == '+' || value_str[16] == ';')) { /* Although the C implementation doesn't (currently) generate them, any custom +-suffix is explicitly valid. */ /* TODO(klempner): We should consider preallocating common values such @@ -102,8 +104,7 @@ static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) { } else { /* TODO(klempner): We're currently allowing this, but we shouldn't see it without a proxy so log for now. */ - gpr_log(GPR_INFO, "Unexpected content-type %s", - grpc_mdstr_as_c_string(md->value)); + gpr_log(GPR_INFO, "Unexpected content-type %s", value_str); } return NULL; } else if (md->key == GRPC_MDSTR_TE || md->key == GRPC_MDSTR_METHOD || diff --git a/test/core/bad_client/tests/server_registered_method.headers b/test/core/bad_client/tests/server_registered_method.headers index 06ee73c82ee..2640cc9cb8d 100644 --- a/test/core/bad_client/tests/server_registered_method.headers +++ b/test/core/bad_client/tests/server_registered_method.headers @@ -1,4 +1,4 @@ -# headers used in simple_request.c +# headers used in server_registered_method.c # use tools/codegen/core/gen_header_frame.py to generate the binary strings # contained in the source code :path: /registered/bar diff --git a/test/core/bad_client/tests/simple_request.c b/test/core/bad_client/tests/simple_request.c index ac0fdde876f..d6b85aefb58 100644 --- a/test/core/bad_client/tests/simple_request.c +++ b/test/core/bad_client/tests/simple_request.c @@ -77,6 +77,27 @@ "\x10\x0cgrpc-timeout\x02" \ "5S" +#define PFX_STR_UNUSUAL2 \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ + "\x00\x00\xf4\x01\x04\x00\x00\x00\x01" /* headers: generated from \ + simple_request_unusual2.headers \ + in this directory */ \ + "\x10\x05:path\x08/foo/bar" \ + "\x10\x07:scheme\x04http" \ + "\x10\x07:method\x04POST" \ + "\x10\x04host\x09localhost" \ + "\x10\x0c" \ + "content-type\x1e" \ + "application/grpc;this-is-valid" \ + "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" \ + "\x10\x02te\x08trailers" \ + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" \ + "\x10\x0cgrpc-timeout\x03" \ + "10S" \ + "\x10\x0cgrpc-timeout\x02" \ + "5S" + static void *tag(intptr_t t) { return (void *)t; } static void verifier(grpc_server *server, grpc_completion_queue *cq, @@ -120,6 +141,7 @@ int main(int argc, char **argv) { /* basic request: check that things are working */ GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR, 0); GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR_UNUSUAL, 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR_UNUSUAL2, 0); /* push an illegal data frame */ GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR diff --git a/test/core/bad_client/tests/simple_request_unusual2.headers b/test/core/bad_client/tests/simple_request_unusual2.headers new file mode 100644 index 00000000000..f70920f3725 --- /dev/null +++ b/test/core/bad_client/tests/simple_request_unusual2.headers @@ -0,0 +1,13 @@ +# headers used in simple_request.c +# use tools/codegen/core/gen_header_frame.py to generate the binary strings +# contained in the source code +:path: /foo/bar +:scheme: http +:method: POST +host: localhost +content-type: application/grpc;this-is-valid +grpc-accept-encoding: deflate,identity,gzip +te: trailers +user-agent: bad-client grpc-c/0.12.0.0 (linux) +grpc-timeout: 10S +grpc-timeout: 5S From 85c3ab0b0b1c3abf7f8b2c7538e5ca147c88d557 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 26 Apr 2016 17:17:02 -0700 Subject: [PATCH 11/15] fix #5912 --- src/csharp/Grpc.IntegrationTesting/InteropClient.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs index 54365179603..b3b1abf1bca 100644 --- a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs +++ b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs @@ -494,7 +494,8 @@ namespace Grpc.IntegrationTesting } var ex = Assert.ThrowsAsync(async () => await call.ResponseStream.MoveNext()); - Assert.AreEqual(StatusCode.DeadlineExceeded, ex.Status.StatusCode); + // We can't guarantee the status code always DeadlineExceeded. See issue #2685. + Assert.Contains(ex.Status.StatusCode, new[] { StatusCode.DeadlineExceeded, StatusCode.Internal }); } Console.WriteLine("Passed!"); } From 825471c38718a770b4ce763f8fad45b26ebe1766 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 25 Apr 2016 16:52:25 -0700 Subject: [PATCH 12/15] Add --compiler python3.4 option to run_tests.py --- tools/run_tests/build_python.sh | 12 +++++++----- tools/run_tests/run_python.sh | 6 ++++-- tools/run_tests/run_tests.py | 34 ++++++++++++++------------------- tox.ini | 2 +- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/tools/run_tests/build_python.sh b/tools/run_tests/build_python.sh index 30d121007fb..594c20b14c3 100755 --- a/tools/run_tests/build_python.sh +++ b/tools/run_tests/build_python.sh @@ -33,6 +33,8 @@ set -ex # change to grpc repo root cd $(dirname $0)/../.. +TOX_PYTHON_ENV="$1" + ROOT=`pwd` export LD_LIBRARY_PATH=$ROOT/libs/$CONFIG export DYLD_LIBRARY_PATH=$ROOT/libs/$CONFIG @@ -47,9 +49,9 @@ then export GRPC_PYTHON_ENABLE_CYTHON_TRACING=1 fi -tox --notest +tox -e ${TOX_PYTHON_ENV} --notest -$ROOT/.tox/py27/bin/python $ROOT/setup.py build -$ROOT/.tox/py27/bin/python $ROOT/setup.py build_py -$ROOT/.tox/py27/bin/python $ROOT/setup.py build_ext --inplace -$ROOT/.tox/py27/bin/python $ROOT/setup.py gather --test +$ROOT/.tox/${TOX_PYTHON_ENV}/bin/python $ROOT/setup.py build +$ROOT/.tox/${TOX_PYTHON_ENV}/bin/python $ROOT/setup.py build_py +$ROOT/.tox/${TOX_PYTHON_ENV}/bin/python $ROOT/setup.py build_ext --inplace +$ROOT/.tox/${TOX_PYTHON_ENV}/bin/python $ROOT/setup.py gather --test diff --git a/tools/run_tests/run_python.sh b/tools/run_tests/run_python.sh index a93ef2576db..7a3ce6b821a 100755 --- a/tools/run_tests/run_python.sh +++ b/tools/run_tests/run_python.sh @@ -33,6 +33,8 @@ set -ex # change to grpc repo root cd $(dirname $0)/../.. +TOX_PYTHON_ENV="$1" + ROOT=`pwd` export LD_LIBRARY_PATH=$ROOT/libs/$CONFIG export DYLD_LIBRARY_PATH=$ROOT/libs/$CONFIG @@ -45,9 +47,9 @@ export GRPC_PYTHON_USE_PRECOMPILED_BINARIES=0 if [ "$CONFIG" = "gcov" ] then export GRPC_PYTHON_ENABLE_CYTHON_TRACING=1 - tox + tox -e ${TOX_PYTHON_ENV} else - $ROOT/.tox/py27/bin/python $ROOT/setup.py test_lite + $ROOT/.tox/${TOX_PYTHON_ENV}/bin/python $ROOT/setup.py test_lite fi mkdir -p $ROOT/reports diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 4b9898539d5..dea481ef90d 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -356,25 +356,20 @@ class PhpLanguage(object): class PythonLanguage(object): - def __init__(self): - self._build_python_versions = ['2.7'] - self._has_python_versions = [] - def configure(self, config, args): self.config = config self.args = args - _check_compiler(self.args.compiler, ['default']) + self._tox_env = self._get_tox_env(self.args.compiler) def test_specs(self): # load list of known test suites with open('src/python/grpcio/tests/tests.json') as tests_json_file: tests_json = json.load(tests_json_file) environment = dict(_FORCE_ENVIRON_FOR_WRAPPERS) - environment['PYVER'] = '2.7' environment['PYTHONPATH'] = os.path.abspath('src/python/gens') if self.config.build_config != 'gcov': return [self.config.job_spec( - ['tools/run_tests/run_python.sh'], + ['tools/run_tests/run_python.sh', self._tox_env], None, environ=dict(environment.items() + [('GRPC_PYTHON_TESTRUNNER_FILTER', suite_name)]), @@ -399,18 +394,7 @@ class PythonLanguage(object): return [] def build_steps(self): - commands = [] - for python_version in self._build_python_versions: - try: - with open(os.devnull, 'w') as output: - subprocess.check_call(['which', 'python' + python_version], - stdout=output, stderr=output) - commands.append(['tools/run_tests/build_python.sh', python_version]) - self._has_python_versions.append(python_version) - except: - jobset.message('WARNING', 'Missing Python ' + python_version, - do_newline=True) - return commands + return [['tools/run_tests/build_python.sh', self._tox_env]] def post_tests_steps(self): return [] @@ -421,6 +405,15 @@ class PythonLanguage(object): def dockerfile_dir(self): return 'tools/dockerfile/test/python_jessie_%s' % _docker_arch_suffix(self.args.arch) + def _get_tox_env(self, compiler): + """Returns name of tox environment based on selected compiler.""" + if compiler == 'python2.7' or compiler == 'default': + return 'py27' + elif compiler == 'python3.4': + return 'py34' + else: + raise Exception('Compiler %s not supported.' % compiler) + def __str__(self): return 'python' @@ -808,7 +801,8 @@ argp.add_argument('--compiler', choices=['default', 'gcc4.4', 'gcc4.9', 'gcc5.3', 'clang3.4', 'clang3.6', - 'vs2010', 'vs2013', 'vs2015'], + 'vs2010', 'vs2013', 'vs2015', + 'python2.7', 'python3.4'], default='default', help='Selects compiler to use. Allowed values depend on the platform and language.') argp.add_argument('--build_only', diff --git a/tox.ini b/tox.ini index a655935219f..66b74a32db0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ # GRPC Python tox (test environment) settings [tox] skipsdist = true -envlist = py27 +envlist = py27,py34 [testenv] setenv = From ee9de2faeed5c7505ee4a34227a97485abd7d5dc Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 26 Apr 2016 18:59:47 -0700 Subject: [PATCH 13/15] cleanup build_interop.sh for python --- tools/dockerfile/grpc_interop_python/build_interop.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tools/dockerfile/grpc_interop_python/build_interop.sh b/tools/dockerfile/grpc_interop_python/build_interop.sh index 6454a4f5e25..f29c59da8e8 100755 --- a/tools/dockerfile/grpc_interop_python/build_interop.sh +++ b/tools/dockerfile/grpc_interop_python/build_interop.sh @@ -39,8 +39,4 @@ cp -r /var/local/jenkins/service_account $HOME || true cd /var/local/git/grpc -make - -# build Python interop client and server -CONFIG=opt ./tools/run_tests/build_python.sh - +tools/run_tests/run_tests.py -l python -c opt --build_only From 640d71dda90fee3dbb66f1b50c9b42058d063244 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 27 Apr 2016 07:17:58 -0700 Subject: [PATCH 14/15] Use cpp macros for the "application/grpc" string and its length. Also remove unnecessary strlen() call. --- src/core/lib/channel/http_server_filter.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index ad3462bff4f..192783f4ed7 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -39,6 +39,9 @@ #include "src/core/lib/profiling/timers.h" #include "src/core/lib/transport/static_metadata.h" +#define EXPECTED_CONTENT_TYPE "application/grpc" +#define EXPECTED_CONTENT_TYPE_LENGTH sizeof(EXPECTED_CONTENT_TYPE) - 1 + typedef struct call_data { uint8_t seen_path; uint8_t seen_method; @@ -93,9 +96,10 @@ static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) { return NULL; } else if (md->key == GRPC_MDSTR_CONTENT_TYPE) { const char* value_str = grpc_mdstr_as_c_string(md->value); - if (strncmp(value_str, "application/grpc", 16) == 0 && - (strlen(value_str) == 16 || - value_str[16] == '+' || value_str[16] == ';')) { + if (strncmp(value_str, EXPECTED_CONTENT_TYPE, + EXPECTED_CONTENT_TYPE_LENGTH) == 0 && + (value_str[EXPECTED_CONTENT_TYPE_LENGTH] == '+' || + value_str[EXPECTED_CONTENT_TYPE_LENGTH] == ';')) { /* Although the C implementation doesn't (currently) generate them, any custom +-suffix is explicitly valid. */ /* TODO(klempner): We should consider preallocating common values such From 1f3319bc88009355a07cbc757e007a659c5beaf8 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 27 Apr 2016 10:59:19 -0700 Subject: [PATCH 15/15] Fixed clang formatting problems. --- src/core/lib/channel/http_server_filter.c | 2 +- test/core/bad_client/tests/simple_request.c | 36 ++++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index 192783f4ed7..59dded63428 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -95,7 +95,7 @@ static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) { require */ return NULL; } else if (md->key == GRPC_MDSTR_CONTENT_TYPE) { - const char* value_str = grpc_mdstr_as_c_string(md->value); + const char *value_str = grpc_mdstr_as_c_string(md->value); if (strncmp(value_str, EXPECTED_CONTENT_TYPE, EXPECTED_CONTENT_TYPE_LENGTH) == 0 && (value_str[EXPECTED_CONTENT_TYPE_LENGTH] == '+' || diff --git a/test/core/bad_client/tests/simple_request.c b/test/core/bad_client/tests/simple_request.c index d6b85aefb58..3ae6eb3592d 100644 --- a/test/core/bad_client/tests/simple_request.c +++ b/test/core/bad_client/tests/simple_request.c @@ -77,25 +77,25 @@ "\x10\x0cgrpc-timeout\x02" \ "5S" -#define PFX_STR_UNUSUAL2 \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ - "\x00\x00\xf4\x01\x04\x00\x00\x00\x01" /* headers: generated from \ +#define PFX_STR_UNUSUAL2 \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ + "\x00\x00\xf4\x01\x04\x00\x00\x00\x01" /* headers: generated from \ simple_request_unusual2.headers \ - in this directory */ \ - "\x10\x05:path\x08/foo/bar" \ - "\x10\x07:scheme\x04http" \ - "\x10\x07:method\x04POST" \ - "\x10\x04host\x09localhost" \ - "\x10\x0c" \ - "content-type\x1e" \ - "application/grpc;this-is-valid" \ - "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" \ - "\x10\x02te\x08trailers" \ - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" \ - "\x10\x0cgrpc-timeout\x03" \ - "10S" \ - "\x10\x0cgrpc-timeout\x02" \ + in this directory */ \ + "\x10\x05:path\x08/foo/bar" \ + "\x10\x07:scheme\x04http" \ + "\x10\x07:method\x04POST" \ + "\x10\x04host\x09localhost" \ + "\x10\x0c" \ + "content-type\x1e" \ + "application/grpc;this-is-valid" \ + "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" \ + "\x10\x02te\x08trailers" \ + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" \ + "\x10\x0cgrpc-timeout\x03" \ + "10S" \ + "\x10\x0cgrpc-timeout\x02" \ "5S" static void *tag(intptr_t t) { return (void *)t; }