Merge pull request #4286 from jtattermusch/win_64bit

Make grpc compile on win64bit
pull/4385/head
Craig Tiller 9 years ago
commit dd4b0000b6
  1. 7
      include/grpc++/impl/rpc_service_method.h
  2. 13
      src/core/iomgr/tcp_windows.c
  3. 4
      src/core/security/json_token.c
  4. 29
      src/core/support/string.c
  5. 10
      src/core/support/string.h
  6. 7
      src/core/transport/chttp2/timeout_encoding.c
  7. 10
      src/cpp/proto/proto_utils.cc
  8. 50
      test/core/support/string_test.c
  9. 3
      tools/run_tests/jobset.py
  10. 75
      tools/run_tests/run_tests.py
  11. 10
      vsprojects/build_vs2010.bat
  12. 0
      vsprojects/build_vs2013.bat
  13. 10
      vsprojects/build_vs2015.bat

@ -34,6 +34,7 @@
#ifndef GRPCXX_IMPL_RPC_SERVICE_METHOD_H
#define GRPCXX_IMPL_RPC_SERVICE_METHOD_H
#include <climits>
#include <functional>
#include <map>
#include <memory>
@ -251,7 +252,11 @@ class RpcService {
void AddMethod(RpcServiceMethod* method) { methods_.emplace_back(method); }
RpcServiceMethod* GetMethod(int i) { return methods_[i].get(); }
int GetMethodCount() const { return methods_.size(); }
int GetMethodCount() const {
// On win x64, int is only 32bit
GPR_ASSERT(methods_.size() <= INT_MAX);
return (int)methods_.size();
}
private:
std::vector<std::unique_ptr<RpcServiceMethod>> methods_;

@ -197,7 +197,7 @@ static void win_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
tcp->read_slice = gpr_slice_malloc(8192);
buffer.len = GPR_SLICE_LENGTH(tcp->read_slice);
buffer.len = (ULONG)GPR_SLICE_LENGTH(tcp->read_slice); // we know slice size fits in 32bit.
buffer.buf = (char *)GPR_SLICE_START_PTR(tcp->read_slice);
TCP_REF(tcp, "read");
@ -273,6 +273,7 @@ static void win_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
WSABUF local_buffers[16];
WSABUF *allocated = NULL;
WSABUF *buffers = local_buffers;
size_t len;
if (tcp->shutting_down) {
grpc_exec_ctx_enqueue(exec_ctx, cb, 0);
@ -281,19 +282,21 @@ static void win_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
tcp->write_cb = cb;
tcp->write_slices = slices;
GPR_ASSERT(tcp->write_slices->count <= UINT_MAX);
if (tcp->write_slices->count > GPR_ARRAY_SIZE(local_buffers)) {
buffers = (WSABUF *)gpr_malloc(sizeof(WSABUF) * tcp->write_slices->count);
allocated = buffers;
}
for (i = 0; i < tcp->write_slices->count; i++) {
buffers[i].len = GPR_SLICE_LENGTH(tcp->write_slices->slices[i]);
len = GPR_SLICE_LENGTH(tcp->write_slices->slices[i]);
GPR_ASSERT(len <= ULONG_MAX);
buffers[i].len = (ULONG) len;
buffers[i].buf = (char *)GPR_SLICE_START_PTR(tcp->write_slices->slices[i]);
}
/* First, let's try a synchronous, non-blocking write. */
status = WSASend(socket->socket, buffers, tcp->write_slices->count,
status = WSASend(socket->socket, buffers, (DWORD)tcp->write_slices->count,
&bytes_sent, 0, NULL, NULL);
info->wsa_error = status == 0 ? 0 : WSAGetLastError();
@ -322,7 +325,7 @@ static void win_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
/* If we got a WSAEWOULDBLOCK earlier, then we need to re-do the same
operation, this time asynchronously. */
memset(&socket->write_info.overlapped, 0, sizeof(OVERLAPPED));
status = WSASend(socket->socket, buffers, tcp->write_slices->count,
status = WSASend(socket->socket, buffers, (DWORD)tcp->write_slices->count,
&bytes_sent, 0, &socket->write_info.overlapped, NULL);
if (allocated) gpr_free(allocated);

@ -215,8 +215,8 @@ static char *encoded_jwt_claim(const grpc_auth_json_key *json_key,
gpr_log(GPR_INFO, "Cropping token lifetime to maximum allowed value.");
expiration = gpr_time_add(now, grpc_max_auth_token_lifetime);
}
gpr_ltoa(now.tv_sec, now_str);
gpr_ltoa(expiration.tv_sec, expiration_str);
gpr_int64toa(now.tv_sec, now_str);
gpr_int64toa(expiration.tv_sec, expiration_str);
child =
create_child(NULL, json, "iss", json_key->client_email, GRPC_JSON_STRING);

@ -153,8 +153,8 @@ void gpr_reverse_bytes(char *str, int len) {
}
int gpr_ltoa(long value, char *string) {
long sign;
int i = 0;
int neg = value < 0;
if (value == 0) {
string[0] = '0';
@ -162,12 +162,33 @@ int gpr_ltoa(long value, char *string) {
return 1;
}
if (neg) value = -value;
sign = value < 0 ? -1 : 1;
while (value) {
string[i++] = (char)('0' + value % 10);
string[i++] = (char)('0' + sign * (value % 10));
value /= 10;
}
if (neg) string[i++] = '-';
if (sign < 0) string[i++] = '-';
gpr_reverse_bytes(string, i);
string[i] = 0;
return i;
}
int gpr_int64toa(gpr_int64 value, char *string) {
gpr_int64 sign;
int i = 0;
if (value == 0) {
string[0] = '0';
string[1] = 0;
return 1;
}
sign = value < 0 ? -1 : 1;
while (value) {
string[i++] = (char)('0' + sign * (value % 10));
value /= 10;
}
if (sign < 0) string[i++] = '-';
gpr_reverse_bytes(string, i);
string[i] = 0;
return i;

@ -70,6 +70,16 @@ int gpr_parse_bytes_to_uint32(const char *data, size_t length,
output must be at least GPR_LTOA_MIN_BUFSIZE bytes long. */
int gpr_ltoa(long value, char *output);
/* Minimum buffer size for calling int64toa */
#define GPR_INT64TOA_MIN_BUFSIZE (3 * sizeof(gpr_int64))
/* Convert an int64 to a string in base 10; returns the length of the
output string (or 0 on failure).
output must be at least GPR_INT64TOA_MIN_BUFSIZE bytes long.
NOTE: This function ensures sufficient bit width even on Win x64,
where long is 32bit is size.*/
int gpr_int64toa(gpr_int64 value, char *output);
/* Reverse a run of bytes */
void gpr_reverse_bytes(char *str, int len);

@ -36,6 +36,7 @@
#include <stdio.h>
#include <string.h>
#include <grpc/support/port_platform.h>
#include "src/core/support/string.h"
static int round_up(int x, int divisor) {
@ -57,13 +58,13 @@ static int round_up_to_three_sig_figs(int x) {
/* encode our minimum viable timeout value */
static void enc_tiny(char *buffer) { memcpy(buffer, "1n", 3); }
static void enc_ext(char *buffer, long value, char ext) {
int n = gpr_ltoa(value, buffer);
static void enc_ext(char *buffer, gpr_int64 value, char ext) {
int n = gpr_int64toa(value, buffer);
buffer[n] = ext;
buffer[n + 1] = 0;
}
static void enc_seconds(char *buffer, long sec) {
static void enc_seconds(char *buffer, gpr_int64 sec) {
if (sec % 3600 == 0) {
enc_ext(buffer, sec / 3600, 'H');
} else if (sec % 60 == 0) {

@ -33,6 +33,8 @@
#include <grpc++/impl/proto_utils.h>
#include <climits>
#include <grpc/grpc.h>
#include <grpc/byte_buffer.h>
#include <grpc/byte_buffer_reader.h>
@ -70,7 +72,9 @@ class GrpcBufferWriter GRPC_FINAL
slice_ = gpr_slice_malloc(block_size_);
}
*data = GPR_SLICE_START_PTR(slice_);
byte_count_ += * size = GPR_SLICE_LENGTH(slice_);
// On win x64, int is only 32bit
GPR_ASSERT(GPR_SLICE_LENGTH(slice_) <= INT_MAX);
byte_count_ += * size = (int)GPR_SLICE_LENGTH(slice_);
gpr_slice_buffer_add(slice_buffer_, slice_);
return true;
}
@ -124,7 +128,9 @@ class GrpcBufferReader GRPC_FINAL
}
gpr_slice_unref(slice_);
*data = GPR_SLICE_START_PTR(slice_);
byte_count_ += * size = GPR_SLICE_LENGTH(slice_);
// On win x64, int is only 32bit
GPR_ASSERT(GPR_SLICE_LENGTH(slice_) <= INT_MAX);
byte_count_ += * size = (int)GPR_SLICE_LENGTH(slice_);
return true;
}

@ -33,6 +33,7 @@
#include "src/core/support/string.h"
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
@ -286,6 +287,53 @@ static void test_strsplit(void) {
gpr_free(parts);
}
static void test_ltoa() {
char *str;
char buf[GPR_LTOA_MIN_BUFSIZE];
LOG_TEST_NAME("test_ltoa");
/* zero */
GPR_ASSERT(1 == gpr_ltoa(0, buf));
GPR_ASSERT(0 == strcmp("0", buf));
/* positive number */
GPR_ASSERT(3 == gpr_ltoa(123, buf));
GPR_ASSERT(0 == strcmp("123", buf));
/* negative number */
GPR_ASSERT(6 == gpr_ltoa(-12345, buf));
GPR_ASSERT(0 == strcmp("-12345", buf));
/* large negative - we don't know the size of long in advance */
GPR_ASSERT(gpr_asprintf(&str, "%lld", (long long)LONG_MIN));
GPR_ASSERT(strlen(str) == (size_t)gpr_ltoa(LONG_MIN, buf));
GPR_ASSERT(0 == strcmp(str, buf));
gpr_free(str);
}
static void test_int64toa() {
char buf[GPR_INT64TOA_MIN_BUFSIZE];
LOG_TEST_NAME("test_int64toa");
/* zero */
GPR_ASSERT(1 == gpr_int64toa(0, buf));
GPR_ASSERT(0 == strcmp("0", buf));
/* positive */
GPR_ASSERT(3 == gpr_int64toa(123, buf));
GPR_ASSERT(0 == strcmp("123", buf));
/* large positive */
GPR_ASSERT(19 == gpr_int64toa(9223372036854775807LL, buf));
GPR_ASSERT(0 == strcmp("9223372036854775807", buf));
/* large negative */
GPR_ASSERT(20 == gpr_int64toa(-9223372036854775807LL - 1, buf));
GPR_ASSERT(0 == strcmp("-9223372036854775808", buf));
}
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
test_strdup();
@ -296,5 +344,7 @@ int main(int argc, char **argv) {
test_strjoin();
test_strjoin_sep();
test_strsplit();
test_ltoa();
test_int64toa();
return 0;
}

@ -178,6 +178,9 @@ class JobSpec(object):
def __cmp__(self, other):
return self.identity() == other.identity()
def __repr__(self):
return 'JobSpec(shortname=%s, cmdline=%s)' % (self.shortname, self.cmdline)
class JobResult(object):

@ -508,6 +508,43 @@ _WINDOWS_CONFIG = {
}
def _windows_arch_option(arch):
"""Returns msbuild cmdline option for selected architecture."""
if arch == 'default' or arch == 'windows_x86':
return '/p:Platform=Win32'
elif arch == 'windows_x64':
return '/p:Platform=x64'
else:
print 'Architecture %s not supported on current platform.' % arch
sys.exit(1)
def _windows_build_bat(compiler):
"""Returns name of build.bat for selected compiler."""
if compiler == 'default' or compiler == 'vs2013':
return 'vsprojects\\build_vs2013.bat'
elif compiler == 'vs2015':
return 'vsprojects\\build_vs2015.bat'
elif compiler == 'vs2010':
return 'vsprojects\\build_vs2010.bat'
else:
print 'Compiler %s not supported.' % compiler
sys.exit(1)
def _windows_toolset_option(compiler):
"""Returns msbuild PlatformToolset for selected compiler."""
if compiler == 'default' or compiler == 'vs2013':
return '/p:PlatformToolset=v120'
elif compiler == 'vs2015':
return '/p:PlatformToolset=v140'
elif compiler == 'vs2010':
return '/p:PlatformToolset=v100'
else:
print 'Compiler %s not supported.' % compiler
sys.exit(1)
def runs_per_test_type(arg_str):
"""Auxilary function to parse the "runs_per_test" flag.
@ -572,6 +609,19 @@ argp.add_argument('--allow_flakes',
action='store_const',
const=True,
help='Allow flaky tests to show as passing (re-runs failed tests up to five times)')
argp.add_argument('--arch',
choices=['default', 'windows_x86', 'windows_x64'],
default='default',
help='Selects architecture to target. For some platforms "default" is the only supported choice.')
argp.add_argument('--compiler',
choices=['default', 'vs2010', 'vs2013', 'vs2015'],
default='default',
help='Selects compiler to use. For some platforms "default" is the only supported choice.')
argp.add_argument('--build_only',
default=False,
action='store_const',
const=True,
help='Perform all the build steps but dont run any tests.')
argp.add_argument('-a', '--antagonists', default=0, type=int)
argp.add_argument('-x', '--xml_report', default=None, type=str,
help='Generates a JUnit-compatible XML report')
@ -633,6 +683,14 @@ if len(build_configs) > 1:
print language, 'does not support multiple build configurations'
sys.exit(1)
if platform_string() != 'windows':
if args.arch != 'default':
print 'Architecture %s not supported on current platform.' % args.arch
sys.exit(1)
if args.compiler != 'default':
print 'Compiler %s not supported on current platform.' % args.compiler
sys.exit(1)
if platform_string() == 'windows':
def make_jobspec(cfg, targets, makefile='Makefile'):
extra_args = []
@ -643,9 +701,11 @@ if platform_string() == 'windows':
# disable PDB generation: it's broken, and we don't need it during CI
extra_args.extend(['/p:Jenkins=true'])
return [
jobset.JobSpec(['vsprojects\\build.bat',
jobset.JobSpec([_windows_build_bat(args.compiler),
'vsprojects\\%s.sln' % target,
'/p:Configuration=%s' % _WINDOWS_CONFIG[cfg]] +
'/p:Configuration=%s' % _WINDOWS_CONFIG[cfg],
_windows_toolset_option(args.compiler),
_windows_arch_option(args.arch)] +
extra_args,
shell=True, timeout_seconds=90*60)
for target in targets]
@ -840,7 +900,7 @@ def _calculate_num_runs_failures(list_of_results):
def _build_and_run(
check_cancelled, newline_on_success, cache, xml_report=None):
check_cancelled, newline_on_success, cache, xml_report=None, build_only=False):
"""Do one pass of building & running tests."""
# build latest sequentially
num_failures, _ = jobset.run(
@ -848,6 +908,9 @@ def _build_and_run(
newline_on_success=newline_on_success, travis=args.travis)
if num_failures:
return 1
if build_only:
return 0
# start antagonists
antagonists = [subprocess.Popen(['tools/run_tests/antagonist.py'])
@ -925,7 +988,8 @@ if forever:
previous_success = success
success = _build_and_run(check_cancelled=have_files_changed,
newline_on_success=False,
cache=test_cache) == 0
cache=test_cache,
build_only=args.build_only) == 0
if not previous_success and success:
jobset.message('SUCCESS',
'All tests are now passing properly',
@ -937,7 +1001,8 @@ else:
result = _build_and_run(check_cancelled=lambda: False,
newline_on_success=args.newline_on_success,
cache=test_cache,
xml_report=args.xml_report)
xml_report=args.xml_report,
build_only=args.build_only)
if result == 0:
jobset.message('SUCCESS', 'All tests passed', do_newline=True)
else:

@ -0,0 +1,10 @@
@rem Convenience wrapper that runs specified gRPC target using msbuild
@rem Usage: build.bat TARGET_NAME
setlocal
@rem Set VS variables (uses Visual Studio 2010)
@call "%VS100COMNTOOLS%\..\..\vc\vcvarsall.bat" x86
msbuild %*
exit /b %ERRORLEVEL%
endlocal

@ -0,0 +1,10 @@
@rem Convenience wrapper that runs specified gRPC target using msbuild
@rem Usage: build.bat TARGET_NAME
setlocal
@rem Set VS variables (uses Visual Studio 2015)
@call "%VS140COMNTOOLS%\..\..\vc\vcvarsall.bat" x86
msbuild %*
exit /b %ERRORLEVEL%
endlocal
Loading…
Cancel
Save