From 87b4f2b23f2250673c5cfecb4de21932b3ece394 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Sun, 9 Aug 2015 13:52:19 -0700 Subject: [PATCH 01/32] wip. we need a way to pass args to server construction --- include/grpc/compression.h | 1 + src/core/channel/channel_args.c | 42 +++++++++++++++++++++++++++++++++ src/core/channel/channel_args.h | 14 +++++++++++ test/cpp/interop/server.cc | 2 -- 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/include/grpc/compression.h b/include/grpc/compression.h index e35fb03eb2a..a1a3236d3bf 100644 --- a/include/grpc/compression.h +++ b/include/grpc/compression.h @@ -42,6 +42,7 @@ extern "C" { /** To be used in channel arguments */ #define GRPC_COMPRESSION_ALGORITHM_ARG "grpc.compression_algorithm" +#define GRPC_COMPRESSION_ALGORITHM_STATE_ARG "grpc.compression_algorithm_state" /* The various compression algorithms supported by GRPC */ typedef enum { diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c index c430b56fa2d..77449c0df5f 100644 --- a/src/core/channel/channel_args.c +++ b/src/core/channel/channel_args.c @@ -37,6 +37,7 @@ #include #include +#include #include @@ -146,3 +147,44 @@ grpc_channel_args *grpc_channel_args_set_compression_algorithm( tmp.value.integer = algorithm; return grpc_channel_args_copy_and_add(a, &tmp, 1); } + +static gpr_uint32 find_compression_algorithm_states_bitset( + const grpc_channel_args *a) { + size_t i; + gpr_uint32 states_bitset = 0; + if (a == NULL) return 0; + for (i = 0; i < a->num_args; ++i) { + if (a->args[i].type == GRPC_ARG_INTEGER && + !strcmp(GRPC_COMPRESSION_ALGORITHM_STATE_ARG, a->args[i].key)) { + states_bitset = a->args[i].value.integer; + break; + } + } + return states_bitset; +} + +grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( + grpc_channel_args *a, + grpc_compression_algorithm algorithm, + int state) { + gpr_uint32 states_bitset = find_compression_algorithm_states_bitset(a); + grpc_arg tmp; + + if (state != 0) { + GPR_BITSET(&states_bitset, algorithm); + } else { + GPR_BITCLEAR(&states_bitset, algorithm); + } + + tmp.type = GRPC_ARG_INTEGER; + tmp.key = GRPC_COMPRESSION_ALGORITHM_STATE_ARG; + tmp.value.integer = states_bitset; + return grpc_channel_args_copy_and_add(a, &tmp, 1); +} + +int grpc_channel_args_compression_algorithm_get_state( + grpc_channel_args *a, + grpc_compression_algorithm algorithm) { + const gpr_uint32 states_bitset = find_compression_algorithm_states_bitset(a); + return GPR_BITGET(states_bitset, algorithm); +} diff --git a/src/core/channel/channel_args.h b/src/core/channel/channel_args.h index 7e6ddd3997a..f1a75117af4 100644 --- a/src/core/channel/channel_args.h +++ b/src/core/channel/channel_args.h @@ -67,4 +67,18 @@ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( grpc_channel_args *grpc_channel_args_set_compression_algorithm( grpc_channel_args *a, grpc_compression_algorithm algorithm); +/** Sets the support for the given compression algorithm. By default, all + * compression algorithms are enabled. Disabling an algorithm set by + * grpc_channel_args_set_compression_algorithm disables compression altogether + * */ +grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( + grpc_channel_args *a, + grpc_compression_algorithm algorithm, + int enabled); + +/** Returns the state (true for enabled, false for disabled) for \a algorithm */ +int grpc_channel_args_compression_algorithm_get_state( + grpc_channel_args *a, + grpc_compression_algorithm algorithm); + #endif /* GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_ARGS_H */ diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc index 0097d1678c2..0485e447e5c 100644 --- a/test/cpp/interop/server.cc +++ b/test/cpp/interop/server.cc @@ -148,8 +148,6 @@ class TestServiceImpl : public TestService::Service { return Status(grpc::StatusCode::INTERNAL, "Error creating payload."); } } - const gpr_uint32 client_accept_encodings_bitset = - inspector.GetEncodingsAcceptedByClient(); if (request->has_response_status()) { return Status(static_cast From b58b346fbebab3feb6ffa0122aca223bc2f63952 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Sun, 9 Aug 2015 13:52:19 -0700 Subject: [PATCH 02/32] wip. we need a way to pass args to server construction --- include/grpc/compression.h | 1 + src/core/channel/channel_args.c | 42 +++++++++++++++++++++++++++++++++ src/core/channel/channel_args.h | 14 +++++++++++ test/cpp/interop/server.cc | 2 -- 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/include/grpc/compression.h b/include/grpc/compression.h index e35fb03eb2a..a1a3236d3bf 100644 --- a/include/grpc/compression.h +++ b/include/grpc/compression.h @@ -42,6 +42,7 @@ extern "C" { /** To be used in channel arguments */ #define GRPC_COMPRESSION_ALGORITHM_ARG "grpc.compression_algorithm" +#define GRPC_COMPRESSION_ALGORITHM_STATE_ARG "grpc.compression_algorithm_state" /* The various compression algorithms supported by GRPC */ typedef enum { diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c index c430b56fa2d..10199f7719c 100644 --- a/src/core/channel/channel_args.c +++ b/src/core/channel/channel_args.c @@ -37,6 +37,7 @@ #include #include +#include #include @@ -146,3 +147,44 @@ grpc_channel_args *grpc_channel_args_set_compression_algorithm( tmp.value.integer = algorithm; return grpc_channel_args_copy_and_add(a, &tmp, 1); } + +static gpr_uint32 find_compression_algorithm_states_bitset( + const grpc_channel_args *a) { + size_t i; + gpr_uint32 states_bitset = 0; + if (a == NULL) return 0; + for (i = 0; i < a->num_args; ++i) { + if (a->args[i].type == GRPC_ARG_INTEGER && + !strcmp(GRPC_COMPRESSION_ALGORITHM_STATE_ARG, a->args[i].key)) { + states_bitset = a->args[i].value.integer; + break; + } + } + return states_bitset; +} + +grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( + grpc_channel_args *a, + grpc_compression_algorithm algorithm, + int state) { + gpr_uint32 states_bitset = find_compression_algorithm_states_bitset(a); + grpc_arg tmp; + + if (state != 0) { + GPR_BITSET(&states_bitset, algorithm); + } else { + GPR_BITCLEAR(&states_bitset, algorithm); + } + + tmp.type = GRPC_ARG_INTEGER; + tmp.key = GRPC_COMPRESSION_ALGORITHM_STATE_ARG; + tmp.value.integer = states_bitset; + return grpc_channel_args_copy_and_add(a, &tmp, 1); +} + +int grpc_channel_args_compression_algorithm_get_state( + grpc_channel_args *a, + grpc_compression_algorithm algorithm) { + const gpr_uint32 states_bitset = find_compression_algorithm_states_bitset(a); + return GPR_BITGET(states_bitset, algorithm); +} diff --git a/src/core/channel/channel_args.h b/src/core/channel/channel_args.h index 7e6ddd3997a..f1a75117af4 100644 --- a/src/core/channel/channel_args.h +++ b/src/core/channel/channel_args.h @@ -67,4 +67,18 @@ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( grpc_channel_args *grpc_channel_args_set_compression_algorithm( grpc_channel_args *a, grpc_compression_algorithm algorithm); +/** Sets the support for the given compression algorithm. By default, all + * compression algorithms are enabled. Disabling an algorithm set by + * grpc_channel_args_set_compression_algorithm disables compression altogether + * */ +grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( + grpc_channel_args *a, + grpc_compression_algorithm algorithm, + int enabled); + +/** Returns the state (true for enabled, false for disabled) for \a algorithm */ +int grpc_channel_args_compression_algorithm_get_state( + grpc_channel_args *a, + grpc_compression_algorithm algorithm); + #endif /* GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_ARGS_H */ diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc index 0097d1678c2..0485e447e5c 100644 --- a/test/cpp/interop/server.cc +++ b/test/cpp/interop/server.cc @@ -148,8 +148,6 @@ class TestServiceImpl : public TestService::Service { return Status(grpc::StatusCode::INTERNAL, "Error creating payload."); } } - const gpr_uint32 client_accept_encodings_bitset = - inspector.GetEncodingsAcceptedByClient(); if (request->has_response_status()) { return Status(static_cast From beac88ca56f4710e86668f2cbbd80e02e0607f9c Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Mon, 10 Aug 2015 13:39:52 -0700 Subject: [PATCH 03/32] Server: added the ability to disable compression algorithm --- include/grpc++/server.h | 3 +- include/grpc++/server_builder.h | 23 +++++++------ include/grpc/compression.h | 21 ++++++++++++ src/core/channel/channel_args.c | 27 +++++++-------- src/core/channel/channel_args.h | 15 +++++---- src/core/channel/compress_filter.c | 28 +++++++++++++++- src/core/compression/algorithm.c | 23 +++++++++++++ src/cpp/server/server.cc | 25 +++++++++----- src/cpp/server/server_builder.cc | 53 ++++++++++++++++++++++-------- 9 files changed, 164 insertions(+), 54 deletions(-) diff --git a/include/grpc++/server.h b/include/grpc++/server.h index 94ee0b6a4ac..07dbd7fd202 100644 --- a/include/grpc++/server.h +++ b/include/grpc++/server.h @@ -43,6 +43,7 @@ #include #include #include +#include struct grpc_server; @@ -81,7 +82,7 @@ class Server GRPC_FINAL : public GrpcLibrary, private CallHook { // ServerBuilder use only Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned, - int max_message_size); + int max_message_size, grpc_compression_options compression_options); // Register a service. This call does not take ownership of the service. // The service must exist for the lifetime of the Server instance. bool RegisterService(const grpc::string *host, RpcService* service); diff --git a/include/grpc++/server_builder.h b/include/grpc++/server_builder.h index 44ee00eec9c..47efbb78346 100644 --- a/include/grpc++/server_builder.h +++ b/include/grpc++/server_builder.h @@ -37,6 +37,7 @@ #include #include +#include #include namespace grpc { @@ -59,24 +60,24 @@ class ServerBuilder { // The service must exist for the lifetime of the Server instance returned by // BuildAndStart(). // Matches requests with any :authority - void RegisterService(SynchronousService* service); + ServerBuilder& RegisterService(SynchronousService* service); // Register an asynchronous service. // This call does not take ownership of the service or completion queue. // The service and completion queuemust exist for the lifetime of the Server // instance returned by BuildAndStart(). // Matches requests with any :authority - void RegisterAsyncService(AsynchronousService* service); + ServerBuilder& RegisterAsyncService(AsynchronousService* service); // Register a generic service. // Matches requests with any :authority - void RegisterAsyncGenericService(AsyncGenericService* service); + ServerBuilder& RegisterAsyncGenericService(AsyncGenericService* service); // Register a service. This call does not take ownership of the service. // The service must exist for the lifetime of the Server instance returned by // BuildAndStart(). // Only matches requests with :authority \a host - void RegisterService(const grpc::string& host, + ServerBuilder& RegisterService(const grpc::string& host, SynchronousService* service); // Register an asynchronous service. @@ -84,22 +85,23 @@ class ServerBuilder { // The service and completion queuemust exist for the lifetime of the Server // instance returned by BuildAndStart(). // Only matches requests with :authority \a host - void RegisterAsyncService(const grpc::string& host, + ServerBuilder& RegisterAsyncService(const grpc::string& host, AsynchronousService* service); // Set max message size in bytes. - void SetMaxMessageSize(int max_message_size) { - max_message_size_ = max_message_size; - } + ServerBuilder& SetMaxMessageSize(int max_message_size); // Add a listening port. Can be called multiple times. - void AddListeningPort(const grpc::string& addr, + ServerBuilder& AddListeningPort(const grpc::string& addr, std::shared_ptr creds, int* selected_port = nullptr); // Set the thread pool used for running appliation rpc handlers. // Does not take ownership. - void SetThreadPool(ThreadPoolInterface* thread_pool); + ServerBuilder& SetThreadPool(ThreadPoolInterface* thread_pool); + + // Set the compression options to be used by the server. + ServerBuilder& SetCompressionOptions(const grpc_compression_options& options); // Add a completion queue for handling asynchronous services // Caller is required to keep this completion queue live until calling @@ -126,6 +128,7 @@ class ServerBuilder { }; int max_message_size_; + grpc_compression_options compression_options_; std::vector>> services_; std::vector>> async_services_; std::vector ports_; diff --git a/include/grpc/compression.h b/include/grpc/compression.h index a1a3236d3bf..82e326fe0ec 100644 --- a/include/grpc/compression.h +++ b/include/grpc/compression.h @@ -36,6 +36,8 @@ #include +#include + #ifdef __cplusplus extern "C" { #endif @@ -61,6 +63,11 @@ typedef enum { GRPC_COMPRESS_LEVEL_COUNT } grpc_compression_level; +typedef struct grpc_compression_options { + gpr_uint32 enabled_algorithms_bitset; /**< All algs are enabled by default */ + grpc_compression_algorithm default_compression_algorithm; /**< for channel */ +} grpc_compression_options; + /** Parses the first \a name_length bytes of \a name as a * grpc_compression_algorithm instance, updating \a algorithm. Returns 1 upon * success, 0 otherwise. */ @@ -84,6 +91,20 @@ grpc_compression_level grpc_compression_level_for_algorithm( grpc_compression_algorithm grpc_compression_algorithm_for_level( grpc_compression_level level); +void grpc_compression_options_init(grpc_compression_options *opts); + +/** Mark \a algorithm as enabled in \a opts. */ +void grpc_compression_options_enable_algorithm( + grpc_compression_options *opts, grpc_compression_algorithm algorithm); + +/** Mark \a algorithm as disabled in \a opts. */ +void grpc_compression_options_disable_algorithm( + grpc_compression_options *opts, grpc_compression_algorithm algorithm); + +/** Returns true if \a algorithm is marked as enabled in \a opts. */ +int grpc_compression_options_is_algorithm_enabled( + const grpc_compression_options *opts, grpc_compression_algorithm algorithm); + #ifdef __cplusplus } #endif diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c index 10199f7719c..7d97b795531 100644 --- a/src/core/channel/channel_args.c +++ b/src/core/channel/channel_args.c @@ -148,16 +148,19 @@ grpc_channel_args *grpc_channel_args_set_compression_algorithm( return grpc_channel_args_copy_and_add(a, &tmp, 1); } +/** Returns the compression algorithm's enabled states bitset from \a a. If not + * found, return a biset will all algorithms enabled */ static gpr_uint32 find_compression_algorithm_states_bitset( const grpc_channel_args *a) { - size_t i; - gpr_uint32 states_bitset = 0; - if (a == NULL) return 0; - for (i = 0; i < a->num_args; ++i) { - if (a->args[i].type == GRPC_ARG_INTEGER && - !strcmp(GRPC_COMPRESSION_ALGORITHM_STATE_ARG, a->args[i].key)) { - states_bitset = a->args[i].value.integer; - break; + gpr_uint32 states_bitset = (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; + if (a != NULL) { + size_t i; + for (i = 0; i < a->num_args; ++i) { + if (a->args[i].type == GRPC_ARG_INTEGER && + !strcmp(GRPC_COMPRESSION_ALGORITHM_STATE_ARG, a->args[i].key)) { + states_bitset = a->args[i].value.integer; + break; + } } } return states_bitset; @@ -182,9 +185,7 @@ grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( return grpc_channel_args_copy_and_add(a, &tmp, 1); } -int grpc_channel_args_compression_algorithm_get_state( - grpc_channel_args *a, - grpc_compression_algorithm algorithm) { - const gpr_uint32 states_bitset = find_compression_algorithm_states_bitset(a); - return GPR_BITGET(states_bitset, algorithm); +int grpc_channel_args_compression_algorithm_get_states( + const grpc_channel_args *a) { + return find_compression_algorithm_states_bitset(a); } diff --git a/src/core/channel/channel_args.h b/src/core/channel/channel_args.h index f1a75117af4..e557f9a9d92 100644 --- a/src/core/channel/channel_args.h +++ b/src/core/channel/channel_args.h @@ -68,17 +68,20 @@ grpc_channel_args *grpc_channel_args_set_compression_algorithm( grpc_channel_args *a, grpc_compression_algorithm algorithm); /** Sets the support for the given compression algorithm. By default, all - * compression algorithms are enabled. Disabling an algorithm set by - * grpc_channel_args_set_compression_algorithm disables compression altogether + * compression algorithms are enabled. It's an error to disable an algorithm set + * by grpc_channel_args_set_compression_algorithm. * */ grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( grpc_channel_args *a, grpc_compression_algorithm algorithm, int enabled); -/** Returns the state (true for enabled, false for disabled) for \a algorithm */ -int grpc_channel_args_compression_algorithm_get_state( - grpc_channel_args *a, - grpc_compression_algorithm algorithm); +/** Returns the bitset representing the support state (true for enabled, false + * for disabled) for compression algorithms. + * + * The i-th bit of the returned bitset corresponds to the i-th entry in the + * grpc_compression_algorithm enum. */ +int grpc_channel_args_compression_algorithm_get_states( + const grpc_channel_args *a); #endif /* GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_ARGS_H */ diff --git a/src/core/channel/compress_filter.c b/src/core/channel/compress_filter.c index 2fd4c8cae6c..065fe258dc8 100644 --- a/src/core/channel/compress_filter.c +++ b/src/core/channel/compress_filter.c @@ -70,6 +70,8 @@ typedef struct channel_data { grpc_mdelem *mdelem_accept_encoding; /** The default, channel-level, compression algorithm */ grpc_compression_algorithm default_compression_algorithm; + /** Compression options for the channel */ + grpc_compression_options compression_options; } channel_data; /** Compress \a slices in place using \a algorithm. Returns 1 if compression did @@ -102,7 +104,17 @@ static grpc_mdelem* compression_md_filter(void *user_data, grpc_mdelem *md) { const char *md_c_str = grpc_mdstr_as_c_string(md->value); if (!grpc_compression_algorithm_parse(md_c_str, strlen(md_c_str), &calld->compression_algorithm)) { - gpr_log(GPR_ERROR, "Invalid compression algorithm: '%s'. Ignoring.", + gpr_log(GPR_ERROR, + "Invalid compression algorithm: '%s' (unknown). Ignoring.", + md_c_str); + calld->compression_algorithm = GRPC_COMPRESS_NONE; + } + if (grpc_compression_options_is_algorithm_enabled( + &channeld->compression_options, calld->compression_algorithm) == 0) + { + gpr_log(GPR_ERROR, + "Invalid compression algorithm: '%s' (previously disabled). " + "Ignoring.", md_c_str); calld->compression_algorithm = GRPC_COMPRESS_NONE; } @@ -297,8 +309,17 @@ static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master, char *accept_encoding_str; size_t accept_encoding_str_len; + grpc_compression_options_init(&channeld->compression_options); + channeld->compression_options.enabled_algorithms_bitset = + grpc_channel_args_compression_algorithm_get_states(args); + channeld->default_compression_algorithm = grpc_channel_args_get_compression_algorithm(args); + /* Make sure the default isn't disabled. */ + GPR_ASSERT(grpc_compression_options_is_algorithm_enabled( + &channeld->compression_options, channeld->default_compression_algorithm)); + channeld->compression_options.default_compression_algorithm = + channeld->default_compression_algorithm; channeld->mdstr_request_compression_algorithm_key = grpc_mdstr_from_string(mdctx, GRPC_COMPRESS_REQUEST_ALGORITHM_KEY, 0); @@ -311,6 +332,11 @@ static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master, for (algo_idx = 0; algo_idx < GRPC_COMPRESS_ALGORITHMS_COUNT; ++algo_idx) { char *algorithm_name; + /* skip disabled algorithms */ + if (grpc_compression_options_is_algorithm_enabled( + &channeld->compression_options, algo_idx) == 0) { + continue; + } GPR_ASSERT(grpc_compression_algorithm_name(algo_idx, &algorithm_name) != 0); channeld->mdelem_compression_algorithms[algo_idx] = grpc_mdelem_from_metadata_strings( diff --git a/src/core/compression/algorithm.c b/src/core/compression/algorithm.c index dbf4721d13e..6514fcd26f6 100644 --- a/src/core/compression/algorithm.c +++ b/src/core/compression/algorithm.c @@ -33,7 +33,9 @@ #include #include + #include +#include int grpc_compression_algorithm_parse(const char* name, size_t name_length, grpc_compression_algorithm *algorithm) { @@ -102,3 +104,24 @@ grpc_compression_level grpc_compression_level_for_algorithm( } abort(); } + +void grpc_compression_options_init(grpc_compression_options *opts) { + opts->enabled_algorithms_bitset = (1u << GRPC_COMPRESS_ALGORITHMS_COUNT)-1; + opts->default_compression_algorithm = GRPC_COMPRESS_NONE; +} + +void grpc_compression_options_enable_algorithm( + grpc_compression_options *opts, grpc_compression_algorithm algorithm) { + GPR_BITSET(&opts->enabled_algorithms_bitset, algorithm); +} + +void grpc_compression_options_disable_algorithm( + grpc_compression_options *opts, grpc_compression_algorithm algorithm) { + GPR_BITCLEAR(&opts->enabled_algorithms_bitset, algorithm); +} + +int grpc_compression_options_is_algorithm_enabled( + const grpc_compression_options *opts, + grpc_compression_algorithm algorithm) { + return GPR_BITGET(opts->enabled_algorithms_bitset, algorithm); +} diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index ab87b22f5fb..6e576ab8b39 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -163,27 +163,34 @@ class Server::SyncRequest GRPC_FINAL : public CompletionQueueTag { grpc_completion_queue* cq_; }; -static grpc_server* CreateServer(int max_message_size) { +static grpc_server* CreateServer( + int max_message_size, const grpc_compression_options& compression_options) { if (max_message_size > 0) { - grpc_arg arg; - arg.type = GRPC_ARG_INTEGER; - arg.key = const_cast(GRPC_ARG_MAX_MESSAGE_LENGTH); - arg.value.integer = max_message_size; - grpc_channel_args args = {1, &arg}; - return grpc_server_create(&args); + grpc_arg args[2]; + args[0].type = GRPC_ARG_INTEGER; + args[0].key = const_cast(GRPC_ARG_MAX_MESSAGE_LENGTH); + args[0].value.integer = max_message_size; + + args[1].type = GRPC_ARG_INTEGER; + args[1].key = const_cast(GRPC_COMPRESSION_ALGORITHM_STATE_ARG); + args[1].value.integer = compression_options.enabled_algorithms_bitset; + + grpc_channel_args channel_args = {2, args}; + return grpc_server_create(&channel_args); } else { return grpc_server_create(nullptr); } } Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned, - int max_message_size) + int max_message_size, + grpc_compression_options compression_options) : max_message_size_(max_message_size), started_(false), shutdown_(false), num_running_cb_(0), sync_methods_(new std::list), - server_(CreateServer(max_message_size)), + server_(CreateServer(max_message_size, compression_options)), thread_pool_(thread_pool), thread_pool_owned_(thread_pool_owned) { grpc_server_register_completion_queue(server_, cq_.cq()); diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index f723d4611ae..425b0521280 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -42,7 +42,9 @@ namespace grpc { ServerBuilder::ServerBuilder() - : max_message_size_(-1), generic_service_(nullptr), thread_pool_(nullptr) {} + : max_message_size_(-1), generic_service_(nullptr), thread_pool_(nullptr) { + grpc_compression_options_init(&compression_options_); +} std::unique_ptr ServerBuilder::AddCompletionQueue() { ServerCompletionQueue* cq = new ServerCompletionQueue(); @@ -50,44 +52,65 @@ std::unique_ptr ServerBuilder::AddCompletionQueue() { return std::unique_ptr(cq); } -void ServerBuilder::RegisterService(SynchronousService* service) { +ServerBuilder& ServerBuilder::RegisterService(SynchronousService* service) { services_.emplace_back(new NamedService(service->service())); + return *this; } -void ServerBuilder::RegisterAsyncService(AsynchronousService* service) { +ServerBuilder& ServerBuilder::RegisterAsyncService( + AsynchronousService* service) { async_services_.emplace_back(new NamedService(service)); + return *this; } -void ServerBuilder::RegisterService( +ServerBuilder& ServerBuilder::RegisterService( const grpc::string& addr, SynchronousService* service) { services_.emplace_back(new NamedService(addr, service->service())); + return *this; } -void ServerBuilder::RegisterAsyncService( +ServerBuilder& ServerBuilder::RegisterAsyncService( const grpc::string& addr, AsynchronousService* service) { - async_services_.emplace_back(new NamedService(addr, service)); + async_services_.emplace_back( + new NamedService(addr, service)); + return *this; } -void ServerBuilder::RegisterAsyncGenericService(AsyncGenericService* service) { +ServerBuilder& ServerBuilder::RegisterAsyncGenericService( + AsyncGenericService* service) { if (generic_service_) { gpr_log(GPR_ERROR, "Adding multiple AsyncGenericService is unsupported for now. " "Dropping the service %p", service); - return; + } else { + generic_service_ = service; } - generic_service_ = service; + return *this; +} + +ServerBuilder& ServerBuilder::SetMaxMessageSize(int max_message_size) { + max_message_size_ = max_message_size; + return *this; } -void ServerBuilder::AddListeningPort(const grpc::string& addr, +ServerBuilder& ServerBuilder::AddListeningPort(const grpc::string& addr, std::shared_ptr creds, int* selected_port) { Port port = {addr, creds, selected_port}; ports_.push_back(port); + return *this; } -void ServerBuilder::SetThreadPool(ThreadPoolInterface* thread_pool) { +ServerBuilder& ServerBuilder::SetThreadPool(ThreadPoolInterface* thread_pool) { thread_pool_ = thread_pool; + return *this; +} + +ServerBuilder& ServerBuilder::SetCompressionOptions( + const grpc_compression_options& options) { + compression_options_ = options; + return *this; } std::unique_ptr ServerBuilder::BuildAndStart() { @@ -100,8 +123,9 @@ std::unique_ptr ServerBuilder::BuildAndStart() { thread_pool_ = CreateDefaultThreadPool(); thread_pool_owned = true; } - std::unique_ptr server( - new Server(thread_pool_, thread_pool_owned, max_message_size_)); + std::unique_ptr server(new Server(thread_pool_, thread_pool_owned, + max_message_size_, + compression_options_)); for (auto cq = cqs_.begin(); cq != cqs_.end(); ++cq) { grpc_server_register_completion_queue(server->server_, (*cq)->cq()); } @@ -113,7 +137,8 @@ std::unique_ptr ServerBuilder::BuildAndStart() { } for (auto service = async_services_.begin(); service != async_services_.end(); service++) { - if (!server->RegisterAsyncService((*service)->host.get(), (*service)->service)) { + if (!server->RegisterAsyncService((*service)->host.get(), + (*service)->service)) { return nullptr; } } From d6fd3dbb78093070c1c97f867f2b6f4d0ed8da5b Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Wed, 19 Aug 2015 11:23:55 -0700 Subject: [PATCH 04/32] typo --- src/core/channel/channel_args.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c index 7d97b795531..4a18246e7cb 100644 --- a/src/core/channel/channel_args.c +++ b/src/core/channel/channel_args.c @@ -149,7 +149,7 @@ grpc_channel_args *grpc_channel_args_set_compression_algorithm( } /** Returns the compression algorithm's enabled states bitset from \a a. If not - * found, return a biset will all algorithms enabled */ + * found, return a biset with all algorithms enabled */ static gpr_uint32 find_compression_algorithm_states_bitset( const grpc_channel_args *a) { gpr_uint32 states_bitset = (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; From cb30410b1063845cc3a0205741a72c9c96e07638 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Wed, 19 Aug 2015 15:50:54 -0700 Subject: [PATCH 05/32] Comments and derived bugfixes. --- src/core/channel/channel_args.c | 48 +++++++++++++++++++----------- src/core/channel/compress_filter.c | 9 +++--- src/cpp/server/server.cc | 27 +++++++++-------- 3 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c index 4a18246e7cb..55b4cb6170c 100644 --- a/src/core/channel/channel_args.c +++ b/src/core/channel/channel_args.c @@ -148,44 +148,58 @@ grpc_channel_args *grpc_channel_args_set_compression_algorithm( return grpc_channel_args_copy_and_add(a, &tmp, 1); } -/** Returns the compression algorithm's enabled states bitset from \a a. If not - * found, return a biset with all algorithms enabled */ -static gpr_uint32 find_compression_algorithm_states_bitset( - const grpc_channel_args *a) { - gpr_uint32 states_bitset = (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; +/** Returns 1 if the argument for compression algorithm's enabled states bitset + * was found in \a a, returning the arg's value in \a states. Otherwise, returns + * 0. */ +static int find_compression_algorithm_states_bitset( + const grpc_channel_args *a, int **states_arg) { if (a != NULL) { size_t i; for (i = 0; i < a->num_args; ++i) { if (a->args[i].type == GRPC_ARG_INTEGER && !strcmp(GRPC_COMPRESSION_ALGORITHM_STATE_ARG, a->args[i].key)) { - states_bitset = a->args[i].value.integer; - break; + *states_arg = &a->args[i].value.integer; + return 1; /* GPR_TRUE */ } } } - return states_bitset; + return 0; /* GPR_FALSE */ } grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( grpc_channel_args *a, grpc_compression_algorithm algorithm, int state) { - gpr_uint32 states_bitset = find_compression_algorithm_states_bitset(a); - grpc_arg tmp; + int *states_arg; + grpc_channel_args *result = a; + const int states_arg_found = + find_compression_algorithm_states_bitset(a, &states_arg); + + if (!states_arg_found) { + /* create a new arg */ + grpc_arg tmp; + tmp.type = GRPC_ARG_INTEGER; + tmp.key = GRPC_COMPRESSION_ALGORITHM_STATE_ARG; + states_arg = &tmp.value.integer; + result = grpc_channel_args_copy_and_add(a, &tmp, 1); + } + /* update either the new arg's value or the already present one */ if (state != 0) { - GPR_BITSET(&states_bitset, algorithm); + GPR_BITSET(states_arg, algorithm); } else { - GPR_BITCLEAR(&states_bitset, algorithm); + GPR_BITCLEAR(states_arg, algorithm); } - tmp.type = GRPC_ARG_INTEGER; - tmp.key = GRPC_COMPRESSION_ALGORITHM_STATE_ARG; - tmp.value.integer = states_bitset; - return grpc_channel_args_copy_and_add(a, &tmp, 1); + return result; } int grpc_channel_args_compression_algorithm_get_states( const grpc_channel_args *a) { - return find_compression_algorithm_states_bitset(a); + int *states_arg; + if (find_compression_algorithm_states_bitset(a, &states_arg)) { + return *states_arg; + } else { + return (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; /* All algs. enabled */ + } } diff --git a/src/core/channel/compress_filter.c b/src/core/channel/compress_filter.c index 68060f9da36..0729b5cf5a4 100644 --- a/src/core/channel/compress_filter.c +++ b/src/core/channel/compress_filter.c @@ -306,6 +306,7 @@ static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master, channel_data *channeld = elem->channel_data; grpc_compression_algorithm algo_idx; const char *supported_algorithms_names[GRPC_COMPRESS_ALGORITHMS_COUNT - 1]; + size_t supported_algorithms_idx = 0; char *accept_encoding_str; size_t accept_encoding_str_len; @@ -344,15 +345,15 @@ static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master, GRPC_MDSTR_REF(channeld->mdstr_outgoing_compression_algorithm_key), grpc_mdstr_from_string(mdctx, algorithm_name, 0)); if (algo_idx > 0) { - supported_algorithms_names[algo_idx - 1] = algorithm_name; + supported_algorithms_names[supported_algorithms_idx++] = algorithm_name; } } /* TODO(dgq): gpr_strjoin_sep could be made to work with statically allocated * arrays, as to avoid the heap allocs */ - accept_encoding_str = gpr_strjoin_sep( - supported_algorithms_names, GPR_ARRAY_SIZE(supported_algorithms_names), - ", ", &accept_encoding_str_len); + accept_encoding_str = + gpr_strjoin_sep(supported_algorithms_names, supported_algorithms_idx, + ", ", &accept_encoding_str_len); channeld->mdelem_accept_encoding = grpc_mdelem_from_metadata_strings( mdctx, GRPC_MDSTR_REF(channeld->mdstr_compression_capabilities_key), diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index 3e9ba5c0764..eb2a9849933 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -187,21 +187,22 @@ class Server::SyncRequest GRPC_FINAL : public CompletionQueueTag { static grpc_server* CreateServer( int max_message_size, const grpc_compression_options& compression_options) { + grpc_arg args[2]; + size_t args_idx = 0; if (max_message_size > 0) { - grpc_arg args[2]; - args[0].type = GRPC_ARG_INTEGER; - args[0].key = const_cast(GRPC_ARG_MAX_MESSAGE_LENGTH); - args[0].value.integer = max_message_size; - - args[1].type = GRPC_ARG_INTEGER; - args[1].key = const_cast(GRPC_COMPRESSION_ALGORITHM_STATE_ARG); - args[1].value.integer = compression_options.enabled_algorithms_bitset; - - grpc_channel_args channel_args = {2, args}; - return grpc_server_create(&channel_args, nullptr); - } else { - return grpc_server_create(nullptr, nullptr); + args[args_idx].type = GRPC_ARG_INTEGER; + args[args_idx].key = const_cast(GRPC_ARG_MAX_MESSAGE_LENGTH); + args[args_idx].value.integer = max_message_size; + args_idx++; } + + args[args_idx].type = GRPC_ARG_INTEGER; + args[args_idx].key = const_cast(GRPC_COMPRESSION_ALGORITHM_STATE_ARG); + args[args_idx].value.integer = compression_options.enabled_algorithms_bitset; + args_idx++; + + grpc_channel_args channel_args = {args_idx, args}; + return grpc_server_create(&channel_args, nullptr); } Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned, From d514b21cc842fc388eec4e7c260b2c6a3de27c17 Mon Sep 17 00:00:00 2001 From: vjpai Date: Mon, 31 Aug 2015 16:27:35 -0700 Subject: [PATCH 06/32] Put timeout on server shutdown --- test/cpp/qps/server_async.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc index 4160392cbec..d51de8bd7f6 100644 --- a/test/cpp/qps/server_async.cc +++ b/test/cpp/qps/server_async.cc @@ -101,7 +101,9 @@ class AsyncQpsServerTest : public Server { } } ~AsyncQpsServerTest() { - server_->Shutdown(); + auto deadline = std::chrono::high_resolution_clock::now() + + std::chrono::seconds(10); + server_->Shutdown(deadline); for (auto ss = shutdown_state_.begin(); ss != shutdown_state_.end(); ++ss) { (*ss)->set_shutdown(); } From 5c4543d9f5d1d98c4a79d5a2e28d74c532cfec31 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Thu, 3 Sep 2015 15:49:56 -0700 Subject: [PATCH 07/32] Introduced a registry for LB policies. --- BUILD | 12 +++ Makefile | 4 + build.yaml | 2 + gRPC.podspec | 6 ++ .../client_config/lb_policies/pick_first.c | 21 ++++- .../client_config/lb_policies/pick_first.h | 9 +- src/core/client_config/lb_policy_factory.c | 49 ++++++++++ src/core/client_config/lb_policy_factory.h | 70 +++++++++++++++ src/core/client_config/lb_policy_registry.c | 89 +++++++++++++++++++ src/core/client_config/lb_policy_registry.h | 55 ++++++++++++ .../client_config/resolvers/dns_resolver.c | 19 ++-- .../resolvers/sockaddr_resolver.c | 19 ++-- .../resolvers/zookeeper_resolver.c | 20 ++--- src/core/surface/init.c | 4 + tools/doxygen/Doxyfile.core.internal | 4 + tools/run_tests/sources_and_headers.json | 12 +++ vsprojects/vcxproj/grpc/grpc.vcxproj | 6 ++ vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 12 +++ .../grpc_unsecure/grpc_unsecure.vcxproj | 6 ++ .../grpc_unsecure.vcxproj.filters | 12 +++ 20 files changed, 393 insertions(+), 38 deletions(-) create mode 100644 src/core/client_config/lb_policy_factory.c create mode 100644 src/core/client_config/lb_policy_factory.h create mode 100644 src/core/client_config/lb_policy_registry.c create mode 100644 src/core/client_config/lb_policy_registry.h diff --git a/BUILD b/BUILD index 7511320a4ce..363bab0ff4e 100644 --- a/BUILD +++ b/BUILD @@ -158,6 +158,8 @@ cc_library( "src/core/client_config/connector.h", "src/core/client_config/lb_policies/pick_first.h", "src/core/client_config/lb_policy.h", + "src/core/client_config/lb_policy_factory.h", + "src/core/client_config/lb_policy_registry.h", "src/core/client_config/resolver.h", "src/core/client_config/resolver_factory.h", "src/core/client_config/resolver_registry.h", @@ -283,6 +285,8 @@ cc_library( "src/core/client_config/connector.c", "src/core/client_config/lb_policies/pick_first.c", "src/core/client_config/lb_policy.c", + "src/core/client_config/lb_policy_factory.c", + "src/core/client_config/lb_policy_registry.c", "src/core/client_config/resolver.c", "src/core/client_config/resolver_factory.c", "src/core/client_config/resolver_registry.c", @@ -428,6 +432,8 @@ cc_library( "src/core/client_config/connector.h", "src/core/client_config/lb_policies/pick_first.h", "src/core/client_config/lb_policy.h", + "src/core/client_config/lb_policy_factory.h", + "src/core/client_config/lb_policy_registry.h", "src/core/client_config/resolver.h", "src/core/client_config/resolver_factory.h", "src/core/client_config/resolver_registry.h", @@ -533,6 +539,8 @@ cc_library( "src/core/client_config/connector.c", "src/core/client_config/lb_policies/pick_first.c", "src/core/client_config/lb_policy.c", + "src/core/client_config/lb_policy_factory.c", + "src/core/client_config/lb_policy_registry.c", "src/core/client_config/resolver.c", "src/core/client_config/resolver_factory.c", "src/core/client_config/resolver_registry.c", @@ -1047,6 +1055,8 @@ objc_library( "src/core/client_config/connector.c", "src/core/client_config/lb_policies/pick_first.c", "src/core/client_config/lb_policy.c", + "src/core/client_config/lb_policy_factory.c", + "src/core/client_config/lb_policy_registry.c", "src/core/client_config/resolver.c", "src/core/client_config/resolver_factory.c", "src/core/client_config/resolver_registry.c", @@ -1189,6 +1199,8 @@ objc_library( "src/core/client_config/connector.h", "src/core/client_config/lb_policies/pick_first.h", "src/core/client_config/lb_policy.h", + "src/core/client_config/lb_policy_factory.h", + "src/core/client_config/lb_policy_registry.h", "src/core/client_config/resolver.h", "src/core/client_config/resolver_factory.h", "src/core/client_config/resolver_registry.h", diff --git a/Makefile b/Makefile index 00875cd8e7d..cee909b743f 100644 --- a/Makefile +++ b/Makefile @@ -4045,6 +4045,8 @@ LIBGRPC_SRC = \ src/core/client_config/connector.c \ src/core/client_config/lb_policies/pick_first.c \ src/core/client_config/lb_policy.c \ + src/core/client_config/lb_policy_factory.c \ + src/core/client_config/lb_policy_registry.c \ src/core/client_config/resolver.c \ src/core/client_config/resolver_factory.c \ src/core/client_config/resolver_registry.c \ @@ -4320,6 +4322,8 @@ LIBGRPC_UNSECURE_SRC = \ src/core/client_config/connector.c \ src/core/client_config/lb_policies/pick_first.c \ src/core/client_config/lb_policy.c \ + src/core/client_config/lb_policy_factory.c \ + src/core/client_config/lb_policy_registry.c \ src/core/client_config/resolver.c \ src/core/client_config/resolver_factory.c \ src/core/client_config/resolver_registry.c \ diff --git a/build.yaml b/build.yaml index 31a1e328a8a..c01807878fe 100644 --- a/build.yaml +++ b/build.yaml @@ -46,6 +46,7 @@ filegroups: src/core/channel/context.h, src/core/channel/http_client_filter.h, src/core/channel/http_server_filter.h, src/core/channel/noop_filter.h, src/core/client_config/client_config.h, src/core/client_config/connector.h, src/core/client_config/lb_policies/pick_first.h, src/core/client_config/lb_policy.h, + src/core/client_config/lb_policy_factory.h, src/core/client_config/lb_policy_registry.h, src/core/client_config/resolver.h, src/core/client_config/resolver_factory.h, src/core/client_config/resolver_registry.h, src/core/client_config/resolvers/dns_resolver.h, src/core/client_config/resolvers/sockaddr_resolver.h, src/core/client_config/subchannel.h, @@ -85,6 +86,7 @@ filegroups: src/core/channel/connected_channel.c, src/core/channel/http_client_filter.c, src/core/channel/http_server_filter.c, src/core/channel/noop_filter.c, src/core/client_config/client_config.c, src/core/client_config/connector.c, src/core/client_config/lb_policies/pick_first.c, src/core/client_config/lb_policy.c, + src/core/client_config/lb_policy_factory.c, src/core/client_config/lb_policy_registry.c, src/core/client_config/resolver.c, src/core/client_config/resolver_factory.c, src/core/client_config/resolver_registry.c, src/core/client_config/resolvers/dns_resolver.c, src/core/client_config/resolvers/sockaddr_resolver.c, src/core/client_config/subchannel.c, diff --git a/gRPC.podspec b/gRPC.podspec index d0e1e2d848d..aaa6abb15c3 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -160,6 +160,8 @@ Pod::Spec.new do |s| 'src/core/client_config/connector.h', 'src/core/client_config/lb_policies/pick_first.h', 'src/core/client_config/lb_policy.h', + 'src/core/client_config/lb_policy_factory.h', + 'src/core/client_config/lb_policy_registry.h', 'src/core/client_config/resolver.h', 'src/core/client_config/resolver_factory.h', 'src/core/client_config/resolver_registry.h', @@ -292,6 +294,8 @@ Pod::Spec.new do |s| 'src/core/client_config/connector.c', 'src/core/client_config/lb_policies/pick_first.c', 'src/core/client_config/lb_policy.c', + 'src/core/client_config/lb_policy_factory.c', + 'src/core/client_config/lb_policy_registry.c', 'src/core/client_config/resolver.c', 'src/core/client_config/resolver_factory.c', 'src/core/client_config/resolver_registry.c', @@ -434,6 +438,8 @@ Pod::Spec.new do |s| 'src/core/client_config/connector.h', 'src/core/client_config/lb_policies/pick_first.h', 'src/core/client_config/lb_policy.h', + 'src/core/client_config/lb_policy_factory.h', + 'src/core/client_config/lb_policy_registry.h', 'src/core/client_config/resolver.h', 'src/core/client_config/resolver_factory.h', 'src/core/client_config/resolver_registry.h', diff --git a/src/core/client_config/lb_policies/pick_first.c b/src/core/client_config/lb_policies/pick_first.c index 5ae2e0ea520..1c5d058d97f 100644 --- a/src/core/client_config/lb_policies/pick_first.c +++ b/src/core/client_config/lb_policies/pick_first.c @@ -31,6 +31,7 @@ * */ +#include "src/core/client_config/lb_policy_factory.h" #include "src/core/client_config/lb_policies/pick_first.h" #include @@ -314,8 +315,13 @@ static const grpc_lb_policy_vtable pick_first_lb_policy_vtable = { pf_check_connectivity, pf_notify_on_state_change}; -grpc_lb_policy *grpc_create_pick_first_lb_policy(grpc_subchannel **subchannels, - size_t num_subchannels) { +static void pick_first_factory_ref(grpc_lb_policy_factory *factory) {} + +static void pick_first_factory_unref(grpc_lb_policy_factory *factory) {} + +static grpc_lb_policy *create_pick_first(grpc_lb_policy_factory *factory, + grpc_subchannel **subchannels, + size_t num_subchannels) { pick_first_lb_policy *p = gpr_malloc(sizeof(*p)); GPR_ASSERT(num_subchannels); memset(p, 0, sizeof(*p)); @@ -330,3 +336,14 @@ grpc_lb_policy *grpc_create_pick_first_lb_policy(grpc_subchannel **subchannels, gpr_mu_init(&p->mu); return &p->base; } + +static const grpc_lb_policy_factory_vtable pick_first_factory_vtable = { + pick_first_factory_ref, pick_first_factory_unref, create_pick_first, + "pick_first"}; + +static grpc_lb_policy_factory pick_first_lb_policy_factory = { + &pick_first_factory_vtable}; + +grpc_lb_policy_factory *grpc_pick_first_lb_factory_create() { + return &pick_first_lb_policy_factory; +} diff --git a/src/core/client_config/lb_policies/pick_first.h b/src/core/client_config/lb_policies/pick_first.h index 31394985e5e..3ca53ad42af 100644 --- a/src/core/client_config/lb_policies/pick_first.h +++ b/src/core/client_config/lb_policies/pick_first.h @@ -34,11 +34,10 @@ #ifndef GRPC_INTERNAL_CORE_CLIENT_CONFIG_PICK_FIRST_H #define GRPC_INTERNAL_CORE_CLIENT_CONFIG_PICK_FIRST_H -#include "src/core/client_config/lb_policy.h" +#include "src/core/client_config/lb_policy_factory.h" -/** Returns a load balancing policy instance that picks up the first subchannel - * from \a subchannels to succesfully connect */ -grpc_lb_policy *grpc_create_pick_first_lb_policy(grpc_subchannel **subchannels, - size_t num_subchannels); +/** Returns a load balancing factory for the pick first policy, which picks up + * the first subchannel from \a subchannels to succesfully connect */ +grpc_lb_policy_factory *grpc_pick_first_lb_factory_create(); #endif diff --git a/src/core/client_config/lb_policy_factory.c b/src/core/client_config/lb_policy_factory.c new file mode 100644 index 00000000000..533f973cea0 --- /dev/null +++ b/src/core/client_config/lb_policy_factory.c @@ -0,0 +1,49 @@ +/* + * + * 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 "src/core/client_config/lb_policy_factory.h" + +void grpc_lb_policy_factory_ref(grpc_lb_policy_factory *factory) { + factory->vtable->ref(factory); +} +void grpc_lb_policy_factory_unref(grpc_lb_policy_factory *factory) { + factory->vtable->unref(factory); +} + +grpc_lb_policy *grpc_lb_policy_factory_create_lb_policy( + grpc_lb_policy_factory *factory, grpc_subchannel **subchannels, + size_t num_subchannels) { + if (factory == NULL) return NULL; + return factory->vtable->create_lb_policy(factory, subchannels, + num_subchannels); +} diff --git a/src/core/client_config/lb_policy_factory.h b/src/core/client_config/lb_policy_factory.h new file mode 100644 index 00000000000..ba057648f77 --- /dev/null +++ b/src/core/client_config/lb_policy_factory.h @@ -0,0 +1,70 @@ +/* + * + * 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. + * + */ + +#ifndef GRPC_INTERNAL_CORE_CLIENT_CONFIG_LB_POLICY_FACTORY_H +#define GRPC_INTERNAL_CORE_CLIENT_CONFIG_LB_POLICY_FACTORY_H + +#include "src/core/client_config/lb_policy.h" +#include "src/core/client_config/subchannel.h" + +typedef struct grpc_lb_policy_factory grpc_lb_policy_factory; +typedef struct grpc_lb_policy_factory_vtable grpc_lb_policy_factory_vtable; + +/** grpc_lb_policy provides grpc_client_config objects to grpc_channel + objects */ +struct grpc_lb_policy_factory { + const grpc_lb_policy_factory_vtable *vtable; +}; + +struct grpc_lb_policy_factory_vtable { + void (*ref)(grpc_lb_policy_factory *factory); + void (*unref)(grpc_lb_policy_factory *factory); + + /** Implementation of grpc_lb_policy_factory_create_lb_policy */ + grpc_lb_policy *(*create_lb_policy)(grpc_lb_policy_factory *factory, + grpc_subchannel **subchannels, + size_t num_subchannels); + + /** Name for the LB policy this factory implements */ + const char *name; +}; + +void grpc_lb_policy_factory_ref(grpc_lb_policy_factory *factory); +void grpc_lb_policy_factory_unref(grpc_lb_policy_factory *factory); + +/** Create a lb_policy instance. */ +grpc_lb_policy *grpc_lb_policy_factory_create_lb_policy( + grpc_lb_policy_factory *factory, grpc_subchannel **subchannels, + size_t num_subchannels); + +#endif /* GRPC_INTERNAL_CORE_CONFIG_LB_POLICY_FACTORY_H */ diff --git a/src/core/client_config/lb_policy_registry.c b/src/core/client_config/lb_policy_registry.c new file mode 100644 index 00000000000..0a3ebbe4b3e --- /dev/null +++ b/src/core/client_config/lb_policy_registry.c @@ -0,0 +1,89 @@ +/* + * + * 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 "src/core/client_config/lb_policy_registry.h" + +#include + +#define MAX_POLICIES 10 + +static grpc_lb_policy_factory *g_all_of_the_lb_policies[MAX_POLICIES]; +static int g_number_of_lb_policies = 0; + +static grpc_lb_policy_factory *g_default_lb_policy_factory; + +void grpc_lb_policy_registry_init(grpc_lb_policy_factory *default_factory) { + g_number_of_lb_policies = 0; + g_default_lb_policy_factory = default_factory; +} + +void grpc_lb_policy_registry_shutdown(void) { + int i; + for (i = 0; i < g_number_of_lb_policies; i++) { + grpc_lb_policy_factory_unref(g_all_of_the_lb_policies[i]); + } +} + +void grpc_register_lb_policy(grpc_lb_policy_factory *factory) { + int i; + for (i = 0; i < g_number_of_lb_policies; i++) { + GPR_ASSERT(0 != strcmp(factory->vtable->name, + g_all_of_the_lb_policies[i]->vtable->name)); + } + GPR_ASSERT(g_number_of_lb_policies != MAX_POLICIES); + grpc_lb_policy_factory_ref(factory); + g_all_of_the_lb_policies[g_number_of_lb_policies++] = factory; +} + +static grpc_lb_policy_factory *lookup_factory(const char* name) { + int i; + + if (name == NULL) return NULL; + + for (i = 0; i < g_number_of_lb_policies; i++) { + if (0 == strcmp(name, g_all_of_the_lb_policies[i]->vtable->name)) { + return g_all_of_the_lb_policies[i]; + } + } + + return NULL; +} + +grpc_lb_policy *grpc_lb_policy_create(const char *name, + grpc_subchannel **subchannels, + size_t num_subchannels) { + grpc_lb_policy_factory *factory = lookup_factory(name); + grpc_lb_policy *lb_policy = grpc_lb_policy_factory_create_lb_policy( + factory, subchannels, num_subchannels); + return lb_policy; +} diff --git a/src/core/client_config/lb_policy_registry.h b/src/core/client_config/lb_policy_registry.h new file mode 100644 index 00000000000..75114d9f02e --- /dev/null +++ b/src/core/client_config/lb_policy_registry.h @@ -0,0 +1,55 @@ +/* + * + * 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. + * + */ + +#ifndef GRPC_INTERNAL_CORE_CLIENT_CONFIG_LB_POLICY_REGISTRY_H +#define GRPC_INTERNAL_CORE_CLIENT_CONFIG_LB_POLICY_REGISTRY_H + +#include "src/core/client_config/lb_policy_factory.h" + +/** Initialize the registry and set \a default_factory as the factory to be + * returned when no name is provided in a lookup */ +void grpc_lb_policy_registry_init(grpc_lb_policy_factory *default_factory); +void grpc_lb_policy_registry_shutdown(void); + +/** Register a LB policy factory. */ +void grpc_register_lb_policy(grpc_lb_policy_factory *factory); + +/** Create a \a grpc_lb_policy instance. + * + * If \a name is NULL, the default factory from \a grpc_lb_policy_registry_init + * will be returned. */ +grpc_lb_policy *grpc_lb_policy_create(const char *name, + grpc_subchannel **subchannels, + size_t num_subchannels); + +#endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_LB_POLICY_REGISTRY_H */ diff --git a/src/core/client_config/resolvers/dns_resolver.c b/src/core/client_config/resolvers/dns_resolver.c index 84643c464a9..830f3f52868 100644 --- a/src/core/client_config/resolvers/dns_resolver.c +++ b/src/core/client_config/resolvers/dns_resolver.c @@ -39,7 +39,7 @@ #include #include -#include "src/core/client_config/lb_policies/pick_first.h" +#include "src/core/client_config/lb_policy_registry.h" #include "src/core/client_config/subchannel_factory_decorators/add_channel_arg.h" #include "src/core/iomgr/resolve_address.h" #include "src/core/support/string.h" @@ -55,9 +55,8 @@ typedef struct { char *default_port; /** subchannel factory */ grpc_subchannel_factory *subchannel_factory; - /** load balancing policy factory */ - grpc_lb_policy *(*lb_policy_factory)(grpc_subchannel **subchannels, - size_t num_subchannels); + /** load balancing policy name */ + char *lb_policy_name; /** mutex guarding the rest of the state */ gpr_mu mu; @@ -144,7 +143,8 @@ static void dns_on_resolved(void *arg, grpc_resolved_addresses *addresses) { subchannels[i] = grpc_subchannel_factory_create_subchannel( r->subchannel_factory, &args); } - lb_policy = r->lb_policy_factory(subchannels, addresses->naddrs); + lb_policy = grpc_lb_policy_create(r->lb_policy_name, subchannels, + addresses->naddrs); grpc_client_config_set_lb_policy(config, lb_policy); GRPC_LB_POLICY_UNREF(lb_policy, "construction"); grpc_resolved_addresses_destroy(addresses); @@ -193,13 +193,13 @@ static void dns_destroy(grpc_resolver *gr) { grpc_subchannel_factory_unref(r->subchannel_factory); gpr_free(r->name); gpr_free(r->default_port); + gpr_free(r->lb_policy_name); gpr_free(r); } static grpc_resolver *dns_create( grpc_uri *uri, const char *default_port, - grpc_lb_policy *(*lb_policy_factory)(grpc_subchannel **subchannels, - size_t num_subchannels), + const char* lb_policy_name, grpc_subchannel_factory *subchannel_factory) { dns_resolver *r; const char *path = uri->path; @@ -220,7 +220,7 @@ static grpc_resolver *dns_create( r->default_port = gpr_strdup(default_port); r->subchannel_factory = subchannel_factory; grpc_subchannel_factory_ref(subchannel_factory); - r->lb_policy_factory = lb_policy_factory; + r->lb_policy_name = gpr_strdup(lb_policy_name); return &r->base; } @@ -235,8 +235,7 @@ static void dns_factory_unref(grpc_resolver_factory *factory) {} static grpc_resolver *dns_factory_create_resolver( grpc_resolver_factory *factory, grpc_uri *uri, grpc_subchannel_factory *subchannel_factory) { - return dns_create(uri, "https", grpc_create_pick_first_lb_policy, - subchannel_factory); + return dns_create(uri, "https", "pick_first", subchannel_factory); } char *dns_factory_get_default_host_name(grpc_resolver_factory *factory, diff --git a/src/core/client_config/resolvers/sockaddr_resolver.c b/src/core/client_config/resolvers/sockaddr_resolver.c index 0d8540a5665..1bff1d7abf4 100644 --- a/src/core/client_config/resolvers/sockaddr_resolver.c +++ b/src/core/client_config/resolvers/sockaddr_resolver.c @@ -45,7 +45,7 @@ #include #include -#include "src/core/client_config/lb_policies/pick_first.h" +#include "src/core/client_config/lb_policy_registry.h" #include "src/core/iomgr/resolve_address.h" #include "src/core/support/string.h" @@ -56,9 +56,8 @@ typedef struct { gpr_refcount refs; /** subchannel factory */ grpc_subchannel_factory *subchannel_factory; - /** load balancing policy factory */ - grpc_lb_policy *(*lb_policy_factory)(grpc_subchannel **subchannels, - size_t num_subchannels); + /** load balancing policy name */ + char *lb_policy_name; /** the addresses that we've 'resolved' */ struct sockaddr_storage *addrs; @@ -136,7 +135,8 @@ static void sockaddr_maybe_finish_next_locked(sockaddr_resolver *r) { subchannels[i] = grpc_subchannel_factory_create_subchannel( r->subchannel_factory, &args); } - lb_policy = r->lb_policy_factory(subchannels, r->num_addrs); + lb_policy = + grpc_lb_policy_create(r->lb_policy_name, subchannels, r->num_addrs); gpr_free(subchannels); grpc_client_config_set_lb_policy(cfg, lb_policy); GRPC_LB_POLICY_UNREF(lb_policy, "unix"); @@ -153,6 +153,7 @@ static void sockaddr_destroy(grpc_resolver *gr) { grpc_subchannel_factory_unref(r->subchannel_factory); gpr_free(r->addrs); gpr_free(r->addrs_len); + gpr_free(r->lb_policy_name); gpr_free(r); } @@ -271,9 +272,7 @@ done: static void do_nothing(void *ignored) {} static grpc_resolver *sockaddr_create( - grpc_uri *uri, - grpc_lb_policy *(*lb_policy_factory)(grpc_subchannel **subchannels, - size_t num_subchannels), + grpc_uri *uri, const char *lb_policy_name, grpc_subchannel_factory *subchannel_factory, int parse(grpc_uri *uri, struct sockaddr_storage *dst, int *len)) { size_t i; @@ -320,7 +319,7 @@ static grpc_resolver *sockaddr_create( gpr_mu_init(&r->mu); grpc_resolver_init(&r->base, &sockaddr_resolver_vtable); r->subchannel_factory = subchannel_factory; - r->lb_policy_factory = lb_policy_factory; + r->lb_policy_name = gpr_strdup(lb_policy_name); grpc_subchannel_factory_ref(subchannel_factory); return &r->base; @@ -338,7 +337,7 @@ static void sockaddr_factory_unref(grpc_resolver_factory *factory) {} static grpc_resolver *name##_factory_create_resolver( \ grpc_resolver_factory *factory, grpc_uri *uri, \ grpc_subchannel_factory *subchannel_factory) { \ - return sockaddr_create(uri, grpc_create_pick_first_lb_policy, \ + return sockaddr_create(uri, "pick_first", \ subchannel_factory, parse_##name); \ } \ static const grpc_resolver_factory_vtable name##_factory_vtable = { \ diff --git a/src/core/client_config/resolvers/zookeeper_resolver.c b/src/core/client_config/resolvers/zookeeper_resolver.c index da399f99548..8b89100245b 100644 --- a/src/core/client_config/resolvers/zookeeper_resolver.c +++ b/src/core/client_config/resolvers/zookeeper_resolver.c @@ -41,7 +41,7 @@ #include #include -#include "src/core/client_config/lb_policies/pick_first.h" +#include "src/core/client_config/lb_policy_registry.h" #include "src/core/client_config/resolver_registry.h" #include "src/core/iomgr/resolve_address.h" #include "src/core/support/string.h" @@ -59,9 +59,8 @@ typedef struct { char *name; /** subchannel factory */ grpc_subchannel_factory *subchannel_factory; - /** load balancing policy factory */ - grpc_lb_policy *(*lb_policy_factory)(grpc_subchannel **subchannels, - size_t num_subchannels); + /** load balancing policy name */ + char *lb_policy_name; /** mutex guarding the rest of the state */ gpr_mu mu; @@ -192,7 +191,8 @@ static void zookeeper_on_resolved(void *arg, subchannels[i] = grpc_subchannel_factory_create_subchannel( r->subchannel_factory, &args); } - lb_policy = r->lb_policy_factory(subchannels, addresses->naddrs); + lb_policy = + grpc_lb_policy_create(r->lb_policy_name, subchannels, addresses->naddrs); grpc_client_config_set_lb_policy(config, lb_policy); GRPC_LB_POLICY_UNREF(lb_policy, "construction"); grpc_resolved_addresses_destroy(addresses); @@ -420,13 +420,12 @@ static void zookeeper_destroy(grpc_resolver *gr) { } grpc_subchannel_factory_unref(r->subchannel_factory); gpr_free(r->name); + gpr_free(r->lb_policy_name); gpr_free(r); } static grpc_resolver *zookeeper_create( - grpc_uri *uri, - grpc_lb_policy *(*lb_policy_factory)(grpc_subchannel **subchannels, - size_t num_subchannels), + grpc_uri *uri, const char *lb_policy_name, grpc_subchannel_factory *subchannel_factory) { zookeeper_resolver *r; size_t length; @@ -451,7 +450,7 @@ static grpc_resolver *zookeeper_create( r->name = gpr_strdup(path); r->subchannel_factory = subchannel_factory; - r->lb_policy_factory = lb_policy_factory; + r->lb_policy_name = gpr_strdup(lb_policy_name); grpc_subchannel_factory_ref(subchannel_factory); /** Initializes zookeeper client */ @@ -490,8 +489,7 @@ static char *zookeeper_factory_get_default_hostname( static grpc_resolver *zookeeper_factory_create_resolver( grpc_resolver_factory *factory, grpc_uri *uri, grpc_subchannel_factory *subchannel_factory) { - return zookeeper_create(uri, grpc_create_pick_first_lb_policy, - subchannel_factory); + return zookeeper_create(uri, "pick_first", subchannel_factory); } static const grpc_resolver_factory_vtable zookeeper_factory_vtable = { diff --git a/src/core/surface/init.c b/src/core/surface/init.c index 0d48cd42d72..03bd026a42e 100644 --- a/src/core/surface/init.c +++ b/src/core/surface/init.c @@ -40,6 +40,8 @@ #include #include #include "src/core/channel/channel_stack.h" +#include "src/core/client_config/lb_policy_registry.h" +#include "src/core/client_config/lb_policies/pick_first.h" #include "src/core/client_config/resolver_registry.h" #include "src/core/client_config/resolvers/dns_resolver.h" #include "src/core/client_config/resolvers/sockaddr_resolver.h" @@ -85,6 +87,8 @@ void grpc_init(void) { gpr_mu_lock(&g_init_mu); if (++g_initializations == 1) { gpr_time_init(); + grpc_lb_policy_registry_init(grpc_pick_first_lb_factory_create()); + grpc_register_lb_policy(grpc_pick_first_lb_factory_create()); grpc_resolver_registry_init("dns:///"); grpc_register_resolver_type(grpc_dns_resolver_factory_create()); grpc_register_resolver_type(grpc_ipv4_resolver_factory_create()); diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index fdc32c77765..acfb38e629a 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -794,6 +794,8 @@ src/core/client_config/client_config.h \ src/core/client_config/connector.h \ src/core/client_config/lb_policies/pick_first.h \ src/core/client_config/lb_policy.h \ +src/core/client_config/lb_policy_factory.h \ +src/core/client_config/lb_policy_registry.h \ src/core/client_config/resolver.h \ src/core/client_config/resolver_factory.h \ src/core/client_config/resolver_registry.h \ @@ -919,6 +921,8 @@ src/core/client_config/client_config.c \ src/core/client_config/connector.c \ src/core/client_config/lb_policies/pick_first.c \ src/core/client_config/lb_policy.c \ +src/core/client_config/lb_policy_factory.c \ +src/core/client_config/lb_policy_registry.c \ src/core/client_config/resolver.c \ src/core/client_config/resolver_factory.c \ src/core/client_config/resolver_registry.c \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 3a94b9ee6b5..2d2108f1c28 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -12246,6 +12246,8 @@ "src/core/client_config/connector.h", "src/core/client_config/lb_policies/pick_first.h", "src/core/client_config/lb_policy.h", + "src/core/client_config/lb_policy_factory.h", + "src/core/client_config/lb_policy_registry.h", "src/core/client_config/resolver.h", "src/core/client_config/resolver_factory.h", "src/core/client_config/resolver_registry.h", @@ -12392,6 +12394,10 @@ "src/core/client_config/lb_policies/pick_first.h", "src/core/client_config/lb_policy.c", "src/core/client_config/lb_policy.h", + "src/core/client_config/lb_policy_factory.c", + "src/core/client_config/lb_policy_factory.h", + "src/core/client_config/lb_policy_registry.c", + "src/core/client_config/lb_policy_registry.h", "src/core/client_config/resolver.c", "src/core/client_config/resolver.h", "src/core/client_config/resolver_factory.c", @@ -12726,6 +12732,8 @@ "src/core/client_config/connector.h", "src/core/client_config/lb_policies/pick_first.h", "src/core/client_config/lb_policy.h", + "src/core/client_config/lb_policy_factory.h", + "src/core/client_config/lb_policy_registry.h", "src/core/client_config/resolver.h", "src/core/client_config/resolver_factory.h", "src/core/client_config/resolver_registry.h", @@ -12858,6 +12866,10 @@ "src/core/client_config/lb_policies/pick_first.h", "src/core/client_config/lb_policy.c", "src/core/client_config/lb_policy.h", + "src/core/client_config/lb_policy_factory.c", + "src/core/client_config/lb_policy_factory.h", + "src/core/client_config/lb_policy_registry.c", + "src/core/client_config/lb_policy_registry.h", "src/core/client_config/resolver.c", "src/core/client_config/resolver.h", "src/core/client_config/resolver_factory.c", diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index 852da5d95f7..2eda9e32e67 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -256,6 +256,8 @@ + + @@ -418,6 +420,10 @@ + + + + diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index b334602e020..7026da89abd 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -106,6 +106,12 @@ src\core\client_config + + src\core\client_config + + + src\core\client_config + src\core\client_config @@ -530,6 +536,12 @@ src\core\client_config + + src\core\client_config + + + src\core\client_config + src\core\client_config diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj index f069aa52253..b48fa462e6f 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -235,6 +235,8 @@ + + @@ -357,6 +359,10 @@ + + + + diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index 35f8599cb9f..8e3ee19b925 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -46,6 +46,12 @@ src\core\client_config + + src\core\client_config + + + src\core\client_config + src\core\client_config @@ -428,6 +434,12 @@ src\core\client_config + + src\core\client_config + + + src\core\client_config + src\core\client_config From df2631187cd9f63e3e1019cdf2c5d14f4ce62371 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 4 Sep 2015 13:26:49 -0700 Subject: [PATCH 08/32] allow usable auth for JWT token creds interop test --- doc/interop-test-descriptions.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/interop-test-descriptions.md b/doc/interop-test-descriptions.md index ddeee66d67c..61b611129f0 100644 --- a/doc/interop-test-descriptions.md +++ b/doc/interop-test-descriptions.md @@ -513,7 +513,9 @@ token (created by the project's key file) Test caller should set flag `--service_account_key_file` with the path to json key file downloaded from -https://console.developers.google.com. +https://console.developers.google.com. Alternately, if using a +usable auth implementation, she may specify the file location in the environment +variable GOOGLE_APPLICATION_CREDENTIALS. Server features: * [UnaryCall][] @@ -540,7 +542,7 @@ Client asserts: * call was successful * received SimpleResponse.username is not empty and is in the json key file used by the auth library. The client can optionally check the username matches the -email address in the key file. +email address in the key file or equals the value of `--default_service_account` flag. * response payload body is 314159 bytes in size * clients are free to assert that the response payload body contents are zero and comparing the entire response message against a golden response From e3a65a111ccef0b26062c4f25591909ca4127119 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 4 Sep 2015 14:01:48 -0700 Subject: [PATCH 09/32] Allow using service account credential for per_rpc_creds interop test. --- doc/interop-test-descriptions.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/interop-test-descriptions.md b/doc/interop-test-descriptions.md index ddeee66d67c..adbfc87a7f7 100644 --- a/doc/interop-test-descriptions.md +++ b/doc/interop-test-descriptions.md @@ -598,7 +598,7 @@ json key file or GCE default service account email. Similar to the other auth tests, this test is only for cloud-to-prod path. -This test verifies unary calls succeed in sending messages using a JWT +This test verifies unary calls succeed in sending messages using a JWT or a service account credentials set on the RPC. The test @@ -606,6 +606,10 @@ The test downloaded from https://console.developers.google.com. Alternately, if using a usable auth implementation, it may specify the file location in the environment variable GOOGLE_APPLICATION_CREDENTIALS +- optionally uses the flag `--oauth_scope` for the oauth scope if implementator +wishes to use service account credential instead of JWT credential. For testing +against grpc-test.sandbox.google.com, oauth scope +"https://www.googleapis.com/auth/xapi.zoo" should be used. Server features: * [UnaryCall][] From 796d0a22fccc6a3617b59018a95ce512a0126731 Mon Sep 17 00:00:00 2001 From: vjpai Date: Tue, 8 Sep 2015 09:47:00 -0700 Subject: [PATCH 10/32] Removing some unused vestiges --- src/core/surface/call.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/core/surface/call.c b/src/core/surface/call.c index a8b4d65fbc0..6ece56371b4 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -61,18 +61,6 @@ - status/close recv (depending on client/server) */ #define MAX_CONCURRENT_COMPLETIONS 6 -typedef enum { REQ_INITIAL = 0, REQ_READY, REQ_DONE } req_state; - -typedef enum { - SEND_NOTHING, - SEND_INITIAL_METADATA, - SEND_BUFFERED_INITIAL_METADATA, - SEND_MESSAGE, - SEND_BUFFERED_MESSAGE, - SEND_TRAILING_METADATA_AND_FINISH, - SEND_FINISH -} send_action; - typedef struct { grpc_ioreq_completion_func on_complete; void *user_data; From c824eb4e90fe150b113b2ceaa14fa4105718cc46 Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Tue, 8 Sep 2015 19:03:18 +0000 Subject: [PATCH 11/32] Make servers and stubs context managers Servers and stubs were context managers in the Alpha API; they may not need to be in the Beta API but it's easy enough to do, eases migration, and probably helps some use cases. For now the stub is given empty __enter__ and __exit__ methods; we can always come back and implement the actual work of context management in a later change. --- src/python/grpcio/grpc/beta/_server.py | 18 ++++++++++++++++-- src/python/grpcio/grpc/beta/_stub.py | 6 ++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/python/grpcio/grpc/beta/_server.py b/src/python/grpcio/grpc/beta/_server.py index daa42c475ad..05b954d1860 100644 --- a/src/python/grpcio/grpc/beta/_server.py +++ b/src/python/grpcio/grpc/beta/_server.py @@ -86,13 +86,13 @@ class Server(interfaces.Server): return self._grpc_link.add_port( address, server_credentials._intermediary_low_credentials) # pylint: disable=protected-access - def start(self): + def _start(self): self._grpc_link.join_link(self._end_link) self._end_link.join_link(self._grpc_link) self._grpc_link.start() self._end_link.start() - def stop(self, grace): + def _stop(self, grace): stop_event = threading.Event() if 0 < grace: disassembly_thread = threading.Thread( @@ -105,6 +105,20 @@ class Server(interfaces.Server): _disassemble(self._grpc_link, self._end_link, self._pool, stop_event, 0) return stop_event + def start(self): + self._start() + + def stop(self, grace): + return self._stop(grace) + + def __enter__(self): + self._start() + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + self._stop(0).wait() + return False + def server( implementations, multi_implementation, request_deserializers, diff --git a/src/python/grpcio/grpc/beta/_stub.py b/src/python/grpcio/grpc/beta/_stub.py index cfbecb852b2..11dab889cd0 100644 --- a/src/python/grpcio/grpc/beta/_stub.py +++ b/src/python/grpcio/grpc/beta/_stub.py @@ -49,6 +49,12 @@ class _AutoIntermediary(object): def __getattr__(self, attr): return getattr(self._delegate, attr) + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + return False + def __del__(self): self._on_deletion() From 3b0fefb246caf9cf983d8ab7b69ce97b8ea7ba48 Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Tue, 8 Sep 2015 19:09:51 +0000 Subject: [PATCH 12/32] Beta maintenance of Python dependencies (1) Move dependency on protobuf from grpcio to grpcio_test. While the most-commonly-foreseen use case of grpcio makes use of protobuf, technically protobuf is not strictly needed and there's no actual in-code relationship between grpcio and protobuf. (2) Loosen the dependency on protobuf from ==3.0.0a3 to >=3.0.0a3. (3) Update all references to 0.10.0* to 0.11.0. (4) Alphabetize the grpcio_test dependencies. --- src/python/grpcio/requirements.txt | 1 - src/python/grpcio_health_checking/setup.py | 4 ++-- src/python/grpcio_test/requirements.txt | 5 +++-- src/python/grpcio_test/setup.py | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/python/grpcio/requirements.txt b/src/python/grpcio/requirements.txt index 43395df03b9..608ba402e09 100644 --- a/src/python/grpcio/requirements.txt +++ b/src/python/grpcio/requirements.txt @@ -1,3 +1,2 @@ enum34==1.0.4 futures==2.2.0 -protobuf==3.0.0a3 diff --git a/src/python/grpcio_health_checking/setup.py b/src/python/grpcio_health_checking/setup.py index fcde0dab8c9..38629aa8159 100644 --- a/src/python/grpcio_health_checking/setup.py +++ b/src/python/grpcio_health_checking/setup.py @@ -51,7 +51,7 @@ _PACKAGE_DIRECTORIES = { } _INSTALL_REQUIRES = ( - 'grpcio>=0.10.0a0', + 'grpcio>=0.11.0', ) _SETUP_REQUIRES = _INSTALL_REQUIRES @@ -63,7 +63,7 @@ _COMMAND_CLASS = { setuptools.setup( name='grpcio_health_checking', - version='0.10.0a0', + version='0.11.0', packages=list(_PACKAGES), package_dir=_PACKAGE_DIRECTORIES, install_requires=_INSTALL_REQUIRES, diff --git a/src/python/grpcio_test/requirements.txt b/src/python/grpcio_test/requirements.txt index 856198def57..cf8b8a89994 100644 --- a/src/python/grpcio_test/requirements.txt +++ b/src/python/grpcio_test/requirements.txt @@ -1,5 +1,6 @@ +grpcio>=0.11.0 +oauth2client>=1.4.7 +protobuf>=3.0.0a3 pytest>=2.6 pytest-cov>=2.0 pytest-xdist>=1.11 -oauth2client>=1.4.7 -grpcio>=0.10.0a0 diff --git a/src/python/grpcio_test/setup.py b/src/python/grpcio_test/setup.py index 802dd1e53af..161578a5153 100644 --- a/src/python/grpcio_test/setup.py +++ b/src/python/grpcio_test/setup.py @@ -71,7 +71,7 @@ _SETUP_REQUIRES = ( _INSTALL_REQUIRES = ( 'oauth2client>=1.4.7', - 'grpcio>=0.10.0a0', + 'grpcio>=0.11.0', ) _COMMAND_CLASS = { @@ -80,7 +80,7 @@ _COMMAND_CLASS = { setuptools.setup( name='grpcio_test', - version='0.10.0a0', + version='0.11.0', packages=_PACKAGES, package_dir=_PACKAGE_DIRECTORIES, package_data=_PACKAGE_DATA, From 526789159c00221aaaeb3b02b5add70b5c5fcb6d Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Mon, 7 Sep 2015 11:28:58 -0700 Subject: [PATCH 13/32] Added queries and fragments to uri parser --- src/core/client_config/uri_parser.c | 127 +++++++++++++++++++--- src/core/client_config/uri_parser.h | 2 + test/core/client_config/uri_parser_test.c | 37 +++++-- 3 files changed, 139 insertions(+), 27 deletions(-) diff --git a/src/core/client_config/uri_parser.c b/src/core/client_config/uri_parser.c index 410a61c8cf3..36ecfa5e8e1 100644 --- a/src/core/client_config/uri_parser.c +++ b/src/core/client_config/uri_parser.c @@ -60,13 +60,80 @@ static grpc_uri *bad_uri(const char *uri_text, int pos, const char *section, return NULL; } -static char *copy_fragment(const char *src, int begin, int end) { +/** Returns a copy of \a src[begin, end) */ +static char *copy_component(const char *src, int begin, int end) { char *out = gpr_malloc(end - begin + 1); memcpy(out, src + begin, end - begin); out[end - begin] = 0; return out; } +/** Returns how many chars to advance if \a uri_text[i] begins a valid \a pchar + * production. If \a uri_text[i] introduces an invalid \a pchar (such as percent + * sign not followed by two hex digits), -1 is returned. */ +static int parse_pchar(const char *uri_text, int i) { + /* pchar = unreserved / pct-encoded / sub-delims / ":" / "@" + * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" + * pct-encoded = "%" HEXDIG HEXDIG + * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" + / "*" / "+" / "," / ";" / "=" */ + char c = uri_text[i]; + if ( ((c >= 'A') && (c <= 'Z')) || + ((c >= 'a') && (c <= 'z')) || + ((c >= '0') && (c <= '9')) || + (c == '-' || c == '.' || c == '_' || c == '~') || /* unreserved */ + + (c == '!' || c == '$' || c == '&' || c == '\'' || c == '$' || c == '&' || + c == '(' || c == ')' || c == '*' || c == '+' || c == ',' || c == ';' || + c == '=') /* sub-delims */ ) { + return 1; + } + if (c == '%') { /* pct-encoded */ + int j; + if (uri_text[i+1] == 0 || uri_text[i+2] == 0) { + return -1; + } + for (j = i + 1; j < 2; j++) { + c = uri_text[j]; + if (!(((c >= '0') && (c <= '9')) || + ((c >= 'a') && (c <= 'f')) || + ((c >= 'A') && (c <= 'F')))) { + return -1; + } + } + return 2; + } + return 0; +} + +/* *( pchar / "?" / "/" ) */ +static int parse_query(const char *uri_text, int i) { + char c; + while ((c = uri_text[i]) != 0) { + const int advance = parse_pchar(uri_text, i); /* pchar */ + switch (advance) { + case 0: /* uri_text[i] isn't in pchar */ + /* maybe it's ? or / */ + if (uri_text[i] == '?' || uri_text[i] == '/') { + i++; + break; + } else { + return i; + } + case 1: + case 2: + i += advance; + break; + default: /* uri_text[i] introduces an invalid URI */ + return -i; + } + } + return i; /* first uri_text position past the \a query production, maybe \0 */ +} + +/* alias for consistency */ +static int (*parse_fragment)(const char *uri_text, int i) = parse_query; + grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors) { grpc_uri *uri; int scheme_begin = 0; @@ -75,6 +142,10 @@ grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors) { int authority_end = -1; int path_begin = -1; int path_end = -1; + int query_begin = -1; + int query_end = -1; + int fragment_begin = -1; + int fragment_end = -1; int i; for (i = scheme_begin; uri_text[i] != 0; i++) { @@ -99,15 +170,9 @@ grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors) { if (uri_text[scheme_end + 1] == '/' && uri_text[scheme_end + 2] == '/') { authority_begin = scheme_end + 3; for (i = authority_begin; uri_text[i] != 0 && authority_end == -1; i++) { - if (uri_text[i] == '/') { + if (uri_text[i] == '/' || uri_text[i] == '?' || uri_text[i] == '#') { authority_end = i; } - if (uri_text[i] == '?') { - return bad_uri(uri_text, i, "query_not_supported", suppress_errors); - } - if (uri_text[i] == '#') { - return bad_uri(uri_text, i, "fragment_not_supported", suppress_errors); - } } if (authority_end == -1 && uri_text[i] == 0) { authority_end = i; @@ -122,20 +187,48 @@ grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors) { } for (i = path_begin; uri_text[i] != 0; i++) { - if (uri_text[i] == '?') { - return bad_uri(uri_text, i, "query_not_supported", suppress_errors); + if (uri_text[i] == '?' || uri_text[i] == '#') { + path_end = i; + break; } - if (uri_text[i] == '#') { - return bad_uri(uri_text, i, "fragment_not_supported", suppress_errors); + } + if (path_end == -1 && uri_text[i] == 0) { + path_end = i; + } + if (path_end == -1) { + return bad_uri(uri_text, i, "path", suppress_errors); + } + + if (uri_text[i] == '?') { + query_begin = i + 1; + i = parse_query(uri_text, query_begin); + if (i < 0) { + return bad_uri(uri_text, -i, "query", suppress_errors); + } else if (uri_text[i] != 0 && uri_text[i] != '#') { + /* We must be at the end or at the beginning of a fragment */ + return bad_uri(uri_text, i, "query", suppress_errors); + } + query_end = i; + } + if (uri_text[i] == '#') { + fragment_begin = i + 1; + i = parse_fragment(uri_text, fragment_begin); + if (i < 0) { + return bad_uri(uri_text, i - fragment_end, "fragment", suppress_errors); + } else if (uri_text[i] != 0) { + /* We must be at the end */ + return bad_uri(uri_text, i, "fragment", suppress_errors); } + fragment_end = i; } - path_end = i; uri = gpr_malloc(sizeof(*uri)); memset(uri, 0, sizeof(*uri)); - uri->scheme = copy_fragment(uri_text, scheme_begin, scheme_end); - uri->authority = copy_fragment(uri_text, authority_begin, authority_end); - uri->path = copy_fragment(uri_text, path_begin, path_end); + uri->scheme = copy_component(uri_text, scheme_begin, scheme_end); + uri->authority = copy_component(uri_text, authority_begin, authority_end); + uri->path = copy_component(uri_text, path_begin, path_end); + uri->query = copy_component(uri_text, query_begin, query_end); + uri->fragment = copy_component(uri_text, fragment_begin, fragment_end); return uri; } @@ -145,5 +238,7 @@ void grpc_uri_destroy(grpc_uri *uri) { gpr_free(uri->scheme); gpr_free(uri->authority); gpr_free(uri->path); + gpr_free(uri->query); + gpr_free(uri->fragment); gpr_free(uri); } diff --git a/src/core/client_config/uri_parser.h b/src/core/client_config/uri_parser.h index ce4e6aecb09..b8daa13bd4f 100644 --- a/src/core/client_config/uri_parser.h +++ b/src/core/client_config/uri_parser.h @@ -38,6 +38,8 @@ typedef struct { char *scheme; char *authority; char *path; + char *query; + char *fragment; } grpc_uri; /** parse a uri, return NULL on failure */ diff --git a/test/core/client_config/uri_parser_test.c b/test/core/client_config/uri_parser_test.c index d324029c7ef..580c18b699d 100644 --- a/test/core/client_config/uri_parser_test.c +++ b/test/core/client_config/uri_parser_test.c @@ -40,12 +40,15 @@ #include "test/core/util/test_config.h" static void test_succeeds(const char *uri_text, const char *scheme, - const char *authority, const char *path) { + const char *authority, const char *path, + const char *query, const char* fragment) { grpc_uri *uri = grpc_uri_parse(uri_text, 0); GPR_ASSERT(uri); GPR_ASSERT(0 == strcmp(scheme, uri->scheme)); GPR_ASSERT(0 == strcmp(authority, uri->authority)); GPR_ASSERT(0 == strcmp(path, uri->path)); + GPR_ASSERT(0 == strcmp(query, uri->query)); + GPR_ASSERT(0 == strcmp(fragment, uri->fragment)); grpc_uri_destroy(uri); } @@ -55,17 +58,29 @@ static void test_fails(const char *uri_text) { int main(int argc, char **argv) { grpc_test_init(argc, argv); - test_succeeds("http://www.google.com", "http", "www.google.com", ""); - test_succeeds("dns:///foo", "dns", "", "/foo"); - test_succeeds("http://www.google.com:90", "http", "www.google.com:90", ""); - test_succeeds("a192.4-df:foo.coom", "a192.4-df", "", "foo.coom"); - test_succeeds("a+b:foo.coom", "a+b", "", "foo.coom"); + test_succeeds("http://www.google.com", "http", "www.google.com", "", "", ""); + test_succeeds("dns:///foo", "dns", "", "/foo", "", ""); + test_succeeds("http://www.google.com:90", "http", "www.google.com:90", "", "", + ""); + test_succeeds("a192.4-df:foo.coom", "a192.4-df", "", "foo.coom", "", ""); + test_succeeds("a+b:foo.coom", "a+b", "", "foo.coom", "", ""); test_succeeds("zookeeper://127.0.0.1:2181/foo/bar", "zookeeper", - "127.0.0.1:2181", "/foo/bar"); + "127.0.0.1:2181", "/foo/bar", "", ""); + test_succeeds("http://www.google.com?yay-i'm-using-queries", "http", + "www.google.com", "", "yay-i'm-using-queries", ""); + test_succeeds("dns:foo.com#fragment-all-the-things", "dns", "", "foo.com", "", + "fragment-all-the-things"); + test_succeeds("http:?legit", "http", "", "", "legit", ""); + test_succeeds("unix:#this-is-ok-too", "unix", "", "", "", "this-is-ok-too"); + test_succeeds("http:?legit#twice", "http", "", "", "legit", "twice"); + test_succeeds("http://foo?bar#lol?", "http", "foo", "", "bar", "lol?"); + test_succeeds("http://foo?bar#lol?/", "http", "foo", "", "bar", "lol?/"); + test_fails("xyz"); - test_fails("http://www.google.com?why-are-you-using-queries"); - test_fails("dns:foo.com#fragments-arent-supported-here"); - test_fails("http:?huh"); - test_fails("unix:#yeah-right"); + test_fails("http:?dangling-pct-%0"); + test_fails("http://foo?[bar]"); + test_fails("http://foo?x[bar]"); + test_fails("http://foo?bar#lol#"); + return 0; } From 6a70b012391a1c17f85cde6e02f80337e2913d69 Mon Sep 17 00:00:00 2001 From: Paul Marks Date: Tue, 8 Sep 2015 18:11:15 -0700 Subject: [PATCH 14/32] Reintroduce DNS-based cases to dualstack_socket_test.c. These were dropped before the initial release because they depended on a hostname that was only resolvable inside Google. The newer unittest.grpc.io domain is publicly accessible. Allow the tests to be skipped, just in case someone is running an isolated machine, or a DNS resolver that doesn't permit external domains to return loopback addresses. --- test/core/end2end/dualstack_socket_test.c | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/core/end2end/dualstack_socket_test.c b/test/core/end2end/dualstack_socket_test.c index fcc12952bf9..7da80886e15 100644 --- a/test/core/end2end/dualstack_socket_test.c +++ b/test/core/end2end/dualstack_socket_test.c @@ -40,6 +40,7 @@ #include #include "src/core/support/string.h" +#include "src/core/iomgr/resolve_address.h" #include "src/core/iomgr/socket_utils_posix.h" #include "test/core/end2end/cq_verifier.h" @@ -263,6 +264,15 @@ void test_connect(const char *server_host, const char *client_host, int port, gpr_free(details); } +int external_dns_works(const char *host) { + grpc_resolved_addresses *res = grpc_blocking_resolve_address(host, "80"); + if (res != NULL) { + gpr_free(res); + return 1; + } + return 0; +} + int main(int argc, char **argv) { int do_ipv6 = 1; @@ -308,6 +318,25 @@ int main(int argc, char **argv) { test_connect("::1", "ipv4:127.0.0.1", 0, 0); test_connect("127.0.0.1", "ipv6:[::1]", 0, 0); } + + if (!external_dns_works("loopback46.unittest.grpc.io")) { + gpr_log(GPR_INFO, "Skipping tests that depend on *.unittest.grpc.io."); + } else { + test_connect("loopback46.unittest.grpc.io", + "loopback4.unittest.grpc.io", 0, 1); + test_connect("loopback4.unittest.grpc.io", + "loopback46.unittest.grpc.io", 0, 1); + if (do_ipv6) { + test_connect("loopback46.unittest.grpc.io", + "loopback6.unittest.grpc.io", 0, 1); + test_connect("loopback6.unittest.grpc.io", + "loopback46.unittest.grpc.io", 0, 1); + test_connect("loopback4.unittest.grpc.io", + "loopback6.unittest.grpc.io", 0, 0); + test_connect("loopback6.unittest.grpc.io", + "loopback4.unittest.grpc.io", 0, 0); + } + } } grpc_shutdown(); From 675aee6a743b205c48a037a6e2829645ae7ae512 Mon Sep 17 00:00:00 2001 From: Julien Boeuf Date: Tue, 8 Sep 2015 17:21:05 -0700 Subject: [PATCH 15/32] Fixing #3286 - We cannot use call_data after the final callback as this one may trigger the deletion of the call object (hence the call_data). --- src/core/security/server_auth_filter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/security/server_auth_filter.c b/src/core/security/server_auth_filter.c index b767f854987..d134201e87c 100644 --- a/src/core/security/server_auth_filter.c +++ b/src/core/security/server_auth_filter.c @@ -128,9 +128,11 @@ static void on_md_processing_done( calld->num_consumed_md = num_consumed_md; grpc_metadata_batch_filter(&calld->md_op->data.metadata, remove_consumed_md, elem); + grpc_metadata_array_destroy(&calld->md); calld->on_done_recv->cb(calld->on_done_recv->cb_arg, 1); } else { gpr_slice message; + grpc_metadata_array_destroy(&calld->md); error_details = error_details != NULL ? error_details : "Authentication metadata processing failed."; @@ -139,7 +141,6 @@ static void on_md_processing_done( grpc_transport_stream_op_add_close(&calld->transport_op, status, &message); grpc_call_next_op(elem, &calld->transport_op); } - grpc_metadata_array_destroy(&calld->md); } static void auth_on_recv(void *user_data, int success) { From 0bee681ab15b3eef5833ca6a93a92cbc6d2ccd5d Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Tue, 8 Sep 2015 20:35:45 -0700 Subject: [PATCH 16/32] Bump version of gRPC.podspec to 0.11 Technically unnecessary, but for consistency with the other beta releases. --- gRPC.podspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gRPC.podspec b/gRPC.podspec index d0e1e2d848d..df3c8ee55cd 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -36,14 +36,14 @@ Pod::Spec.new do |s| s.name = 'gRPC' - s.version = '0.7.0' + s.version = '0.11.0' s.summary = 'gRPC client library for iOS/OSX' s.homepage = 'http://www.grpc.io' s.license = 'New BSD' s.authors = { 'The gRPC contributors' => 'grpc-packages@google.com' } # s.source = { :git => 'https://github.com/grpc/grpc.git', - # :tag => 'release-0_10_0-objectivec-0.6.0' } + # :tag => 'release-0_11_0-objectivec-0.11.0' } s.ios.deployment_target = '6.0' s.osx.deployment_target = '10.8' @@ -585,6 +585,6 @@ Pod::Spec.new do |s| ss.dependency 'gRPC/GRPCClient' ss.dependency 'gRPC/RxLibrary' - ss.dependency 'Protobuf', '~> 3.0.0-alpha-3' + ss.dependency 'Protobuf', '~> 3.0.0-alpha-4' end end From 7f51a041b4bc6e0eb45bc3adde40ab4bf1d63551 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Tue, 8 Sep 2015 21:31:59 -0700 Subject: [PATCH 17/32] Restrict deployment targets to the protobuf requirement. --- gRPC.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gRPC.podspec b/gRPC.podspec index df3c8ee55cd..4edc3e5dc7a 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -45,8 +45,8 @@ Pod::Spec.new do |s| # s.source = { :git => 'https://github.com/grpc/grpc.git', # :tag => 'release-0_11_0-objectivec-0.11.0' } - s.ios.deployment_target = '6.0' - s.osx.deployment_target = '10.8' + s.ios.deployment_target = '7.1' + s.osx.deployment_target = '10.9' s.requires_arc = true objc_dir = 'src/objective-c' From c7705c7c4701fc1cdc512fb0867b0fd699d69b2e Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Wed, 9 Sep 2015 17:21:11 -0700 Subject: [PATCH 18/32] Introduced grpc_lb_policy_args --- src/core/client_config/lb_policies/pick_first.c | 13 ++++++------- src/core/client_config/lb_policy_factory.c | 6 ++---- src/core/client_config/lb_policy_factory.h | 11 +++++++---- src/core/client_config/lb_policy_registry.c | 5 ++--- src/core/client_config/lb_policy_registry.h | 3 +-- src/core/client_config/resolvers/dns_resolver.c | 6 ++++-- .../client_config/resolvers/sockaddr_resolver.c | 5 ++++- 7 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/core/client_config/lb_policies/pick_first.c b/src/core/client_config/lb_policies/pick_first.c index 1c5d058d97f..c8262e92efa 100644 --- a/src/core/client_config/lb_policies/pick_first.c +++ b/src/core/client_config/lb_policies/pick_first.c @@ -320,18 +320,17 @@ static void pick_first_factory_ref(grpc_lb_policy_factory *factory) {} static void pick_first_factory_unref(grpc_lb_policy_factory *factory) {} static grpc_lb_policy *create_pick_first(grpc_lb_policy_factory *factory, - grpc_subchannel **subchannels, - size_t num_subchannels) { + grpc_lb_policy_args *args) { pick_first_lb_policy *p = gpr_malloc(sizeof(*p)); - GPR_ASSERT(num_subchannels); + GPR_ASSERT(args->num_subchannels > 0); memset(p, 0, sizeof(*p)); grpc_lb_policy_init(&p->base, &pick_first_lb_policy_vtable); - p->subchannels = gpr_malloc(sizeof(grpc_subchannel *) * num_subchannels); - p->num_subchannels = num_subchannels; + p->subchannels = gpr_malloc(sizeof(grpc_subchannel *) * args->num_subchannels); + p->num_subchannels = args->num_subchannels; grpc_connectivity_state_init(&p->state_tracker, GRPC_CHANNEL_IDLE, "pick_first"); - memcpy(p->subchannels, subchannels, - sizeof(grpc_subchannel *) * num_subchannels); + memcpy(p->subchannels, args->subchannels, + sizeof(grpc_subchannel *) * args->num_subchannels); grpc_iomgr_closure_init(&p->connectivity_changed, pf_connectivity_changed, p); gpr_mu_init(&p->mu); return &p->base; diff --git a/src/core/client_config/lb_policy_factory.c b/src/core/client_config/lb_policy_factory.c index 533f973cea0..0c097e05421 100644 --- a/src/core/client_config/lb_policy_factory.c +++ b/src/core/client_config/lb_policy_factory.c @@ -41,9 +41,7 @@ void grpc_lb_policy_factory_unref(grpc_lb_policy_factory *factory) { } grpc_lb_policy *grpc_lb_policy_factory_create_lb_policy( - grpc_lb_policy_factory *factory, grpc_subchannel **subchannels, - size_t num_subchannels) { + grpc_lb_policy_factory *factory, grpc_lb_policy_args *args) { if (factory == NULL) return NULL; - return factory->vtable->create_lb_policy(factory, subchannels, - num_subchannels); + return factory->vtable->create_lb_policy(factory, args); } diff --git a/src/core/client_config/lb_policy_factory.h b/src/core/client_config/lb_policy_factory.h index ba057648f77..04610316ee4 100644 --- a/src/core/client_config/lb_policy_factory.h +++ b/src/core/client_config/lb_policy_factory.h @@ -46,14 +46,18 @@ struct grpc_lb_policy_factory { const grpc_lb_policy_factory_vtable *vtable; }; +typedef struct grpc_lb_policy_args { + grpc_subchannel **subchannels; + size_t num_subchannels; +} grpc_lb_policy_args; + struct grpc_lb_policy_factory_vtable { void (*ref)(grpc_lb_policy_factory *factory); void (*unref)(grpc_lb_policy_factory *factory); /** Implementation of grpc_lb_policy_factory_create_lb_policy */ grpc_lb_policy *(*create_lb_policy)(grpc_lb_policy_factory *factory, - grpc_subchannel **subchannels, - size_t num_subchannels); + grpc_lb_policy_args *args); /** Name for the LB policy this factory implements */ const char *name; @@ -64,7 +68,6 @@ void grpc_lb_policy_factory_unref(grpc_lb_policy_factory *factory); /** Create a lb_policy instance. */ grpc_lb_policy *grpc_lb_policy_factory_create_lb_policy( - grpc_lb_policy_factory *factory, grpc_subchannel **subchannels, - size_t num_subchannels); + grpc_lb_policy_factory *factory, grpc_lb_policy_args *args); #endif /* GRPC_INTERNAL_CORE_CONFIG_LB_POLICY_FACTORY_H */ diff --git a/src/core/client_config/lb_policy_registry.c b/src/core/client_config/lb_policy_registry.c index 0a3ebbe4b3e..ae4a077ef3e 100644 --- a/src/core/client_config/lb_policy_registry.c +++ b/src/core/client_config/lb_policy_registry.c @@ -80,10 +80,9 @@ static grpc_lb_policy_factory *lookup_factory(const char* name) { } grpc_lb_policy *grpc_lb_policy_create(const char *name, - grpc_subchannel **subchannels, - size_t num_subchannels) { + grpc_lb_policy_args *args) { grpc_lb_policy_factory *factory = lookup_factory(name); grpc_lb_policy *lb_policy = grpc_lb_policy_factory_create_lb_policy( - factory, subchannels, num_subchannels); + factory, args); return lb_policy; } diff --git a/src/core/client_config/lb_policy_registry.h b/src/core/client_config/lb_policy_registry.h index 75114d9f02e..96fc2a16285 100644 --- a/src/core/client_config/lb_policy_registry.h +++ b/src/core/client_config/lb_policy_registry.h @@ -49,7 +49,6 @@ void grpc_register_lb_policy(grpc_lb_policy_factory *factory); * If \a name is NULL, the default factory from \a grpc_lb_policy_registry_init * will be returned. */ grpc_lb_policy *grpc_lb_policy_create(const char *name, - grpc_subchannel **subchannels, - size_t num_subchannels); + grpc_lb_policy_args *args); #endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_LB_POLICY_REGISTRY_H */ diff --git a/src/core/client_config/resolvers/dns_resolver.c b/src/core/client_config/resolvers/dns_resolver.c index 830f3f52868..c389f46c26b 100644 --- a/src/core/client_config/resolvers/dns_resolver.c +++ b/src/core/client_config/resolvers/dns_resolver.c @@ -134,6 +134,7 @@ static void dns_on_resolved(void *arg, grpc_resolved_addresses *addresses) { grpc_lb_policy *lb_policy; size_t i; if (addresses) { + grpc_lb_policy_args lb_policy_args; config = grpc_client_config_create(); subchannels = gpr_malloc(sizeof(grpc_subchannel *) * addresses->naddrs); for (i = 0; i < addresses->naddrs; i++) { @@ -143,8 +144,9 @@ static void dns_on_resolved(void *arg, grpc_resolved_addresses *addresses) { subchannels[i] = grpc_subchannel_factory_create_subchannel( r->subchannel_factory, &args); } - lb_policy = grpc_lb_policy_create(r->lb_policy_name, subchannels, - addresses->naddrs); + lb_policy_args.subchannels = subchannels; + lb_policy_args.num_subchannels = addresses->naddrs; + lb_policy = grpc_lb_policy_create(r->lb_policy_name, &lb_policy_args); grpc_client_config_set_lb_policy(config, lb_policy); GRPC_LB_POLICY_UNREF(lb_policy, "construction"); grpc_resolved_addresses_destroy(addresses); diff --git a/src/core/client_config/resolvers/sockaddr_resolver.c b/src/core/client_config/resolvers/sockaddr_resolver.c index 1bff1d7abf4..d378ab963e5 100644 --- a/src/core/client_config/resolvers/sockaddr_resolver.c +++ b/src/core/client_config/resolvers/sockaddr_resolver.c @@ -121,6 +121,7 @@ static void sockaddr_next(grpc_resolver *resolver, static void sockaddr_maybe_finish_next_locked(sockaddr_resolver *r) { grpc_client_config *cfg; grpc_lb_policy *lb_policy; + grpc_lb_policy_args lb_policy_args; grpc_subchannel **subchannels; grpc_subchannel_args args; @@ -135,8 +136,10 @@ static void sockaddr_maybe_finish_next_locked(sockaddr_resolver *r) { subchannels[i] = grpc_subchannel_factory_create_subchannel( r->subchannel_factory, &args); } + lb_policy_args.subchannels = subchannels; + lb_policy_args.num_subchannels = r->num_addrs; lb_policy = - grpc_lb_policy_create(r->lb_policy_name, subchannels, r->num_addrs); + grpc_lb_policy_create(r->lb_policy_name, &lb_policy_args); gpr_free(subchannels); grpc_client_config_set_lb_policy(cfg, lb_policy); GRPC_LB_POLICY_UNREF(lb_policy, "unix"); From 1db5a8b30d9ca94c669f99c73f752c8033ae00cc Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Wed, 9 Sep 2015 18:09:00 -0700 Subject: [PATCH 19/32] Fixed typo from bad merge --- src/core/surface/call.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/surface/call.c b/src/core/surface/call.c index a8b4d65fbc0..e91b7379bc7 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -545,7 +545,7 @@ static void set_encodings_accepted_by_peer( gpr_slice_buffer accept_encoding_parts; gpr_slice_buffer_init(&accept_encoding_parts); - gpr_slice_split(accept_encoding_slice, ", ", &accept_encoding_parts); + gpr_slice_split(accept_encoding_slice, ",", &accept_encoding_parts); /* No need to zero call->encodings_accepted_by_peer: grpc_call_create already * zeroes the whole grpc_call */ From 6c99ad0b7623f91eabc358f84cbe0b1d70b6bc33 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Thu, 10 Sep 2015 08:30:51 -0700 Subject: [PATCH 20/32] Python version set to 0.11.0b0 --- src/python/grpcio/setup.py | 2 +- src/python/grpcio_health_checking/setup.py | 4 ++-- src/python/grpcio_test/requirements.txt | 2 +- src/python/grpcio_test/setup.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/python/grpcio/setup.py b/src/python/grpcio/setup.py index 4735ce080b0..151b2bfcb4d 100644 --- a/src/python/grpcio/setup.py +++ b/src/python/grpcio/setup.py @@ -104,7 +104,7 @@ _COMMAND_CLASS = { setuptools.setup( name='grpcio', - version='0.11.0', + version='0.11.0b0', ext_modules=_EXTENSION_MODULES, packages=list(_PACKAGES), package_dir=_PACKAGE_DIRECTORIES, diff --git a/src/python/grpcio_health_checking/setup.py b/src/python/grpcio_health_checking/setup.py index 38629aa8159..35253ba3123 100644 --- a/src/python/grpcio_health_checking/setup.py +++ b/src/python/grpcio_health_checking/setup.py @@ -51,7 +51,7 @@ _PACKAGE_DIRECTORIES = { } _INSTALL_REQUIRES = ( - 'grpcio>=0.11.0', + 'grpcio>=0.11.0b0', ) _SETUP_REQUIRES = _INSTALL_REQUIRES @@ -63,7 +63,7 @@ _COMMAND_CLASS = { setuptools.setup( name='grpcio_health_checking', - version='0.11.0', + version='0.11.0b0', packages=list(_PACKAGES), package_dir=_PACKAGE_DIRECTORIES, install_requires=_INSTALL_REQUIRES, diff --git a/src/python/grpcio_test/requirements.txt b/src/python/grpcio_test/requirements.txt index cf8b8a89994..fea80ca07f1 100644 --- a/src/python/grpcio_test/requirements.txt +++ b/src/python/grpcio_test/requirements.txt @@ -1,4 +1,4 @@ -grpcio>=0.11.0 +grpcio>=0.11.0b0 oauth2client>=1.4.7 protobuf>=3.0.0a3 pytest>=2.6 diff --git a/src/python/grpcio_test/setup.py b/src/python/grpcio_test/setup.py index 161578a5153..216119f0e7b 100644 --- a/src/python/grpcio_test/setup.py +++ b/src/python/grpcio_test/setup.py @@ -71,7 +71,7 @@ _SETUP_REQUIRES = ( _INSTALL_REQUIRES = ( 'oauth2client>=1.4.7', - 'grpcio>=0.11.0', + 'grpcio>=0.11.0b0', ) _COMMAND_CLASS = { @@ -80,7 +80,7 @@ _COMMAND_CLASS = { setuptools.setup( name='grpcio_test', - version='0.11.0', + version='0.11.0b0', packages=_PACKAGES, package_dir=_PACKAGE_DIRECTORIES, package_data=_PACKAGE_DATA, From 38fc0bb3d591246b527d52ec19583a833ab84f8b Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Thu, 10 Sep 2015 08:49:57 -0700 Subject: [PATCH 21/32] Fix Python docgen The old package directory handling was stale in grpcio's setup.py command support module and docgen had a typo. --- src/python/grpcio/commands.py | 2 +- tools/distrib/python/docgen.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py index 89c0fbf0f3f..8a2f2d6283e 100644 --- a/src/python/grpcio/commands.py +++ b/src/python/grpcio/commands.py @@ -64,7 +64,7 @@ class SphinxDocumentation(setuptools.Command): import sphinx.apidoc metadata = self.distribution.metadata src_dir = os.path.join( - os.getcwd(), self.distribution.package_dir['grpc']) + os.getcwd(), self.distribution.package_dir[''], 'grpc') sys.path.append(src_dir) sphinx.apidoc.main([ '', '--force', '--full', '-H', metadata.name, '-A', metadata.author, diff --git a/tools/distrib/python/docgen.py b/tools/distrib/python/docgen.py index d76792c56f4..2acd3cc12f2 100755 --- a/tools/distrib/python/docgen.py +++ b/tools/distrib/python/docgen.py @@ -81,7 +81,7 @@ if args.submit: assert args.doc_branch github_user = args.gh_user github_repository_owner = ( - args.gh_repo_owner if args.gh_repo_owner else gh_user) + args.gh_repo_owner if args.gh_repo_owner else args.gh_user) # Create a temporary directory out of tree, checkout gh-pages from the # specified repository, edit it, and push it. It's up to the user to then go # onto GitHub and make a PR against grpc/grpc:gh-pages. From 061d288f559f786c1541f56192303314a61e5489 Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Tue, 8 Sep 2015 21:34:33 +0000 Subject: [PATCH 22/32] Beta Python documentation correction and update --- examples/python/helloworld/README.md | 3 - examples/python/helloworld/greeter_client.py | 9 +- examples/python/helloworld/greeter_server.py | 6 +- examples/python/route_guide/README.md | 36 ++- .../python/route_guide/route_guide_client.py | 21 +- .../python/route_guide/route_guide_pb2.py | 267 +++++++++++++----- .../python/route_guide/route_guide_server.py | 6 +- examples/python/route_guide/run_codegen.sh | 2 +- 8 files changed, 230 insertions(+), 120 deletions(-) mode change 100755 => 100644 examples/python/helloworld/greeter_client.py mode change 100755 => 100644 examples/python/route_guide/route_guide_client.py diff --git a/examples/python/helloworld/README.md b/examples/python/helloworld/README.md index 8fde0d2315c..070b9e88376 100644 --- a/examples/python/helloworld/README.md +++ b/examples/python/helloworld/README.md @@ -91,9 +91,6 @@ Which internally invokes the proto-compiler as: $ protoc -I ../../protos --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_python_plugin` ../../protos/helloworld.proto ``` -Optionally, you can just skip the code generation step as the generated python module has already -been generated for you (helloworld_pb2.py). - ### The client Client-side code can be found in [greeter_client.py](greeter_client.py). diff --git a/examples/python/helloworld/greeter_client.py b/examples/python/helloworld/greeter_client.py old mode 100755 new mode 100644 index 370ce467703..561b25bcb2e --- a/examples/python/helloworld/greeter_client.py +++ b/examples/python/helloworld/greeter_client.py @@ -29,15 +29,18 @@ """The Python implementation of the GRPC helloworld.Greeter client.""" +from grpc.beta import implementations + import helloworld_pb2 _TIMEOUT_SECONDS = 10 def run(): - with helloworld_pb2.early_adopter_create_Greeter_stub('localhost', 50051) as stub: - response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'), _TIMEOUT_SECONDS) - print "Greeter client received: " + response.message + channel = implementations.insecure_channel('localhost', 50051) + stub = helloworld_pb2.beta_create_Greeter_stub(channel) + response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'), _TIMEOUT_SECONDS) + print "Greeter client received: " + response.message if __name__ == '__main__': diff --git a/examples/python/helloworld/greeter_server.py b/examples/python/helloworld/greeter_server.py index 81353666b10..1514d8f270b 100644 --- a/examples/python/helloworld/greeter_server.py +++ b/examples/python/helloworld/greeter_server.py @@ -36,15 +36,15 @@ import helloworld_pb2 _ONE_DAY_IN_SECONDS = 60 * 60 * 24 -class Greeter(helloworld_pb2.EarlyAdopterGreeterServicer): +class Greeter(helloworld_pb2.BetaGreeterServicer): def SayHello(self, request, context): return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name) def serve(): - server = helloworld_pb2.early_adopter_create_Greeter_server( - Greeter(), 50051, None, None) + server = helloworld_pb2.beta_create_Greeter_server(Greeter()) + server.add_insecure_port('[::]:50051') server.start() try: while True: diff --git a/examples/python/route_guide/README.md b/examples/python/route_guide/README.md index 636e134964d..cb1aa7d78ae 100644 --- a/examples/python/route_guide/README.md +++ b/examples/python/route_guide/README.md @@ -29,7 +29,7 @@ Then change your current directory to `examples/python/route_guide`: $ cd examples/python/route_guide ``` -You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Python quick start guide](../python). +You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Python quick start guide](../helloworld). ## Defining the service @@ -99,12 +99,11 @@ $ protoc -I ../../protos --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`w Note that as we've already provided a version of the generated code in the example repository, running this command regenerates the appropriate file rather than creates a new one. The generated code file is called `route_guide_pb2.py` and contains: - classes for the messages defined in route_guide.proto - abstract classes for the service defined in route_guide.proto - - `EarlyAdopterRouteGuideServicer`, which defines the interface for implementations of the RouteGuide service - - `EarlyAdopterRouteGuideServer`, which may be started and stopped - - `EarlyAdopterRouteGuideStub`, which can be used by clients to invoke RouteGuide RPCs + - `BetaRouteGuideServicer`, which defines the interface for implementations of the RouteGuide service + - `BetaRouteGuideStub`, which can be used by clients to invoke RouteGuide RPCs - functions for application use - - `early_adopter_create_RouteGuide_server`, which creates a gRPC server given an `EarlyAdopterRouteGuideServicer` object - - `early_adopter_create_RouteGuide_stub`, which can be used by clients to create a stub object + - `beta_create_RouteGuide_server`, which creates a gRPC server given a `BetaRouteGuideServicer` object + - `beta_create_RouteGuide_stub`, which can be used by clients to create a stub object ## Creating the server @@ -119,11 +118,11 @@ You can find the example `RouteGuide` server in [route_guide_server.py](route_gu ### Implementing RouteGuide -`route_guide_server.py` has a `RouteGuideServicer` class that implements the generated interface `route_guide_pb2.EarlyAdopterRouteGuideServicer`: +`route_guide_server.py` has a `RouteGuideServicer` class that implements the generated interface `route_guide_pb2.BetaRouteGuideServicer`: ```python # RouteGuideServicer provides an implementation of the methods of the RouteGuide service. -class RouteGuideServicer(route_guide_pb2.EarlyAdopterRouteGuideServicer): +class RouteGuideServicer(route_guide_pb2.BetaRouteGuideServicer): ``` `RouteGuideServicer` implements all the `RouteGuide` service methods. @@ -141,7 +140,7 @@ Let's look at the simplest type first, `GetFeature`, which just gets a `Point` f return feature ``` -The method is passed a `route_guide_pb2.Point` request for the RPC, and an `RpcContext` object that provides RPC-specific information such as timeout limits. It returns a `route_guide_pb2.Feature` response. +The method is passed a `route_guide_pb2.Point` request for the RPC, and a `ServicerContext` object that provides RPC-specific information such as timeout limits. It returns a `route_guide_pb2.Feature` response. #### Response-streaming RPC @@ -212,8 +211,8 @@ Once you have implemented all the `RouteGuide` methods, the next step is to star ```python def serve(): - server = route_guide_pb2.early_adopter_create_RouteGuide_server( - RouteGuideServicer(), 50051, None, None) + server = route_guide_pb2.beta_create_RouteGuide_server(RouteGuideServicer()) + server.add_insecure_port('[::]:50051') server.start() ``` @@ -228,17 +227,14 @@ You can see the complete example client code in [route_guide_client.py](route_gu To call service methods, we first need to create a *stub*. -We use the `early_adopter_create_RouteGuide_stub` function of the `route_guide_pb2` module, generated from our .proto. +We use the `beta_create_RouteGuide_stub` function of the `route_guide_pb2` module, generated from our .proto. ```python -stub = RouteGuide::Stub.new('localhost', 50051) +channel = implementations.insecure_channel('localhost', 50051) +stub = beta_create_RouteGuide_stub(channel) ``` -The returned object implements all the methods defined by the `EarlyAdopterRouteGuideStub` interface, and is also a [context manager](https://docs.python.org/2/library/stdtypes.html#typecontextmanager). All RPCs invoked on the stub must be invoked within the stub's context, so it is common for stubs to be created and used with a [with statement](https://docs.python.org/2/reference/compound_stmts.html#the-with-statement): - -```python -with route_guide_pb2.early_adopter_create_RouteGuide_stub('localhost', 50051) as stub: -``` +The returned object implements all the methods defined by the `BetaRouteGuideStub` interface. ### Calling service methods @@ -255,7 +251,7 @@ feature = stub.GetFeature(point, timeout_in_seconds) An asynchronous call to `GetFeature` is similar, but like calling a local method asynchronously in a thread pool: ```python -feature_future = stub.GetFeature.async(point, timeout_in_seconds) +feature_future = stub.GetFeature.future(point, timeout_in_seconds) feature = feature_future.result() ``` @@ -276,7 +272,7 @@ route_summary = stub.RecordRoute(point_sequence, timeout_in_seconds) ``` ```python -route_summary_future = stub.RecordRoute.async(point_sequence, timeout_in_seconds) +route_summary_future = stub.RecordRoute.future(point_sequence, timeout_in_seconds) route_summary = route_summary_future.result() ``` diff --git a/examples/python/route_guide/route_guide_client.py b/examples/python/route_guide/route_guide_client.py old mode 100755 new mode 100644 index 078231543e1..b1dfad551dc --- a/examples/python/route_guide/route_guide_client.py +++ b/examples/python/route_guide/route_guide_client.py @@ -32,6 +32,8 @@ import random import time +from grpc.beta import implementations + import route_guide_pb2 import route_guide_resources @@ -115,15 +117,16 @@ def guide_route_chat(stub): def run(): - with route_guide_pb2.early_adopter_create_RouteGuide_stub('localhost', 50051) as stub: - print "-------------- GetFeature --------------" - guide_get_feature(stub) - print "-------------- ListFeatures --------------" - guide_list_features(stub) - print "-------------- RecordRoute --------------" - guide_record_route(stub) - print "-------------- RouteChat --------------" - guide_route_chat(stub) + channel = implementations.insecure_channel('localhost', 50051) + stub = route_guide_pb2.beta_create_RouteGuide_stub(channel) + print "-------------- GetFeature --------------" + guide_get_feature(stub) + print "-------------- ListFeatures --------------" + guide_list_features(stub) + print "-------------- RecordRoute --------------" + guide_record_route(stub) + print "-------------- RouteChat --------------" + guide_route_chat(stub) if __name__ == '__main__': diff --git a/examples/python/route_guide/route_guide_pb2.py b/examples/python/route_guide/route_guide_pb2.py index 2a4532bb750..d4d9f8dcd5d 100644 --- a/examples/python/route_guide/route_guide_pb2.py +++ b/examples/python/route_guide/route_guide_pb2.py @@ -1,8 +1,6 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: route_guide.proto -import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection @@ -17,8 +15,9 @@ _sym_db = _symbol_database.Default() DESCRIPTOR = _descriptor.FileDescriptor( name='route_guide.proto', - package='', - serialized_pb=_b('\n\x11route_guide.proto\",\n\x05Point\x12\x10\n\x08latitude\x18\x01 \x01(\x05\x12\x11\n\tlongitude\x18\x02 \x01(\x05\"3\n\tRectangle\x12\x12\n\x02lo\x18\x01 \x01(\x0b\x32\x06.Point\x12\x12\n\x02hi\x18\x02 \x01(\x0b\x32\x06.Point\"1\n\x07\x46\x65\x61ture\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x18\n\x08location\x18\x02 \x01(\x0b\x32\x06.Point\"6\n\tRouteNote\x12\x18\n\x08location\x18\x01 \x01(\x0b\x32\x06.Point\x12\x0f\n\x07message\x18\x02 \x01(\t\"b\n\x0cRouteSummary\x12\x13\n\x0bpoint_count\x18\x01 \x01(\x05\x12\x15\n\rfeature_count\x18\x02 \x01(\x05\x12\x10\n\x08\x64istance\x18\x03 \x01(\x05\x12\x14\n\x0c\x65lapsed_time\x18\x04 \x01(\x05\x32\xad\x01\n\nRouteGuide\x12 \n\nGetFeature\x12\x06.Point\x1a\x08.Feature\"\x00\x12(\n\x0cListFeatures\x12\n.Rectangle\x1a\x08.Feature\"\x00\x30\x01\x12(\n\x0bRecordRoute\x12\x06.Point\x1a\r.RouteSummary\"\x00(\x01\x12)\n\tRouteChat\x12\n.RouteNote\x1a\n.RouteNote\"\x00(\x01\x30\x01') + package='routeguide', + syntax='proto3', + serialized_pb=b'\n\x11route_guide.proto\x12\nrouteguide\",\n\x05Point\x12\x10\n\x08latitude\x18\x01 \x01(\x05\x12\x11\n\tlongitude\x18\x02 \x01(\x05\"I\n\tRectangle\x12\x1d\n\x02lo\x18\x01 \x01(\x0b\x32\x11.routeguide.Point\x12\x1d\n\x02hi\x18\x02 \x01(\x0b\x32\x11.routeguide.Point\"<\n\x07\x46\x65\x61ture\x12\x0c\n\x04name\x18\x01 \x01(\t\x12#\n\x08location\x18\x02 \x01(\x0b\x32\x11.routeguide.Point\"A\n\tRouteNote\x12#\n\x08location\x18\x01 \x01(\x0b\x32\x11.routeguide.Point\x12\x0f\n\x07message\x18\x02 \x01(\t\"b\n\x0cRouteSummary\x12\x13\n\x0bpoint_count\x18\x01 \x01(\x05\x12\x15\n\rfeature_count\x18\x02 \x01(\x05\x12\x10\n\x08\x64istance\x18\x03 \x01(\x05\x12\x14\n\x0c\x65lapsed_time\x18\x04 \x01(\x05\x32\x85\x02\n\nRouteGuide\x12\x36\n\nGetFeature\x12\x11.routeguide.Point\x1a\x13.routeguide.Feature\"\x00\x12>\n\x0cListFeatures\x12\x15.routeguide.Rectangle\x1a\x13.routeguide.Feature\"\x00\x30\x01\x12>\n\x0bRecordRoute\x12\x11.routeguide.Point\x1a\x18.routeguide.RouteSummary\"\x00(\x01\x12?\n\tRouteChat\x12\x15.routeguide.RouteNote\x1a\x15.routeguide.RouteNote\"\x00(\x01\x30\x01\x42\x0f\n\x07\x65x.grpc\xa2\x02\x03RTGb\x06proto3' ) _sym_db.RegisterFileDescriptor(DESCRIPTOR) @@ -27,20 +26,20 @@ _sym_db.RegisterFileDescriptor(DESCRIPTOR) _POINT = _descriptor.Descriptor( name='Point', - full_name='Point', + full_name='routeguide.Point', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( - name='latitude', full_name='Point.latitude', index=0, + name='latitude', full_name='routeguide.Point.latitude', index=0, number=1, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='longitude', full_name='Point.longitude', index=1, + name='longitude', full_name='routeguide.Point.longitude', index=1, number=2, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, @@ -54,30 +53,31 @@ _POINT = _descriptor.Descriptor( ], options=None, is_extendable=False, + syntax='proto3', extension_ranges=[], oneofs=[ ], - serialized_start=21, - serialized_end=65, + serialized_start=33, + serialized_end=77, ) _RECTANGLE = _descriptor.Descriptor( name='Rectangle', - full_name='Rectangle', + full_name='routeguide.Rectangle', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( - name='lo', full_name='Rectangle.lo', index=0, + name='lo', full_name='routeguide.Rectangle.lo', index=0, number=1, type=11, cpp_type=10, label=1, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='hi', full_name='Rectangle.hi', index=1, + name='hi', full_name='routeguide.Rectangle.hi', index=1, number=2, type=11, cpp_type=10, label=1, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, @@ -91,30 +91,31 @@ _RECTANGLE = _descriptor.Descriptor( ], options=None, is_extendable=False, + syntax='proto3', extension_ranges=[], oneofs=[ ], - serialized_start=67, - serialized_end=118, + serialized_start=79, + serialized_end=152, ) _FEATURE = _descriptor.Descriptor( name='Feature', - full_name='Feature', + full_name='routeguide.Feature', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( - name='name', full_name='Feature.name', index=0, + name='name', full_name='routeguide.Feature.name', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), + has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='location', full_name='Feature.location', index=1, + name='location', full_name='routeguide.Feature.location', index=1, number=2, type=11, cpp_type=10, label=1, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, @@ -128,32 +129,33 @@ _FEATURE = _descriptor.Descriptor( ], options=None, is_extendable=False, + syntax='proto3', extension_ranges=[], oneofs=[ ], - serialized_start=120, - serialized_end=169, + serialized_start=154, + serialized_end=214, ) _ROUTENOTE = _descriptor.Descriptor( name='RouteNote', - full_name='RouteNote', + full_name='routeguide.RouteNote', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( - name='location', full_name='RouteNote.location', index=0, + name='location', full_name='routeguide.RouteNote.location', index=0, number=1, type=11, cpp_type=10, label=1, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='message', full_name='RouteNote.message', index=1, + name='message', full_name='routeguide.RouteNote.message', index=1, number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), + has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), @@ -165,44 +167,45 @@ _ROUTENOTE = _descriptor.Descriptor( ], options=None, is_extendable=False, + syntax='proto3', extension_ranges=[], oneofs=[ ], - serialized_start=171, - serialized_end=225, + serialized_start=216, + serialized_end=281, ) _ROUTESUMMARY = _descriptor.Descriptor( name='RouteSummary', - full_name='RouteSummary', + full_name='routeguide.RouteSummary', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( - name='point_count', full_name='RouteSummary.point_count', index=0, + name='point_count', full_name='routeguide.RouteSummary.point_count', index=0, number=1, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='feature_count', full_name='RouteSummary.feature_count', index=1, + name='feature_count', full_name='routeguide.RouteSummary.feature_count', index=1, number=2, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='distance', full_name='RouteSummary.distance', index=2, + name='distance', full_name='routeguide.RouteSummary.distance', index=2, number=3, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='elapsed_time', full_name='RouteSummary.elapsed_time', index=3, + name='elapsed_time', full_name='routeguide.RouteSummary.elapsed_time', index=3, number=4, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, @@ -216,11 +219,12 @@ _ROUTESUMMARY = _descriptor.Descriptor( ], options=None, is_extendable=False, + syntax='proto3', extension_ranges=[], oneofs=[ ], - serialized_start=227, - serialized_end=325, + serialized_start=283, + serialized_end=381, ) _RECTANGLE.fields_by_name['lo'].message_type = _POINT @@ -236,58 +240,61 @@ DESCRIPTOR.message_types_by_name['RouteSummary'] = _ROUTESUMMARY Point = _reflection.GeneratedProtocolMessageType('Point', (_message.Message,), dict( DESCRIPTOR = _POINT, __module__ = 'route_guide_pb2' - # @@protoc_insertion_point(class_scope:Point) + # @@protoc_insertion_point(class_scope:routeguide.Point) )) _sym_db.RegisterMessage(Point) Rectangle = _reflection.GeneratedProtocolMessageType('Rectangle', (_message.Message,), dict( DESCRIPTOR = _RECTANGLE, __module__ = 'route_guide_pb2' - # @@protoc_insertion_point(class_scope:Rectangle) + # @@protoc_insertion_point(class_scope:routeguide.Rectangle) )) _sym_db.RegisterMessage(Rectangle) Feature = _reflection.GeneratedProtocolMessageType('Feature', (_message.Message,), dict( DESCRIPTOR = _FEATURE, __module__ = 'route_guide_pb2' - # @@protoc_insertion_point(class_scope:Feature) + # @@protoc_insertion_point(class_scope:routeguide.Feature) )) _sym_db.RegisterMessage(Feature) RouteNote = _reflection.GeneratedProtocolMessageType('RouteNote', (_message.Message,), dict( DESCRIPTOR = _ROUTENOTE, __module__ = 'route_guide_pb2' - # @@protoc_insertion_point(class_scope:RouteNote) + # @@protoc_insertion_point(class_scope:routeguide.RouteNote) )) _sym_db.RegisterMessage(RouteNote) RouteSummary = _reflection.GeneratedProtocolMessageType('RouteSummary', (_message.Message,), dict( DESCRIPTOR = _ROUTESUMMARY, __module__ = 'route_guide_pb2' - # @@protoc_insertion_point(class_scope:RouteSummary) + # @@protoc_insertion_point(class_scope:routeguide.RouteSummary) )) _sym_db.RegisterMessage(RouteSummary) +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), b'\n\007ex.grpc\242\002\003RTG') import abc -from grpc._adapter import fore -from grpc._adapter import rear -from grpc.framework.assembly import implementations -from grpc.framework.assembly import utilities +from grpc.beta import implementations as beta_implementations +from grpc.early_adopter import implementations as early_adopter_implementations +from grpc.framework.alpha import utilities as alpha_utilities +from grpc.framework.common import cardinality +from grpc.framework.interfaces.face import utilities as face_utilities class EarlyAdopterRouteGuideServicer(object): """""" __metaclass__ = abc.ABCMeta @abc.abstractmethod - def GetFeature(self, request): + def GetFeature(self, request, context): raise NotImplementedError() @abc.abstractmethod - def ListFeatures(self, request): + def ListFeatures(self, request, context): raise NotImplementedError() @abc.abstractmethod - def RecordRoute(self, request_iterator): + def RecordRoute(self, request_iterator, context): raise NotImplementedError() @abc.abstractmethod - def RouteChat(self, request_iterator): + def RouteChat(self, request_iterator, context): raise NotImplementedError() class EarlyAdopterRouteGuideServer(object): """""" @@ -317,54 +324,158 @@ class EarlyAdopterRouteGuideStub(object): def RouteChat(self, request_iterator): raise NotImplementedError() RouteChat.async = None -def early_adopter_create_RouteGuide_server(servicer, port, root_certificates, key_chain_pairs): - method_implementations = { - "GetFeature": utilities.unary_unary_inline(servicer.GetFeature), - "ListFeatures": utilities.unary_stream_inline(servicer.ListFeatures), - "RecordRoute": utilities.stream_unary_inline(servicer.RecordRoute), - "RouteChat": utilities.stream_stream_inline(servicer.RouteChat), +def early_adopter_create_RouteGuide_server(servicer, port, private_key=None, certificate_chain=None): + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + method_service_descriptions = { + "GetFeature": alpha_utilities.unary_unary_service_description( + servicer.GetFeature, + route_guide_pb2.Point.FromString, + route_guide_pb2.Feature.SerializeToString, + ), + "ListFeatures": alpha_utilities.unary_stream_service_description( + servicer.ListFeatures, + route_guide_pb2.Rectangle.FromString, + route_guide_pb2.Feature.SerializeToString, + ), + "RecordRoute": alpha_utilities.stream_unary_service_description( + servicer.RecordRoute, + route_guide_pb2.Point.FromString, + route_guide_pb2.RouteSummary.SerializeToString, + ), + "RouteChat": alpha_utilities.stream_stream_service_description( + servicer.RouteChat, + route_guide_pb2.RouteNote.FromString, + route_guide_pb2.RouteNote.SerializeToString, + ), + } + return early_adopter_implementations.server("routeguide.RouteGuide", method_service_descriptions, port, private_key=private_key, certificate_chain=certificate_chain) +def early_adopter_create_RouteGuide_stub(host, port, metadata_transformer=None, secure=False, root_certificates=None, private_key=None, certificate_chain=None, server_host_override=None): + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + method_invocation_descriptions = { + "GetFeature": alpha_utilities.unary_unary_invocation_description( + route_guide_pb2.Point.SerializeToString, + route_guide_pb2.Feature.FromString, + ), + "ListFeatures": alpha_utilities.unary_stream_invocation_description( + route_guide_pb2.Rectangle.SerializeToString, + route_guide_pb2.Feature.FromString, + ), + "RecordRoute": alpha_utilities.stream_unary_invocation_description( + route_guide_pb2.Point.SerializeToString, + route_guide_pb2.RouteSummary.FromString, + ), + "RouteChat": alpha_utilities.stream_stream_invocation_description( + route_guide_pb2.RouteNote.SerializeToString, + route_guide_pb2.RouteNote.FromString, + ), } + return early_adopter_implementations.stub("routeguide.RouteGuide", method_invocation_descriptions, host, port, metadata_transformer=metadata_transformer, secure=secure, root_certificates=root_certificates, private_key=private_key, certificate_chain=certificate_chain, server_host_override=server_host_override) + +class BetaRouteGuideServicer(object): + """""" + __metaclass__ = abc.ABCMeta + @abc.abstractmethod + def GetFeature(self, request, context): + raise NotImplementedError() + @abc.abstractmethod + def ListFeatures(self, request, context): + raise NotImplementedError() + @abc.abstractmethod + def RecordRoute(self, request_iterator, context): + raise NotImplementedError() + @abc.abstractmethod + def RouteChat(self, request_iterator, context): + raise NotImplementedError() + +class BetaRouteGuideStub(object): + """The interface to which stubs will conform.""" + __metaclass__ = abc.ABCMeta + @abc.abstractmethod + def GetFeature(self, request, timeout): + raise NotImplementedError() + GetFeature.future = None + @abc.abstractmethod + def ListFeatures(self, request, timeout): + raise NotImplementedError() + @abc.abstractmethod + def RecordRoute(self, request_iterator, timeout): + raise NotImplementedError() + RecordRoute.future = None + @abc.abstractmethod + def RouteChat(self, request_iterator, timeout): + raise NotImplementedError() + +def beta_create_RouteGuide_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None): + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 import route_guide_pb2 import route_guide_pb2 import route_guide_pb2 import route_guide_pb2 request_deserializers = { - "GetFeature": route_guide_pb2.Point.FromString, - "ListFeatures": route_guide_pb2.Rectangle.FromString, - "RecordRoute": route_guide_pb2.Point.FromString, - "RouteChat": route_guide_pb2.RouteNote.FromString, + ('routeguide.RouteGuide', 'GetFeature'): route_guide_pb2.Point.FromString, + ('routeguide.RouteGuide', 'ListFeatures'): route_guide_pb2.Rectangle.FromString, + ('routeguide.RouteGuide', 'RecordRoute'): route_guide_pb2.Point.FromString, + ('routeguide.RouteGuide', 'RouteChat'): route_guide_pb2.RouteNote.FromString, } response_serializers = { - "GetFeature": lambda x: x.SerializeToString(), - "ListFeatures": lambda x: x.SerializeToString(), - "RecordRoute": lambda x: x.SerializeToString(), - "RouteChat": lambda x: x.SerializeToString(), + ('routeguide.RouteGuide', 'GetFeature'): route_guide_pb2.Feature.SerializeToString, + ('routeguide.RouteGuide', 'ListFeatures'): route_guide_pb2.Feature.SerializeToString, + ('routeguide.RouteGuide', 'RecordRoute'): route_guide_pb2.RouteSummary.SerializeToString, + ('routeguide.RouteGuide', 'RouteChat'): route_guide_pb2.RouteNote.SerializeToString, } - link = fore.activated_fore_link(port, request_deserializers, response_serializers, root_certificates, key_chain_pairs) - return implementations.assemble_service(method_implementations, link) -def early_adopter_create_RouteGuide_stub(host, port): method_implementations = { - "GetFeature": utilities.unary_unary_inline(None), - "ListFeatures": utilities.unary_stream_inline(None), - "RecordRoute": utilities.stream_unary_inline(None), - "RouteChat": utilities.stream_stream_inline(None), + ('routeguide.RouteGuide', 'GetFeature'): face_utilities.unary_unary_inline(servicer.GetFeature), + ('routeguide.RouteGuide', 'ListFeatures'): face_utilities.unary_stream_inline(servicer.ListFeatures), + ('routeguide.RouteGuide', 'RecordRoute'): face_utilities.stream_unary_inline(servicer.RecordRoute), + ('routeguide.RouteGuide', 'RouteChat'): face_utilities.stream_stream_inline(servicer.RouteChat), } + server_options = beta_implementations.server_options(request_deserializers=request_deserializers, response_serializers=response_serializers, thread_pool=pool, thread_pool_size=pool_size, default_timeout=default_timeout, maximum_timeout=maximum_timeout) + return beta_implementations.server(method_implementations, options=server_options) + +def beta_create_RouteGuide_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None): import route_guide_pb2 import route_guide_pb2 import route_guide_pb2 import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + request_serializers = { + ('routeguide.RouteGuide', 'GetFeature'): route_guide_pb2.Point.SerializeToString, + ('routeguide.RouteGuide', 'ListFeatures'): route_guide_pb2.Rectangle.SerializeToString, + ('routeguide.RouteGuide', 'RecordRoute'): route_guide_pb2.Point.SerializeToString, + ('routeguide.RouteGuide', 'RouteChat'): route_guide_pb2.RouteNote.SerializeToString, + } response_deserializers = { - "GetFeature": route_guide_pb2.Feature.FromString, - "ListFeatures": route_guide_pb2.Feature.FromString, - "RecordRoute": route_guide_pb2.RouteSummary.FromString, - "RouteChat": route_guide_pb2.RouteNote.FromString, + ('routeguide.RouteGuide', 'GetFeature'): route_guide_pb2.Feature.FromString, + ('routeguide.RouteGuide', 'ListFeatures'): route_guide_pb2.Feature.FromString, + ('routeguide.RouteGuide', 'RecordRoute'): route_guide_pb2.RouteSummary.FromString, + ('routeguide.RouteGuide', 'RouteChat'): route_guide_pb2.RouteNote.FromString, } - request_serializers = { - "GetFeature": lambda x: x.SerializeToString(), - "ListFeatures": lambda x: x.SerializeToString(), - "RecordRoute": lambda x: x.SerializeToString(), - "RouteChat": lambda x: x.SerializeToString(), + cardinalities = { + 'GetFeature': cardinality.Cardinality.UNARY_UNARY, + 'ListFeatures': cardinality.Cardinality.UNARY_STREAM, + 'RecordRoute': cardinality.Cardinality.STREAM_UNARY, + 'RouteChat': cardinality.Cardinality.STREAM_STREAM, } - link = rear.activated_rear_link(host, port, request_serializers, response_deserializers) - return implementations.assemble_dynamic_inline_stub(method_implementations, link) + stub_options = beta_implementations.stub_options(host=host, metadata_transformer=metadata_transformer, request_serializers=request_serializers, response_deserializers=response_deserializers, thread_pool=pool, thread_pool_size=pool_size) + return beta_implementations.dynamic_stub(channel, 'routeguide.RouteGuide', cardinalities, options=stub_options) # @@protoc_insertion_point(module_scope) diff --git a/examples/python/route_guide/route_guide_server.py b/examples/python/route_guide/route_guide_server.py index 44bbacf5f32..f23b98bf367 100644 --- a/examples/python/route_guide/route_guide_server.py +++ b/examples/python/route_guide/route_guide_server.py @@ -65,7 +65,7 @@ def get_distance(start, end): R = 6371000; # metres return R * c; -class RouteGuideServicer(route_guide_pb2.EarlyAdopterRouteGuideServicer): +class RouteGuideServicer(route_guide_pb2.BetaRouteGuideServicer): """Provides methods that implement functionality of route guide server.""" def __init__(self): @@ -121,8 +121,8 @@ class RouteGuideServicer(route_guide_pb2.EarlyAdopterRouteGuideServicer): def serve(): - server = route_guide_pb2.early_adopter_create_RouteGuide_server( - RouteGuideServicer(), 50051, None, None) + server = route_guide_pb2.beta_create_RouteGuide_server(RouteGuideServicer()) + server.add_insecure_port('[::]:50051') server.start() try: while True: diff --git a/examples/python/route_guide/run_codegen.sh b/examples/python/route_guide/run_codegen.sh index 689e0978de6..a5759025b8d 100755 --- a/examples/python/route_guide/run_codegen.sh +++ b/examples/python/route_guide/run_codegen.sh @@ -1,4 +1,4 @@ #!/bin/bash # Runs the protoc with gRPC plugin to generate protocol messages and gRPC stubs. -protoc -I . --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_python_plugin` route_guide.proto +protoc -I ../../protos --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_python_plugin` ../../protos/route_guide.proto From 3121fd4d757991e7ef95a7b6b370b83c23ba61b6 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Sep 2015 09:56:20 -0700 Subject: [PATCH 23/32] Sign conversion fixes --- Makefile | 2 +- src/core/channel/channel_args.c | 8 +-- src/core/channel/channel_stack.c | 2 +- src/core/channel/compress_filter.c | 3 +- src/core/client_config/connector.h | 2 +- .../client_config/resolvers/dns_resolver.c | 2 +- .../resolvers/sockaddr_resolver.c | 15 +++--- src/core/client_config/uri_parser.c | 34 +++++++------ src/core/debug/trace.c | 10 ++-- src/core/httpcli/parser.c | 8 +-- src/core/iomgr/alarm.c | 2 +- src/core/iomgr/alarm_heap.c | 20 ++++---- src/core/iomgr/alarm_heap.h | 4 +- src/core/iomgr/pollset_posix.c | 2 +- src/core/iomgr/resolve_address.h | 2 +- src/core/iomgr/tcp_client.h | 2 +- src/core/iomgr/tcp_client_posix.c | 2 +- src/core/security/base64.c | 10 ++-- src/core/security/jwt_verifier.c | 4 +- src/core/surface/secure_channel_create.c | 2 +- src/core/tsi/fake_transport_security.c | 9 ++-- src/core/tsi/ssl_transport_security.c | 51 +++++++++++-------- templates/Makefile.template | 2 +- test/core/end2end/tests/bad_hostname.c | 2 +- test/core/end2end/tests/cancel_after_accept.c | 4 +- .../cancel_after_accept_and_writes_closed.c | 4 +- test/core/end2end/tests/cancel_after_invoke.c | 2 +- .../core/end2end/tests/cancel_before_invoke.c | 4 +- .../end2end/tests/census_simple_request.c | 4 +- test/core/end2end/tests/default_host.c | 4 +- test/core/end2end/tests/disappearing_server.c | 4 +- ..._server_shutdown_finishes_inflight_calls.c | 4 +- .../end2end/tests/graceful_server_shutdown.c | 4 +- .../core/end2end/tests/invoke_large_request.c | 6 +-- .../end2end/tests/max_concurrent_streams.c | 16 +++--- test/core/end2end/tests/max_message_length.c | 4 +- test/core/end2end/tests/ping_pong_streaming.c | 14 ++--- test/core/end2end/tests/registered_call.c | 4 +- ...esponse_with_binary_metadata_and_payload.c | 6 +-- ...quest_response_with_metadata_and_payload.c | 6 +-- .../tests/request_response_with_payload.c | 6 +-- ...est_response_with_payload_and_call_creds.c | 8 +-- ...ponse_with_trailing_metadata_and_payload.c | 6 +-- .../tests/request_with_compressed_payload.c | 6 +-- test/core/end2end/tests/request_with_flags.c | 2 +- .../tests/request_with_large_metadata.c | 8 +-- .../core/end2end/tests/request_with_payload.c | 6 +-- .../end2end/tests/server_finishes_request.c | 4 +- .../end2end/tests/simple_delayed_request.c | 4 +- test/core/end2end/tests/simple_request.c | 4 +- ...equest_with_high_initial_sequence_number.c | 4 +- test/core/util/parse_hexstring.c | 2 +- test/core/util/reconnect_server.c | 3 +- test/core/util/test_config.c | 4 +- 54 files changed, 193 insertions(+), 164 deletions(-) diff --git a/Makefile b/Makefile index f902cfcfb72..b8a4af2fe6f 100644 --- a/Makefile +++ b/Makefile @@ -251,7 +251,7 @@ CXXFLAGS += -std=c++11 else CXXFLAGS += -std=c++0x endif -CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter +CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter -Wsign-conversion LDFLAGS += -g CPPFLAGS += $(CPPFLAGS_$(CONFIG)) diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c index 54ee75af289..31ce3a83fde 100644 --- a/src/core/channel/channel_args.c +++ b/src/core/channel/channel_args.c @@ -177,9 +177,9 @@ grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( if (states_arg_found) { if (state != 0) { - GPR_BITSET(states_arg, algorithm); + GPR_BITSET((unsigned *)states_arg, algorithm); } else { - GPR_BITCLEAR(states_arg, algorithm); + GPR_BITCLEAR((unsigned *)states_arg, algorithm); } } else { /* create a new arg */ @@ -189,9 +189,9 @@ grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( /* all enabled by default */ tmp.value.integer = (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; if (state != 0) { - GPR_BITSET(&tmp.value.integer, algorithm); + GPR_BITSET((unsigned *)&tmp.value.integer, algorithm); } else { - GPR_BITCLEAR(&tmp.value.integer, algorithm); + GPR_BITCLEAR((unsigned *)&tmp.value.integer, algorithm); } result = grpc_channel_args_copy_and_add(*a, &tmp, 1); grpc_channel_args_destroy(*a); diff --git a/src/core/channel/channel_stack.c b/src/core/channel/channel_stack.c index cd7c182ef27..4eb5df5de3e 100644 --- a/src/core/channel/channel_stack.c +++ b/src/core/channel/channel_stack.c @@ -57,7 +57,7 @@ int grpc_trace_channel = 0; /* Given a size, round up to the next multiple of sizeof(void*) */ #define ROUND_UP_TO_ALIGNMENT_SIZE(x) \ - (((x) + GPR_MAX_ALIGNMENT - 1) & ~(GPR_MAX_ALIGNMENT - 1)) + (((x) + GPR_MAX_ALIGNMENT - 1u) & ~(GPR_MAX_ALIGNMENT - 1u)) size_t grpc_channel_stack_size(const grpc_channel_filter **filters, size_t filter_count) { diff --git a/src/core/channel/compress_filter.c b/src/core/channel/compress_filter.c index 762a4edc73c..0b85c7b4fa6 100644 --- a/src/core/channel/compress_filter.c +++ b/src/core/channel/compress_filter.c @@ -48,7 +48,8 @@ typedef struct call_data { gpr_slice_buffer slices; /**< Buffers up input slices to be compressed */ grpc_linked_mdelem compression_algorithm_storage; grpc_linked_mdelem accept_encoding_storage; - int remaining_slice_bytes; /**< Input data to be read, as per BEGIN_MESSAGE */ + gpr_uint32 + remaining_slice_bytes; /**< Input data to be read, as per BEGIN_MESSAGE */ int written_initial_metadata; /**< Already processed initial md? */ /** Compression algorithm we'll try to use. It may be given by incoming * metadata, or by the channel's default compression settings. */ diff --git a/src/core/client_config/connector.h b/src/core/client_config/connector.h index edcb10a36ec..39f34679901 100644 --- a/src/core/client_config/connector.h +++ b/src/core/client_config/connector.h @@ -50,7 +50,7 @@ typedef struct { grpc_pollset_set *interested_parties; /** address to connect to */ const struct sockaddr *addr; - int addr_len; + size_t addr_len; /** deadline for connection */ gpr_timespec deadline; /** channel arguments (to be passed to transport) */ diff --git a/src/core/client_config/resolvers/dns_resolver.c b/src/core/client_config/resolvers/dns_resolver.c index 84643c464a9..5124c4476ab 100644 --- a/src/core/client_config/resolvers/dns_resolver.c +++ b/src/core/client_config/resolvers/dns_resolver.c @@ -140,7 +140,7 @@ static void dns_on_resolved(void *arg, grpc_resolved_addresses *addresses) { for (i = 0; i < addresses->naddrs; i++) { memset(&args, 0, sizeof(args)); args.addr = (struct sockaddr *)(addresses->addrs[i].addr); - args.addr_len = addresses->addrs[i].len; + args.addr_len = (size_t)addresses->addrs[i].len; subchannels[i] = grpc_subchannel_factory_create_subchannel( r->subchannel_factory, &args); } diff --git a/src/core/client_config/resolvers/sockaddr_resolver.c b/src/core/client_config/resolvers/sockaddr_resolver.c index 0d8540a5665..4a3c14545ad 100644 --- a/src/core/client_config/resolvers/sockaddr_resolver.c +++ b/src/core/client_config/resolvers/sockaddr_resolver.c @@ -63,7 +63,7 @@ typedef struct { /** the addresses that we've 'resolved' */ struct sockaddr_storage *addrs; /** the corresponding length of the addresses */ - int *addrs_len; + size_t *addrs_len; /** how many elements in \a addrs */ size_t num_addrs; @@ -157,7 +157,8 @@ static void sockaddr_destroy(grpc_resolver *gr) { } #ifdef GPR_POSIX_SOCKET -static int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr, int *len) { +static int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr, + size_t *len) { struct sockaddr_un *un = (struct sockaddr_un *)addr; un->sun_family = AF_UNIX; @@ -189,7 +190,8 @@ static char *ipv6_get_default_authority(grpc_resolver_factory *factory, return ip_get_default_authority(uri); } -static int parse_ipv4(grpc_uri *uri, struct sockaddr_storage *addr, int *len) { +static int parse_ipv4(grpc_uri *uri, struct sockaddr_storage *addr, + size_t *len) { const char *host_port = uri->path; char *host; char *port; @@ -229,7 +231,8 @@ done: return result; } -static int parse_ipv6(grpc_uri *uri, struct sockaddr_storage *addr, int *len) { +static int parse_ipv6(grpc_uri *uri, struct sockaddr_storage *addr, + size_t *len) { const char *host_port = uri->path; char *host; char *port; @@ -275,7 +278,7 @@ static grpc_resolver *sockaddr_create( grpc_lb_policy *(*lb_policy_factory)(grpc_subchannel **subchannels, size_t num_subchannels), grpc_subchannel_factory *subchannel_factory, - int parse(grpc_uri *uri, struct sockaddr_storage *dst, int *len)) { + int parse(grpc_uri *uri, struct sockaddr_storage *dst, size_t *len)) { size_t i; int errors_found = 0; /* GPR_FALSE */ sockaddr_resolver *r; @@ -296,7 +299,7 @@ static grpc_resolver *sockaddr_create( gpr_slice_split(path_slice, ",", &path_parts); r->num_addrs = path_parts.count; r->addrs = gpr_malloc(sizeof(struct sockaddr_storage) * r->num_addrs); - r->addrs_len = gpr_malloc(sizeof(int) * r->num_addrs); + r->addrs_len = gpr_malloc(sizeof(*r->addrs_len) * r->num_addrs); for(i = 0; i < r->num_addrs; i++) { grpc_uri ith_uri = *uri; diff --git a/src/core/client_config/uri_parser.c b/src/core/client_config/uri_parser.c index 410a61c8cf3..5c2aa46e538 100644 --- a/src/core/client_config/uri_parser.c +++ b/src/core/client_config/uri_parser.c @@ -39,10 +39,10 @@ #include #include -static grpc_uri *bad_uri(const char *uri_text, int pos, const char *section, +static grpc_uri *bad_uri(const char *uri_text, size_t pos, const char *section, int suppress_errors) { char *line_prefix; - int pfx_len; + size_t pfx_len; if (!suppress_errors) { gpr_asprintf(&line_prefix, "bad uri.%s: '", section); @@ -60,8 +60,10 @@ static grpc_uri *bad_uri(const char *uri_text, int pos, const char *section, return NULL; } -static char *copy_fragment(const char *src, int begin, int end) { - char *out = gpr_malloc(end - begin + 1); +static char *copy_fragment(const char *src, size_t begin, size_t end) { + char *out; + GPR_ASSERT(end >= begin); + out = gpr_malloc(end - begin + 1); memcpy(out, src + begin, end - begin); out[end - begin] = 0; return out; @@ -69,13 +71,14 @@ static char *copy_fragment(const char *src, int begin, int end) { grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors) { grpc_uri *uri; - int scheme_begin = 0; - int scheme_end = -1; - int authority_begin = -1; - int authority_end = -1; - int path_begin = -1; - int path_end = -1; - int i; + size_t scheme_begin = 0; +#define NOT_SET (~(size_t)0) + size_t scheme_end = NOT_SET; + size_t authority_begin = NOT_SET; + size_t authority_end = NOT_SET; + size_t path_begin = NOT_SET; + size_t path_end = NOT_SET; + size_t i; for (i = scheme_begin; uri_text[i] != 0; i++) { if (uri_text[i] == ':') { @@ -92,13 +95,14 @@ grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors) { } break; } - if (scheme_end == -1) { + if (scheme_end == NOT_SET) { return bad_uri(uri_text, i, "scheme", suppress_errors); } if (uri_text[scheme_end + 1] == '/' && uri_text[scheme_end + 2] == '/') { authority_begin = scheme_end + 3; - for (i = authority_begin; uri_text[i] != 0 && authority_end == -1; i++) { + for (i = authority_begin; uri_text[i] != 0 && authority_end == NOT_SET; + i++) { if (uri_text[i] == '/') { authority_end = i; } @@ -109,10 +113,10 @@ grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors) { return bad_uri(uri_text, i, "fragment_not_supported", suppress_errors); } } - if (authority_end == -1 && uri_text[i] == 0) { + if (authority_end == NOT_SET && uri_text[i] == 0) { authority_end = i; } - if (authority_end == -1) { + if (authority_end == NOT_SET) { return bad_uri(uri_text, i, "authority", suppress_errors); } /* TODO(ctiller): parse the authority correctly */ diff --git a/src/core/debug/trace.c b/src/core/debug/trace.c index 1014b1f4db6..3b35d81cd84 100644 --- a/src/core/debug/trace.c +++ b/src/core/debug/trace.c @@ -59,9 +59,13 @@ void grpc_register_tracer(const char *name, int *flag) { static void add(const char *beg, const char *end, char ***ss, size_t *ns) { size_t n = *ns; size_t np = n + 1; - char *s = gpr_malloc(end - beg + 1); - memcpy(s, beg, end - beg); - s[end - beg] = 0; + char *s; + size_t len; + GPR_ASSERT(end >= beg); + len = (size_t)(end - beg); + s = gpr_malloc(len + 1); + memcpy(s, beg, len); + s[len] = 0; *ss = gpr_realloc(*ss, sizeof(char **) * np); (*ss)[n] = s; *ns = np; diff --git a/src/core/httpcli/parser.c b/src/core/httpcli/parser.c index 7b2a62060c3..404906d5ae2 100644 --- a/src/core/httpcli/parser.c +++ b/src/core/httpcli/parser.c @@ -96,13 +96,15 @@ static int add_header(grpc_httpcli_parser *parser) { gpr_log(GPR_ERROR, "Didn't find ':' in header string"); goto error; } - hdr.key = buf2str(beg, cur - beg); + GPR_ASSERT(cur >= beg); + hdr.key = buf2str(beg, (size_t)(cur - beg)); cur++; /* skip : */ while (cur != end && (*cur == ' ' || *cur == '\t')) { cur++; } - hdr.value = buf2str(cur, end - cur - 2); + GPR_ASSERT(end - cur >= 2); + hdr.value = buf2str(cur, (size_t)(end - cur) - 2); if (parser->r.hdr_count == parser->hdr_capacity) { parser->hdr_capacity = @@ -171,7 +173,7 @@ static int addbyte(grpc_httpcli_parser *parser, gpr_uint8 byte) { parser->r.body = gpr_realloc((void *)parser->r.body, parser->body_capacity); } - ((char *)parser->r.body)[parser->r.body_length] = byte; + parser->r.body[parser->r.body_length] = (char)byte; parser->r.body_length++; return 1; } diff --git a/src/core/iomgr/alarm.c b/src/core/iomgr/alarm.c index ddb30dc4bba..e31793475fb 100644 --- a/src/core/iomgr/alarm.c +++ b/src/core/iomgr/alarm.c @@ -83,7 +83,7 @@ static gpr_timespec compute_min_deadline(shard_type *shard) { } void grpc_alarm_list_init(gpr_timespec now) { - int i; + gpr_uint32 i; gpr_mu_init(&g_mu); gpr_mu_init(&g_checker_mu); diff --git a/src/core/iomgr/alarm_heap.c b/src/core/iomgr/alarm_heap.c index daed251982a..7bafdffcefd 100644 --- a/src/core/iomgr/alarm_heap.c +++ b/src/core/iomgr/alarm_heap.c @@ -43,9 +43,9 @@ position. This functor is called each time immediately after modifying a value in the underlying container, with the offset of the modified element as its argument. */ -static void adjust_upwards(grpc_alarm **first, int i, grpc_alarm *t) { +static void adjust_upwards(grpc_alarm **first, gpr_uint32 i, grpc_alarm *t) { while (i > 0) { - int parent = (i - 1) / 2; + gpr_uint32 parent = (i - 1u) / 2u; if (gpr_time_cmp(first[parent]->deadline, t->deadline) >= 0) break; first[i] = first[parent]; first[i]->heap_index = i; @@ -58,12 +58,12 @@ static void adjust_upwards(grpc_alarm **first, int i, grpc_alarm *t) { /* Adjusts a heap so as to move a hole at position i farther away from the root, until a suitable position is found for element t. Then, copies t into that position. */ -static void adjust_downwards(grpc_alarm **first, int i, int length, - grpc_alarm *t) { +static void adjust_downwards(grpc_alarm **first, gpr_uint32 i, + gpr_uint32 length, grpc_alarm *t) { for (;;) { - int left_child = 1 + 2 * i; - int right_child; - int next_i; + gpr_uint32 left_child = 1u + 2u * i; + gpr_uint32 right_child; + gpr_uint32 next_i; if (left_child >= length) break; right_child = left_child + 1; next_i = right_child < length && @@ -93,8 +93,8 @@ static void maybe_shrink(grpc_alarm_heap *heap) { } static void note_changed_priority(grpc_alarm_heap *heap, grpc_alarm *alarm) { - int i = alarm->heap_index; - int parent = (i - 1) / 2; + gpr_uint32 i = alarm->heap_index; + gpr_uint32 parent = (i - 1u) / 2u; if (gpr_time_cmp(heap->alarms[parent]->deadline, alarm->deadline) < 0) { adjust_upwards(heap->alarms, i, alarm); } else { @@ -122,7 +122,7 @@ int grpc_alarm_heap_add(grpc_alarm_heap *heap, grpc_alarm *alarm) { } void grpc_alarm_heap_remove(grpc_alarm_heap *heap, grpc_alarm *alarm) { - int i = alarm->heap_index; + gpr_uint32 i = alarm->heap_index; if (i == heap->alarm_count - 1) { heap->alarm_count--; maybe_shrink(heap); diff --git a/src/core/iomgr/alarm_heap.h b/src/core/iomgr/alarm_heap.h index 60db6c991b6..91d6ee3ca22 100644 --- a/src/core/iomgr/alarm_heap.h +++ b/src/core/iomgr/alarm_heap.h @@ -38,8 +38,8 @@ typedef struct { grpc_alarm **alarms; - int alarm_count; - int alarm_capacity; + gpr_uint32 alarm_count; + gpr_uint32 alarm_capacity; } grpc_alarm_heap; /* return 1 if the new alarm is the first alarm in the heap */ diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c index 6bd1b61f242..93aa3ad662c 100644 --- a/src/core/iomgr/pollset_posix.c +++ b/src/core/iomgr/pollset_posix.c @@ -420,7 +420,7 @@ static void basic_pollset_maybe_work(grpc_pollset *pollset, grpc_fd_watcher fd_watcher; int timeout; int r; - int nfds; + nfds_t nfds; if (pollset->in_flight_cbs) { /* Give do_promote priority so we don't starve it out */ diff --git a/src/core/iomgr/resolve_address.h b/src/core/iomgr/resolve_address.h index cc1bd428b07..9f361cb892d 100644 --- a/src/core/iomgr/resolve_address.h +++ b/src/core/iomgr/resolve_address.h @@ -40,7 +40,7 @@ typedef struct { char addr[GRPC_MAX_SOCKADDR_SIZE]; - int len; + size_t len; } grpc_resolved_address; typedef struct { diff --git a/src/core/iomgr/tcp_client.h b/src/core/iomgr/tcp_client.h index 8ad9b818e16..12296bd55b8 100644 --- a/src/core/iomgr/tcp_client.h +++ b/src/core/iomgr/tcp_client.h @@ -46,7 +46,7 @@ in this connection being established (in order to continue their work) */ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *tcp), void *arg, grpc_pollset_set *interested_parties, - const struct sockaddr *addr, int addr_len, + const struct sockaddr *addr, size_t addr_len, gpr_timespec deadline); #endif /* GRPC_INTERNAL_CORE_IOMGR_TCP_CLIENT_H */ diff --git a/src/core/iomgr/tcp_client_posix.c b/src/core/iomgr/tcp_client_posix.c index 66027f87a0d..7ca0a60c31e 100644 --- a/src/core/iomgr/tcp_client_posix.c +++ b/src/core/iomgr/tcp_client_posix.c @@ -195,7 +195,7 @@ finish: void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *ep), void *arg, grpc_pollset_set *interested_parties, - const struct sockaddr *addr, int addr_len, + const struct sockaddr *addr, size_t addr_len, gpr_timespec deadline) { int fd; grpc_dualstack_mode dsmode; diff --git a/src/core/security/base64.c b/src/core/security/base64.c index 8dfaef846f5..5226d2c5786 100644 --- a/src/core/security/base64.c +++ b/src/core/security/base64.c @@ -125,13 +125,14 @@ gpr_slice grpc_base64_decode(const char *b64, int url_safe) { static void decode_one_char(const unsigned char *codes, unsigned char *result, size_t *result_offset) { - gpr_uint32 packed = (codes[0] << 2) | (codes[1] >> 4); + gpr_uint32 packed = ((gpr_uint32)codes[0] << 2) | ((gpr_uint32)codes[1] >> 4); result[(*result_offset)++] = (unsigned char)packed; } static void decode_two_chars(const unsigned char *codes, unsigned char *result, size_t *result_offset) { - gpr_uint32 packed = (codes[0] << 10) | (codes[1] << 4) | (codes[2] >> 2); + gpr_uint32 packed = ((gpr_uint32)codes[0] << 10) | + ((gpr_uint32)codes[1] << 4) | ((gpr_uint32)codes[2] >> 2); result[(*result_offset)++] = (unsigned char)(packed >> 8); result[(*result_offset)++] = (unsigned char)(packed); } @@ -171,8 +172,9 @@ static int decode_group(const unsigned char *codes, size_t num_codes, decode_two_chars(codes, result, result_offset); } else { /* No padding. */ - gpr_uint32 packed = - (codes[0] << 18) | (codes[1] << 12) | (codes[2] << 6) | codes[3]; + gpr_uint32 packed = ((gpr_uint32)codes[0] << 18) | + ((gpr_uint32)codes[1] << 12) | + ((gpr_uint32)codes[2] << 6) | codes[3]; result[(*result_offset)++] = (unsigned char)(packed >> 16); result[(*result_offset)++] = (unsigned char)(packed >> 8); result[(*result_offset)++] = (unsigned char)(packed); diff --git a/src/core/security/jwt_verifier.c b/src/core/security/jwt_verifier.c index 38ad134a6ab..03f8c3783e9 100644 --- a/src/core/security/jwt_verifier.c +++ b/src/core/security/jwt_verifier.c @@ -769,7 +769,7 @@ void grpc_jwt_verifier_verify(grpc_jwt_verifier *verifier, GPR_ASSERT(verifier != NULL && jwt != NULL && audience != NULL && cb != NULL); dot = strchr(cur, '.'); if (dot == NULL) goto error; - json = parse_json_part_from_jwt(cur, dot - cur, &header_buffer); + json = parse_json_part_from_jwt(cur, (size_t)(dot - cur), &header_buffer); if (json == NULL) goto error; header = jose_header_from_json(json, header_buffer); if (header == NULL) goto error; @@ -777,7 +777,7 @@ void grpc_jwt_verifier_verify(grpc_jwt_verifier *verifier, cur = dot + 1; dot = strchr(cur, '.'); if (dot == NULL) goto error; - json = parse_json_part_from_jwt(cur, dot - cur, &claims_buffer); + json = parse_json_part_from_jwt(cur, (size_t)(dot - cur), &claims_buffer); if (json == NULL) goto error; claims = grpc_jwt_claims_from_json(json, claims_buffer); if (claims == NULL) goto error; diff --git a/src/core/surface/secure_channel_create.c b/src/core/surface/secure_channel_create.c index eccee246980..c68ba0e44bf 100644 --- a/src/core/surface/secure_channel_create.c +++ b/src/core/surface/secure_channel_create.c @@ -196,7 +196,7 @@ grpc_channel *grpc_secure_channel_create(grpc_credentials *creds, subchannel_factory *f; #define MAX_FILTERS 3 const grpc_channel_filter *filters[MAX_FILTERS]; - int n = 0; + size_t n = 0; if (grpc_find_security_connector_in_args(args) != NULL) { gpr_log(GPR_ERROR, "Cannot set security context in channel args."); diff --git a/src/core/tsi/fake_transport_security.c b/src/core/tsi/fake_transport_security.c index 29127c42690..a813c302213 100644 --- a/src/core/tsi/fake_transport_security.c +++ b/src/core/tsi/fake_transport_security.c @@ -171,7 +171,7 @@ static tsi_result fill_frame_from_bytes(const unsigned char* incoming_bytes, memcpy(frame->data + frame->offset, bytes_cursor, available_size); bytes_cursor += available_size; frame->offset += available_size; - *incoming_bytes_size = bytes_cursor - incoming_bytes; + *incoming_bytes_size = (size_t)(bytes_cursor - incoming_bytes); return TSI_INCOMPLETE_DATA; } memcpy(frame->data + frame->offset, bytes_cursor, to_read_size); @@ -187,12 +187,12 @@ static tsi_result fill_frame_from_bytes(const unsigned char* incoming_bytes, memcpy(frame->data + frame->offset, bytes_cursor, available_size); frame->offset += available_size; bytes_cursor += available_size; - *incoming_bytes_size = bytes_cursor - incoming_bytes; + *incoming_bytes_size = (size_t)(bytes_cursor - incoming_bytes); return TSI_INCOMPLETE_DATA; } memcpy(frame->data + frame->offset, bytes_cursor, to_read_size); bytes_cursor += to_read_size; - *incoming_bytes_size = bytes_cursor - incoming_bytes; + *incoming_bytes_size = (size_t)(bytes_cursor - incoming_bytes); tsi_fake_frame_reset(frame, 1 /* needs_draining */); return TSI_OK; } @@ -384,7 +384,8 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer( return TSI_OK; } if (!impl->outgoing.needs_draining) { - int next_message_to_send = impl->next_message_to_send + 2; + tsi_fake_handshake_message next_message_to_send = + impl->next_message_to_send + 2; const char* msg_string = tsi_fake_handshake_message_to_string(impl->next_message_to_send); result = bytes_to_frame((unsigned char*)msg_string, strlen(msg_string), diff --git a/src/core/tsi/ssl_transport_security.c b/src/core/tsi/ssl_transport_security.c index 0b416f6c9dd..6add4928658 100644 --- a/src/core/tsi/ssl_transport_security.c +++ b/src/core/tsi/ssl_transport_security.c @@ -131,10 +131,13 @@ static unsigned long openssl_thread_id_cb(void) { static void init_openssl(void) { int i; + int num_locks; SSL_library_init(); SSL_load_error_strings(); OpenSSL_add_all_algorithms(); - openssl_mutexes = malloc(CRYPTO_num_locks() * sizeof(gpr_mu)); + num_locks = CRYPTO_num_locks(); + GPR_ASSERT(num_locks > 0); + openssl_mutexes = malloc((size_t)num_locks * sizeof(gpr_mu)); GPR_ASSERT(openssl_mutexes != NULL); for (i = 0; i < CRYPTO_num_locks(); i++) { gpr_mu_init(&openssl_mutexes[i]); @@ -249,7 +252,7 @@ static tsi_result ssl_get_x509_common_name(X509* cert, unsigned char** utf8, gpr_log(GPR_ERROR, "Could not extract utf8 from asn1 string."); return TSI_OUT_OF_RESOURCES; } - *utf8_size = utf8_returned_size; + *utf8_size = (size_t)utf8_returned_size; return TSI_OK; } @@ -279,8 +282,8 @@ static tsi_result peer_property_from_x509_common_name( /* Gets the subject SANs from an X509 cert as a tsi_peer_property. */ static tsi_result add_subject_alt_names_properties_to_peer( tsi_peer* peer, GENERAL_NAMES* subject_alt_names, - int subject_alt_name_count) { - int i; + size_t subject_alt_name_count) { + size_t i; tsi_result result = TSI_OK; /* Reset for DNS entries filtering. */ @@ -301,7 +304,7 @@ static tsi_result add_subject_alt_names_properties_to_peer( } result = tsi_construct_string_peer_property( TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, - (const char*)dns_name, dns_name_size, + (const char*)dns_name, (size_t)dns_name_size, &peer->properties[peer->property_count++]); OPENSSL_free(dns_name); if (result != TSI_OK) break; @@ -318,9 +321,12 @@ static tsi_result peer_from_x509(X509* cert, int include_certificate_type, X509_get_ext_d2i(cert, NID_subject_alt_name, 0, 0); int subject_alt_name_count = (subject_alt_names != NULL) ? sk_GENERAL_NAME_num(subject_alt_names) : 0; - size_t property_count = (include_certificate_type ? 1 : 0) + - 1 /* common name */ + subject_alt_name_count; - tsi_result result = tsi_construct_peer(property_count, peer); + size_t property_count; + tsi_result result; + GPR_ASSERT(subject_alt_name_count >= 0); + property_count = (include_certificate_type ? (size_t)1 : 0) + + 1 /* common name */ + (size_t)subject_alt_name_count; + result = tsi_construct_peer(property_count, peer); if (result != TSI_OK) return result; do { if (include_certificate_type) { @@ -334,8 +340,8 @@ static tsi_result peer_from_x509(X509* cert, int include_certificate_type, if (result != TSI_OK) break; if (subject_alt_name_count != 0) { - result = add_subject_alt_names_properties_to_peer(peer, subject_alt_names, - subject_alt_name_count); + result = add_subject_alt_names_properties_to_peer( + peer, subject_alt_names, (size_t)subject_alt_name_count); if (result != TSI_OK) break; } } while (0); @@ -387,7 +393,7 @@ static tsi_result do_ssl_read(SSL* ssl, unsigned char* unprotected_bytes, return TSI_PROTOCOL_FAILURE; } } - *unprotected_bytes_size = read_from_ssl; + *unprotected_bytes_size = (size_t)read_from_ssl; return TSI_OK; } @@ -616,7 +622,7 @@ static tsi_result build_alpn_protocol_name_list( gpr_log(GPR_ERROR, "Invalid 0-length protocol name."); return TSI_INVALID_ARGUMENT; } - *protocol_name_list_length += alpn_protocols_lengths[i] + 1; + *protocol_name_list_length += (size_t)alpn_protocols_lengths[i] + 1; } *protocol_name_list = malloc(*protocol_name_list_length); if (*protocol_name_list == NULL) return TSI_OUT_OF_RESOURCES; @@ -648,7 +654,7 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self, tsi_result result = TSI_OK; /* First see if we have some pending data in the SSL BIO. */ - size_t pending_in_ssl = BIO_pending(impl->from_ssl); + int pending_in_ssl = BIO_pending(impl->from_ssl); if (pending_in_ssl > 0) { *unprotected_bytes_size = 0; read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames, @@ -658,7 +664,7 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self, "Could not read from BIO even though some data is pending"); return TSI_INTERNAL_ERROR; } - *protected_output_frames_size = read_from_ssl; + *protected_output_frames_size = (size_t)read_from_ssl; return TSI_OK; } @@ -684,7 +690,7 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self, gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); return TSI_INTERNAL_ERROR; } - *protected_output_frames_size = read_from_ssl; + *protected_output_frames_size = (size_t)read_from_ssl; *unprotected_bytes_size = available; impl->buffer_offset = 0; return TSI_OK; @@ -696,6 +702,7 @@ static tsi_result ssl_protector_protect_flush( tsi_result result = TSI_OK; tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self; int read_from_ssl = 0; + int pending; if (impl->buffer_offset != 0) { result = do_ssl_write(impl->ssl, impl->buffer, impl->buffer_offset); @@ -703,7 +710,9 @@ static tsi_result ssl_protector_protect_flush( impl->buffer_offset = 0; } - *still_pending_size = BIO_pending(impl->from_ssl); + pending = BIO_pending(impl->from_ssl); + GPR_ASSERT(pending >= 0); + *still_pending_size = (size_t)pending; if (*still_pending_size == 0) return TSI_OK; read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames, @@ -712,8 +721,10 @@ static tsi_result ssl_protector_protect_flush( gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); return TSI_INTERNAL_ERROR; } - *protected_output_frames_size = read_from_ssl; - *still_pending_size = BIO_pending(impl->from_ssl); + *protected_output_frames_size = (size_t)read_from_ssl; + pending = BIO_pending(impl->from_ssl); + GPR_ASSERT(pending >= 0); + *still_pending_size = (size_t)pending; return TSI_OK; } @@ -747,7 +758,7 @@ static tsi_result ssl_protector_unprotect( written_into_ssl); return TSI_INTERNAL_ERROR; } - *protected_frames_bytes_size = written_into_ssl; + *protected_frames_bytes_size = (size_t)written_into_ssl; /* Now try to read some data again. */ result = do_ssl_read(impl->ssl, unprotected_bytes, unprotected_bytes_size); @@ -817,7 +828,7 @@ static tsi_result ssl_handshaker_process_bytes_from_peer( impl->result = TSI_INTERNAL_ERROR; return impl->result; } - *bytes_size = bytes_written_into_ssl_size; + *bytes_size = (size_t)bytes_written_into_ssl_size; if (!tsi_handshaker_is_in_progress(self)) { impl->result = TSI_OK; diff --git a/templates/Makefile.template b/templates/Makefile.template index 797f0ab57fa..5be4eedfee0 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -265,7 +265,7 @@ CXXFLAGS += -std=c++11 else CXXFLAGS += -std=c++0x endif -CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter +CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter -Wsign-conversion LDFLAGS += -g CPPFLAGS += $(CPPFLAGS_$(CONFIG)) diff --git a/test/core/end2end/tests/bad_hostname.c b/test/core/end2end/tests/bad_hostname.c index 8f28fa1e630..93e2df1e43b 100644 --- a/test/core/end2end/tests/bad_hostname.c +++ b/test/core/end2end/tests/bad_hostname.c @@ -146,7 +146,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(1), 1); diff --git a/test/core/end2end/tests/cancel_after_accept.c b/test/core/end2end/tests/cancel_after_accept.c index 313e0b05bda..10e62275ab0 100644 --- a/test/core/end2end/tests/cancel_after_accept.c +++ b/test/core/end2end/tests/cancel_after_accept.c @@ -165,7 +165,7 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = grpc_server_request_call(f.server, &s, &call_details, @@ -195,7 +195,7 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(3), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(3), NULL); GPR_ASSERT(GRPC_CALL_OK == error); GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c, NULL)); diff --git a/test/core/end2end/tests/cancel_after_accept_and_writes_closed.c b/test/core/end2end/tests/cancel_after_accept_and_writes_closed.c index 2430a6d218f..4fed5be5f79 100644 --- a/test/core/end2end/tests/cancel_after_accept_and_writes_closed.c +++ b/test/core/end2end/tests/cancel_after_accept_and_writes_closed.c @@ -169,7 +169,7 @@ static void test_cancel_after_accept_and_writes_closed( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = grpc_server_request_call(f.server, &s, &call_details, @@ -199,7 +199,7 @@ static void test_cancel_after_accept_and_writes_closed( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(3), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(3), NULL); GPR_ASSERT(GRPC_CALL_OK == error); GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c, NULL)); diff --git a/test/core/end2end/tests/cancel_after_invoke.c b/test/core/end2end/tests/cancel_after_invoke.c index 9991ee02f0c..40595e4c7b9 100644 --- a/test/core/end2end/tests/cancel_after_invoke.c +++ b/test/core/end2end/tests/cancel_after_invoke.c @@ -101,7 +101,7 @@ static void end_test(grpc_end2end_test_fixture *f) { /* Cancel after invoke, no payload */ static void test_cancel_after_invoke(grpc_end2end_test_config config, - cancellation_mode mode, int test_ops) { + cancellation_mode mode, size_t test_ops) { grpc_op ops[6]; grpc_op *op; grpc_call *c; diff --git a/test/core/end2end/tests/cancel_before_invoke.c b/test/core/end2end/tests/cancel_before_invoke.c index 8b582e0c422..c049e0c2d63 100644 --- a/test/core/end2end/tests/cancel_before_invoke.c +++ b/test/core/end2end/tests/cancel_before_invoke.c @@ -99,7 +99,7 @@ static void end_test(grpc_end2end_test_fixture *f) { /* Cancel before invoke */ static void test_cancel_before_invoke(grpc_end2end_test_config config, - int test_ops) { + size_t test_ops) { grpc_op ops[6]; grpc_op *op; grpc_call *c; @@ -189,7 +189,7 @@ static void test_cancel_before_invoke(grpc_end2end_test_config config, } void grpc_end2end_tests(grpc_end2end_test_config config) { - int i; + size_t i; for (i = 1; i <= 6; i++) { test_cancel_before_invoke(config, i); } diff --git a/test/core/end2end/tests/census_simple_request.c b/test/core/end2end/tests/census_simple_request.c index 36b9e928844..adf855ca60b 100644 --- a/test/core/end2end/tests/census_simple_request.c +++ b/test/core/end2end/tests/census_simple_request.c @@ -145,7 +145,7 @@ static void test_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -173,7 +173,7 @@ static void test_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); diff --git a/test/core/end2end/tests/default_host.c b/test/core/end2end/tests/default_host.c index 57f65b834b0..7b62505a9a0 100644 --- a/test/core/end2end/tests/default_host.c +++ b/test/core/end2end/tests/default_host.c @@ -154,7 +154,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(error == GRPC_CALL_OK); error = @@ -191,7 +191,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(error == GRPC_CALL_OK); cq_expect_completion(cqv, tag(102), 1); diff --git a/test/core/end2end/tests/disappearing_server.c b/test/core/end2end/tests/disappearing_server.c index 09762705e32..de3ea16f667 100644 --- a/test/core/end2end/tests/disappearing_server.c +++ b/test/core/end2end/tests/disappearing_server.c @@ -131,7 +131,7 @@ static void do_request_and_shutdown_server(grpc_end2end_test_fixture *f, op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -163,7 +163,7 @@ static void do_request_and_shutdown_server(grpc_end2end_test_fixture *f, op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); diff --git a/test/core/end2end/tests/early_server_shutdown_finishes_inflight_calls.c b/test/core/end2end/tests/early_server_shutdown_finishes_inflight_calls.c index 233bc9bee2a..ad7def09a94 100644 --- a/test/core/end2end/tests/early_server_shutdown_finishes_inflight_calls.c +++ b/test/core/end2end/tests/early_server_shutdown_finishes_inflight_calls.c @@ -139,7 +139,7 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -155,7 +155,7 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); /* shutdown and destroy the server */ diff --git a/test/core/end2end/tests/graceful_server_shutdown.c b/test/core/end2end/tests/graceful_server_shutdown.c index d4e7a1ac6d1..df420a9846d 100644 --- a/test/core/end2end/tests/graceful_server_shutdown.c +++ b/test/core/end2end/tests/graceful_server_shutdown.c @@ -146,7 +146,7 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -178,7 +178,7 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); diff --git a/test/core/end2end/tests/invoke_large_request.c b/test/core/end2end/tests/invoke_large_request.c index 76770845116..f79d146da10 100644 --- a/test/core/end2end/tests/invoke_large_request.c +++ b/test/core/end2end/tests/invoke_large_request.c @@ -171,7 +171,7 @@ static void test_invoke_large_request(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -192,7 +192,7 @@ static void test_invoke_large_request(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); @@ -216,7 +216,7 @@ static void test_invoke_large_request(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(103), 1); diff --git a/test/core/end2end/tests/max_concurrent_streams.c b/test/core/end2end/tests/max_concurrent_streams.c index 0ba620b8514..87eb4dd451e 100644 --- a/test/core/end2end/tests/max_concurrent_streams.c +++ b/test/core/end2end/tests/max_concurrent_streams.c @@ -147,7 +147,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -175,7 +175,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); @@ -280,7 +280,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c1, ops, op - ops, tag(301), NULL); + error = grpc_call_start_batch(c1, ops, (size_t)(op - ops), tag(301), NULL); GPR_ASSERT(GRPC_CALL_OK == error); op = ops; @@ -297,7 +297,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c1, ops, op - ops, tag(302), NULL); + error = grpc_call_start_batch(c1, ops, (size_t)(op - ops), tag(302), NULL); GPR_ASSERT(GRPC_CALL_OK == error); op = ops; @@ -310,7 +310,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c2, ops, op - ops, tag(401), NULL); + error = grpc_call_start_batch(c2, ops, (size_t)(op - ops), tag(401), NULL); GPR_ASSERT(GRPC_CALL_OK == error); op = ops; @@ -327,7 +327,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c2, ops, op - ops, tag(402), NULL); + error = grpc_call_start_batch(c2, ops, (size_t)(op - ops), tag(402), NULL); GPR_ASSERT(GRPC_CALL_OK == error); got_client_start = 0; @@ -372,7 +372,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s1, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s1, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); @@ -406,7 +406,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s2, ops, op - ops, tag(202), NULL); + error = grpc_call_start_batch(s2, ops, (size_t)(op - ops), tag(202), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(live_call + 2), 1); diff --git a/test/core/end2end/tests/max_message_length.c b/test/core/end2end/tests/max_message_length.c index 2b9560716fd..782b9d0f264 100644 --- a/test/core/end2end/tests/max_message_length.c +++ b/test/core/end2end/tests/max_message_length.c @@ -167,7 +167,7 @@ static void test_max_message_length(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -183,7 +183,7 @@ static void test_max_message_length(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); diff --git a/test/core/end2end/tests/ping_pong_streaming.c b/test/core/end2end/tests/ping_pong_streaming.c index 43abda4d7f3..39682d8bc50 100644 --- a/test/core/end2end/tests/ping_pong_streaming.c +++ b/test/core/end2end/tests/ping_pong_streaming.c @@ -154,7 +154,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -175,7 +175,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(101), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(101), NULL); GPR_ASSERT(GRPC_CALL_OK == error); for (i = 0; i < messages; i++) { @@ -193,7 +193,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(2), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), NULL); GPR_ASSERT(GRPC_CALL_OK == error); op = ops; @@ -202,7 +202,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); cq_verify(cqv); @@ -213,7 +213,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(103), 1); cq_expect_completion(cqv, tag(2), 1); @@ -233,7 +233,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(3), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(3), NULL); GPR_ASSERT(GRPC_CALL_OK == error); op = ops; @@ -244,7 +244,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(104), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(104), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(1), 1); diff --git a/test/core/end2end/tests/registered_call.c b/test/core/end2end/tests/registered_call.c index eddce6ded44..b3156e0248a 100644 --- a/test/core/end2end/tests/registered_call.c +++ b/test/core/end2end/tests/registered_call.c @@ -148,7 +148,7 @@ static void simple_request_body(grpc_end2end_test_fixture f, void *rc) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -176,7 +176,7 @@ static void simple_request_body(grpc_end2end_test_fixture f, void *rc) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); diff --git a/test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c b/test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c index 2345f940443..21e0bbcc49c 100644 --- a/test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c +++ b/test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c @@ -191,7 +191,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -213,7 +213,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); @@ -237,7 +237,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(103), 1); diff --git a/test/core/end2end/tests/request_response_with_metadata_and_payload.c b/test/core/end2end/tests/request_response_with_metadata_and_payload.c index a4cc27896cf..d0604cc6b6f 100644 --- a/test/core/end2end/tests/request_response_with_metadata_and_payload.c +++ b/test/core/end2end/tests/request_response_with_metadata_and_payload.c @@ -175,7 +175,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -197,7 +197,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); @@ -221,7 +221,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(103), 1); diff --git a/test/core/end2end/tests/request_response_with_payload.c b/test/core/end2end/tests/request_response_with_payload.c index ff00ae6d9dd..0b303268fc6 100644 --- a/test/core/end2end/tests/request_response_with_payload.c +++ b/test/core/end2end/tests/request_response_with_payload.c @@ -164,7 +164,7 @@ static void request_response_with_payload(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -185,7 +185,7 @@ static void request_response_with_payload(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); @@ -209,7 +209,7 @@ static void request_response_with_payload(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(103), 1); diff --git a/test/core/end2end/tests/request_response_with_payload_and_call_creds.c b/test/core/end2end/tests/request_response_with_payload_and_call_creds.c index d862274fe31..08bba06f40a 100644 --- a/test/core/end2end/tests/request_response_with_payload_and_call_creds.c +++ b/test/core/end2end/tests/request_response_with_payload_and_call_creds.c @@ -247,7 +247,7 @@ static void request_response_with_payload_and_call_creds( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -280,7 +280,7 @@ static void request_response_with_payload_and_call_creds( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); @@ -304,7 +304,7 @@ static void request_response_with_payload_and_call_creds( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(103), 1); @@ -464,7 +464,7 @@ static void test_request_with_server_rejecting_client_creds( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(error == GRPC_CALL_OK); cq_expect_completion(cqv, tag(1), 1); diff --git a/test/core/end2end/tests/request_response_with_trailing_metadata_and_payload.c b/test/core/end2end/tests/request_response_with_trailing_metadata_and_payload.c index 8b764751f6a..c040b9fac14 100644 --- a/test/core/end2end/tests/request_response_with_trailing_metadata_and_payload.c +++ b/test/core/end2end/tests/request_response_with_trailing_metadata_and_payload.c @@ -178,7 +178,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -200,7 +200,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); @@ -225,7 +225,7 @@ static void test_request_response_with_metadata_and_payload( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(103), 1); diff --git a/test/core/end2end/tests/request_with_compressed_payload.c b/test/core/end2end/tests/request_with_compressed_payload.c index 299943c548f..c50eaba8b24 100644 --- a/test/core/end2end/tests/request_with_compressed_payload.c +++ b/test/core/end2end/tests/request_with_compressed_payload.c @@ -186,7 +186,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -215,7 +215,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); @@ -234,7 +234,7 @@ static void request_with_payload_template( op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(103), 1); diff --git a/test/core/end2end/tests/request_with_flags.c b/test/core/end2end/tests/request_with_flags.c index eb2e5dc7e8b..b9cdf5168ce 100644 --- a/test/core/end2end/tests/request_with_flags.c +++ b/test/core/end2end/tests/request_with_flags.c @@ -160,7 +160,7 @@ static void test_invoke_request_with_flags( op->reserved = NULL; op++; expectation = call_start_batch_expected_result; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(expectation == error); if (expectation == GRPC_CALL_OK) { diff --git a/test/core/end2end/tests/request_with_large_metadata.c b/test/core/end2end/tests/request_with_large_metadata.c index 98e47aaf98e..87529639a76 100644 --- a/test/core/end2end/tests/request_with_large_metadata.c +++ b/test/core/end2end/tests/request_with_large_metadata.c @@ -121,7 +121,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { char *details = NULL; size_t details_capacity = 0; int was_cancelled = 2; - const int large_size = 64 * 1024; + const size_t large_size = 64 * 1024; c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", "foo.test.google.fr", deadline, NULL); @@ -167,7 +167,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -188,7 +188,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); @@ -207,7 +207,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(103), 1); diff --git a/test/core/end2end/tests/request_with_payload.c b/test/core/end2end/tests/request_with_payload.c index 149dbaeb002..a323b43ab08 100644 --- a/test/core/end2end/tests/request_with_payload.c +++ b/test/core/end2end/tests/request_with_payload.c @@ -158,7 +158,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( @@ -178,7 +178,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); @@ -197,7 +197,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(103), 1); diff --git a/test/core/end2end/tests/server_finishes_request.c b/test/core/end2end/tests/server_finishes_request.c index 8bacc6c7303..bdc18a5e381 100644 --- a/test/core/end2end/tests/server_finishes_request.c +++ b/test/core/end2end/tests/server_finishes_request.c @@ -145,7 +145,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -173,7 +173,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); diff --git a/test/core/end2end/tests/simple_delayed_request.c b/test/core/end2end/tests/simple_delayed_request.c index 9133aacc352..14e0ac8f665 100644 --- a/test/core/end2end/tests/simple_delayed_request.c +++ b/test/core/end2end/tests/simple_delayed_request.c @@ -140,7 +140,7 @@ static void simple_delayed_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); config.init_server(f, server_args); @@ -170,7 +170,7 @@ static void simple_delayed_request_body(grpc_end2end_test_config config, op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); diff --git a/test/core/end2end/tests/simple_request.c b/test/core/end2end/tests/simple_request.c index 0f62d958ae0..a8746408372 100644 --- a/test/core/end2end/tests/simple_request.c +++ b/test/core/end2end/tests/simple_request.c @@ -155,7 +155,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -192,7 +192,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); diff --git a/test/core/end2end/tests/simple_request_with_high_initial_sequence_number.c b/test/core/end2end/tests/simple_request_with_high_initial_sequence_number.c index 0067bb4bef7..44d6a60c104 100644 --- a/test/core/end2end/tests/simple_request_with_high_initial_sequence_number.c +++ b/test/core/end2end/tests/simple_request_with_high_initial_sequence_number.c @@ -149,7 +149,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); error = @@ -177,7 +177,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); diff --git a/test/core/util/parse_hexstring.c b/test/core/util/parse_hexstring.c index bf5bc84b483..0bac8fef329 100644 --- a/test/core/util/parse_hexstring.c +++ b/test/core/util/parse_hexstring.c @@ -35,7 +35,7 @@ #include gpr_slice parse_hexstring(const char *hexstring) { - int nibbles = 0; + size_t nibbles = 0; const char *p = 0; gpr_uint8 *out; gpr_uint8 temp; diff --git a/test/core/util/reconnect_server.c b/test/core/util/reconnect_server.c index a06cb50b3a3..35d84d0f3d8 100644 --- a/test/core/util/reconnect_server.c +++ b/test/core/util/reconnect_server.c @@ -81,7 +81,8 @@ static void on_connect(void *arg, grpc_endpoint *tcp) { } else { if (last_colon == NULL) { gpr_log(GPR_ERROR, "peer does not contain a ':'"); - } else if (strncmp(server->peer, peer, last_colon - peer) != 0) { + } else if (strncmp(server->peer, peer, (size_t)(last_colon - peer)) != + 0) { gpr_log(GPR_ERROR, "mismatched peer! %s vs %s", server->peer, peer); } gpr_free(peer); diff --git a/test/core/util/test_config.c b/test/core/util/test_config.c index 685bdff5308..f5d5cdb57c5 100644 --- a/test/core/util/test_config.c +++ b/test/core/util/test_config.c @@ -42,12 +42,12 @@ double g_fixture_slowdown_factor = 1.0; #if GPR_GETPID_IN_UNISTD_H #include -static int seed(void) { return getpid(); } +static unsigned seed(void) { return (unsigned)getpid(); } #endif #if GPR_GETPID_IN_PROCESS_H #include -static int seed(void) { return _getpid(); } +static unsigned seed(void) { return _getpid(); } #endif #if GPR_WINDOWS_CRASH_HANDLER From 6ff393f4051f03c9bdebb2ca840f993f9924fd56 Mon Sep 17 00:00:00 2001 From: Tim Emiola Date: Thu, 10 Sep 2015 11:42:47 -0700 Subject: [PATCH 24/32] Remove redundant docker files from grpc repo --- tools/dockerfile/grpc_build_deb/Dockerfile | 51 ------------------ tools/dockerfile/grpc_build_deb/version.txt | 1 - tools/dockerfile/grpc_ruby_deb/Dockerfile | 60 --------------------- tools/dockerfile/grpc_ruby_deb/README.md | 5 -- 4 files changed, 117 deletions(-) delete mode 100644 tools/dockerfile/grpc_build_deb/Dockerfile delete mode 100644 tools/dockerfile/grpc_build_deb/version.txt delete mode 100644 tools/dockerfile/grpc_ruby_deb/Dockerfile delete mode 100644 tools/dockerfile/grpc_ruby_deb/README.md diff --git a/tools/dockerfile/grpc_build_deb/Dockerfile b/tools/dockerfile/grpc_build_deb/Dockerfile deleted file mode 100644 index 7f025b67125..00000000000 --- a/tools/dockerfile/grpc_build_deb/Dockerfile +++ /dev/null @@ -1,51 +0,0 @@ -# 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. - -# Dockerfile to build Debian packages for gRPC C core. -FROM grpc/base - -# Add the file containing the gRPC version -ADD version.txt version.txt - -# Add the update-to-date distpackages folder -ADD distpackages distpackages - -# Install dependencies -RUN echo 'deb http://http.debian.net/debian experimental main contrib non-free' >> /etc/apt/sources.list -RUN apt-get update \ - && apt-get -t experimental install -y openssl=1.0.2-1 \ - && apt-get install -y lintian - -# Get the source from GitHub -RUN git clone https://github.com/grpc/grpc.git /var/local/git/grpc -RUN cd /var/local/git/grpc && \ - git pull --recurse-submodules && \ - git submodule update --init --recursive - -RUN /bin/bash -l -c 'cd /distpackages && ./build_deb_packages.sh' diff --git a/tools/dockerfile/grpc_build_deb/version.txt b/tools/dockerfile/grpc_build_deb/version.txt deleted file mode 100644 index a918a2aa18d..00000000000 --- a/tools/dockerfile/grpc_build_deb/version.txt +++ /dev/null @@ -1 +0,0 @@ -0.6.0 diff --git a/tools/dockerfile/grpc_ruby_deb/Dockerfile b/tools/dockerfile/grpc_ruby_deb/Dockerfile deleted file mode 100644 index 679fa51f5d5..00000000000 --- a/tools/dockerfile/grpc_ruby_deb/Dockerfile +++ /dev/null @@ -1,60 +0,0 @@ -# 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. - -# Dockerfile for gRPC Ruby, but using Debian packages for gRPC C core. -FROM grpc/ruby_base - -# Pull the latest sources -RUN cd /var/local/git/grpc \ - && git pull --recurse-submodules \ - && git submodule update --init --recursive - -# Make sure we don't rely on things that shouldn't be there. -RUN make clean -C /var/local/git/grpc - -# Debian packages need to be supplied externally -ADD libgrpc_amd64.deb libgrpc_amd64.deb -ADD libgrpc-dev_amd64.deb libgrpc-dev_amd64.deb - -# Install the C core .deb packages -RUN /bin/bash -l -c 'dpkg -i libgrpc_amd64.deb libgrpc-dev_amd64.deb' - -# Build ruby gRPC and run its tests -RUN /bin/bash -l -c 'cd /var/local/git/grpc/src/ruby && bundle && rake' - -# Add a cacerts directory containing the Google root pem file, allowing the -# ruby client to access the production test instance -ADD cacerts cacerts - -# Add a service_account directory containing the auth creds file -ADD service_account service_account - -# Specify the default command such that the interop server runs on its known -# testing port -CMD ["/bin/bash", "-l", "-c", "ruby /var/local/git/grpc/src/ruby/bin/interop/interop_server.rb --use_tls --port 8060"] diff --git a/tools/dockerfile/grpc_ruby_deb/README.md b/tools/dockerfile/grpc_ruby_deb/README.md deleted file mode 100644 index 0a3716b9385..00000000000 --- a/tools/dockerfile/grpc_ruby_deb/README.md +++ /dev/null @@ -1,5 +0,0 @@ -GRPC RUBY Base Dockerfile (Debian package version) -======================== - -Dockerfile for creating the Ruby gRPC development Docker instance. -Uses gRPC C core Debian packages instead of installing it using make. From 32ca48ce0b963949ff29d2dcd526b174679779aa Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Sep 2015 11:47:15 -0700 Subject: [PATCH 25/32] Core compiles with -Wsign-conversion --- src/core/iomgr/tcp_posix.c | 21 +++--- src/core/iomgr/tcp_server.h | 2 +- src/core/iomgr/tcp_server_posix.c | 7 +- src/core/iomgr/udp_server.c | 9 +-- src/core/iomgr/udp_server.h | 4 +- src/core/support/stack_lockfree.c | 2 +- src/core/support/stack_lockfree.h | 4 +- src/core/surface/channel.c | 6 +- src/core/surface/channel_create.c | 2 +- src/core/surface/server.c | 11 ++-- src/core/transport/chttp2/bin_encoder.c | 14 ++-- src/core/transport/chttp2/frame_data.c | 16 +++-- src/core/transport/chttp2/frame_goaway.c | 2 +- src/core/transport/chttp2/frame_settings.c | 4 +- src/core/transport/chttp2/hpack_parser.c | 4 +- src/core/transport/chttp2/hpack_parser.h | 2 +- src/core/transport/chttp2/hpack_table.c | 2 +- src/core/transport/chttp2/incoming_metadata.c | 2 +- src/core/transport/chttp2/internal.h | 25 +++---- src/core/transport/chttp2/parsing.c | 22 ++++--- src/core/transport/chttp2/stream_encoder.c | 34 +++++----- src/core/transport/chttp2/timeout_encoding.c | 6 +- src/core/transport/chttp2/varint.c | 5 +- src/core/transport/chttp2/varint.h | 9 +-- src/core/transport/chttp2_transport.c | 5 +- src/core/transport/metadata.c | 3 +- test/core/channel/channel_args_test.c | 11 ++-- test/core/end2end/dualstack_socket_test.c | 4 +- test/core/end2end/no_server_test.c | 4 +- test/core/fling/client.c | 7 +- test/core/fling/fling_stream_test.c | 4 +- test/core/fling/fling_test.c | 2 +- test/core/fling/server.c | 2 +- test/core/httpcli/httpcli_test.c | 2 +- test/core/iomgr/alarm_heap_test.c | 65 ++++++++++--------- test/core/iomgr/tcp_posix_test.c | 36 +++++----- test/core/json/json_rewrite.c | 26 ++++---- test/core/json/json_rewrite_test.c | 28 ++++---- test/core/profiling/timers_test.c | 16 ++--- test/core/security/base64_test.c | 4 +- test/core/security/json_token_test.c | 11 ++-- test/core/support/murmur_hash_test.c | 4 +- test/core/support/slice_test.c | 10 +-- test/core/support/stack_lockfree_test.c | 14 ++-- test/core/support/time_test.c | 18 ++--- test/core/surface/byte_buffer_reader_test.c | 8 +-- test/core/surface/completion_queue_test.c | 8 +-- test/core/surface/lame_client_test.c | 2 +- test/core/transport/chttp2/hpack_table_test.c | 4 +- .../transport/chttp2/stream_encoder_test.c | 10 +-- test/core/transport/chttp2/stream_map_test.c | 6 +- test/core/transport/metadata_test.c | 12 ++-- 52 files changed, 282 insertions(+), 259 deletions(-) diff --git a/src/core/iomgr/tcp_posix.c b/src/core/iomgr/tcp_posix.c index 0db7cd9f0e1..81f04494eb5 100644 --- a/src/core/iomgr/tcp_posix.c +++ b/src/core/iomgr/tcp_posix.c @@ -67,8 +67,8 @@ typedef struct { grpc_endpoint base; grpc_fd *em_fd; int fd; - int iov_size; /* Number of slices to allocate per read attempt */ int finished_edge; + size_t iov_size; /* Number of slices to allocate per read attempt */ size_t slice_size; gpr_refcount refcount; @@ -215,8 +215,9 @@ static void tcp_continue_read(grpc_tcp *tcp) { } else { GPR_ASSERT((size_t)read_bytes <= tcp->incoming_buffer->length); if ((size_t)read_bytes < tcp->incoming_buffer->length) { - gpr_slice_buffer_trim_end(tcp->incoming_buffer, - tcp->incoming_buffer->length - read_bytes); + gpr_slice_buffer_trim_end( + tcp->incoming_buffer, + tcp->incoming_buffer->length - (size_t)read_bytes); } else if (tcp->iov_size < MAX_READ_IOVEC) { ++tcp->iov_size; } @@ -264,12 +265,12 @@ static grpc_endpoint_op_status tcp_read(grpc_endpoint *ep, static grpc_endpoint_op_status tcp_flush(grpc_tcp *tcp) { struct msghdr msg; struct iovec iov[MAX_WRITE_IOVEC]; - int iov_size; + size_t iov_size; ssize_t sent_length; - ssize_t sending_length; - ssize_t trailing; - ssize_t unwind_slice_idx; - ssize_t unwind_byte_idx; + size_t sending_length; + size_t trailing; + size_t unwind_slice_idx; + size_t unwind_byte_idx; for (;;) { sending_length = 0; @@ -319,9 +320,9 @@ static grpc_endpoint_op_status tcp_flush(grpc_tcp *tcp) { } GPR_ASSERT(tcp->outgoing_byte_idx == 0); - trailing = sending_length - sent_length; + trailing = sending_length - (size_t)sent_length; while (trailing > 0) { - ssize_t slice_length; + size_t slice_length; tcp->outgoing_slice_idx--; slice_length = GPR_SLICE_LENGTH( diff --git a/src/core/iomgr/tcp_server.h b/src/core/iomgr/tcp_server.h index 66bb3ef7018..5165f5c5ca8 100644 --- a/src/core/iomgr/tcp_server.h +++ b/src/core/iomgr/tcp_server.h @@ -62,7 +62,7 @@ void grpc_tcp_server_start(grpc_tcp_server *server, grpc_pollset **pollsets, /* TODO(ctiller): deprecate this, and make grpc_tcp_server_add_ports to handle all of the multiple socket port matching logic in one place */ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr, - int addr_len); + size_t addr_len); /* Returns the file descriptor of the Nth listening socket on this server, or -1 if the index is out of bounds. diff --git a/src/core/iomgr/tcp_server_posix.c b/src/core/iomgr/tcp_server_posix.c index 6399aaadb9c..6b81090108f 100644 --- a/src/core/iomgr/tcp_server_posix.c +++ b/src/core/iomgr/tcp_server_posix.c @@ -256,7 +256,8 @@ static int get_max_accept_queue_size(void) { } /* Prepare a recently-created socket for listening. */ -static int prepare_socket(int fd, const struct sockaddr *addr, int addr_len) { +static int prepare_socket(int fd, const struct sockaddr *addr, + size_t addr_len) { struct sockaddr_storage sockname_temp; socklen_t sockname_len; @@ -365,7 +366,7 @@ error: } static int add_socket_to_server(grpc_tcp_server *s, int fd, - const struct sockaddr *addr, int addr_len) { + const struct sockaddr *addr, size_t addr_len) { server_port *sp; int port; char *addr_str; @@ -398,7 +399,7 @@ static int add_socket_to_server(grpc_tcp_server *s, int fd, } int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr, - int addr_len) { + size_t addr_len) { int allocated_port1 = -1; int allocated_port2 = -1; unsigned i; diff --git a/src/core/iomgr/udp_server.c b/src/core/iomgr/udp_server.c index 6429c38b289..95ae698781b 100644 --- a/src/core/iomgr/udp_server.c +++ b/src/core/iomgr/udp_server.c @@ -221,7 +221,8 @@ void grpc_udp_server_destroy( } /* Prepare a recently-created socket for listening. */ -static int prepare_socket(int fd, const struct sockaddr *addr, int addr_len) { +static int prepare_socket(int fd, const struct sockaddr *addr, + size_t addr_len) { struct sockaddr_storage sockname_temp; socklen_t sockname_len; int get_local_ip; @@ -287,7 +288,7 @@ static void on_read(void *arg, int success) { } static int add_socket_to_server(grpc_udp_server *s, int fd, - const struct sockaddr *addr, int addr_len, + const struct sockaddr *addr, size_t addr_len, grpc_udp_server_read_cb read_cb) { server_port *sp; int port; @@ -319,8 +320,8 @@ static int add_socket_to_server(grpc_udp_server *s, int fd, return port; } -int grpc_udp_server_add_port(grpc_udp_server *s, const void *addr, int addr_len, - grpc_udp_server_read_cb read_cb) { +int grpc_udp_server_add_port(grpc_udp_server *s, const void *addr, + size_t addr_len, grpc_udp_server_read_cb read_cb) { int allocated_port1 = -1; int allocated_port2 = -1; unsigned i; diff --git a/src/core/iomgr/udp_server.h b/src/core/iomgr/udp_server.h index fcc4ba6e97c..389f84eccad 100644 --- a/src/core/iomgr/udp_server.h +++ b/src/core/iomgr/udp_server.h @@ -67,8 +67,8 @@ int grpc_udp_server_get_fd(grpc_udp_server *s, unsigned index); /* TODO(ctiller): deprecate this, and make grpc_udp_server_add_ports to handle all of the multiple socket port matching logic in one place */ -int grpc_udp_server_add_port(grpc_udp_server *s, const void *addr, int addr_len, - grpc_udp_server_read_cb read_cb); +int grpc_udp_server_add_port(grpc_udp_server *s, const void *addr, + size_t addr_len, grpc_udp_server_read_cb read_cb); void grpc_udp_server_destroy(grpc_udp_server *server, void (*shutdown_done)(void *shutdown_done_arg), diff --git a/src/core/support/stack_lockfree.c b/src/core/support/stack_lockfree.c index 27ecf62280e..0d4b4bedd9a 100644 --- a/src/core/support/stack_lockfree.c +++ b/src/core/support/stack_lockfree.c @@ -79,7 +79,7 @@ struct gpr_stack_lockfree { #endif }; -gpr_stack_lockfree *gpr_stack_lockfree_create(int entries) { +gpr_stack_lockfree *gpr_stack_lockfree_create(size_t entries) { gpr_stack_lockfree *stack; stack = gpr_malloc(sizeof(*stack)); /* Since we only allocate 16 bits to represent an entry number, diff --git a/src/core/support/stack_lockfree.h b/src/core/support/stack_lockfree.h index eec960fbb01..2bbbe3bd956 100644 --- a/src/core/support/stack_lockfree.h +++ b/src/core/support/stack_lockfree.h @@ -34,11 +34,13 @@ #ifndef GRPC_INTERNAL_CORE_SUPPORT_STACK_LOCKFREE_H #define GRPC_INTERNAL_CORE_SUPPORT_STACK_LOCKFREE_H +#include + typedef struct gpr_stack_lockfree gpr_stack_lockfree; /* This stack must specify the maximum number of entries to track. The current implementation only allows up to 65534 entries */ -gpr_stack_lockfree* gpr_stack_lockfree_create(int entries); +gpr_stack_lockfree* gpr_stack_lockfree_create(size_t entries); void gpr_stack_lockfree_destroy(gpr_stack_lockfree* stack); /* Pass in a valid entry number for the next stack entry */ diff --git a/src/core/surface/channel.c b/src/core/surface/channel.c index 586402e21c3..a89523b3ab6 100644 --- a/src/core/surface/channel.c +++ b/src/core/surface/channel.c @@ -113,7 +113,7 @@ grpc_channel *grpc_channel_create_from_filters( grpc_mdstr_from_string(mdctx, "grpc-message", 0); for (i = 0; i < NUM_CACHED_STATUS_ELEMS; i++) { char buf[GPR_LTOA_MIN_BUFSIZE]; - gpr_ltoa(i, buf); + gpr_ltoa((long)i, buf); channel->grpc_status_elem[i] = grpc_mdelem_from_metadata_strings( mdctx, GRPC_MDSTR_REF(channel->grpc_status_string), grpc_mdstr_from_string(mdctx, buf, 0)); @@ -134,7 +134,7 @@ grpc_channel *grpc_channel_create_from_filters( gpr_log(GPR_ERROR, "%s ignored: it must be >= 0", GRPC_ARG_MAX_MESSAGE_LENGTH); } else { - channel->max_message_length = args->args[i].value.integer; + channel->max_message_length = (gpr_uint32)args->args[i].value.integer; } } else if (0 == strcmp(args->args[i].key, GRPC_ARG_DEFAULT_AUTHORITY)) { if (args->args[i].type != GRPC_ARG_STRING) { @@ -193,7 +193,7 @@ static grpc_call *grpc_channel_create_call_internal( grpc_completion_queue *cq, grpc_mdelem *path_mdelem, grpc_mdelem *authority_mdelem, gpr_timespec deadline) { grpc_mdelem *send_metadata[2]; - int num_metadata = 0; + size_t num_metadata = 0; GPR_ASSERT(channel->is_client); diff --git a/src/core/surface/channel_create.c b/src/core/surface/channel_create.c index 707251da895..9e2cf1cf66e 100644 --- a/src/core/surface/channel_create.c +++ b/src/core/surface/channel_create.c @@ -164,7 +164,7 @@ grpc_channel *grpc_insecure_channel_create(const char *target, grpc_resolver *resolver; subchannel_factory *f; grpc_mdctx *mdctx = grpc_mdctx_create(); - int n = 0; + size_t n = 0; GPR_ASSERT(!reserved); if (grpc_channel_args_is_census_enabled(args)) { filters[n++] = &grpc_client_census_filter; diff --git a/src/core/surface/server.c b/src/core/surface/server.c index 292bf6fab82..c3d80467872 100644 --- a/src/core/surface/server.c +++ b/src/core/surface/server.c @@ -203,7 +203,7 @@ struct grpc_server { gpr_stack_lockfree *request_freelist; /** requested call backing data */ requested_call *requested_calls; - int max_requested_calls; + size_t max_requested_calls; gpr_atm shutdown_flag; gpr_uint8 shutdown_published; @@ -298,7 +298,7 @@ static void channel_broadcaster_shutdown(channel_broadcaster *cb, */ static void request_matcher_init(request_matcher *request_matcher, - int entries) { + size_t entries) { memset(request_matcher, 0, sizeof(*request_matcher)); request_matcher->requests = gpr_stack_lockfree_create(entries); } @@ -817,7 +817,7 @@ grpc_server *grpc_server_create_from_filters( grpc_server_census_filter (optional) - for stats collection and tracing {passed in filter stack} grpc_connected_channel_filter - for interfacing with transports */ - server->channel_filter_count = filter_count + 1 + census_enabled; + server->channel_filter_count = filter_count + 1u + (census_enabled ? 1u : 0u); server->channel_filters = gpr_malloc(server->channel_filter_count * sizeof(grpc_channel_filter *)); server->channel_filters[0] = &server_surface_filter; @@ -825,7 +825,7 @@ grpc_server *grpc_server_create_from_filters( server->channel_filters[1] = &grpc_server_census_filter; } for (i = 0; i < filter_count; i++) { - server->channel_filters[i + 1 + census_enabled] = filters[i]; + server->channel_filters[i + 1u + (census_enabled ? 1u : 0u)] = filters[i]; } server->channel_args = grpc_channel_args_copy(args); @@ -1246,7 +1246,8 @@ static void begin_call(grpc_server *server, call_data *calld, } GRPC_CALL_INTERNAL_REF(calld->call, "server"); - grpc_call_start_ioreq_and_call_back(calld->call, req, r - req, publish, rc); + grpc_call_start_ioreq_and_call_back(calld->call, req, (size_t)(r - req), + publish, rc); } static void done_request_event(void *req, grpc_cq_completion *c) { diff --git a/src/core/transport/chttp2/bin_encoder.c b/src/core/transport/chttp2/bin_encoder.c index dee6dbec8b9..b87d4de04b4 100644 --- a/src/core/transport/chttp2/bin_encoder.c +++ b/src/core/transport/chttp2/bin_encoder.c @@ -68,7 +68,7 @@ gpr_slice grpc_chttp2_base64_encode(gpr_slice input) { size_t output_length = input_triplets * 4 + tail_xtra[tail_case]; gpr_slice output = gpr_slice_malloc(output_length); gpr_uint8 *in = GPR_SLICE_START_PTR(input); - gpr_uint8 *out = GPR_SLICE_START_PTR(output); + char *out = (char *)GPR_SLICE_START_PTR(output); size_t i; /* encode full triplets */ @@ -100,7 +100,7 @@ gpr_slice grpc_chttp2_base64_encode(gpr_slice input) { break; } - GPR_ASSERT(out == GPR_SLICE_END_PTR(output)); + GPR_ASSERT(out == (char *)GPR_SLICE_END_PTR(output)); GPR_ASSERT(in == GPR_SLICE_END_PTR(input)); return output; } @@ -133,7 +133,7 @@ gpr_slice grpc_chttp2_huffman_compress(gpr_slice input) { } if (temp_length) { - *out++ = (temp << (8 - temp_length)) | (0xff >> temp_length); + *out++ = (temp << (8u - temp_length)) | (0xffu >> temp_length); } GPR_ASSERT(out == GPR_SLICE_END_PTR(output)); @@ -157,9 +157,9 @@ static void enc_flush_some(huff_out *out) { static void enc_add2(huff_out *out, gpr_uint8 a, gpr_uint8 b) { b64_huff_sym sa = huff_alphabet[a]; b64_huff_sym sb = huff_alphabet[b]; - out->temp = - (out->temp << (sa.length + sb.length)) | (sa.bits << sb.length) | sb.bits; - out->temp_length += sa.length + sb.length; + out->temp = (out->temp << (sa.length + sb.length)) | + ((gpr_uint32)sa.bits << sb.length) | sb.bits; + out->temp_length += (gpr_uint32)sa.length + (gpr_uint32)sb.length; enc_flush_some(out); } @@ -211,7 +211,7 @@ gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input) { if (out.temp_length) { *out.out++ = - (out.temp << (8 - out.temp_length)) | (0xff >> out.temp_length); + (out.temp << (8u - out.temp_length)) | (0xffu >> out.temp_length); } GPR_ASSERT(out.out <= GPR_SLICE_END_PTR(output)); diff --git a/src/core/transport/chttp2/frame_data.c b/src/core/transport/chttp2/frame_data.c index 474c3d5ee6c..29d19b4e945 100644 --- a/src/core/transport/chttp2/frame_data.c +++ b/src/core/transport/chttp2/frame_data.c @@ -146,19 +146,21 @@ grpc_chttp2_parse_error grpc_chttp2_data_parser_parse( grpc_chttp2_list_add_parsing_seen_stream(transport_parsing, stream_parsing); if ((gpr_uint32)(end - cur) == p->frame_size) { - grpc_sopb_add_slice(&p->incoming_sopb, - gpr_slice_sub(slice, cur - beg, end - beg)); + grpc_sopb_add_slice( + &p->incoming_sopb, + gpr_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg))); p->state = GRPC_CHTTP2_DATA_FH_0; return GRPC_CHTTP2_PARSE_OK; } else if ((gpr_uint32)(end - cur) > p->frame_size) { - grpc_sopb_add_slice( - &p->incoming_sopb, - gpr_slice_sub(slice, cur - beg, cur + p->frame_size - beg)); + grpc_sopb_add_slice(&p->incoming_sopb, + gpr_slice_sub(slice, (size_t)(cur - beg), + (size_t)(cur + p->frame_size - beg))); cur += p->frame_size; goto fh_0; /* loop */ } else { - grpc_sopb_add_slice(&p->incoming_sopb, - gpr_slice_sub(slice, cur - beg, end - beg)); + grpc_sopb_add_slice( + &p->incoming_sopb, + gpr_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg))); p->frame_size -= (end - cur); return GRPC_CHTTP2_PARSE_OK; } diff --git a/src/core/transport/chttp2/frame_goaway.c b/src/core/transport/chttp2/frame_goaway.c index 1ccbba840ce..d40e6fd03a8 100644 --- a/src/core/transport/chttp2/frame_goaway.c +++ b/src/core/transport/chttp2/frame_goaway.c @@ -136,7 +136,7 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse( ++cur; /* fallthrough */ case GRPC_CHTTP2_GOAWAY_DEBUG: - memcpy(p->debug_data + p->debug_pos, cur, end - cur); + memcpy(p->debug_data + p->debug_pos, cur, (size_t)(end - cur)); p->debug_pos += end - cur; p->state = GRPC_CHTTP2_GOAWAY_DEBUG; if (is_last) { diff --git a/src/core/transport/chttp2/frame_settings.c b/src/core/transport/chttp2/frame_settings.c index d42bc000aea..927ae55996f 100644 --- a/src/core/transport/chttp2/frame_settings.c +++ b/src/core/transport/chttp2/frame_settings.c @@ -81,14 +81,14 @@ gpr_slice grpc_chttp2_settings_create(gpr_uint32 *old, const gpr_uint32 *new, gpr_uint8 *p; for (i = 0; i < count; i++) { - n += (new[i] != old[i] || (force_mask & (1 << i)) != 0); + n += (new[i] != old[i] || (force_mask & (1u << i)) != 0); } output = gpr_slice_malloc(9 + 6 * n); p = fill_header(GPR_SLICE_START_PTR(output), 6 * n, 0); for (i = 0; i < count; i++) { - if (new[i] != old[i] || (force_mask & (1 << i)) != 0) { + if (new[i] != old[i] || (force_mask & (1u << i)) != 0) { GPR_ASSERT(i); *p++ = i >> 8; *p++ = i; diff --git a/src/core/transport/chttp2/hpack_parser.c b/src/core/transport/chttp2/hpack_parser.c index f8bff42ed67..f806f59ed73 100644 --- a/src/core/transport/chttp2/hpack_parser.c +++ b/src/core/transport/chttp2/hpack_parser.c @@ -1099,7 +1099,7 @@ static int append_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, gpr_uint8 decoded[3]; switch ((binary_state)p->binary) { case NOT_BINARY: - append_bytes(str, cur, end - cur); + append_bytes(str, cur, (size_t)(end - cur)); return 1; b64_byte0: case B64_BYTE0: @@ -1249,7 +1249,7 @@ static int add_str_bytes(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, static int parse_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, const gpr_uint8 *end) { size_t remaining = p->strlen - p->strgot; - size_t given = end - cur; + size_t given = (size_t)(end - cur); if (remaining <= given) { return add_str_bytes(p, cur, cur + remaining) && finish_str(p) && parse_next(p, cur + remaining, end); diff --git a/src/core/transport/chttp2/hpack_parser.h b/src/core/transport/chttp2/hpack_parser.h index c1768d9d5d9..4f489d67fb4 100644 --- a/src/core/transport/chttp2/hpack_parser.h +++ b/src/core/transport/chttp2/hpack_parser.h @@ -79,7 +79,7 @@ struct grpc_chttp2_hpack_parser { /* number of source bytes read for the currently parsing string */ gpr_uint32 strgot; /* huffman decoding state */ - gpr_uint16 huff_state; + gpr_int16 huff_state; /* is the string being decoded binary? */ gpr_uint8 binary; /* is the current string huffman encoded? */ diff --git a/src/core/transport/chttp2/hpack_table.c b/src/core/transport/chttp2/hpack_table.c index 4fc154380e1..3aeb4dae94e 100644 --- a/src/core/transport/chttp2/hpack_table.c +++ b/src/core/transport/chttp2/hpack_table.c @@ -139,7 +139,7 @@ grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, /* Otherwise, find the value in the list of valid entries */ index -= (GRPC_CHTTP2_LAST_STATIC_ENTRY + 1); if (index < tbl->num_ents) { - gpr_uint32 offset = (tbl->num_ents - 1 - index + tbl->first_ent) % + gpr_uint32 offset = (tbl->num_ents - 1u - index + tbl->first_ent) % GRPC_CHTTP2_MAX_TABLE_COUNT; return tbl->ents[offset]; } diff --git a/src/core/transport/chttp2/incoming_metadata.c b/src/core/transport/chttp2/incoming_metadata.c index 974b864ffb4..d216c421139 100644 --- a/src/core/transport/chttp2/incoming_metadata.c +++ b/src/core/transport/chttp2/incoming_metadata.c @@ -122,7 +122,7 @@ void grpc_incoming_metadata_buffer_move_to_referencing_sopb( for (i = 0; i < sopb->nops; i++) { if (sopb->ops[i].type != GRPC_OP_METADATA) continue; sopb->ops[i].data.metadata.list.tail = - (void *)(delta + (gpr_intptr)sopb->ops[i].data.metadata.list.tail); + (void *)(delta + (gpr_uintptr)sopb->ops[i].data.metadata.list.tail); } src->count = 0; } diff --git a/src/core/transport/chttp2/internal.h b/src/core/transport/chttp2/internal.h index 7a42de9245a..125cd744b7d 100644 --- a/src/core/transport/chttp2/internal.h +++ b/src/core/transport/chttp2/internal.h @@ -609,20 +609,21 @@ extern int grpc_flowctl_trace; else \ stmt -#define GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(reason, transport, context, var, \ - delta) \ - if (!(grpc_flowctl_trace)) { \ - } else { \ - grpc_chttp2_flowctl_trace(__FILE__, __LINE__, reason, #context, #var, \ - transport->is_client, context->id, context->var, \ - delta); \ +#define GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(reason, transport, context, var, \ + delta) \ + if (!(grpc_flowctl_trace)) { \ + } else { \ + grpc_chttp2_flowctl_trace(__FILE__, __LINE__, reason, #context, #var, \ + transport->is_client, context->id, \ + (gpr_int64)(context->var), (gpr_int64)(delta)); \ } -#define GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT(reason, context, var, delta) \ - if (!(grpc_flowctl_trace)) { \ - } else { \ - grpc_chttp2_flowctl_trace(__FILE__, __LINE__, reason, #context, #var, \ - context->is_client, 0, context->var, delta); \ +#define GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT(reason, context, var, delta) \ + if (!(grpc_flowctl_trace)) { \ + } else { \ + grpc_chttp2_flowctl_trace(__FILE__, __LINE__, reason, #context, #var, \ + context->is_client, 0, \ + (gpr_int64)(context->var), (gpr_int64)(delta)); \ } void grpc_chttp2_flowctl_trace(const char *file, int line, const char *reason, diff --git a/src/core/transport/chttp2/parsing.c b/src/core/transport/chttp2/parsing.c index dc5eb18e420..b0f884e2581 100644 --- a/src/core/transport/chttp2/parsing.c +++ b/src/core/transport/chttp2/parsing.c @@ -194,7 +194,8 @@ void grpc_chttp2_publish_reads( GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( "parsed", transport_parsing, stream_parsing, outgoing_window_update, -(gpr_int64)stream_parsing->outgoing_window_update); - stream_global->outgoing_window += stream_parsing->outgoing_window_update; + stream_global->outgoing_window += + (gpr_uint32)stream_global->outgoing_window; stream_parsing->outgoing_window_update = 0; is_zero = stream_global->outgoing_window <= 0; if (was_zero && !is_zero) { @@ -379,9 +380,10 @@ int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, case GRPC_DTS_FRAME: GPR_ASSERT(cur < end); if ((gpr_uint32)(end - cur) == transport_parsing->incoming_frame_size) { - if (!parse_frame_slice( - transport_parsing, - gpr_slice_sub_no_ref(slice, cur - beg, end - beg), 1)) { + if (!parse_frame_slice(transport_parsing, + gpr_slice_sub_no_ref(slice, (size_t)(cur - beg), + (size_t)(end - beg)), + 1)) { return 0; } transport_parsing->deframe_state = GRPC_DTS_FH_0; @@ -389,11 +391,12 @@ int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, return 1; } else if ((gpr_uint32)(end - cur) > transport_parsing->incoming_frame_size) { + size_t cur_offset = (size_t)(cur - beg); if (!parse_frame_slice( transport_parsing, gpr_slice_sub_no_ref( - slice, cur - beg, - cur + transport_parsing->incoming_frame_size - beg), + slice, cur_offset, + cur_offset + transport_parsing->incoming_frame_size), 1)) { return 0; } @@ -401,9 +404,10 @@ int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, transport_parsing->incoming_stream = NULL; goto dts_fh_0; /* loop */ } else { - if (!parse_frame_slice( - transport_parsing, - gpr_slice_sub_no_ref(slice, cur - beg, end - beg), 0)) { + if (!parse_frame_slice(transport_parsing, + gpr_slice_sub_no_ref(slice, (size_t)(cur - beg), + (size_t)(end - beg)), + 0)) { return 0; } transport_parsing->incoming_frame_size -= (end - cur); diff --git a/src/core/transport/chttp2/stream_encoder.c b/src/core/transport/chttp2/stream_encoder.c index 1ea697f71ed..bcae93dc7a2 100644 --- a/src/core/transport/chttp2/stream_encoder.c +++ b/src/core/transport/chttp2/stream_encoder.c @@ -134,7 +134,7 @@ static void begin_new_frame(framer_state *st, frame_type type) { space to add at least about_to_add bytes -- finishes the current frame if needed */ static void ensure_frame_type(framer_state *st, frame_type type, - int need_bytes) { + size_t need_bytes) { if (st->cur_frame_type == type && st->output->length - st->output_length_at_start_of_frame + need_bytes <= GRPC_CHTTP2_MAX_PAYLOAD_LENGTH) { @@ -174,7 +174,7 @@ static void add_header_data(framer_state *st, gpr_slice slice) { } } -static gpr_uint8 *add_tiny_header_data(framer_state *st, int len) { +static gpr_uint8 *add_tiny_header_data(framer_state *st, size_t len) { ensure_frame_type(st, HEADER, len); return gpr_slice_buffer_tiny_add(st->output, len); } @@ -270,7 +270,7 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c, static void emit_indexed(grpc_chttp2_hpack_compressor *c, gpr_uint32 index, framer_state *st) { - int len = GRPC_CHTTP2_VARINT_LENGTH(index, 1); + size_t len = GRPC_CHTTP2_VARINT_LENGTH(index, 1); GRPC_CHTTP2_WRITE_VARINT(index, 1, 0x80, add_tiny_header_data(st, len), len); } @@ -288,11 +288,11 @@ static gpr_slice get_wire_value(grpc_mdelem *elem, gpr_uint8 *huffman_prefix) { static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c, gpr_uint32 key_index, grpc_mdelem *elem, framer_state *st) { - int len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 2); + gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 2); gpr_uint8 huffman_prefix; gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - int len_val = GPR_SLICE_LENGTH(value_slice); - int len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); + gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice); + gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); GRPC_CHTTP2_WRITE_VARINT(key_index, 2, 0x40, add_tiny_header_data(st, len_pfx), len_pfx); GRPC_CHTTP2_WRITE_VARINT(len_val, 1, 0x00, @@ -303,11 +303,11 @@ static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c, static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c, gpr_uint32 key_index, grpc_mdelem *elem, framer_state *st) { - int len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 4); + gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 4); gpr_uint8 huffman_prefix; gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - int len_val = GPR_SLICE_LENGTH(value_slice); - int len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); + gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice); + gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); GRPC_CHTTP2_WRITE_VARINT(key_index, 4, 0x00, add_tiny_header_data(st, len_pfx), len_pfx); GRPC_CHTTP2_WRITE_VARINT(len_val, 1, 0x00, @@ -317,12 +317,12 @@ static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c, static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem, framer_state *st) { - int len_key = GPR_SLICE_LENGTH(elem->key->slice); + gpr_uint32 len_key = GPR_SLICE_LENGTH(elem->key->slice); gpr_uint8 huffman_prefix; gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - int len_val = GPR_SLICE_LENGTH(value_slice); - int len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); - int len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); + gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice); + gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); + gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); *add_tiny_header_data(st, 1) = 0x40; GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00, add_tiny_header_data(st, len_key_len), len_key_len); @@ -334,12 +334,12 @@ static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c, static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem, framer_state *st) { - int len_key = GPR_SLICE_LENGTH(elem->key->slice); + gpr_uint32 len_key = GPR_SLICE_LENGTH(elem->key->slice); gpr_uint8 huffman_prefix; gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - int len_val = GPR_SLICE_LENGTH(value_slice); - int len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); - int len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); + gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice); + gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); + gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); *add_tiny_header_data(st, 1) = 0x00; GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00, add_tiny_header_data(st, len_key_len), len_key_len); diff --git a/src/core/transport/chttp2/timeout_encoding.c b/src/core/transport/chttp2/timeout_encoding.c index 1dd768ada40..40fcdc26dca 100644 --- a/src/core/transport/chttp2/timeout_encoding.c +++ b/src/core/transport/chttp2/timeout_encoding.c @@ -137,14 +137,14 @@ static int is_all_whitespace(const char *p) { int grpc_chttp2_decode_timeout(const char *buffer, gpr_timespec *timeout) { gpr_uint32 x = 0; - const char *p = buffer; + const gpr_uint8 *p = (const gpr_uint8 *)buffer; int have_digit = 0; /* skip whitespace */ for (; *p == ' '; p++) ; /* decode numeric part */ for (; *p >= '0' && *p <= '9'; p++) { - gpr_uint32 xp = x * 10 + *p - '0'; + gpr_uint32 xp = x * 10u + (gpr_uint32)*p - (gpr_uint32)'0'; have_digit = 1; if (xp < x) { *timeout = gpr_inf_future(GPR_CLOCK_REALTIME); @@ -180,5 +180,5 @@ int grpc_chttp2_decode_timeout(const char *buffer, gpr_timespec *timeout) { return 0; } p++; - return is_all_whitespace(p); + return is_all_whitespace((const char *)p); } diff --git a/src/core/transport/chttp2/varint.c b/src/core/transport/chttp2/varint.c index 0722c9ada9b..056f68047b3 100644 --- a/src/core/transport/chttp2/varint.c +++ b/src/core/transport/chttp2/varint.c @@ -33,7 +33,7 @@ #include "src/core/transport/chttp2/varint.h" -int grpc_chttp2_hpack_varint_length(gpr_uint32 tail_value) { +gpr_uint32 grpc_chttp2_hpack_varint_length(gpr_uint32 tail_value) { if (tail_value < (1 << 7)) { return 2; } else if (tail_value < (1 << 14)) { @@ -48,7 +48,8 @@ int grpc_chttp2_hpack_varint_length(gpr_uint32 tail_value) { } void grpc_chttp2_hpack_write_varint_tail(gpr_uint32 tail_value, - gpr_uint8* target, int tail_length) { + gpr_uint8* target, + gpr_uint32 tail_length) { switch (tail_length) { case 5: target[4] = (gpr_uint8)((tail_value >> 28) | 0x80); diff --git a/src/core/transport/chttp2/varint.h b/src/core/transport/chttp2/varint.h index 0a6fb55248d..37856913f82 100644 --- a/src/core/transport/chttp2/varint.h +++ b/src/core/transport/chttp2/varint.h @@ -41,10 +41,11 @@ /* length of a value that needs varint tail encoding (it's bigger than can be bitpacked into the opcode byte) - returned value includes the length of the opcode byte */ -int grpc_chttp2_hpack_varint_length(gpr_uint32 tail_value); +gpr_uint32 grpc_chttp2_hpack_varint_length(gpr_uint32 tail_value); void grpc_chttp2_hpack_write_varint_tail(gpr_uint32 tail_value, - gpr_uint8* target, int tail_length); + gpr_uint8* target, + gpr_uint32 tail_length); /* maximum value that can be bitpacked with the opcode if the opcode has a prefix @@ -54,14 +55,14 @@ void grpc_chttp2_hpack_write_varint_tail(gpr_uint32 tail_value, /* length required to bitpack a value */ #define GRPC_CHTTP2_VARINT_LENGTH(n, prefix_bits) \ ((n) < GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits) \ - ? 1 \ + ? 1u \ : grpc_chttp2_hpack_varint_length( \ (n)-GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits))) #define GRPC_CHTTP2_WRITE_VARINT(n, prefix_bits, prefix_or, target, length) \ do { \ gpr_uint8* tgt = target; \ - if ((length) == 1) { \ + if ((length) == 1u) { \ (tgt)[0] = (prefix_or) | (n); \ } else { \ (tgt)[0] = (prefix_or) | GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits); \ diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c index 9e3d7dd551c..c1a3c0436f2 100644 --- a/src/core/transport/chttp2_transport.c +++ b/src/core/transport/chttp2_transport.c @@ -306,7 +306,7 @@ static void init_transport(grpc_chttp2_transport *t, GRPC_ARG_MAX_CONCURRENT_STREAMS); } else { push_setting(t, GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, - channel_args->args[i].value.integer); + (gpr_uint32)channel_args->args[i].value.integer); } } else if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER)) { @@ -320,7 +320,8 @@ static void init_transport(grpc_chttp2_transport *t, t->global.next_stream_id & 1, is_client ? "client" : "server"); } else { - t->global.next_stream_id = channel_args->args[i].value.integer; + t->global.next_stream_id = + (gpr_uint32)channel_args->args[i].value.integer; } } } diff --git a/src/core/transport/metadata.c b/src/core/transport/metadata.c index 61638764a61..9b07b980b7c 100644 --- a/src/core/transport/metadata.c +++ b/src/core/transport/metadata.c @@ -186,7 +186,8 @@ grpc_mdctx *grpc_mdctx_create(void) { /* This seed is used to prevent remote connections from controlling hash table * collisions. It needs to be somewhat unpredictable to a remote connection. */ - return grpc_mdctx_create_with_seed(gpr_now(GPR_CLOCK_REALTIME).tv_nsec); + return grpc_mdctx_create_with_seed( + (gpr_uint32)gpr_now(GPR_CLOCK_REALTIME).tv_nsec); } static void discard_metadata(grpc_mdctx *ctx) { diff --git a/test/core/channel/channel_args_test.c b/test/core/channel/channel_args_test.c index 87f006acdee..0b74dee41ea 100644 --- a/test/core/channel/channel_args_test.c +++ b/test/core/channel/channel_args_test.c @@ -85,12 +85,13 @@ static void test_set_compression_algorithm(void) { static void test_compression_algorithm_states(void) { grpc_channel_args *ch_args, *ch_args_wo_gzip, *ch_args_wo_gzip_deflate; - int states_bitset; + unsigned states_bitset; size_t i; ch_args = grpc_channel_args_copy_and_add(NULL, NULL, 0); /* by default, all enabled */ - states_bitset = grpc_channel_args_compression_algorithm_get_states(ch_args); + states_bitset = + (unsigned)grpc_channel_args_compression_algorithm_get_states(ch_args); for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { GPR_ASSERT(GPR_BITGET(states_bitset, i)); @@ -104,7 +105,7 @@ static void test_compression_algorithm_states(void) { &ch_args_wo_gzip, GRPC_COMPRESS_DEFLATE, 0); GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate); - states_bitset = grpc_channel_args_compression_algorithm_get_states( + states_bitset = (unsigned)grpc_channel_args_compression_algorithm_get_states( ch_args_wo_gzip_deflate); for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (i == GRPC_COMPRESS_GZIP || i == GRPC_COMPRESS_DEFLATE) { @@ -119,8 +120,8 @@ static void test_compression_algorithm_states(void) { &ch_args_wo_gzip_deflate, GRPC_COMPRESS_GZIP, 1); GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate); - states_bitset = - grpc_channel_args_compression_algorithm_get_states(ch_args_wo_gzip); + states_bitset = (unsigned)grpc_channel_args_compression_algorithm_get_states( + ch_args_wo_gzip); for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { if (i == GRPC_COMPRESS_DEFLATE) { GPR_ASSERT(GPR_BITGET(states_bitset, i) == 0); diff --git a/test/core/end2end/dualstack_socket_test.c b/test/core/end2end/dualstack_socket_test.c index fcc12952bf9..2aee333d277 100644 --- a/test/core/end2end/dualstack_socket_test.c +++ b/test/core/end2end/dualstack_socket_test.c @@ -186,7 +186,7 @@ void test_connect(const char *server_host, const char *client_host, int port, op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); if (expect_ok) { @@ -212,7 +212,7 @@ void test_connect(const char *server_host, const char *client_host, int port, op->data.recv_close_on_server.cancelled = &was_cancelled; op->flags = 0; op++; - error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL); + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); GPR_ASSERT(GRPC_CALL_OK == error); cq_expect_completion(cqv, tag(102), 1); diff --git a/test/core/end2end/no_server_test.c b/test/core/end2end/no_server_test.c index 619627ddd2a..c391003141b 100644 --- a/test/core/end2end/no_server_test.c +++ b/test/core/end2end/no_server_test.c @@ -79,8 +79,8 @@ int main(int argc, char **argv) { op->flags = 0; op->reserved = NULL; op++; - GPR_ASSERT(GRPC_CALL_OK == - grpc_call_start_batch(call, ops, op - ops, tag(1), NULL)); + GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch( + call, ops, (size_t)(op - ops), tag(1), NULL)); /* verify that all tags get completed */ cq_expect_completion(cqv, tag(1), 1); cq_verify(cqv); diff --git a/test/core/fling/client.c b/test/core/fling/client.c index 54c92745107..ed80544e3c7 100644 --- a/test/core/fling/client.c +++ b/test/core/fling/client.c @@ -92,8 +92,9 @@ static void step_ping_pong_request(void) { call = grpc_channel_create_call(channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, "/Reflector/reflectUnary", "localhost", gpr_inf_future(GPR_CLOCK_REALTIME), NULL); - GPR_ASSERT(GRPC_CALL_OK == - grpc_call_start_batch(call, ops, op - ops, (void *)1, NULL)); + GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call, ops, + (size_t)(op - ops), + (void *)1, NULL)); grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); grpc_call_destroy(call); grpc_byte_buffer_destroy(response_payload_recv); @@ -188,7 +189,7 @@ int main(int argc, char **argv) { channel = grpc_insecure_channel_create(target, NULL, NULL); cq = grpc_completion_queue_create(NULL); - the_buffer = grpc_raw_byte_buffer_create(&slice, payload_size); + the_buffer = grpc_raw_byte_buffer_create(&slice, (size_t)payload_size); histogram = gpr_histogram_create(0.01, 60e9); sc.init(); diff --git a/test/core/fling/fling_stream_test.c b/test/core/fling/fling_stream_test.c index 4d9253c0ada..78a73372aa8 100644 --- a/test/core/fling/fling_stream_test.c +++ b/test/core/fling/fling_stream_test.c @@ -60,10 +60,10 @@ int main(int argc, char **argv) { pid_t svr, cli; /* seed rng with pid, so we don't end up with the same random numbers as a concurrently running test binary */ - srand(getpid()); + srand((unsigned)getpid()); /* figure out where we are */ if (lslash) { - memcpy(root, me, lslash - me); + memcpy(root, me, (size_t)(lslash - me)); root[lslash - me] = 0; } else { strcpy(root, "."); diff --git a/test/core/fling/fling_test.c b/test/core/fling/fling_test.c index 29d90507044..cf43ecfd2de 100644 --- a/test/core/fling/fling_test.c +++ b/test/core/fling/fling_test.c @@ -51,7 +51,7 @@ int main(int argc, char **argv) { gpr_subprocess *svr, *cli; /* figure out where we are */ if (lslash) { - memcpy(root, me, lslash - me); + memcpy(root, me, (size_t)(lslash - me)); root[lslash - me] = 0; } else { strcpy(root, "."); diff --git a/test/core/fling/server.c b/test/core/fling/server.c index 0430ff9ab72..64f95730848 100644 --- a/test/core/fling/server.c +++ b/test/core/fling/server.c @@ -123,7 +123,7 @@ static void handle_unary_method(void) { op->data.recv_close_on_server.cancelled = &was_cancelled; op++; - error = grpc_call_start_batch(call, unary_ops, op - unary_ops, + error = grpc_call_start_batch(call, unary_ops, (size_t)(op - unary_ops), tag(FLING_SERVER_BATCH_OPS_FOR_UNARY), NULL); GPR_ASSERT(GRPC_CALL_OK == error); } diff --git a/test/core/httpcli/httpcli_test.c b/test/core/httpcli/httpcli_test.c index 42b2661c0a3..cf2b10c021a 100644 --- a/test/core/httpcli/httpcli_test.c +++ b/test/core/httpcli/httpcli_test.c @@ -134,7 +134,7 @@ int main(int argc, char **argv) { /* figure out where we are */ if (lslash) { - memcpy(root, me, lslash - me); + memcpy(root, me, (size_t)(lslash - me)); root[lslash - me] = 0; } else { strcpy(root, "."); diff --git a/test/core/iomgr/alarm_heap_test.c b/test/core/iomgr/alarm_heap_test.c index 66b6e4cb64f..13bf7e43f64 100644 --- a/test/core/iomgr/alarm_heap_test.c +++ b/test/core/iomgr/alarm_heap_test.c @@ -48,9 +48,9 @@ static gpr_timespec random_deadline(void) { return ts; } -static grpc_alarm *create_test_elements(int num_elements) { +static grpc_alarm *create_test_elements(size_t num_elements) { grpc_alarm *elems = gpr_malloc(num_elements * sizeof(grpc_alarm)); - int i; + size_t i; for (i = 0; i < num_elements; i++) { elems[i].deadline = random_deadline(); } @@ -63,24 +63,25 @@ static int cmp_elem(const void *a, const void *b) { return i - j; } -static int *all_top(grpc_alarm_heap *pq, int *n) { - int *vec = NULL; - int *need_to_check_children; - int num_need_to_check_children = 0; +static size_t *all_top(grpc_alarm_heap *pq, size_t *n) { + size_t *vec = NULL; + size_t *need_to_check_children; + size_t num_need_to_check_children = 0; *n = 0; if (pq->alarm_count == 0) return vec; - need_to_check_children = gpr_malloc(pq->alarm_count * sizeof(int)); + need_to_check_children = + gpr_malloc(pq->alarm_count * sizeof(*need_to_check_children)); need_to_check_children[num_need_to_check_children++] = 0; - vec = gpr_malloc(pq->alarm_count * sizeof(int)); + vec = gpr_malloc(pq->alarm_count * sizeof(*vec)); while (num_need_to_check_children > 0) { - int ind = need_to_check_children[0]; - int leftchild, rightchild; + size_t ind = need_to_check_children[0]; + size_t leftchild, rightchild; num_need_to_check_children--; memmove(need_to_check_children, need_to_check_children + 1, - num_need_to_check_children * sizeof(int)); + num_need_to_check_children * sizeof(*need_to_check_children)); vec[(*n)++] = ind; - leftchild = 1 + 2 * ind; + leftchild = 1u + 2u * ind; if (leftchild < pq->alarm_count) { if (gpr_time_cmp(pq->alarms[leftchild]->deadline, pq->alarms[ind]->deadline) >= 0) { @@ -101,13 +102,14 @@ static int *all_top(grpc_alarm_heap *pq, int *n) { } static void check_pq_top(grpc_alarm *elements, grpc_alarm_heap *pq, - gpr_uint8 *inpq, int num_elements) { + gpr_uint8 *inpq, size_t num_elements) { gpr_timespec max_deadline = gpr_inf_past(GPR_CLOCK_REALTIME); - int *max_deadline_indices = gpr_malloc(num_elements * sizeof(int)); - int *top_elements; - int num_max_deadline_indices = 0; - int num_top_elements; - int i; + size_t *max_deadline_indices = + gpr_malloc(num_elements * sizeof(*max_deadline_indices)); + size_t *top_elements; + size_t num_max_deadline_indices = 0; + size_t num_top_elements; + size_t i; for (i = 0; i < num_elements; ++i) { if (inpq[i] && gpr_time_cmp(elements[i].deadline, max_deadline) >= 0) { if (gpr_time_cmp(elements[i].deadline, max_deadline) > 0) { @@ -117,7 +119,8 @@ static void check_pq_top(grpc_alarm *elements, grpc_alarm_heap *pq, max_deadline_indices[num_max_deadline_indices++] = elements[i].heap_index; } } - qsort(max_deadline_indices, num_max_deadline_indices, sizeof(int), cmp_elem); + qsort(max_deadline_indices, num_max_deadline_indices, + sizeof(*max_deadline_indices), cmp_elem); top_elements = all_top(pq, &num_top_elements); GPR_ASSERT(num_top_elements == num_max_deadline_indices); for (i = 0; i < num_top_elements; i++) { @@ -128,7 +131,7 @@ static void check_pq_top(grpc_alarm *elements, grpc_alarm_heap *pq, } static int contains(grpc_alarm_heap *pq, grpc_alarm *el) { - int i; + size_t i; for (i = 0; i < pq->alarm_count; i++) { if (pq->alarms[i] == el) return 1; } @@ -136,10 +139,10 @@ static int contains(grpc_alarm_heap *pq, grpc_alarm *el) { } static void check_valid(grpc_alarm_heap *pq) { - int i; + size_t i; for (i = 0; i < pq->alarm_count; ++i) { - int left_child = 1 + 2 * i; - int right_child = left_child + 1; + size_t left_child = 1u + 2u * i; + size_t right_child = left_child + 1u; if (left_child < pq->alarm_count) { GPR_ASSERT(gpr_time_cmp(pq->alarms[i]->deadline, pq->alarms[left_child]->deadline) >= 0); @@ -153,9 +156,9 @@ static void check_valid(grpc_alarm_heap *pq) { static void test1(void) { grpc_alarm_heap pq; - const int num_test_elements = 200; - const int num_test_operations = 10000; - int i; + const size_t num_test_elements = 200; + const size_t num_test_operations = 10000; + size_t i; grpc_alarm *test_elements = create_test_elements(num_test_elements); gpr_uint8 *inpq = gpr_malloc(num_test_elements); @@ -182,7 +185,7 @@ static void test1(void) { check_pq_top(test_elements, &pq, inpq, num_test_elements); for (i = 0; i < num_test_operations; ++i) { - int elem_num = rand() % num_test_elements; + size_t elem_num = (size_t)rand() % num_test_elements; grpc_alarm *el = &test_elements[elem_num]; if (!inpq[elem_num]) { /* not in pq */ GPR_ASSERT(!contains(&pq, el)); @@ -209,11 +212,11 @@ static void test1(void) { static void shrink_test(void) { grpc_alarm_heap pq; - int i; - int expected_size; + size_t i; + size_t expected_size; /* A large random number to allow for multiple shrinkages, at least 512. */ - const int num_elements = rand() % 2000 + 512; + const size_t num_elements = (size_t)rand() % 2000 + 512; grpc_alarm_heap_init(&pq); @@ -243,7 +246,7 @@ static void shrink_test(void) { 4 times the Size and not less than 2 times, but never goes below 16. */ expected_size = pq.alarm_count; while (pq.alarm_count > 0) { - const int which = rand() % pq.alarm_count; + const size_t which = (size_t)rand() % pq.alarm_count; grpc_alarm *te = pq.alarms[which]; grpc_alarm_heap_remove(&pq, te); gpr_free(te); diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c index 8acaa433bb5..b94f5987cae 100644 --- a/test/core/iomgr/tcp_posix_test.c +++ b/test/core/iomgr/tcp_posix_test.c @@ -105,7 +105,7 @@ static size_t fill_socket_partial(int fd, size_t bytes) { do { write_bytes = write(fd, buf, bytes - total_bytes); if (write_bytes > 0) { - total_bytes += write_bytes; + total_bytes += (size_t)write_bytes; } } while ((write_bytes >= 0 || errno == EINTR) && bytes > total_bytes); @@ -116,15 +116,15 @@ static size_t fill_socket_partial(int fd, size_t bytes) { struct read_socket_state { grpc_endpoint *ep; - ssize_t read_bytes; - ssize_t target_read_bytes; + size_t read_bytes; + size_t target_read_bytes; gpr_slice_buffer incoming; grpc_iomgr_closure read_cb; }; -static ssize_t count_slices(gpr_slice *slices, size_t nslices, - int *current_data) { - ssize_t num_bytes = 0; +static size_t count_slices(gpr_slice *slices, size_t nslices, + int *current_data) { + size_t num_bytes = 0; unsigned i, j; unsigned char *buf; for (i = 0; i < nslices; ++i) { @@ -140,7 +140,7 @@ static ssize_t count_slices(gpr_slice *slices, size_t nslices, static void read_cb(void *user_data, int success) { struct read_socket_state *state = (struct read_socket_state *)user_data; - ssize_t read_bytes; + size_t read_bytes; int current_data; GPR_ASSERT(success); @@ -172,11 +172,11 @@ static void read_cb(void *user_data, int success) { } /* Write to a socket, then read from it using the grpc_tcp API. */ -static void read_test(ssize_t num_bytes, ssize_t slice_size) { +static void read_test(size_t num_bytes, size_t slice_size) { int sv[2]; grpc_endpoint *ep; struct read_socket_state state; - ssize_t written_bytes; + size_t written_bytes; gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); gpr_log(GPR_INFO, "Read test of size %d, slice size %d", num_bytes, @@ -222,7 +222,7 @@ static void read_test(ssize_t num_bytes, ssize_t slice_size) { /* Write to a socket until it fills up, then read from it using the grpc_tcp API. */ -static void large_read_test(ssize_t slice_size) { +static void large_read_test(size_t slice_size) { int sv[2]; grpc_endpoint *ep; struct read_socket_state state; @@ -242,7 +242,7 @@ static void large_read_test(ssize_t slice_size) { state.ep = ep; state.read_bytes = 0; - state.target_read_bytes = written_bytes; + state.target_read_bytes = (size_t)written_bytes; gpr_slice_buffer_init(&state.incoming); grpc_iomgr_closure_init(&state.read_cb, read_cb, &state); @@ -275,11 +275,11 @@ struct write_socket_state { int write_done; }; -static gpr_slice *allocate_blocks(ssize_t num_bytes, ssize_t slice_size, +static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size, size_t *num_blocks, int *current_data) { - size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1 : 0); + size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1u : 0u); gpr_slice *slices = gpr_malloc(sizeof(gpr_slice) * nslices); - ssize_t num_bytes_left = num_bytes; + size_t num_bytes_left = num_bytes; unsigned i, j; unsigned char *buf; *num_blocks = nslices; @@ -334,7 +334,7 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { GPR_ASSERT(buf[i] == current); current = (current + 1) % 256; } - bytes_left -= bytes_read; + bytes_left -= (size_t)bytes_read; if (bytes_left == 0) break; } flags = fcntl(fd, F_GETFL, 0); @@ -366,7 +366,7 @@ static ssize_t drain_socket(int fd) { /* Write to a socket using the grpc_tcp API, then drain it directly. Note that if the write does not complete immediately we need to drain the socket in parallel with the read. */ -static void write_test(ssize_t num_bytes, ssize_t slice_size) { +static void write_test(size_t num_bytes, size_t slice_size) { int sv[2]; grpc_endpoint *ep; struct write_socket_state state; @@ -400,7 +400,7 @@ static void write_test(ssize_t num_bytes, ssize_t slice_size) { case GRPC_ENDPOINT_DONE: /* Write completed immediately */ read_bytes = drain_socket(sv[0]); - GPR_ASSERT(read_bytes == num_bytes); + GPR_ASSERT((size_t)read_bytes == num_bytes); break; case GRPC_ENDPOINT_PENDING: drain_socket_blocking(sv[0], num_bytes, num_bytes); @@ -426,7 +426,7 @@ static void write_test(ssize_t num_bytes, ssize_t slice_size) { } void run_tests(void) { - int i = 0; + size_t i = 0; read_test(100, 8192); read_test(10000, 8192); diff --git a/test/core/json/json_rewrite.c b/test/core/json/json_rewrite.c index 02f60a3163c..561bf487b9f 100644 --- a/test/core/json/json_rewrite.c +++ b/test/core/json/json_rewrite.c @@ -81,7 +81,7 @@ grpc_json_writer_vtable writer_vtable = {json_writer_output_char, static void check_string(json_reader_userdata* state, size_t needed) { if (state->free_space >= needed) return; needed -= state->free_space; - needed = (needed + 0xff) & ~0xff; + needed = (needed + 0xffu) & ~0xffu; state->scratchpad = gpr_realloc(state->scratchpad, state->allocated + needed); state->free_space += needed; state->allocated += needed; @@ -103,22 +103,22 @@ static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) { if (c <= 0x7f) { json_reader_string_add_char(userdata, c); } else if (c <= 0x7ff) { - int b1 = 0xc0 | ((c >> 6) & 0x1f); - int b2 = 0x80 | (c & 0x3f); + gpr_uint32 b1 = 0xc0u | ((c >> 6u) & 0x1fu); + gpr_uint32 b2 = 0x80u | (c & 0x3fu); json_reader_string_add_char(userdata, b1); json_reader_string_add_char(userdata, b2); - } else if (c <= 0xffff) { - int b1 = 0xe0 | ((c >> 12) & 0x0f); - int b2 = 0x80 | ((c >> 6) & 0x3f); - int b3 = 0x80 | (c & 0x3f); + } else if (c <= 0xffffu) { + gpr_uint32 b1 = 0xe0u | ((c >> 12u) & 0x0fu); + gpr_uint32 b2 = 0x80u | ((c >> 6u) & 0x3fu); + gpr_uint32 b3 = 0x80u | (c & 0x3fu); json_reader_string_add_char(userdata, b1); json_reader_string_add_char(userdata, b2); json_reader_string_add_char(userdata, b3); - } else if (c <= 0x1fffff) { - int b1 = 0xf0 | ((c >> 18) & 0x07); - int b2 = 0x80 | ((c >> 12) & 0x3f); - int b3 = 0x80 | ((c >> 6) & 0x3f); - int b4 = 0x80 | (c & 0x3f); + } else if (c <= 0x1fffffu) { + gpr_uint32 b1 = 0xf0u | ((c >> 18u) & 0x07u); + gpr_uint32 b2 = 0x80u | ((c >> 12u) & 0x3fu); + gpr_uint32 b3 = 0x80u | ((c >> 6u) & 0x3fu); + gpr_uint32 b4 = 0x80u | (c & 0x3fu); json_reader_string_add_char(userdata, b1); json_reader_string_add_char(userdata, b2); json_reader_string_add_char(userdata, b3); @@ -132,7 +132,7 @@ static gpr_uint32 json_reader_read_char(void* userdata) { r = fgetc(state->in); if (r == EOF) r = GRPC_JSON_READ_CHAR_EOF; - return r; + return (gpr_uint32)r; } static void json_reader_container_begins(void* userdata, grpc_json_type type) { diff --git a/test/core/json/json_rewrite_test.c b/test/core/json/json_rewrite_test.c index f5859322ea1..7cf184950e8 100644 --- a/test/core/json/json_rewrite_test.c +++ b/test/core/json/json_rewrite_test.c @@ -93,7 +93,7 @@ grpc_json_writer_vtable writer_vtable = {json_writer_output_char, static void check_string(json_reader_userdata* state, size_t needed) { if (state->free_space >= needed) return; needed -= state->free_space; - needed = (needed + 0xff) & ~0xff; + needed = (needed + 0xffu) & ~0xffu; state->scratchpad = gpr_realloc(state->scratchpad, state->allocated + needed); state->free_space += needed; state->allocated += needed; @@ -114,23 +114,23 @@ static void json_reader_string_add_char(void* userdata, gpr_uint32 c) { static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) { if (c <= 0x7f) { json_reader_string_add_char(userdata, c); - } else if (c <= 0x7ff) { - int b1 = 0xc0 | ((c >> 6) & 0x1f); - int b2 = 0x80 | (c & 0x3f); + } else if (c <= 0x7ffu) { + gpr_uint32 b1 = 0xc0u | ((c >> 6u) & 0x1fu); + gpr_uint32 b2 = 0x80u | (c & 0x3fu); json_reader_string_add_char(userdata, b1); json_reader_string_add_char(userdata, b2); - } else if (c <= 0xffff) { - int b1 = 0xe0 | ((c >> 12) & 0x0f); - int b2 = 0x80 | ((c >> 6) & 0x3f); - int b3 = 0x80 | (c & 0x3f); + } else if (c <= 0xffffu) { + gpr_uint32 b1 = 0xe0u | ((c >> 12u) & 0x0fu); + gpr_uint32 b2 = 0x80u | ((c >> 6u) & 0x3fu); + gpr_uint32 b3 = 0x80u | (c & 0x3fu); json_reader_string_add_char(userdata, b1); json_reader_string_add_char(userdata, b2); json_reader_string_add_char(userdata, b3); - } else if (c <= 0x1fffff) { - int b1 = 0xf0 | ((c >> 18) & 0x07); - int b2 = 0x80 | ((c >> 12) & 0x3f); - int b3 = 0x80 | ((c >> 6) & 0x3f); - int b4 = 0x80 | (c & 0x3f); + } else if (c <= 0x1fffffu) { + gpr_uint32 b1 = 0xf0u | ((c >> 18u) & 0x07u); + gpr_uint32 b2 = 0x80u | ((c >> 12u) & 0x3fu); + gpr_uint32 b3 = 0x80u | ((c >> 6u) & 0x3fu); + gpr_uint32 b4 = 0x80u | (c & 0x3fu); json_reader_string_add_char(userdata, b1); json_reader_string_add_char(userdata, b2); json_reader_string_add_char(userdata, b3); @@ -151,7 +151,7 @@ static gpr_uint32 json_reader_read_char(void* userdata) { r = fgetc(state->in); if (r == EOF) r = GRPC_JSON_READ_CHAR_EOF; - return r; + return (gpr_uint32)r; } static void json_reader_container_begins(void* userdata, grpc_json_type type) { diff --git a/test/core/profiling/timers_test.c b/test/core/profiling/timers_test.c index 12b08c115e5..b79cde64bdb 100644 --- a/test/core/profiling/timers_test.c +++ b/test/core/profiling/timers_test.c @@ -35,22 +35,22 @@ #include #include "test/core/util/test_config.h" -void test_log_events(int num_seqs) { - int start = 0; - int *state; +void test_log_events(size_t num_seqs) { + size_t start = 0; + size_t *state; state = calloc(num_seqs, sizeof(state[0])); while (start < num_seqs) { - int i; - int row; + size_t i; + size_t row; if (state[start] == 3) { /* Already done with this posn */ start++; continue; } - row = rand() % 10; /* how many in a row */ + row = (size_t)rand() % 10; /* how many in a row */ for (i = start; (i < start + row) && (i < num_seqs); i++) { - int j; - int advance = 1 + rand() % 3; /* how many to advance by */ + size_t j; + size_t advance = 1 + (size_t)rand() % 3; /* how many to advance by */ for (j = 0; j < advance; j++) { switch (state[i]) { case 0: diff --git a/test/core/security/base64_test.c b/test/core/security/base64_test.c index f8b7ebf5549..6d49b6d1a1f 100644 --- a/test/core/security/base64_test.c +++ b/test/core/security/base64_test.c @@ -70,7 +70,7 @@ static void test_full_range_encode_decode_b64(int url_safe, int multiline) { size_t i; char *b64; gpr_slice orig_decoded; - for (i = 0; i < sizeof(orig); i++) orig[i] = (char)i; + for (i = 0; i < sizeof(orig); i++) orig[i] = (gpr_uint8)i; /* Try all the different paddings. */ for (i = 0; i < 3; i++) { @@ -122,7 +122,7 @@ static void test_url_safe_unsafe_mismtach_failure(void) { char *b64; gpr_slice orig_decoded; int url_safe = 1; - for (i = 0; i < sizeof(orig); i++) orig[i] = (char)i; + for (i = 0; i < sizeof(orig); i++) orig[i] = (gpr_uint8)i; b64 = grpc_base64_encode(orig, sizeof(orig), url_safe, 0); orig_decoded = grpc_base64_decode(b64, !url_safe); diff --git a/test/core/security/json_token_test.c b/test/core/security/json_token_test.c index 0bac61eb54c..740fd018b61 100644 --- a/test/core/security/json_token_test.c +++ b/test/core/security/json_token_test.c @@ -391,20 +391,21 @@ static void test_jwt_encode_and_sign( char *jwt = jwt_encode_and_sign_func(&json_key); const char *dot = strchr(jwt, '.'); GPR_ASSERT(dot != NULL); - parsed_header = parse_json_part_from_jwt(jwt, dot - jwt, &scratchpad); + parsed_header = + parse_json_part_from_jwt(jwt, (size_t)(dot - jwt), &scratchpad); GPR_ASSERT(parsed_header != NULL); check_jwt_header(parsed_header); - offset = dot - jwt + 1; + offset = (size_t)(dot - jwt) + 1; grpc_json_destroy(parsed_header); gpr_free(scratchpad); dot = strchr(jwt + offset, '.'); GPR_ASSERT(dot != NULL); - parsed_claim = - parse_json_part_from_jwt(jwt + offset, dot - (jwt + offset), &scratchpad); + parsed_claim = parse_json_part_from_jwt( + jwt + offset, (size_t)(dot - (jwt + offset)), &scratchpad); GPR_ASSERT(parsed_claim != NULL); check_jwt_claim_func(parsed_claim); - offset = dot - jwt + 1; + offset = (size_t)(dot - jwt) + 1; grpc_json_destroy(parsed_claim); gpr_free(scratchpad); diff --git a/test/core/support/murmur_hash_test.c b/test/core/support/murmur_hash_test.c index 2462abf7deb..1e5279f4629 100644 --- a/test/core/support/murmur_hash_test.c +++ b/test/core/support/murmur_hash_test.c @@ -48,7 +48,7 @@ static void verification_test(hash_func hash, gpr_uint32 expected) { gpr_uint8 key[256]; gpr_uint32 hashes[256]; gpr_uint32 final = 0; - int i; + size_t i; memset(key, 0, sizeof(key)); memset(hashes, 0, sizeof(hashes)); @@ -58,7 +58,7 @@ static void verification_test(hash_func hash, gpr_uint32 expected) { for (i = 0; i < 256; i++) { key[i] = (uint8_t)i; - hashes[i] = hash(key, i, 256 - i); + hashes[i] = hash(key, i, 256u - i); } /* Then hash the result array */ diff --git a/test/core/support/slice_test.c b/test/core/support/slice_test.c index 3ca87427dde..a84ad50cf3b 100644 --- a/test/core/support/slice_test.c +++ b/test/core/support/slice_test.c @@ -66,7 +66,7 @@ static void test_slice_malloc_returns_something_sensible(void) { } /* We must be able to write to every byte of the data */ for (i = 0; i < length; i++) { - GPR_SLICE_START_PTR(slice)[i] = (char)i; + GPR_SLICE_START_PTR(slice)[i] = (gpr_uint8)i; } /* And finally we must succeed in destroying the slice */ gpr_slice_unref(slice); @@ -143,10 +143,10 @@ static void check_head_tail(gpr_slice slice, gpr_slice head, gpr_slice tail) { GPR_SLICE_START_PTR(tail), GPR_SLICE_LENGTH(tail))); } -static void test_slice_split_head_works(int length) { +static void test_slice_split_head_works(size_t length) { gpr_slice slice; gpr_slice head, tail; - int i; + size_t i; LOG_TEST_NAME("test_slice_split_head_works"); gpr_log(GPR_INFO, "length=%d", length); @@ -171,10 +171,10 @@ static void test_slice_split_head_works(int length) { gpr_slice_unref(slice); } -static void test_slice_split_tail_works(int length) { +static void test_slice_split_tail_works(size_t length) { gpr_slice slice; gpr_slice head, tail; - int i; + size_t i; LOG_TEST_NAME("test_slice_split_tail_works"); gpr_log(GPR_INFO, "length=%d", length); diff --git a/test/core/support/stack_lockfree_test.c b/test/core/support/stack_lockfree_test.c index 02ec3154d56..4a2a0532d8a 100644 --- a/test/core/support/stack_lockfree_test.c +++ b/test/core/support/stack_lockfree_test.c @@ -46,9 +46,10 @@ #define MAX_THREADS 32 -static void test_serial_sized(int size) { +static void test_serial_sized(size_t size) { gpr_stack_lockfree *stack = gpr_stack_lockfree_create(size); - int i; + size_t i; + size_t j; /* First try popping empty */ GPR_ASSERT(gpr_stack_lockfree_pop(stack) == -1); @@ -60,12 +61,11 @@ static void test_serial_sized(int size) { /* Now add repeatedly more items and check them */ for (i = 1; i < size; i *= 2) { - int j; for (j = 0; j <= i; j++) { GPR_ASSERT(gpr_stack_lockfree_push(stack, j) == (j == 0)); } for (j = 0; j <= i; j++) { - GPR_ASSERT(gpr_stack_lockfree_pop(stack) == i - j); + GPR_ASSERT(gpr_stack_lockfree_pop(stack) == (int)(i - j)); } GPR_ASSERT(gpr_stack_lockfree_pop(stack) == -1); } @@ -74,7 +74,7 @@ static void test_serial_sized(int size) { } static void test_serial() { - int i; + size_t i; for (i = 128; i < MAX_STACK_SIZE; i *= 2) { test_serial_sized(i); } @@ -107,7 +107,7 @@ static void test_mt_body(void *v) { } } -static void test_mt_sized(int size, int nth) { +static void test_mt_sized(size_t size, int nth) { gpr_stack_lockfree *stack; struct test_arg args[MAX_THREADS]; gpr_thd_id thds[MAX_THREADS]; @@ -137,7 +137,7 @@ static void test_mt_sized(int size, int nth) { } static void test_mt() { - int size, nth; + size_t size, nth; for (nth = 1; nth < MAX_THREADS; nth++) { for (size = 128; size < MAX_STACK_SIZE; size *= 2) { test_mt_sized(size, nth); diff --git a/test/core/support/time_test.c b/test/core/support/time_test.c index 594863c2788..ce35edd83cc 100644 --- a/test/core/support/time_test.c +++ b/test/core/support/time_test.c @@ -43,14 +43,14 @@ #include #include "test/core/util/test_config.h" -static void to_fp(void *arg, const char *buf, int len) { +static void to_fp(void *arg, const char *buf, size_t len) { fwrite(buf, 1, len, (FILE *)arg); } /* Convert gpr_uintmax x to ascii base b (2..16), and write with (*writer)(arg, ...), zero padding to "chars" digits). */ static void u_to_s(gpr_uintmax x, unsigned base, int chars, - void (*writer)(void *arg, const char *buf, int len), + void (*writer)(void *arg, const char *buf, size_t len), void *arg) { char buf[64]; char *p = buf + sizeof(buf); @@ -59,25 +59,25 @@ static void u_to_s(gpr_uintmax x, unsigned base, int chars, x /= base; chars--; } while (x != 0 || chars > 0); - (*writer)(arg, p, buf + sizeof(buf) - p); + (*writer)(arg, p, (size_t)(buf + sizeof(buf) - p)); } /* Convert gpr_intmax x to ascii base b (2..16), and write with (*writer)(arg, ...), zero padding to "chars" digits). */ static void i_to_s(gpr_intmax x, unsigned base, int chars, - void (*writer)(void *arg, const char *buf, int len), + void (*writer)(void *arg, const char *buf, size_t len), void *arg) { if (x < 0) { (*writer)(arg, "-", 1); - u_to_s(-x, base, chars - 1, writer, arg); + u_to_s((gpr_uintmax)-x, base, chars - 1, writer, arg); } else { - u_to_s(x, base, chars, writer, arg); + u_to_s((gpr_uintmax)x, base, chars, writer, arg); } } /* Convert ts to ascii, and write with (*writer)(arg, ...). */ static void ts_to_s(gpr_timespec t, - void (*writer)(void *arg, const char *buf, int len), + void (*writer)(void *arg, const char *buf, size_t len), void *arg) { if (t.tv_sec < 0 && t.tv_nsec != 0) { t.tv_sec++; @@ -96,7 +96,7 @@ static void test_values(void) { x = gpr_inf_future(GPR_CLOCK_REALTIME); fprintf(stderr, "far future "); - u_to_s(x.tv_sec, 16, 16, &to_fp, stderr); + i_to_s(x.tv_sec, 16, 16, &to_fp, stderr); fprintf(stderr, "\n"); GPR_ASSERT(x.tv_sec >= INT_MAX); fprintf(stderr, "far future "); @@ -105,7 +105,7 @@ static void test_values(void) { x = gpr_inf_past(GPR_CLOCK_REALTIME); fprintf(stderr, "far past "); - u_to_s(x.tv_sec, 16, 16, &to_fp, stderr); + i_to_s(x.tv_sec, 16, 16, &to_fp, stderr); fprintf(stderr, "\n"); GPR_ASSERT(x.tv_sec <= INT_MIN); fprintf(stderr, "far past "); diff --git a/test/core/surface/byte_buffer_reader_test.c b/test/core/surface/byte_buffer_reader_test.c index d9c60e42122..560e0ac7b23 100644 --- a/test/core/surface/byte_buffer_reader_test.c +++ b/test/core/surface/byte_buffer_reader_test.c @@ -113,14 +113,14 @@ static void test_read_none_compressed_slice(void) { } static void read_compressed_slice(grpc_compression_algorithm algorithm, - int input_size) { + size_t input_size) { gpr_slice input_slice; gpr_slice_buffer sliceb_in; gpr_slice_buffer sliceb_out; grpc_byte_buffer *buffer; grpc_byte_buffer_reader reader; gpr_slice read_slice; - int read_count = 0; + size_t read_count = 0; gpr_slice_buffer_init(&sliceb_in); gpr_slice_buffer_init(&sliceb_out); @@ -149,13 +149,13 @@ static void read_compressed_slice(grpc_compression_algorithm algorithm, } static void test_read_gzip_compressed_slice(void) { - const int INPUT_SIZE = 2048; + const size_t INPUT_SIZE = 2048; LOG_TEST("test_read_gzip_compressed_slice"); read_compressed_slice(GRPC_COMPRESS_GZIP, INPUT_SIZE); } static void test_read_deflate_compressed_slice(void) { - const int INPUT_SIZE = 2048; + const size_t INPUT_SIZE = 2048; LOG_TEST("test_read_deflate_compressed_slice"); read_compressed_slice(GRPC_COMPRESS_DEFLATE, INPUT_SIZE); } diff --git a/test/core/surface/completion_queue_test.c b/test/core/surface/completion_queue_test.c index c382b2a5aa3..0eeb5dac459 100644 --- a/test/core/surface/completion_queue_test.c +++ b/test/core/surface/completion_queue_test.c @@ -177,7 +177,7 @@ typedef struct test_thread_options { gpr_event on_phase1_done; gpr_event *phase2; gpr_event on_finished; - int events_triggered; + size_t events_triggered; int id; grpc_completion_queue *cc; } test_thread_options; @@ -251,14 +251,14 @@ static void consumer_thread(void *arg) { } } -static void test_threading(int producers, int consumers) { +static void test_threading(size_t producers, size_t consumers) { test_thread_options *options = gpr_malloc((producers + consumers) * sizeof(test_thread_options)); gpr_event phase1 = GPR_EVENT_INIT; gpr_event phase2 = GPR_EVENT_INIT; grpc_completion_queue *cc = grpc_completion_queue_create(NULL); - int i; - int total_consumed = 0; + size_t i; + size_t total_consumed = 0; static int optid = 101; gpr_log(GPR_INFO, "%s: %d producers, %d consumers", "test_threading", diff --git a/test/core/surface/lame_client_test.c b/test/core/surface/lame_client_test.c index 96434193c95..0d29bea5559 100644 --- a/test/core/surface/lame_client_test.c +++ b/test/core/surface/lame_client_test.c @@ -82,7 +82,7 @@ int main(int argc, char **argv) { op->flags = 0; op->reserved = NULL; op++; - error = grpc_call_start_batch(call, ops, op - ops, tag(1), NULL); + error = grpc_call_start_batch(call, ops, (size_t)(op - ops), tag(1), NULL); GPR_ASSERT(GRPC_CALL_OK == error); /* the call should immediately fail */ diff --git a/test/core/transport/chttp2/hpack_table_test.c b/test/core/transport/chttp2/hpack_table_test.c index 15b37d17b68..ec0a569371a 100644 --- a/test/core/transport/chttp2/hpack_table_test.c +++ b/test/core/transport/chttp2/hpack_table_test.c @@ -49,8 +49,8 @@ static void assert_str(const grpc_chttp2_hptbl *tbl, grpc_mdstr *mdstr, GPR_ASSERT(gpr_slice_str_cmp(mdstr->slice, str) == 0); } -static void assert_index(const grpc_chttp2_hptbl *tbl, int idx, const char *key, - const char *value) { +static void assert_index(const grpc_chttp2_hptbl *tbl, size_t idx, + const char *key, const char *value) { grpc_mdelem *md = grpc_chttp2_hptbl_lookup(tbl, idx); assert_str(tbl, md->key, key); assert_str(tbl, md->value, value); diff --git a/test/core/transport/chttp2/stream_encoder_test.c b/test/core/transport/chttp2/stream_encoder_test.c index e6731ff1953..4bb503b4e9f 100644 --- a/test/core/transport/chttp2/stream_encoder_test.c +++ b/test/core/transport/chttp2/stream_encoder_test.c @@ -52,8 +52,8 @@ int g_failure = 0; grpc_stream_op_buffer g_sopb; void **to_delete = NULL; -int num_to_delete = 0; -int cap_to_delete = 0; +size_t num_to_delete = 0; +size_t cap_to_delete = 0; static gpr_slice create_test_slice(size_t length) { gpr_slice slice = gpr_slice_malloc(length); @@ -126,8 +126,8 @@ static void test_small_data_framing(void) { verify_sopb(10, 0, 5, "000005 0000 deadbeef 00000000ff"); } -static void add_sopb_headers(int n, ...) { - int i; +static void add_sopb_headers(size_t n, ...) { + size_t i; grpc_metadata_batch b; va_list l; grpc_linked_mdelem *e = gpr_malloc(sizeof(*e) * n); @@ -336,7 +336,7 @@ static void run_test(void (*test)(), const char *name) { } int main(int argc, char **argv) { - int i; + size_t i; grpc_test_init(argc, argv); TEST(test_small_data_framing); TEST(test_basic_headers); diff --git a/test/core/transport/chttp2/stream_map_test.c b/test/core/transport/chttp2/stream_map_test.c index b0bb3a89048..72aaafd18d7 100644 --- a/test/core/transport/chttp2/stream_map_test.c +++ b/test/core/transport/chttp2/stream_map_test.c @@ -203,9 +203,9 @@ static void test_periodic_compaction(size_t n) { } int main(int argc, char **argv) { - int n = 1; - int prev = 1; - int tmp; + size_t n = 1; + size_t prev = 1; + size_t tmp; grpc_test_init(argc, argv); diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c index 4a4d4bcb8a1..1861442bb1d 100644 --- a/test/core/transport/metadata_test.c +++ b/test/core/transport/metadata_test.c @@ -177,11 +177,11 @@ static void test_spin_creating_the_same_thing(void) { static void test_things_stick_around(void) { grpc_mdctx *ctx; - int i, j; + size_t i, j; char *buffer; - int nstrs = 1000; + size_t nstrs = 1000; grpc_mdstr **strs = gpr_malloc(sizeof(grpc_mdstr *) * nstrs); - int *shuf = gpr_malloc(sizeof(int) * nstrs); + size_t *shuf = gpr_malloc(sizeof(size_t) * nstrs); grpc_mdstr *test; LOG_TEST("test_things_stick_around"); @@ -201,9 +201,9 @@ static void test_things_stick_around(void) { } for (i = 0; i < nstrs; i++) { - int p = rand() % nstrs; - int q = rand() % nstrs; - int temp = shuf[p]; + size_t p = (size_t)rand() % nstrs; + size_t q = (size_t)rand() % nstrs; + size_t temp = shuf[p]; shuf[p] = shuf[q]; shuf[q] = temp; } From 841c880c2be590aff22be5e7ff2aefed2019ce22 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Sep 2015 13:06:37 -0700 Subject: [PATCH 26/32] Core compiles with -Wsign-conversion --- Makefile | 4 +- .../resolvers/zookeeper_resolver.c | 6 +- templates/Makefile.template | 3696 +++++++++-------- 3 files changed, 1854 insertions(+), 1852 deletions(-) diff --git a/Makefile b/Makefile index f8da66625cf..5a3f1ea7412 100644 --- a/Makefile +++ b/Makefile @@ -245,13 +245,13 @@ ifdef EXTRA_DEFINES DEFINES += $(EXTRA_DEFINES) endif -CFLAGS += -std=c89 -pedantic +CFLAGS += -std=c89 -pedantic -Wsign-conversion ifeq ($(HAS_CXX11),true) CXXFLAGS += -std=c++11 else CXXFLAGS += -std=c++0x endif -CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter -Wsign-conversion +CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter LDFLAGS += -g CPPFLAGS += $(CPPFLAGS_$(CONFIG)) diff --git a/src/core/client_config/resolvers/zookeeper_resolver.c b/src/core/client_config/resolvers/zookeeper_resolver.c index da399f99548..9a732b14174 100644 --- a/src/core/client_config/resolvers/zookeeper_resolver.c +++ b/src/core/client_config/resolvers/zookeeper_resolver.c @@ -244,7 +244,7 @@ static void zookeeper_dns_resolved(void *arg, } /** Parses JSON format address of a zookeeper node */ -static char *zookeeper_parse_address(const char *value, int value_len) { +static char *zookeeper_parse_address(const char *value, size_t value_len) { grpc_json *json; grpc_json *cur; const char *host; @@ -294,7 +294,7 @@ static void zookeeper_get_children_node_completion(int rc, const char *value, return; } - address = zookeeper_parse_address(value, value_len); + address = zookeeper_parse_address(value, (size_t)value_len); if (address != NULL) { /** Further resolves address by DNS */ grpc_resolve_address(address, NULL, zookeeper_dns_resolved, r); @@ -364,7 +364,7 @@ static void zookeeper_get_node_completion(int rc, const char *value, /** If zookeeper node of path r->name does not have address (i.e. service node), get its children */ - address = zookeeper_parse_address(value, value_len); + address = zookeeper_parse_address(value, (size_t)value_len); if (address != NULL) { r->resolved_addrs = gpr_malloc(sizeof(grpc_resolved_addresses)); r->resolved_addrs->addrs = NULL; diff --git a/templates/Makefile.template b/templates/Makefile.template index 5be4eedfee0..79640180f68 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -1,1874 +1,1876 @@ -# GRPC global makefile -# This currently builds C and C++ code. -# This file has been automatically generated from a template file. -# Please look at the templates directory instead. -# This file can be regenerated from the template by running -# tools/buildgen/generate_projects.sh - -# 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. -<%! - import re - import os - - proto_re = re.compile('(.*)\\.proto') - - def proto_to_cc(filename): - m = proto_re.match(filename) - if not m: - return filename - return '$(GENDIR)/' + m.group(1) + '.pb.cc $(GENDIR)/' + m.group(1) + '.grpc.pb.cc' - - sources_that_need_openssl = set() - sources_that_don_t_need_openssl = set() -%> - - -# Basic platform detection -HOST_SYSTEM = $(shell uname | cut -f 1 -d_) -ifeq ($(SYSTEM),) -SYSTEM = $(HOST_SYSTEM) -endif -ifeq ($(SYSTEM),MSYS) -SYSTEM = MINGW32 -endif -ifeq ($(SYSTEM),MINGW64) -SYSTEM = MINGW32 -endif - - -ifndef BUILDDIR -BUILDDIR = . -endif - -HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false) -HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false) -HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false) - -ifeq ($(HAS_CC),true) -DEFAULT_CC = cc -DEFAULT_CXX = c++ -else -ifeq ($(HAS_GCC),true) -DEFAULT_CC = gcc -DEFAULT_CXX = g++ -else -ifeq ($(HAS_CLANG),true) -DEFAULT_CC = clang -DEFAULT_CXX = clang++ -else -DEFAULT_CC = no_c_compiler -DEFAULT_CXX = no_c++_compiler -endif -endif -endif - - -BINDIR = $(BUILDDIR)/bins -OBJDIR = $(BUILDDIR)/objs -LIBDIR = $(BUILDDIR)/libs -GENDIR = $(BUILDDIR)/gens - -# Configurations - -VALID_CONFIG_opt = 1 -CC_opt = $(DEFAULT_CC) -CXX_opt = $(DEFAULT_CXX) -LD_opt = $(DEFAULT_CC) -LDXX_opt = $(DEFAULT_CXX) -CPPFLAGS_opt = -O2 -LDFLAGS_opt = -DEFINES_opt = NDEBUG - -VALID_CONFIG_basicprof = 1 -CC_basicprof = $(DEFAULT_CC) -CXX_basicprof = $(DEFAULT_CXX) -LD_basicprof = $(DEFAULT_CC) -LDXX_basicprof = $(DEFAULT_CXX) -CPPFLAGS_basicprof = -O2 -DGRPC_BASIC_PROFILER -DGRPC_TIMERS_RDTSC -LDFLAGS_basicprof = -DEFINES_basicprof = NDEBUG - -VALID_CONFIG_stapprof = 1 -CC_stapprof = $(DEFAULT_CC) -CXX_stapprof = $(DEFAULT_CXX) -LD_stapprof = $(DEFAULT_CC) -LDXX_stapprof = $(DEFAULT_CXX) -CPPFLAGS_stapprof = -O2 -DGRPC_STAP_PROFILER -LDFLAGS_stapprof = -DEFINES_stapprof = NDEBUG - -VALID_CONFIG_dbg = 1 -CC_dbg = $(DEFAULT_CC) -CXX_dbg = $(DEFAULT_CXX) -LD_dbg = $(DEFAULT_CC) -LDXX_dbg = $(DEFAULT_CXX) -CPPFLAGS_dbg = -O0 -LDFLAGS_dbg = -DEFINES_dbg = _DEBUG DEBUG - -VALID_CONFIG_mutrace = 1 -CC_mutrace = $(DEFAULT_CC) -CXX_mutrace = $(DEFAULT_CXX) -LD_mutrace = $(DEFAULT_CC) -LDXX_mutrace = $(DEFAULT_CXX) -CPPFLAGS_mutrace = -O0 -LDFLAGS_mutrace = -rdynamic -DEFINES_mutrace = _DEBUG DEBUG - -VALID_CONFIG_valgrind = 1 -REQUIRE_CUSTOM_LIBRARIES_valgrind = 1 -CC_valgrind = $(DEFAULT_CC) -CXX_valgrind = $(DEFAULT_CXX) -LD_valgrind = $(DEFAULT_CC) -LDXX_valgrind = $(DEFAULT_CXX) -CPPFLAGS_valgrind = -O0 -OPENSSL_CFLAGS_valgrind = -DPURIFY -LDFLAGS_valgrind = -DEFINES_valgrind = _DEBUG DEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20 - -VALID_CONFIG_tsan = 1 -REQUIRE_CUSTOM_LIBRARIES_tsan = 1 -CC_tsan = clang -CXX_tsan = clang++ -LD_tsan = clang -LDXX_tsan = clang++ -CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-error=unused-command-line-argument -LDFLAGS_tsan = -fsanitize=thread -DEFINES_tsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10 - -VALID_CONFIG_asan = 1 -REQUIRE_CUSTOM_LIBRARIES_asan = 1 -CC_asan = clang -CXX_asan = clang++ -LD_asan = clang -LDXX_asan = clang++ -CPPFLAGS_asan = -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-error=unused-command-line-argument -LDFLAGS_asan = -fsanitize=address -DEFINES_asan = GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 - -VALID_CONFIG_msan = 1 -REQUIRE_CUSTOM_LIBRARIES_msan = 1 -CC_msan = clang -CXX_msan = clang++-libc++ -LD_msan = clang -LDXX_msan = clang++-libc++ -CPPFLAGS_msan = -O0 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-error=unused-command-line-argument -OPENSSL_CFLAGS_msan = -DPURIFY -LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -DEFINES_msan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=4 - -VALID_CONFIG_ubsan = 1 -REQUIRE_CUSTOM_LIBRARIES_ubsan = 1 -CC_ubsan = clang -CXX_ubsan = clang++ -LD_ubsan = clang -LDXX_ubsan = clang++ -CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer -Wno-error=unused-command-line-argument -OPENSSL_CFLAGS_ubsan = -DPURIFY -LDFLAGS_ubsan = -fsanitize=undefined -DEFINES_ubsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 - -VALID_CONFIG_gcov = 1 -CC_gcov = gcc -CXX_gcov = g++ -LD_gcov = gcc -LDXX_gcov = g++ -CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage -LDFLAGS_gcov = -fprofile-arcs -ftest-coverage -DEFINES_gcov = _DEBUG DEBUG - - -# General settings. -# You may want to change these depending on your system. - -prefix ?= /usr/local - -PROTOC = protoc -DTRACE = dtrace -CONFIG ?= opt -CC = $(CC_$(CONFIG)) -CXX = $(CXX_$(CONFIG)) -LD = $(LD_$(CONFIG)) -LDXX = $(LDXX_$(CONFIG)) -AR = ar -ifeq ($(SYSTEM),Linux) -STRIP = strip --strip-unneeded -else -ifeq ($(SYSTEM),Darwin) -STRIP = strip -x -else -STRIP = strip -endif -endif -INSTALL = install -RM = rm -f -PKG_CONFIG = pkg-config - -ifndef VALID_CONFIG_$(CONFIG) -$(error Invalid CONFIG value '$(CONFIG)') -endif - -ifeq ($(SYSTEM),Linux) -TMPOUT = /dev/null -else -TMPOUT = `mktemp /tmp/test-out-XXXXXX` -endif - -# Detect if we can use C++11 -CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc -HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false) - -# The HOST compiler settings are used to compile the protoc plugins. -# In most cases, you won't have to change anything, but if you are -# cross-compiling, you can override these variables from GNU make's -# command line: make CC=cross-gcc HOST_CC=gcc - -HOST_CC = $(CC) -HOST_CXX = $(CXX) -HOST_LD = $(LD) -HOST_LDXX = $(LDXX) - -ifdef EXTRA_DEFINES -DEFINES += $(EXTRA_DEFINES) -endif - -CFLAGS += -std=c89 -pedantic -ifeq ($(HAS_CXX11),true) -CXXFLAGS += -std=c++11 -else -CXXFLAGS += -std=c++0x -endif -CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter -Wsign-conversion -LDFLAGS += -g - -CPPFLAGS += $(CPPFLAGS_$(CONFIG)) -DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\" -LDFLAGS += $(LDFLAGS_$(CONFIG)) - -ifneq ($(SYSTEM),MINGW32) -PIC_CPPFLAGS = -fPIC -CPPFLAGS += -fPIC -LDFLAGS += -fPIC -endif - -INCLUDES = . include $(GENDIR) -LDFLAGS += -Llibs/$(CONFIG) - -ifeq ($(SYSTEM),Darwin) -ifneq ($(wildcard /usr/local/ssl/include),) -INCLUDES += /usr/local/ssl/include -endif -ifneq ($(wildcard /opt/local/include),) -INCLUDES += /opt/local/include -endif -ifneq ($(wildcard /usr/local/include),) -INCLUDES += /usr/local/include -endif -LIBS = m z -ifneq ($(wildcard /usr/local/ssl/lib),) -LDFLAGS += -L/usr/local/ssl/lib -endif -ifneq ($(wildcard /opt/local/lib),) -LDFLAGS += -L/opt/local/lib -endif -ifneq ($(wildcard /usr/local/lib),) -LDFLAGS += -L/usr/local/lib -endif -endif - -ifeq ($(SYSTEM),Linux) -LIBS = rt m z pthread -LDFLAGS += -pthread -endif - -ifeq ($(SYSTEM),MINGW32) -LIBS = m z pthread -LDFLAGS += -pthread -endif - -GTEST_LIB = -Ithird_party/googletest/include -Ithird_party/googletest third_party/googletest/src/gtest-all.cc -GTEST_LIB += -lgflags -ifeq ($(V),1) -E = @: -Q = -else -E = @echo -Q = @ -endif - -VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build} - -CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES)) -CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS) - -LDFLAGS += $(ARCH_FLAGS) -LDLIBS += $(addprefix -l, $(LIBS)) -LDLIBSXX += $(addprefix -l, $(LIBSXX)) - -HOST_CPPFLAGS = $(CPPFLAGS) -HOST_CFLAGS = $(CFLAGS) -HOST_CXXFLAGS = $(CXXFLAGS) -HOST_LDFLAGS = $(LDFLAGS) -HOST_LDLIBS = $(LDLIBS) - - -# These are automatically computed variables. -# There shouldn't be any need to change anything from now on. - --include cache.mk - -CACHE_MK = - -HAS_PKG_CONFIG ?= $(shell command -v $(PKG_CONFIG) >/dev/null 2>&1 && echo true || echo false) - -ifeq ($(HAS_PKG_CONFIG), true) -CACHE_MK += HAS_PKG_CONFIG = true, -endif - -PC_TEMPLATE = prefix=$(prefix),\ -exec_prefix=${'\$${prefix}'},\ -includedir=${'\$${prefix}'}/include,\ -libdir=${'\$${exec_prefix}'}/lib,\ -,\ -Name: $(PC_NAME),\ -Description: $(PC_DESCRIPTION),\ -Version: $(VERSION),\ -Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\ -Requires.private: $(PC_REQUIRES_PRIVATE),\ -Libs: -L${'\$${libdir}'} $(PC_LIB),\ -Libs.private: $(PC_LIBS_PRIVATE) - -# gpr .pc file -PC_NAME = gRPC Portable Runtime -PC_DESCRIPTION = gRPC Portable Runtime -PC_CFLAGS = -pthread -PC_REQUIRES_PRIVATE = -PC_LIBS_PRIVATE = -lpthread -PC_LIB = -lgpr -ifneq ($(SYSTEM),Darwin) -PC_LIBS_PRIVATE += -lrt -endif -GPR_PC_FILE := $(PC_TEMPLATE) - -ifeq ($(SYSTEM),MINGW32) -SHARED_EXT = dll -endif -ifeq ($(SYSTEM),Darwin) -SHARED_EXT = dylib -endif -ifeq ($(SHARED_EXT),) -SHARED_EXT = so.$(VERSION) -endif - -ifeq ($(wildcard .git),) -IS_GIT_FOLDER = false -else -IS_GIT_FOLDER = true -endif - -ifeq ($(SYSTEM),Linux) -OPENSSL_REQUIRES_DL = true -endif - -ifeq ($(SYSTEM),Darwin) -OPENSSL_REQUIRES_DL = true -endif - -ifeq ($(HAS_PKG_CONFIG),true) -OPENSSL_ALPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.2 openssl -OPENSSL_NPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.1 openssl -ZLIB_CHECK_CMD = $(PKG_CONFIG) --exists zlib -PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.0.0-alpha-3 protobuf -else # HAS_PKG_CONFIG - -ifeq ($(SYSTEM),MINGW32) -OPENSSL_LIBS = ssl32 eay32 -else -OPENSSL_LIBS = ssl crypto -endif - -OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS) -OPENSSL_NPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/openssl-npn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS) -ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS) -PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS) - -ifeq ($(OPENSSL_REQUIRES_DL),true) -OPENSSL_ALPN_CHECK_CMD += -ldl -OPENSSL_NPN_CHECK_CMD += -ldl -endif - -endif # HAS_PKG_CONFIG - -PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS) - -PROTOC_CHECK_CMD = which protoc > /dev/null -PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3 -DTRACE_CHECK_CMD = which dtrace > /dev/null -SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS) -ZOOKEEPER_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zookeeper.c $(LDFLAGS) -lzookeeper_mt - -ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG) -HAS_SYSTEM_PERFTOOLS ?= $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false) -ifeq ($(HAS_SYSTEM_PERFTOOLS),true) -DEFINES += GRPC_HAVE_PERFTOOLS -LIBS += profiler -CACHE_MK += HAS_SYSTEM_PERFTOOLS = true, -endif -endif - -HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false) -ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG) -HAS_SYSTEM_OPENSSL_ALPN ?= $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false) -ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true) -HAS_SYSTEM_OPENSSL_NPN = true -CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true, -else -HAS_SYSTEM_OPENSSL_NPN ?= $(shell $(OPENSSL_NPN_CHECK_CMD) 2> /dev/null && echo true || echo false) -endif -ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true) -CACHE_MK += HAS_SYSTEM_OPENSSL_NPN = true, -endif -HAS_SYSTEM_ZLIB ?= $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false) -ifeq ($(HAS_SYSTEM_ZLIB),true) -CACHE_MK += HAS_SYSTEM_ZLIB = true, -endif -HAS_SYSTEM_PROTOBUF ?= $(HAS_SYSTEM_PROTOBUF_VERIFY) -ifeq ($(HAS_SYSTEM_PROTOBUF),true) -CACHE_MK += HAS_SYSTEM_PROTOBUF = true, -endif -else -# override system libraries if the config requires a custom compiled library -HAS_SYSTEM_OPENSSL_ALPN = false -HAS_SYSTEM_OPENSSL_NPN = false -HAS_SYSTEM_ZLIB = false -HAS_SYSTEM_PROTOBUF = false -endif - -HAS_PROTOC ?= $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false) -ifeq ($(HAS_PROTOC),true) -CACHE_MK += HAS_PROTOC = true, -HAS_VALID_PROTOC ?= $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false) -ifeq ($(HAS_VALID_PROTOC),true) -CACHE_MK += HAS_VALID_PROTOC = true, -endif -else -HAS_VALID_PROTOC = false -endif - -# Check for Systemtap (https://sourceware.org/systemtap/), first by making sure is present -# in the system and secondly by checking for the "dtrace" binary (on Linux, this is part of the Systemtap -# distribution. It's part of the base system on BSD/Solaris machines). -ifndef HAS_SYSTEMTAP -HAS_SYSTEMTAP_HEADERS = $(shell $(SYSTEMTAP_HEADERS_CHECK_CMD) 2> /dev/null && echo true || echo false) -HAS_DTRACE = $(shell $(DTRACE_CHECK_CMD) 2> /dev/null && echo true || echo false) -HAS_SYSTEMTAP = false -ifeq ($(HAS_SYSTEMTAP_HEADERS),true) -ifeq ($(HAS_DTRACE),true) -HAS_SYSTEMTAP = true -endif -endif -endif - -ifeq ($(HAS_SYSTEMTAP),true) -CACHE_MK += HAS_SYSTEMTAP = true, -endif - -HAS_ZOOKEEPER = $(shell $(ZOOKEEPER_CHECK_CMD) 2> /dev/null && echo true || echo false) - -# Note that for testing purposes, one can do: -# make HAS_EMBEDDED_OPENSSL_ALPN=false -# to emulate the fact we do not have OpenSSL in the third_party folder. -ifeq ($(wildcard third_party/openssl/ssl/ssl.h),) -HAS_EMBEDDED_OPENSSL_ALPN = false -else -HAS_EMBEDDED_OPENSSL_ALPN = true -endif - -ifeq ($(wildcard third_party/zlib/zlib.h),) -HAS_EMBEDDED_ZLIB = false -else -HAS_EMBEDDED_ZLIB = true -endif - -ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),) -HAS_EMBEDDED_PROTOBUF = false -ifneq ($(HAS_VALID_PROTOC),true) -NO_PROTOC = true -endif -else -HAS_EMBEDDED_PROTOBUF = true -endif - -PC_REQUIRES_GRPC = gpr -PC_LIBS_GRPC = - -ifeq ($(HAS_SYSTEM_ZLIB),false) -ifeq ($(HAS_EMBEDDED_ZLIB),true) -ZLIB_DEP = $(LIBDIR)/$(CONFIG)/zlib/libz.a -CPPFLAGS += -Ithird_party/zlib -LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib -else -DEP_MISSING += zlib -endif -else -ifeq ($(HAS_PKG_CONFIG),true) -CPPFLAGS += $(shell $(PKG_CONFIG) --cflags zlib) -LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L zlib) -PC_REQUIRES_GRPC += zlib -else -PC_LIBS_GRPC += -lz -endif -endif - -OPENSSL_PKG_CONFIG = false - -PC_REQUIRES_SECURE = -PC_LIBS_SECURE = - -ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true) -ifeq ($(HAS_PKG_CONFIG),true) -OPENSSL_PKG_CONFIG = true -PC_REQUIRES_SECURE = openssl -CPPFLAGS := $(shell $(PKG_CONFIG) --cflags openssl) $(CPPFLAGS) -LDFLAGS_OPENSSL_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L openssl) -ifeq ($(SYSTEM),Linux) -ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),) -LDFLAGS_OPENSSL_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L openssl | sed s/L/Wl,-rpath,/) -endif -endif -LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS) -else -LIBS_SECURE = $(OPENSSL_LIBS) -ifeq ($(OPENSSL_REQUIRES_DL),true) -LIBS_SECURE += dl -PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE)) -endif -endif -else -ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true) -USE_SYSTEM_OPENSSL = false -OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a -OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a -# need to prefix these to ensure overriding system libraries -CPPFLAGS := -Ithird_party/openssl/include $(CPPFLAGS) -LDFLAGS := -L$(LIBDIR)/$(CONFIG)/openssl $(LDFLAGS) -ifeq ($(OPENSSL_REQUIRES_DL),true) -LIBS_SECURE = dl -endif -else -ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true) -USE_SYSTEM_OPENSSL = true -CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0 -LIBS_SECURE = $(OPENSSL_LIBS) -ifeq ($(OPENSSL_REQUIRES_DL),true) -LIBS_SECURE += dl -endif -else -NO_SECURE = true -endif -endif -endif - -ifeq ($(OPENSSL_PKG_CONFIG),true) -LDLIBS_SECURE += $(shell $(PKG_CONFIG) --libs-only-l openssl) -else -LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE)) -endif - -# grpc .pc file -PC_NAME = gRPC -PC_DESCRIPTION = high performance general RPC framework -PC_CFLAGS = -PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC) $(PC_REQUIRES_SECURE) -PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) $(PC_LIBS_SECURE) -PC_LIB = -lgrpc -GRPC_PC_FILE := $(PC_TEMPLATE) - -# gprc_unsecure .pc file -PC_NAME = gRPC unsecure -PC_DESCRIPTION = high performance general RPC framework without SSL -PC_CFLAGS = -PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC) -PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) -PC_LIB = -lgrpc -GRPC_UNSECURE_PC_FILE := $(PC_TEMPLATE) - -# gprc_zookeeper .pc file -PC_NAME = gRPC zookeeper -PC_DESCRIPTION = gRPC's zookeeper plugin -PC_CFLAGS = -PC_REQUIRES_PRIVATE = -PC_LIBS_PRIVATE = -lzookeeper_mt -GRPC_ZOOKEEPER_PC_FILE := $(PC_TEMPLATE) - -PROTOBUF_PKG_CONFIG = false - -PC_REQUIRES_GRPCXX = -PC_LIBS_GRPCXX = - -CPPFLAGS := -Ithird_party/googletest/include $(CPPFLAGS) - -ifeq ($(HAS_SYSTEM_PROTOBUF),true) -ifeq ($(HAS_PKG_CONFIG),true) -PROTOBUF_PKG_CONFIG = true -PC_REQUIRES_GRPCXX = protobuf -CPPFLAGS := $(shell $(PKG_CONFIG) --cflags protobuf) $(CPPFLAGS) -LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L protobuf) -ifeq ($(SYSTEM),Linux) -ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),) -LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L protobuf | sed s/L/Wl,-rpath,/) -endif -endif -else -PC_LIBS_GRPCXX = -lprotobuf -endif -else -ifeq ($(HAS_EMBEDDED_PROTOBUF),true) -PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a -CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS) -LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS) -PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc -else -NO_PROTOBUF = true -endif -endif - -LIBS_PROTOBUF = protobuf -LIBS_PROTOC = protoc protobuf - -HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC)) - -ifeq ($(PROTOBUF_PKG_CONFIG),true) -LDLIBS_PROTOBUF += $(shell $(PKG_CONFIG) --libs-only-l protobuf) -else -LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF)) -endif - -# grpc++ .pc file -PC_NAME = gRPC++ -PC_DESCRIPTION = C++ wrapper for gRPC -PC_CFLAGS = -PC_REQUIRES_PRIVATE = grpc $(PC_REQUIRES_GRPCXX) -PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX) -PC_LIB = -lgrpc++ -GRPCXX_PC_FILE := $(PC_TEMPLATE) - -# grpc++_unsecure .pc file -PC_NAME = gRPC++ unsecure -PC_DESCRIPTION = C++ wrapper for gRPC without SSL -PC_CFLAGS = -PC_REQUIRES_PRIVATE = grpc_unsecure $(PC_REQUIRES_GRPCXX) -PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX) -PC_LIB = -lgrpc++ -GRPCXX_UNSECURE_PC_FILE := $(PC_TEMPLATE) - -ifeq ($(MAKECMDGOALS),clean) -NO_DEPS = true -endif - -INSTALL_OK = false -ifeq ($(HAS_VALID_PROTOC),true) -ifeq ($(HAS_SYSTEM_PROTOBUF_VERIFY),true) -INSTALL_OK = true -endif -endif - -.SECONDARY = %.pb.h %.pb.cc - -PROTOC_PLUGINS =\ -% for tgt in targets: -% if tgt.build == 'protoc': - $(BINDIR)/$(CONFIG)/${tgt.name}\ -% endif -% endfor - -ifeq ($(DEP_MISSING),) -all: static shared plugins\ -% for tgt in targets: -% if tgt.build == 'all': - $(BINDIR)/$(CONFIG)/${tgt.name}\ -% endif -% endfor - -dep_error: - @echo "You shouldn't see this message - all of your dependencies are correct." -else -all: dep_error git_update stop - -dep_error: - @echo - @echo "DEPENDENCY ERROR" - @echo - @echo "You are missing system dependencies that are essential to build grpc," - @echo "and the third_party directory doesn't have them:" - @echo - @echo " $(DEP_MISSING)" - @echo - @echo "Installing the development packages for your system will solve" - @echo "this issue. Please consult INSTALL to get more information." - @echo - @echo "If you need information about why these tests failed, run:" - @echo - @echo " make run_dep_checks" - @echo -endif - -git_update: -ifeq ($(IS_GIT_FOLDER),true) - @echo "Additionally, since you are in a git clone, you can download the" - @echo "missing dependencies in third_party by running the following command:" - @echo - @echo " git submodule update --init" - @echo -endif - -openssl_dep_error: openssl_dep_message git_update stop - -protobuf_dep_error: protobuf_dep_message git_update stop - -protoc_dep_error: protoc_dep_message git_update stop - -openssl_dep_message: - @echo - @echo "DEPENDENCY ERROR" - @echo - @echo "The target you are trying to run requires OpenSSL." - @echo "Your system doesn't have it, and neither does the third_party directory." - @echo - @echo "Please consult INSTALL to get more information." - @echo - @echo "If you need information about why these tests failed, run:" - @echo - @echo " make run_dep_checks" - @echo - -protobuf_dep_message: - @echo - @echo "DEPENDENCY ERROR" - @echo - @echo "The target you are trying to run requires protobuf 3.0.0+" - @echo "Your system doesn't have it, and neither does the third_party directory." - @echo - @echo "Please consult INSTALL to get more information." - @echo - @echo "If you need information about why these tests failed, run:" - @echo - @echo " make run_dep_checks" - @echo - -protoc_dep_message: - @echo - @echo "DEPENDENCY ERROR" - @echo - @echo "The target you are trying to run requires protobuf-compiler 3.0.0+" - @echo "Your system doesn't have it, and neither does the third_party directory." - @echo - @echo "Please consult INSTALL to get more information." - @echo - @echo "If you need information about why these tests failed, run:" - @echo - @echo " make run_dep_checks" - @echo - -systemtap_dep_error: - @echo - @echo "DEPENDENCY ERROR" - @echo - @echo "Under the '$(CONFIG)' configutation, the target you are trying " - @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other " - @echo "platforms such as Solaris and *BSD). " - @echo - @echo "Please consult INSTALL to get more information." - @echo - -stop: - @false - -% for tgt in targets: -${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name} -% endfor - -run_dep_checks: - $(OPENSSL_ALPN_CHECK_CMD) || true - $(OPENSSL_NPN_CHECK_CMD) || true - $(ZLIB_CHECK_CMD) || true - $(PERFTOOLS_CHECK_CMD) || true - $(PROTOBUF_CHECK_CMD) || true - $(PROTOC_CHECK_VERSION_CMD) || true - $(ZOOKEEPER_CHECK_CMD) || true - -$(LIBDIR)/$(CONFIG)/zlib/libz.a: - $(E) "[MAKE] Building zlib" - $(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="$(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(ZLIB_CFLAGS_EXTRA)" ./configure --static) - $(Q)$(MAKE) -C third_party/zlib clean - $(Q)$(MAKE) -C third_party/zlib - $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/zlib - $(Q)cp third_party/zlib/libz.a $(LIBDIR)/$(CONFIG)/zlib - -$(LIBDIR)/$(CONFIG)/openssl/libssl.a: - $(E) "[MAKE] Building openssl for $(SYSTEM)" -ifeq ($(SYSTEM),Darwin) - $(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_EXTRA)" ./Configure darwin64-x86_64-cc) -else -ifeq ($(SYSTEM),MINGW32) - @echo "We currently don't have a good way to compile OpenSSL in-place under msys." - @echo "Please provide a OpenSSL in your mingw32 system." - @echo - @echo "Note that you can find a compatible version of the libraries here:" - @echo - @echo "http://slproweb.com/products/Win32OpenSSL.html" - @echo - @echo "If you decide to install that one, take the full version. The light" - @echo "version only contains compiled DLLs, without the development files." - @echo - @echo "When installing, chose to copy the OpenSSL dlls to the OpenSSL binaries" - @echo "directory. This way we'll link to them directly." - @echo - @echo "You can then re-start the build the following way:" - @echo - @echo " CPPFLAGS=-I/c/OpenSSL-Win64/include LDFLAGS=-L/c/OpenSSL-Win64 make" - @false -else - $(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_EXTRA)" ./config no-asm $(OPENSSL_CONFIG_$(CONFIG))) -endif -endif - $(Q)$(MAKE) -j 1 -C third_party/openssl clean - $(Q)(unset CPPFLAGS; $(MAKE) -j 1 -C third_party/openssl build_crypto build_ssl) - $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/openssl - $(Q)cp third_party/openssl/libssl.a third_party/openssl/libcrypto.a $(LIBDIR)/$(CONFIG)/openssl - -third_party/protobuf/configure: - $(E) "[AUTOGEN] Preparing protobuf" - $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete) - -$(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure - $(E) "[MAKE] Building protobuf" - $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g $(PROTOBUF_LDFLAGS_EXTRA)" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g $(PROTOBUF_CPPFLAGS_EXTRA)" ./configure --disable-shared --enable-static) - $(Q)$(MAKE) -C third_party/protobuf clean - $(Q)$(MAKE) -C third_party/protobuf - $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf - $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf - $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf - $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf - $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf - -static: static_c static_cxx - -static_c: pc_c pc_c_unsecure cache.mk pc_gpr pc_c_zookeeper\ -% for lib in libs: -% if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None): - $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ -% endif -% endfor - static_zookeeper_libs - - -static_cxx: pc_cxx pc_cxx_unsecure pc_gpr cache.mk \ -% for lib in libs: -% if lib.build == 'all' and lib.language == 'c++': - $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ -% endif -% endfor - - -shared: shared_c shared_cxx - -shared_c: pc_c pc_c_unsecure pc_gpr cache.mk pc_c_zookeeper\ -% for lib in libs: -% if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None): - $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\ -% endif -% endfor - shared_zookeeper_libs - -shared_cxx: pc_cxx pc_cxx_unsecure cache.mk\ -% for lib in libs: -% if lib.build == 'all' and lib.language == 'c++': - $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\ -% endif -% endfor - - -shared_csharp: shared_c \ -% for lib in libs: -% if lib.build == 'all' and lib.language == 'csharp': - $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\ -% endif -% endfor - -ifeq ($(HAS_ZOOKEEPER),true) -static_zookeeper_libs:\ -% for lib in libs: -% if lib.build == 'all' and lib.language == 'c' and 'zookeeper' in lib.get('external_deps', []): - $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ -% endif -% endfor - -shared_zookeeper_libs:\ -% for lib in libs: -% if lib.build == 'all' and lib.language == 'c' and 'zookeeper' in lib.get('external_deps', []): - $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\ -% endif -% endfor - -else - -static_zookeeper_libs: - -shared_zookeeper_libs: - -endif - -grpc_csharp_ext: shared_csharp - -plugins: $(PROTOC_PLUGINS) - -privatelibs: privatelibs_c privatelibs_cxx - -privatelibs_c: \ -% for lib in libs: -% if lib.build == 'private' and lib.language == 'c' and not lib.get('external_deps', None): - $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ -% endif -% endfor +%YAML 1.2 +--- | + # GRPC global makefile + # This currently builds C and C++ code. + # This file has been automatically generated from a template file. + # Please look at the templates directory instead. + # This file can be regenerated from the template by running + # tools/buildgen/generate_projects.sh + + # 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. + <%! + import re + import os + + proto_re = re.compile('(.*)\\.proto') + + def proto_to_cc(filename): + m = proto_re.match(filename) + if not m: + return filename + return '$(GENDIR)/' + m.group(1) + '.pb.cc $(GENDIR)/' + m.group(1) + '.grpc.pb.cc' + + sources_that_need_openssl = set() + sources_that_don_t_need_openssl = set() + %> + + + # Basic platform detection + HOST_SYSTEM = $(shell uname | cut -f 1 -d_) + ifeq ($(SYSTEM),) + SYSTEM = $(HOST_SYSTEM) + endif + ifeq ($(SYSTEM),MSYS) + SYSTEM = MINGW32 + endif + ifeq ($(SYSTEM),MINGW64) + SYSTEM = MINGW32 + endif + + + ifndef BUILDDIR + BUILDDIR = . + endif + + HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false) + HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false) + HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false) + + ifeq ($(HAS_CC),true) + DEFAULT_CC = cc + DEFAULT_CXX = c++ + else + ifeq ($(HAS_GCC),true) + DEFAULT_CC = gcc + DEFAULT_CXX = g++ + else + ifeq ($(HAS_CLANG),true) + DEFAULT_CC = clang + DEFAULT_CXX = clang++ + else + DEFAULT_CC = no_c_compiler + DEFAULT_CXX = no_c++_compiler + endif + endif + endif + + + BINDIR = $(BUILDDIR)/bins + OBJDIR = $(BUILDDIR)/objs + LIBDIR = $(BUILDDIR)/libs + GENDIR = $(BUILDDIR)/gens + + # Configurations + + VALID_CONFIG_opt = 1 + CC_opt = $(DEFAULT_CC) + CXX_opt = $(DEFAULT_CXX) + LD_opt = $(DEFAULT_CC) + LDXX_opt = $(DEFAULT_CXX) + CPPFLAGS_opt = -O2 + LDFLAGS_opt = + DEFINES_opt = NDEBUG + + VALID_CONFIG_basicprof = 1 + CC_basicprof = $(DEFAULT_CC) + CXX_basicprof = $(DEFAULT_CXX) + LD_basicprof = $(DEFAULT_CC) + LDXX_basicprof = $(DEFAULT_CXX) + CPPFLAGS_basicprof = -O2 -DGRPC_BASIC_PROFILER -DGRPC_TIMERS_RDTSC + LDFLAGS_basicprof = + DEFINES_basicprof = NDEBUG + + VALID_CONFIG_stapprof = 1 + CC_stapprof = $(DEFAULT_CC) + CXX_stapprof = $(DEFAULT_CXX) + LD_stapprof = $(DEFAULT_CC) + LDXX_stapprof = $(DEFAULT_CXX) + CPPFLAGS_stapprof = -O2 -DGRPC_STAP_PROFILER + LDFLAGS_stapprof = + DEFINES_stapprof = NDEBUG + + VALID_CONFIG_dbg = 1 + CC_dbg = $(DEFAULT_CC) + CXX_dbg = $(DEFAULT_CXX) + LD_dbg = $(DEFAULT_CC) + LDXX_dbg = $(DEFAULT_CXX) + CPPFLAGS_dbg = -O0 + LDFLAGS_dbg = + DEFINES_dbg = _DEBUG DEBUG + + VALID_CONFIG_mutrace = 1 + CC_mutrace = $(DEFAULT_CC) + CXX_mutrace = $(DEFAULT_CXX) + LD_mutrace = $(DEFAULT_CC) + LDXX_mutrace = $(DEFAULT_CXX) + CPPFLAGS_mutrace = -O0 + LDFLAGS_mutrace = -rdynamic + DEFINES_mutrace = _DEBUG DEBUG + + VALID_CONFIG_valgrind = 1 + REQUIRE_CUSTOM_LIBRARIES_valgrind = 1 + CC_valgrind = $(DEFAULT_CC) + CXX_valgrind = $(DEFAULT_CXX) + LD_valgrind = $(DEFAULT_CC) + LDXX_valgrind = $(DEFAULT_CXX) + CPPFLAGS_valgrind = -O0 + OPENSSL_CFLAGS_valgrind = -DPURIFY + LDFLAGS_valgrind = + DEFINES_valgrind = _DEBUG DEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20 + + VALID_CONFIG_tsan = 1 + REQUIRE_CUSTOM_LIBRARIES_tsan = 1 + CC_tsan = clang + CXX_tsan = clang++ + LD_tsan = clang + LDXX_tsan = clang++ + CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-error=unused-command-line-argument + LDFLAGS_tsan = -fsanitize=thread + DEFINES_tsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10 + + VALID_CONFIG_asan = 1 + REQUIRE_CUSTOM_LIBRARIES_asan = 1 + CC_asan = clang + CXX_asan = clang++ + LD_asan = clang + LDXX_asan = clang++ + CPPFLAGS_asan = -O0 -fsanitize=address -fno-omit-frame-pointer -Wno-error=unused-command-line-argument + LDFLAGS_asan = -fsanitize=address + DEFINES_asan = GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 + + VALID_CONFIG_msan = 1 + REQUIRE_CUSTOM_LIBRARIES_msan = 1 + CC_msan = clang + CXX_msan = clang++-libc++ + LD_msan = clang + LDXX_msan = clang++-libc++ + CPPFLAGS_msan = -O0 -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-error=unused-command-line-argument + OPENSSL_CFLAGS_msan = -DPURIFY + LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 + DEFINES_msan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=4 + + VALID_CONFIG_ubsan = 1 + REQUIRE_CUSTOM_LIBRARIES_ubsan = 1 + CC_ubsan = clang + CXX_ubsan = clang++ + LD_ubsan = clang + LDXX_ubsan = clang++ + CPPFLAGS_ubsan = -O1 -fsanitize=undefined -fno-omit-frame-pointer -Wno-error=unused-command-line-argument + OPENSSL_CFLAGS_ubsan = -DPURIFY + LDFLAGS_ubsan = -fsanitize=undefined + DEFINES_ubsan = NDEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 + + VALID_CONFIG_gcov = 1 + CC_gcov = gcc + CXX_gcov = g++ + LD_gcov = gcc + LDXX_gcov = g++ + CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage + LDFLAGS_gcov = -fprofile-arcs -ftest-coverage + DEFINES_gcov = _DEBUG DEBUG + + + # General settings. + # You may want to change these depending on your system. + + prefix ?= /usr/local + + PROTOC = protoc + DTRACE = dtrace + CONFIG ?= opt + CC = $(CC_$(CONFIG)) + CXX = $(CXX_$(CONFIG)) + LD = $(LD_$(CONFIG)) + LDXX = $(LDXX_$(CONFIG)) + AR = ar + ifeq ($(SYSTEM),Linux) + STRIP = strip --strip-unneeded + else + ifeq ($(SYSTEM),Darwin) + STRIP = strip -x + else + STRIP = strip + endif + endif + INSTALL = install + RM = rm -f + PKG_CONFIG = pkg-config + + ifndef VALID_CONFIG_$(CONFIG) + $(error Invalid CONFIG value '$(CONFIG)') + endif + + ifeq ($(SYSTEM),Linux) + TMPOUT = /dev/null + else + TMPOUT = `mktemp /tmp/test-out-XXXXXX` + endif + + # Detect if we can use C++11 + CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc + HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false) + + # The HOST compiler settings are used to compile the protoc plugins. + # In most cases, you won't have to change anything, but if you are + # cross-compiling, you can override these variables from GNU make's + # command line: make CC=cross-gcc HOST_CC=gcc + + HOST_CC = $(CC) + HOST_CXX = $(CXX) + HOST_LD = $(LD) + HOST_LDXX = $(LDXX) + + ifdef EXTRA_DEFINES + DEFINES += $(EXTRA_DEFINES) + endif + + CFLAGS += -std=c89 -pedantic -Wsign-conversion + ifeq ($(HAS_CXX11),true) + CXXFLAGS += -std=c++11 + else + CXXFLAGS += -std=c++0x + endif + CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter + LDFLAGS += -g + + CPPFLAGS += $(CPPFLAGS_$(CONFIG)) + DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\" + LDFLAGS += $(LDFLAGS_$(CONFIG)) + + ifneq ($(SYSTEM),MINGW32) + PIC_CPPFLAGS = -fPIC + CPPFLAGS += -fPIC + LDFLAGS += -fPIC + endif + + INCLUDES = . include $(GENDIR) + LDFLAGS += -Llibs/$(CONFIG) + + ifeq ($(SYSTEM),Darwin) + ifneq ($(wildcard /usr/local/ssl/include),) + INCLUDES += /usr/local/ssl/include + endif + ifneq ($(wildcard /opt/local/include),) + INCLUDES += /opt/local/include + endif + ifneq ($(wildcard /usr/local/include),) + INCLUDES += /usr/local/include + endif + LIBS = m z + ifneq ($(wildcard /usr/local/ssl/lib),) + LDFLAGS += -L/usr/local/ssl/lib + endif + ifneq ($(wildcard /opt/local/lib),) + LDFLAGS += -L/opt/local/lib + endif + ifneq ($(wildcard /usr/local/lib),) + LDFLAGS += -L/usr/local/lib + endif + endif + + ifeq ($(SYSTEM),Linux) + LIBS = rt m z pthread + LDFLAGS += -pthread + endif + + ifeq ($(SYSTEM),MINGW32) + LIBS = m z pthread + LDFLAGS += -pthread + endif + + GTEST_LIB = -Ithird_party/googletest/include -Ithird_party/googletest third_party/googletest/src/gtest-all.cc + GTEST_LIB += -lgflags + ifeq ($(V),1) + E = @: + Q = + else + E = @echo + Q = @ + endif + + VERSION = ${settings.version.major}.${settings.version.minor}.${settings.version.micro}.${settings.version.build} + + CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES)) + CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS) + + LDFLAGS += $(ARCH_FLAGS) + LDLIBS += $(addprefix -l, $(LIBS)) + LDLIBSXX += $(addprefix -l, $(LIBSXX)) + + HOST_CPPFLAGS = $(CPPFLAGS) + HOST_CFLAGS = $(CFLAGS) + HOST_CXXFLAGS = $(CXXFLAGS) + HOST_LDFLAGS = $(LDFLAGS) + HOST_LDLIBS = $(LDLIBS) + + + # These are automatically computed variables. + # There shouldn't be any need to change anything from now on. + + -include cache.mk + + CACHE_MK = + + HAS_PKG_CONFIG ?= $(shell command -v $(PKG_CONFIG) >/dev/null 2>&1 && echo true || echo false) + + ifeq ($(HAS_PKG_CONFIG), true) + CACHE_MK += HAS_PKG_CONFIG = true, + endif + + PC_TEMPLATE = prefix=$(prefix),\ + exec_prefix=${'\$${prefix}'},\ + includedir=${'\$${prefix}'}/include,\ + libdir=${'\$${exec_prefix}'}/lib,\ + ,\ + Name: $(PC_NAME),\ + Description: $(PC_DESCRIPTION),\ + Version: $(VERSION),\ + Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\ + Requires.private: $(PC_REQUIRES_PRIVATE),\ + Libs: -L${'\$${libdir}'} $(PC_LIB),\ + Libs.private: $(PC_LIBS_PRIVATE) + + # gpr .pc file + PC_NAME = gRPC Portable Runtime + PC_DESCRIPTION = gRPC Portable Runtime + PC_CFLAGS = -pthread + PC_REQUIRES_PRIVATE = + PC_LIBS_PRIVATE = -lpthread + PC_LIB = -lgpr + ifneq ($(SYSTEM),Darwin) + PC_LIBS_PRIVATE += -lrt + endif + GPR_PC_FILE := $(PC_TEMPLATE) + + ifeq ($(SYSTEM),MINGW32) + SHARED_EXT = dll + endif + ifeq ($(SYSTEM),Darwin) + SHARED_EXT = dylib + endif + ifeq ($(SHARED_EXT),) + SHARED_EXT = so.$(VERSION) + endif + + ifeq ($(wildcard .git),) + IS_GIT_FOLDER = false + else + IS_GIT_FOLDER = true + endif + + ifeq ($(SYSTEM),Linux) + OPENSSL_REQUIRES_DL = true + endif + + ifeq ($(SYSTEM),Darwin) + OPENSSL_REQUIRES_DL = true + endif + + ifeq ($(HAS_PKG_CONFIG),true) + OPENSSL_ALPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.2 openssl + OPENSSL_NPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.1 openssl + ZLIB_CHECK_CMD = $(PKG_CONFIG) --exists zlib + PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.0.0-alpha-3 protobuf + else # HAS_PKG_CONFIG + + ifeq ($(SYSTEM),MINGW32) + OPENSSL_LIBS = ssl32 eay32 + else + OPENSSL_LIBS = ssl crypto + endif + + OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS) + OPENSSL_NPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/openssl-npn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS) + ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS) + PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS) + + ifeq ($(OPENSSL_REQUIRES_DL),true) + OPENSSL_ALPN_CHECK_CMD += -ldl + OPENSSL_NPN_CHECK_CMD += -ldl + endif + + endif # HAS_PKG_CONFIG + + PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS) + + PROTOC_CHECK_CMD = which protoc > /dev/null + PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3 + DTRACE_CHECK_CMD = which dtrace > /dev/null + SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS) + ZOOKEEPER_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zookeeper.c $(LDFLAGS) -lzookeeper_mt + + ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG) + HAS_SYSTEM_PERFTOOLS ?= $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false) + ifeq ($(HAS_SYSTEM_PERFTOOLS),true) + DEFINES += GRPC_HAVE_PERFTOOLS + LIBS += profiler + CACHE_MK += HAS_SYSTEM_PERFTOOLS = true, + endif + endif + + HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false) + ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG) + HAS_SYSTEM_OPENSSL_ALPN ?= $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false) + ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true) + HAS_SYSTEM_OPENSSL_NPN = true + CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true, + else + HAS_SYSTEM_OPENSSL_NPN ?= $(shell $(OPENSSL_NPN_CHECK_CMD) 2> /dev/null && echo true || echo false) + endif + ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true) + CACHE_MK += HAS_SYSTEM_OPENSSL_NPN = true, + endif + HAS_SYSTEM_ZLIB ?= $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false) + ifeq ($(HAS_SYSTEM_ZLIB),true) + CACHE_MK += HAS_SYSTEM_ZLIB = true, + endif + HAS_SYSTEM_PROTOBUF ?= $(HAS_SYSTEM_PROTOBUF_VERIFY) + ifeq ($(HAS_SYSTEM_PROTOBUF),true) + CACHE_MK += HAS_SYSTEM_PROTOBUF = true, + endif + else + # override system libraries if the config requires a custom compiled library + HAS_SYSTEM_OPENSSL_ALPN = false + HAS_SYSTEM_OPENSSL_NPN = false + HAS_SYSTEM_ZLIB = false + HAS_SYSTEM_PROTOBUF = false + endif + + HAS_PROTOC ?= $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false) + ifeq ($(HAS_PROTOC),true) + CACHE_MK += HAS_PROTOC = true, + HAS_VALID_PROTOC ?= $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false) + ifeq ($(HAS_VALID_PROTOC),true) + CACHE_MK += HAS_VALID_PROTOC = true, + endif + else + HAS_VALID_PROTOC = false + endif + + # Check for Systemtap (https://sourceware.org/systemtap/), first by making sure is present + # in the system and secondly by checking for the "dtrace" binary (on Linux, this is part of the Systemtap + # distribution. It's part of the base system on BSD/Solaris machines). + ifndef HAS_SYSTEMTAP + HAS_SYSTEMTAP_HEADERS = $(shell $(SYSTEMTAP_HEADERS_CHECK_CMD) 2> /dev/null && echo true || echo false) + HAS_DTRACE = $(shell $(DTRACE_CHECK_CMD) 2> /dev/null && echo true || echo false) + HAS_SYSTEMTAP = false + ifeq ($(HAS_SYSTEMTAP_HEADERS),true) + ifeq ($(HAS_DTRACE),true) + HAS_SYSTEMTAP = true + endif + endif + endif + + ifeq ($(HAS_SYSTEMTAP),true) + CACHE_MK += HAS_SYSTEMTAP = true, + endif + + HAS_ZOOKEEPER = $(shell $(ZOOKEEPER_CHECK_CMD) 2> /dev/null && echo true || echo false) + + # Note that for testing purposes, one can do: + # make HAS_EMBEDDED_OPENSSL_ALPN=false + # to emulate the fact we do not have OpenSSL in the third_party folder. + ifeq ($(wildcard third_party/openssl/ssl/ssl.h),) + HAS_EMBEDDED_OPENSSL_ALPN = false + else + HAS_EMBEDDED_OPENSSL_ALPN = true + endif + + ifeq ($(wildcard third_party/zlib/zlib.h),) + HAS_EMBEDDED_ZLIB = false + else + HAS_EMBEDDED_ZLIB = true + endif + + ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),) + HAS_EMBEDDED_PROTOBUF = false + ifneq ($(HAS_VALID_PROTOC),true) + NO_PROTOC = true + endif + else + HAS_EMBEDDED_PROTOBUF = true + endif + + PC_REQUIRES_GRPC = gpr + PC_LIBS_GRPC = + + ifeq ($(HAS_SYSTEM_ZLIB),false) + ifeq ($(HAS_EMBEDDED_ZLIB),true) + ZLIB_DEP = $(LIBDIR)/$(CONFIG)/zlib/libz.a + CPPFLAGS += -Ithird_party/zlib + LDFLAGS += -L$(LIBDIR)/$(CONFIG)/zlib + else + DEP_MISSING += zlib + endif + else + ifeq ($(HAS_PKG_CONFIG),true) + CPPFLAGS += $(shell $(PKG_CONFIG) --cflags zlib) + LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L zlib) + PC_REQUIRES_GRPC += zlib + else + PC_LIBS_GRPC += -lz + endif + endif + + OPENSSL_PKG_CONFIG = false + + PC_REQUIRES_SECURE = + PC_LIBS_SECURE = + + ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true) + ifeq ($(HAS_PKG_CONFIG),true) + OPENSSL_PKG_CONFIG = true + PC_REQUIRES_SECURE = openssl + CPPFLAGS := $(shell $(PKG_CONFIG) --cflags openssl) $(CPPFLAGS) + LDFLAGS_OPENSSL_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L openssl) + ifeq ($(SYSTEM),Linux) + ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),) + LDFLAGS_OPENSSL_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L openssl | sed s/L/Wl,-rpath,/) + endif + endif + LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS) + else + LIBS_SECURE = $(OPENSSL_LIBS) + ifeq ($(OPENSSL_REQUIRES_DL),true) + LIBS_SECURE += dl + PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE)) + endif + endif + else + ifeq ($(HAS_EMBEDDED_OPENSSL_ALPN),true) + USE_SYSTEM_OPENSSL = false + OPENSSL_DEP = $(LIBDIR)/$(CONFIG)/openssl/libssl.a + OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/openssl/libssl.a $(LIBDIR)/$(CONFIG)/openssl/libcrypto.a + # need to prefix these to ensure overriding system libraries + CPPFLAGS := -Ithird_party/openssl/include $(CPPFLAGS) + LDFLAGS := -L$(LIBDIR)/$(CONFIG)/openssl $(LDFLAGS) + ifeq ($(OPENSSL_REQUIRES_DL),true) + LIBS_SECURE = dl + endif + else + ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true) + USE_SYSTEM_OPENSSL = true + CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0 + LIBS_SECURE = $(OPENSSL_LIBS) + ifeq ($(OPENSSL_REQUIRES_DL),true) + LIBS_SECURE += dl + endif + else + NO_SECURE = true + endif + endif + endif + + ifeq ($(OPENSSL_PKG_CONFIG),true) + LDLIBS_SECURE += $(shell $(PKG_CONFIG) --libs-only-l openssl) + else + LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE)) + endif + + # grpc .pc file + PC_NAME = gRPC + PC_DESCRIPTION = high performance general RPC framework + PC_CFLAGS = + PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC) $(PC_REQUIRES_SECURE) + PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) $(PC_LIBS_SECURE) + PC_LIB = -lgrpc + GRPC_PC_FILE := $(PC_TEMPLATE) + + # gprc_unsecure .pc file + PC_NAME = gRPC unsecure + PC_DESCRIPTION = high performance general RPC framework without SSL + PC_CFLAGS = + PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GRPC) + PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) + PC_LIB = -lgrpc + GRPC_UNSECURE_PC_FILE := $(PC_TEMPLATE) + + # gprc_zookeeper .pc file + PC_NAME = gRPC zookeeper + PC_DESCRIPTION = gRPC's zookeeper plugin + PC_CFLAGS = + PC_REQUIRES_PRIVATE = + PC_LIBS_PRIVATE = -lzookeeper_mt + GRPC_ZOOKEEPER_PC_FILE := $(PC_TEMPLATE) + + PROTOBUF_PKG_CONFIG = false + + PC_REQUIRES_GRPCXX = + PC_LIBS_GRPCXX = + + CPPFLAGS := -Ithird_party/googletest/include $(CPPFLAGS) + + ifeq ($(HAS_SYSTEM_PROTOBUF),true) + ifeq ($(HAS_PKG_CONFIG),true) + PROTOBUF_PKG_CONFIG = true + PC_REQUIRES_GRPCXX = protobuf + CPPFLAGS := $(shell $(PKG_CONFIG) --cflags protobuf) $(CPPFLAGS) + LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L protobuf) + ifeq ($(SYSTEM),Linux) + ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),) + LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L protobuf | sed s/L/Wl,-rpath,/) + endif + endif + else + PC_LIBS_GRPCXX = -lprotobuf + endif + else + ifeq ($(HAS_EMBEDDED_PROTOBUF),true) + PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a + CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS) + LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS) + PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc + else + NO_PROTOBUF = true + endif + endif + + LIBS_PROTOBUF = protobuf + LIBS_PROTOC = protoc protobuf + + HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC)) + + ifeq ($(PROTOBUF_PKG_CONFIG),true) + LDLIBS_PROTOBUF += $(shell $(PKG_CONFIG) --libs-only-l protobuf) + else + LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF)) + endif + + # grpc++ .pc file + PC_NAME = gRPC++ + PC_DESCRIPTION = C++ wrapper for gRPC + PC_CFLAGS = + PC_REQUIRES_PRIVATE = grpc $(PC_REQUIRES_GRPCXX) + PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX) + PC_LIB = -lgrpc++ + GRPCXX_PC_FILE := $(PC_TEMPLATE) + + # grpc++_unsecure .pc file + PC_NAME = gRPC++ unsecure + PC_DESCRIPTION = C++ wrapper for gRPC without SSL + PC_CFLAGS = + PC_REQUIRES_PRIVATE = grpc_unsecure $(PC_REQUIRES_GRPCXX) + PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX) + PC_LIB = -lgrpc++ + GRPCXX_UNSECURE_PC_FILE := $(PC_TEMPLATE) + + ifeq ($(MAKECMDGOALS),clean) + NO_DEPS = true + endif + + INSTALL_OK = false + ifeq ($(HAS_VALID_PROTOC),true) + ifeq ($(HAS_SYSTEM_PROTOBUF_VERIFY),true) + INSTALL_OK = true + endif + endif + + .SECONDARY = %.pb.h %.pb.cc + + PROTOC_PLUGINS =\ + % for tgt in targets: + % if tgt.build == 'protoc': + $(BINDIR)/$(CONFIG)/${tgt.name}\ + % endif + % endfor + + ifeq ($(DEP_MISSING),) + all: static shared plugins\ + % for tgt in targets: + % if tgt.build == 'all': + $(BINDIR)/$(CONFIG)/${tgt.name}\ + % endif + % endfor + + dep_error: + @echo "You shouldn't see this message - all of your dependencies are correct." + else + all: dep_error git_update stop + + dep_error: + @echo + @echo "DEPENDENCY ERROR" + @echo + @echo "You are missing system dependencies that are essential to build grpc," + @echo "and the third_party directory doesn't have them:" + @echo + @echo " $(DEP_MISSING)" + @echo + @echo "Installing the development packages for your system will solve" + @echo "this issue. Please consult INSTALL to get more information." + @echo + @echo "If you need information about why these tests failed, run:" + @echo + @echo " make run_dep_checks" + @echo + endif + + git_update: + ifeq ($(IS_GIT_FOLDER),true) + @echo "Additionally, since you are in a git clone, you can download the" + @echo "missing dependencies in third_party by running the following command:" + @echo + @echo " git submodule update --init" + @echo + endif + + openssl_dep_error: openssl_dep_message git_update stop + + protobuf_dep_error: protobuf_dep_message git_update stop + + protoc_dep_error: protoc_dep_message git_update stop + + openssl_dep_message: + @echo + @echo "DEPENDENCY ERROR" + @echo + @echo "The target you are trying to run requires OpenSSL." + @echo "Your system doesn't have it, and neither does the third_party directory." + @echo + @echo "Please consult INSTALL to get more information." + @echo + @echo "If you need information about why these tests failed, run:" + @echo + @echo " make run_dep_checks" + @echo + + protobuf_dep_message: + @echo + @echo "DEPENDENCY ERROR" + @echo + @echo "The target you are trying to run requires protobuf 3.0.0+" + @echo "Your system doesn't have it, and neither does the third_party directory." + @echo + @echo "Please consult INSTALL to get more information." + @echo + @echo "If you need information about why these tests failed, run:" + @echo + @echo " make run_dep_checks" + @echo + + protoc_dep_message: + @echo + @echo "DEPENDENCY ERROR" + @echo + @echo "The target you are trying to run requires protobuf-compiler 3.0.0+" + @echo "Your system doesn't have it, and neither does the third_party directory." + @echo + @echo "Please consult INSTALL to get more information." + @echo + @echo "If you need information about why these tests failed, run:" + @echo + @echo " make run_dep_checks" + @echo + + systemtap_dep_error: + @echo + @echo "DEPENDENCY ERROR" + @echo + @echo "Under the '$(CONFIG)' configutation, the target you are trying " + @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other " + @echo "platforms such as Solaris and *BSD). " + @echo + @echo "Please consult INSTALL to get more information." + @echo + + stop: + @false + + % for tgt in targets: + ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name} + % endfor + + run_dep_checks: + $(OPENSSL_ALPN_CHECK_CMD) || true + $(OPENSSL_NPN_CHECK_CMD) || true + $(ZLIB_CHECK_CMD) || true + $(PERFTOOLS_CHECK_CMD) || true + $(PROTOBUF_CHECK_CMD) || true + $(PROTOC_CHECK_VERSION_CMD) || true + $(ZOOKEEPER_CHECK_CMD) || true + + $(LIBDIR)/$(CONFIG)/zlib/libz.a: + $(E) "[MAKE] Building zlib" + $(Q)(cd third_party/zlib ; CC="$(CC)" CFLAGS="$(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(ZLIB_CFLAGS_EXTRA)" ./configure --static) + $(Q)$(MAKE) -C third_party/zlib clean + $(Q)$(MAKE) -C third_party/zlib + $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/zlib + $(Q)cp third_party/zlib/libz.a $(LIBDIR)/$(CONFIG)/zlib + + $(LIBDIR)/$(CONFIG)/openssl/libssl.a: + $(E) "[MAKE] Building openssl for $(SYSTEM)" + ifeq ($(SYSTEM),Darwin) + $(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_EXTRA)" ./Configure darwin64-x86_64-cc) + else + ifeq ($(SYSTEM),MINGW32) + @echo "We currently don't have a good way to compile OpenSSL in-place under msys." + @echo "Please provide a OpenSSL in your mingw32 system." + @echo + @echo "Note that you can find a compatible version of the libraries here:" + @echo + @echo "http://slproweb.com/products/Win32OpenSSL.html" + @echo + @echo "If you decide to install that one, take the full version. The light" + @echo "version only contains compiled DLLs, without the development files." + @echo + @echo "When installing, chose to copy the OpenSSL dlls to the OpenSSL binaries" + @echo "directory. This way we'll link to them directly." + @echo + @echo "You can then re-start the build the following way:" + @echo + @echo " CPPFLAGS=-I/c/OpenSSL-Win64/include LDFLAGS=-L/c/OpenSSL-Win64 make" + @false + else + $(Q)(cd third_party/openssl ; CC="$(CC) $(PIC_CPPFLAGS) -fvisibility=hidden $(CPPFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_$(CONFIG)) $(OPENSSL_CFLAGS_EXTRA)" ./config no-asm $(OPENSSL_CONFIG_$(CONFIG))) + endif + endif + $(Q)$(MAKE) -j 1 -C third_party/openssl clean + $(Q)(unset CPPFLAGS; $(MAKE) -j 1 -C third_party/openssl build_crypto build_ssl) + $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/openssl + $(Q)cp third_party/openssl/libssl.a third_party/openssl/libcrypto.a $(LIBDIR)/$(CONFIG)/openssl + + third_party/protobuf/configure: + $(E) "[AUTOGEN] Preparing protobuf" + $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete) + + $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure + $(E) "[MAKE] Building protobuf" + $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g $(PROTOBUF_LDFLAGS_EXTRA)" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g $(PROTOBUF_CPPFLAGS_EXTRA)" ./configure --disable-shared --enable-static) + $(Q)$(MAKE) -C third_party/protobuf clean + $(Q)$(MAKE) -C third_party/protobuf + $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf + $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf + $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf + $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf + $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf + + static: static_c static_cxx + + static_c: pc_c pc_c_unsecure cache.mk pc_gpr pc_c_zookeeper\ + % for lib in libs: + % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None): + $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ + % endif + % endfor + static_zookeeper_libs + + + static_cxx: pc_cxx pc_cxx_unsecure pc_gpr cache.mk \ + % for lib in libs: + % if lib.build == 'all' and lib.language == 'c++': + $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ + % endif + % endfor + + + shared: shared_c shared_cxx + + shared_c: pc_c pc_c_unsecure pc_gpr cache.mk pc_c_zookeeper\ + % for lib in libs: + % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None): + $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\ + % endif + % endfor + shared_zookeeper_libs + + shared_cxx: pc_cxx pc_cxx_unsecure cache.mk\ + % for lib in libs: + % if lib.build == 'all' and lib.language == 'c++': + $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\ + % endif + % endfor + + + shared_csharp: shared_c \ + % for lib in libs: + % if lib.build == 'all' and lib.language == 'csharp': + $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\ + % endif + % endfor + + ifeq ($(HAS_ZOOKEEPER),true) + static_zookeeper_libs:\ + % for lib in libs: + % if lib.build == 'all' and lib.language == 'c' and 'zookeeper' in lib.get('external_deps', []): + $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ + % endif + % endfor + + shared_zookeeper_libs:\ + % for lib in libs: + % if lib.build == 'all' and lib.language == 'c' and 'zookeeper' in lib.get('external_deps', []): + $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\ + % endif + % endfor + + else + + static_zookeeper_libs: + + shared_zookeeper_libs: + + endif + + grpc_csharp_ext: shared_csharp + + plugins: $(PROTOC_PLUGINS) + + privatelibs: privatelibs_c privatelibs_cxx + + privatelibs_c: \ + % for lib in libs: + % if lib.build == 'private' and lib.language == 'c' and not lib.get('external_deps', None): + $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ + % endif + % endfor -pc_gpr: $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc + pc_gpr: $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc -pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc + pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc -pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc - -ifeq ($(HAS_ZOOKEEPER),true) -pc_c_zookeeper: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_zookeeper.pc -else -pc_c_zookeeper: -endif + pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc + + ifeq ($(HAS_ZOOKEEPER),true) + pc_c_zookeeper: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_zookeeper.pc + else + pc_c_zookeeper: + endif -pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc + pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc -pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc + pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc -privatelibs_cxx: \ -% for lib in libs: -% if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None): - $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ -% endif -% endfor + privatelibs_cxx: \ + % for lib in libs: + % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None): + $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ + % endif + % endfor -ifeq ($(HAS_ZOOKEEPER),true) -privatelibs_zookeeper: \ -% for lib in libs: -% if lib.build == 'private' and lib.language == 'c++' and zookeeper in lib.get('external_deps', []): - $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ -% endif -% endfor + ifeq ($(HAS_ZOOKEEPER),true) + privatelibs_zookeeper: \ + % for lib in libs: + % if lib.build == 'private' and lib.language == 'c++' and zookeeper in lib.get('external_deps', []): + $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ + % endif + % endfor -else -privatelibs_zookeeper: -endif + else + privatelibs_zookeeper: + endif -buildtests: buildtests_c buildtests_cxx buildtests_zookeeper + buildtests: buildtests_c buildtests_cxx buildtests_zookeeper -buildtests_c: privatelibs_c\ -% for tgt in targets: -% if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None): - $(BINDIR)/$(CONFIG)/${tgt.name}\ -% endif -% endfor + buildtests_c: privatelibs_c\ + % for tgt in targets: + % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None): + $(BINDIR)/$(CONFIG)/${tgt.name}\ + % endif + % endfor -buildtests_cxx: buildtests_zookeeper privatelibs_cxx\ -% for tgt in targets: -% if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None): - $(BINDIR)/$(CONFIG)/${tgt.name}\ -% endif -% endfor + buildtests_cxx: buildtests_zookeeper privatelibs_cxx\ + % for tgt in targets: + % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None): + $(BINDIR)/$(CONFIG)/${tgt.name}\ + % endif + % endfor -ifeq ($(HAS_ZOOKEEPER),true) -buildtests_zookeeper: privatelibs_zookeeper\ -% for tgt in targets: -% if tgt.build == 'test' and tgt.language == 'c++' and 'zookeeper' in tgt.get('external_deps', []): - $(BINDIR)/$(CONFIG)/${tgt.name}\ -% endif -% endfor + ifeq ($(HAS_ZOOKEEPER),true) + buildtests_zookeeper: privatelibs_zookeeper\ + % for tgt in targets: + % if tgt.build == 'test' and tgt.language == 'c++' and 'zookeeper' in tgt.get('external_deps', []): + $(BINDIR)/$(CONFIG)/${tgt.name}\ + % endif + % endfor -else -buildtests_zookeeper: -endif + else + buildtests_zookeeper: + endif -test: test_c test_cxx test_zookeeper + test: test_c test_cxx test_zookeeper -flaky_test: flaky_test_c flaky_test_cxx flaky_test_zookeeper + flaky_test: flaky_test_c flaky_test_cxx flaky_test_zookeeper -test_c: buildtests_c -% for tgt in targets: -% if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++' and not tgt.get('flaky', False) and not tgt.get('external_deps', None): - $(E) "[RUN] Testing ${tgt.name}" - $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) -% endif -% endfor + test_c: buildtests_c + % for tgt in targets: + % if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++' and not tgt.get('flaky', False) and not tgt.get('external_deps', None): + $(E) "[RUN] Testing ${tgt.name}" + $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) + % endif + % endfor -flaky_test_c: buildtests_c -% for tgt in targets: -% if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++' and tgt.get('flaky', False) and not tgt.get('external_deps', None): - $(E) "[RUN] Testing ${tgt.name}" - $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) -% endif -% endfor + flaky_test_c: buildtests_c + % for tgt in targets: + % if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++' and tgt.get('flaky', False) and not tgt.get('external_deps', None): + $(E) "[RUN] Testing ${tgt.name}" + $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) + % endif + % endfor -test_cxx: test_zookeeper buildtests_cxx -% for tgt in targets: -% if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and not tgt.get('flaky', False) and not tgt.get('external_deps', None): - $(E) "[RUN] Testing ${tgt.name}" - $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) -% endif -% endfor + test_cxx: test_zookeeper buildtests_cxx + % for tgt in targets: + % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and not tgt.get('flaky', False) and not tgt.get('external_deps', None): + $(E) "[RUN] Testing ${tgt.name}" + $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) + % endif + % endfor -flaky_test_cxx: buildtests_cxx -% for tgt in targets: -% if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and tgt.get('flaky', False) and not tgt.get('external_deps', None): - $(E) "[RUN] Testing ${tgt.name}" - $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) -% endif -% endfor - - -ifeq ($(HAS_ZOOKEEPER),true) -test_zookeeper: buildtests_zookeeper -% for tgt in targets: -% if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and not tgt.get('flaky', False) and 'zookeeper' in tgt.get('external_deps', []): - $(E) "[RUN] Testing ${tgt.name}" - $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) -% endif -% endfor - - -flaky_test_zookeeper: buildtests_zookeeper -% for tgt in targets: -% if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and tgt.get('flaky', False) and 'zookeeper' in tgt.get('external_deps', []): - $(E) "[RUN] Testing ${tgt.name}" - $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) -% endif -% endfor - -else -test_zookeeper: -flaky_test_zookeeper: -endif - - -test_python: static_c - $(E) "[RUN] Testing python code" - $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG) - - -tools: tools_c tools_cxx - - -tools_c: privatelibs_c\ -% for tgt in targets: -% if tgt.build == 'tool' and not tgt.language=='c++': - $(BINDIR)/$(CONFIG)/${tgt.name}\ -% endif -% endfor - - -tools_cxx: privatelibs_cxx\ -% for tgt in targets: -% if tgt.build == 'tool' and tgt.language=='c++': - $(BINDIR)/$(CONFIG)/${tgt.name}\ -% endif -% endfor - - -buildbenchmarks: privatelibs\ -% for tgt in targets: -% if tgt.build == 'benchmark': - $(BINDIR)/$(CONFIG)/${tgt.name}\ -% endif -% endfor - - -benchmarks: buildbenchmarks - -strip: strip-static strip-shared - -strip-static: strip-static_c strip-static_cxx - -strip-shared: strip-shared_c strip-shared_cxx - - -# TODO(nnoble): the strip target is stripping in-place, instead -# of copying files in a temporary folder. -# This prevents proper debugging after running make install. - -strip-static_c: static_c -ifeq ($(CONFIG),opt) -% for lib in libs: -% if lib.language == "c": -% if lib.build == "all": -% if not lib.get('external_deps', None): - $(E) "[STRIP] Stripping lib${lib.name}.a" - $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a -% endif -% endif -% endif -% endfor -ifeq ($(HAS_ZOOKEEPER),true) -% for lib in libs: -% if lib.language == "c": -% if lib.build == "all": -% if 'zookeeper' in lib.get('external_deps', []): - $(E) "[STRIP] Stripping lib${lib.name}.a" - $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a -% endif -% endif -% endif -% endfor -endif -endif - -strip-static_cxx: static_cxx -ifeq ($(CONFIG),opt) -% for lib in libs: -% if lib.language == "c++": -% if lib.build == "all": - $(E) "[STRIP] Stripping lib${lib.name}.a" - $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a -% endif -% endif -% endfor -endif - -strip-shared_c: shared_c -ifeq ($(CONFIG),opt) -% for lib in libs: -% if lib.language == "c": -% if lib.build == "all": -% if not lib.get('external_deps', None): - $(E) "[STRIP] Stripping lib${lib.name}.so" - $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) -% endif -% endif -% endif -% endfor -ifeq ($(HAS_ZOOKEEPER),true) -% for lib in libs: -% if lib.language == "c": -% if lib.build == "all": -% if 'zookeeper' in lib.get('external_deps', []): - $(E) "[STRIP] Stripping lib${lib.name}.so" - $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) -% endif -% endif -% endif -% endfor -endif -endif - -strip-shared_cxx: shared_cxx -ifeq ($(CONFIG),opt) -% for lib in libs: -% if lib.language == "c++": -% if lib.build == "all": - $(E) "[STRIP] Stripping lib${lib.name}.so" - $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) -% endif -% endif -% endfor -endif - -strip-shared_csharp: shared_csharp -ifeq ($(CONFIG),opt) -% for lib in libs: -% if lib.language == "csharp": -% if lib.build == "all": - $(E) "[STRIP] Stripping lib${lib.name}.so" - $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) -% endif -% endif -% endfor -endif - -cache.mk:: - $(E) "[MAKE] Generating $@" - $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@ - -$(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc: - $(E) "[MAKE] Generating $@" - $(Q) mkdir -p $(@D) - $(Q) echo "$(GPR_PC_FILE)" | tr , '\n' >$@ - -$(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc: - $(E) "[MAKE] Generating $@" - $(Q) mkdir -p $(@D) - $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@ - -$(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc: - $(E) "[MAKE] Generating $@" - $(Q) mkdir -p $(@D) - $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@ - -$(LIBDIR)/$(CONFIG)/pkgconfig/grpc_zookeeper.pc: - $(E) "[MAKE] Generating $@" - $(Q) mkdir -p $(@D) - $(Q) echo -e "$(GRPC_ZOOKEEPER_PC_FILE)" >$@ - -$(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc: - $(E) "[MAKE] Generating $@" - $(Q) mkdir -p $(@D) - $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@ - -$(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc: - $(E) "[MAKE] Generating $@" - $(Q) mkdir -p $(@D) - $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@ - -% for p in protos: -ifeq ($(NO_PROTOC),true) -$(GENDIR)/${p}.pb.cc: protoc_dep_error -$(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error -else -$(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) - $(E) "[PROTOC] Generating protobuf CC file from $<" - $(Q) mkdir -p `dirname $@` - $(Q) $(PROTOC) --cpp_out=$(GENDIR) $< - -$(GENDIR)/${p}.grpc.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) - $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<" - $(Q) mkdir -p `dirname $@` - $(Q) $(PROTOC) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $< -endif - -% endfor - -ifeq ($(CONFIG),stapprof) -src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h -ifeq ($(HAS_SYSTEMTAP),true) -$(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d - $(E) "[DTRACE] Compiling $<" - $(Q) mkdir -p `dirname $@` - $(Q) $(DTRACE) -C -h -s $< -o $@ -else -$(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop -endif -endif - -$(OBJDIR)/$(CONFIG)/%.o : %.c - $(E) "[C] Compiling $<" - $(Q) mkdir -p `dirname $@` - $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< - -$(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc - $(E) "[CXX] Compiling $<" - $(Q) mkdir -p `dirname $@` - $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< - -$(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc - $(E) "[HOSTCXX] Compiling $<" - $(Q) mkdir -p `dirname $@` - $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< - -$(OBJDIR)/$(CONFIG)/%.o : %.cc - $(E) "[CXX] Compiling $<" - $(Q) mkdir -p `dirname $@` - $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< - -install: install_c install_cxx install-plugins install-certs verify-install - -install_c: install-headers_c install-static_c install-shared_c - -install_cxx: install-headers_cxx install-static_cxx install-shared_cxx - -install_csharp: install-shared_csharp install_c - -install_grpc_csharp_ext: install_csharp - -install-headers: install-headers_c install-headers_cxx - -install-headers_c: - $(E) "[INSTALL] Installing public C headers" - $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1 - $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1 - -install-headers_cxx: - $(E) "[INSTALL] Installing public C++ headers" - $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1 - $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1 - -install-static: install-static_c install-static_cxx - -install-static_c: static_c strip-static_c install-pkg-config_c -% for lib in libs: -% if lib.language == "c": -% if lib.build == "all": -% if not lib.get('external_deps', None): - $(E) "[INSTALL] Installing lib${lib.name}.a" - $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a -% endif -% endif -% endif -% endfor -ifeq ($(HAS_ZOOKEEPER),true) -% for lib in libs: -% if lib.language == "c": -% if lib.build == "all": -% if 'zookeeper' in lib.get('external_deps', []): - $(E) "[INSTALL] Installing lib${lib.name}.a" - $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a -% endif -% endif -% endif -% endfor -endif - -install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx -% for lib in libs: -% if lib.language == "c++": -% if lib.build == "all": - $(E) "[INSTALL] Installing lib${lib.name}.a" - $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a -% endif -% endif -% endfor - -<%def name="install_shared(lang_filter)">\ -% for lib in libs: -% if lib.language == lang_filter: -% if lib.build == "all": -% if not lib.get('external_deps', None): -ifeq ($(SYSTEM),MINGW32) - $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)" - $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT) - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a -else - $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)" - $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT) -ifneq ($(SYSTEM),Darwin) - $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so.${settings.version.major} - $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so -endif -endif -% endif -% endif -% endif -% endfor -ifeq ($(HAS_ZOOKEEPER),true) -% for lib in libs: -% if lib.language == lang_filter: -% if lib.build == "all": -% if 'zookeeper' in lib.get('external_deps', []): -ifeq ($(SYSTEM),MINGW32) - $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)" - $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT) - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a -else - $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)" - $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT) -ifneq ($(SYSTEM),Darwin) - $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so.${settings.version.major} - $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so -endif -endif -% endif -% endif -% endif -% endfor -endif -ifneq ($(SYSTEM),MINGW32) -ifneq ($(SYSTEM),Darwin) - $(Q) ldconfig || true -endif -endif - - -install-shared_c: shared_c strip-shared_c install-pkg-config_c -${install_shared("c")} - -install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx -${install_shared("c++")} - -install-shared_csharp: shared_csharp strip-shared_csharp -${install_shared("csharp")} - -install-plugins: $(PROTOC_PLUGINS) -ifeq ($(SYSTEM),MINGW32) - $(Q) false -else - $(E) "[INSTALL] Installing grpc protoc plugins" -% for tgt in targets: -% if tgt.build == 'protoc': - $(Q) $(INSTALL) -d $(prefix)/bin - $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name} -% endif -% endfor -endif - -install-pkg-config_c: pc_gpr pc_c pc_c_unsecure pc_c_zookeeper - $(E) "[INSTALL] Installing C pkg-config files" - $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc $(prefix)/lib/pkgconfig/gpr.pc - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(prefix)/lib/pkgconfig/grpc.pc - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(prefix)/lib/pkgconfig/grpc_unsecure.pc -ifeq ($(HAS_ZOOKEEPER),true) - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_zookeeper.pc $(prefix)/lib/pkgconfig/grpc_zookeeper.pc -endif - -install-pkg-config_cxx: pc_cxx pc_cxx_unsecure - $(E) "[INSTALL] Installing C++ pkg-config files" - $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc $(prefix)/lib/pkgconfig/grpc++.pc - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc $(prefix)/lib/pkgconfig/grpc++_unsecure.pc - -install-certs: etc/roots.pem - $(E) "[INSTALL] Installing root certificates" - $(Q) $(INSTALL) -d $(prefix)/share/grpc - $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem - -verify-install: -ifeq ($(INSTALL_OK),true) - @echo "Your system looks ready to go." - @echo -else - @echo "We couldn't find protoc 3.0.0+ installed on your system. While this" - @echo "won't prevent grpc from working, you won't be able to compile" - @echo "and run any meaningful code with it." - @echo - @echo - @echo "Please download and install protobuf 3.0.0+ from:" - @echo - @echo " https://github.com/google/protobuf/releases" - @echo - @echo "Once you've done so, or if you think this message is in error," - @echo "you can re-run this check by doing:" - @echo - @echo " make verify-install" -endif - -clean: - $(E) "[CLEAN] Cleaning build directories." - $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk - - -# The various libraries - -% for lib in libs: -${makelib(lib)} -% endfor - - -# All of the test targets, and protoc plugins - -% for tgt in targets: -${maketarget(tgt)} -% endfor - -<%def name="makelib(lib)"> -LIB${lib.name.upper()}_SRC = \\ - -% for src in lib.src: - ${proto_to_cc(src)} \\ - -% endfor - -% if "public_headers" in lib: -% if lib.language == "c++": -PUBLIC_HEADERS_CXX += \\ - -% else: -PUBLIC_HEADERS_C += \\ - -% endif -% for hdr in lib.public_headers: - ${hdr} \\ - -% endfor -% endif - -LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC)))) - -## If the library requires OpenSSL, let's add some restrictions. -% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check': -ifeq ($(NO_SECURE),true) - -# You can't build secure libraries if you don't have OpenSSL. - -$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error - -% if lib.build == "all": -ifeq ($(SYSTEM),MINGW32) -$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error -else -$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error -endif -% endif - -else - -% if lib.language == 'c++': -ifeq ($(NO_PROTOBUF),true) - -# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. - -$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error - -% if lib.build == "all": -ifeq ($(SYSTEM),MINGW32) -$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error -else -$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error -endif -% endif - -else -% endif - -$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\ -## The else here corresponds to the if secure earlier. -% else: -% if lib.language == 'c++': -ifeq ($(NO_PROTOBUF),true) - -# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. - -$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error - -% if lib.build == "all": -ifeq ($(SYSTEM),MINGW32) -$(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error -else -$(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error -endif -% endif - -else - -% endif -$(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP)\ -% endif -% if lib.language == 'c++': - $(PROTOBUF_DEP)\ -% endif - $(LIB${lib.name.upper()}_OBJS) - $(E) "[AR] Creating $@" - $(Q) mkdir -p `dirname $@` - $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a - $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) -% if lib.get('baselib', False): -% if lib.get('secure', 'check') == 'yes': - $(Q) rm -rf tmp-merge-${lib.name} - $(Q) mkdir tmp-merge-${lib.name} - $(Q) ( cd tmp-merge-${lib.name} ; $(AR) x ../$(LIBDIR)/$(CONFIG)/lib${lib.name}.a ) - $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge-${lib.name} ; <%text>ar x ../$${l} ) ; done - $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/__.SYMDEF* - $(Q) ar rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/* - $(Q) rm -rf tmp-merge-${lib.name} -% endif -% endif -ifeq ($(SYSTEM),Darwin) - $(Q) ranlib $(LIBDIR)/$(CONFIG)/lib${lib.name}.a -endif - -<% - - if lib.language == 'c++': - ld = '$(LDXX)' - else: - ld = '$(LD)' - - out_base = '$(LIBDIR)/$(CONFIG)/' + lib.name - out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name - - common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)' - - libs = '' - lib_deps = ' $(ZLIB_DEP)' - mingw_libs = '' - mingw_lib_deps = ' $(ZLIB_DEP)' - if lib.language == 'c++': - lib_deps += ' $(PROTOBUF_DEP)' - mingw_lib_deps += ' $(PROTOBUF_DEP)' - for dep in lib.get('deps', []): - libs = libs + ' -l' + dep - lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)' - mingw_libs = mingw_libs + ' -l' + dep + '-imp' - mingw_lib_deps = mingw_lib_deps + ' $(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)' - - security = lib.get('secure', 'check') - if security == 'yes': - common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)' - - if security in ['yes', 'check']: - for src in lib.src: - if not proto_re.match(src): - sources_that_need_openssl.add(src) - else: - for src in lib.src: - sources_that_don_t_need_openssl.add(src) - - if 'zookeeper' in lib.get('external_deps', []): - libs = libs + ' -lzookeeper_mt' - - if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check': - lib_deps = lib_deps + ' $(OPENSSL_DEP)' - mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)' - - if lib.language == 'c++': - common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)' -%> - -% if lib.build == "all": -ifeq ($(SYSTEM),MINGW32) -${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps} - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=${out_base}.def -Wl,--out-implib=${out_libbase}-imp.a -o ${out_base}.$(SHARED_EXT) ${common}${mingw_libs} -else -${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps} - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` -ifeq ($(SYSTEM),Darwin) - $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name lib${lib.name}.$(SHARED_EXT) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs} -else - $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} -o ${out_libbase}.$(SHARED_EXT) ${common}${libs} - $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major} - $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so -endif -endif -% endif -% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check': -## If the lib was secure, we have to close the Makefile's if that tested -## the presence of OpenSSL. - -endif -% endif -% if lib.language == 'c++': -## If the lib was C++, we have to close the Makefile's if that tested -## the presence of protobuf 3.0.0+ - -endif -% endif - -% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check': -ifneq ($(NO_SECURE),true) -% endif -ifneq ($(NO_DEPS),true) --include $(LIB${lib.name.upper()}_OBJS:.o=.dep) -endif -% if lib.get('secure', 'check') == 'yes' or lib.get('secure', 'check') == 'check': -endif -% endif -% for src in lib.src: -% if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src): -$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))} -% endif -% endfor - - -<%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %> -% if not has_no_sources: -${tgt.name.upper()}_SRC = \\ - -% for src in tgt.src: - ${proto_to_cc(src)} \\ - -% endfor - -${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC)))) -% endif -% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check': -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error - -else - -% endif -## -## We're not trying to add a dependency on building zlib and openssl here, -## as it's already done in the libraries. We're assuming that the build -## trickles down, and that a secure target requires a secure version of -## a library. -## -## That simplifies the codegen a bit, but prevents a fully defined Makefile. -## I can live with that. -## -% if tgt.build == 'protoc' or tgt.language == 'c++': - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/${tgt.name}: \ -% if not has_no_sources: -$(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\ -% endif -% else: -$(BINDIR)/$(CONFIG)/${tgt.name}: \ -% if not has_no_sources: -$(${tgt.name.upper()}_OBJS)\ -% endif -% endif -% for dep in tgt.deps: - $(LIBDIR)/$(CONFIG)/lib${dep}.a\ -% endfor - -% if tgt.language == "c++": -## C++ targets specificies. -% if tgt.build == 'protoc': - $(E) "[HOSTLD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \ -% if not has_no_sources: -$(${tgt.name.upper()}_OBJS)\ -% endif -% else: - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) \ -% if not has_no_sources: -$(${tgt.name.upper()}_OBJS)\ -% endif -% endif -% else: -## C-only targets specificities. - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LD) $(LDFLAGS) \ -% if not has_no_sources: -$(${tgt.name.upper()}_OBJS)\ -% endif -% endif -% for dep in tgt.deps: - $(LIBDIR)/$(CONFIG)/lib${dep}.a\ -% endfor -% if 'zookeeper' in tgt.get('external_deps', []): - -lzookeeper_mt\ -% endif -% if tgt.language == "c++": -% if tgt.build == 'protoc': - $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\ -% else: - $(LDLIBSXX) $(LDLIBS_PROTOBUF)\ -% endif -% endif -% if tgt.build == 'protoc': - $(HOST_LDLIBS)\ -% else: - $(LDLIBS)\ -% endif -% if tgt.build == 'protoc': - $(HOST_LDLIBS_PROTOC)\ -% elif tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check': - $(LDLIBS_SECURE)\ -% endif -% if tgt.language == 'c++' and tgt.build == 'test': - $(GTEST_LIB)\ -% elif tgt.language == 'c++' and tgt.build == 'benchmark': - $(GTEST_LIB)\ -% endif - -o $(BINDIR)/$(CONFIG)/${tgt.name} -% if tgt.build == 'protoc' or tgt.language == 'c++': - -endif -% endif -% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check': - -endif -% endif - -% for src in tgt.src: -$(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \ -% for dep in tgt.deps: - $(LIBDIR)/$(CONFIG)/lib${dep}.a\ -% endfor - -% endfor -% if not has_no_sources: -deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep) -% endif - -% if not has_no_sources: -% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check': -ifneq ($(NO_SECURE),true) -% endif -ifneq ($(NO_DEPS),true) --include $(${tgt.name.upper()}_OBJS:.o=.dep) -endif -% if tgt.get('secure', 'check') == 'yes' or tgt.get('secure', 'check') == 'check': -endif -% endif -% endif - - -ifneq ($(OPENSSL_DEP),) -# This is to ensure the embedded OpenSSL is built beforehand, properly -# installing headers to their final destination on the drive. We need this -# otherwise parallel compilation will fail if a source is compiled first. -% for src in sorted(sources_that_need_openssl): -% if src not in sources_that_don_t_need_openssl: -${src}: $(OPENSSL_DEP) -% endif -% endfor -endif - -.PHONY: all strip tools \ -dep_error openssl_dep_error openssl_dep_message git_update stop \ -buildtests buildtests_c buildtests_cxx \ -test test_c test_cxx \ -install install_c install_cxx \ -install-headers install-headers_c install-headers_cxx \ -install-shared install-shared_c install-shared_cxx \ -install-static install-static_c install-static_cxx \ -strip strip-shared strip-static \ -strip_c strip-shared_c strip-static_c \ -strip_cxx strip-shared_cxx strip-static_cxx \ -dep_c dep_cxx bins_dep_c bins_dep_cxx \ -clean + flaky_test_cxx: buildtests_cxx + % for tgt in targets: + % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and tgt.get('flaky', False) and not tgt.get('external_deps', None): + $(E) "[RUN] Testing ${tgt.name}" + $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) + % endif + % endfor + + + ifeq ($(HAS_ZOOKEEPER),true) + test_zookeeper: buildtests_zookeeper + % for tgt in targets: + % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and not tgt.get('flaky', False) and 'zookeeper' in tgt.get('external_deps', []): + $(E) "[RUN] Testing ${tgt.name}" + $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) + % endif + % endfor + + + flaky_test_zookeeper: buildtests_zookeeper + % for tgt in targets: + % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and tgt.get('flaky', False) and 'zookeeper' in tgt.get('external_deps', []): + $(E) "[RUN] Testing ${tgt.name}" + $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) + % endif + % endfor + + else + test_zookeeper: + flaky_test_zookeeper: + endif + + + test_python: static_c + $(E) "[RUN] Testing python code" + $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG) + + + tools: tools_c tools_cxx + + + tools_c: privatelibs_c\ + % for tgt in targets: + % if tgt.build == 'tool' and not tgt.language=='c++': + $(BINDIR)/$(CONFIG)/${tgt.name}\ + % endif + % endfor + + + tools_cxx: privatelibs_cxx\ + % for tgt in targets: + % if tgt.build == 'tool' and tgt.language=='c++': + $(BINDIR)/$(CONFIG)/${tgt.name}\ + % endif + % endfor + + + buildbenchmarks: privatelibs\ + % for tgt in targets: + % if tgt.build == 'benchmark': + $(BINDIR)/$(CONFIG)/${tgt.name}\ + % endif + % endfor + + + benchmarks: buildbenchmarks + + strip: strip-static strip-shared + + strip-static: strip-static_c strip-static_cxx + + strip-shared: strip-shared_c strip-shared_cxx + + + # TODO(nnoble): the strip target is stripping in-place, instead + # of copying files in a temporary folder. + # This prevents proper debugging after running make install. + + strip-static_c: static_c + ifeq ($(CONFIG),opt) + % for lib in libs: + % if lib.language == "c": + % if lib.build == "all": + % if not lib.get('external_deps', None): + $(E) "[STRIP] Stripping lib${lib.name}.a" + $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a + % endif + % endif + % endif + % endfor + ifeq ($(HAS_ZOOKEEPER),true) + % for lib in libs: + % if lib.language == "c": + % if lib.build == "all": + % if 'zookeeper' in lib.get('external_deps', []): + $(E) "[STRIP] Stripping lib${lib.name}.a" + $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a + % endif + % endif + % endif + % endfor + endif + endif + + strip-static_cxx: static_cxx + ifeq ($(CONFIG),opt) + % for lib in libs: + % if lib.language == "c++": + % if lib.build == "all": + $(E) "[STRIP] Stripping lib${lib.name}.a" + $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a + % endif + % endif + % endfor + endif + + strip-shared_c: shared_c + ifeq ($(CONFIG),opt) + % for lib in libs: + % if lib.language == "c": + % if lib.build == "all": + % if not lib.get('external_deps', None): + $(E) "[STRIP] Stripping lib${lib.name}.so" + $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) + % endif + % endif + % endif + % endfor + ifeq ($(HAS_ZOOKEEPER),true) + % for lib in libs: + % if lib.language == "c": + % if lib.build == "all": + % if 'zookeeper' in lib.get('external_deps', []): + $(E) "[STRIP] Stripping lib${lib.name}.so" + $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) + % endif + % endif + % endif + % endfor + endif + endif + + strip-shared_cxx: shared_cxx + ifeq ($(CONFIG),opt) + % for lib in libs: + % if lib.language == "c++": + % if lib.build == "all": + $(E) "[STRIP] Stripping lib${lib.name}.so" + $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) + % endif + % endif + % endfor + endif + + strip-shared_csharp: shared_csharp + ifeq ($(CONFIG),opt) + % for lib in libs: + % if lib.language == "csharp": + % if lib.build == "all": + $(E) "[STRIP] Stripping lib${lib.name}.so" + $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) + % endif + % endif + % endfor + endif + + cache.mk:: + $(E) "[MAKE] Generating $@" + $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@ + + $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc: + $(E) "[MAKE] Generating $@" + $(Q) mkdir -p $(@D) + $(Q) echo "$(GPR_PC_FILE)" | tr , '\n' >$@ + + $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc: + $(E) "[MAKE] Generating $@" + $(Q) mkdir -p $(@D) + $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@ + + $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc: + $(E) "[MAKE] Generating $@" + $(Q) mkdir -p $(@D) + $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@ + + $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_zookeeper.pc: + $(E) "[MAKE] Generating $@" + $(Q) mkdir -p $(@D) + $(Q) echo -e "$(GRPC_ZOOKEEPER_PC_FILE)" >$@ + + $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc: + $(E) "[MAKE] Generating $@" + $(Q) mkdir -p $(@D) + $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@ + + $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc: + $(E) "[MAKE] Generating $@" + $(Q) mkdir -p $(@D) + $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@ + + % for p in protos: + ifeq ($(NO_PROTOC),true) + $(GENDIR)/${p}.pb.cc: protoc_dep_error + $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error + else + $(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) + $(E) "[PROTOC] Generating protobuf CC file from $<" + $(Q) mkdir -p `dirname $@` + $(Q) $(PROTOC) --cpp_out=$(GENDIR) $< + + $(GENDIR)/${p}.grpc.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) + $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<" + $(Q) mkdir -p `dirname $@` + $(Q) $(PROTOC) --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(BINDIR)/$(CONFIG)/grpc_cpp_plugin $< + endif + + % endfor + + ifeq ($(CONFIG),stapprof) + src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h + ifeq ($(HAS_SYSTEMTAP),true) + $(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d + $(E) "[DTRACE] Compiling $<" + $(Q) mkdir -p `dirname $@` + $(Q) $(DTRACE) -C -h -s $< -o $@ + else + $(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop + endif + endif + + $(OBJDIR)/$(CONFIG)/%.o : %.c + $(E) "[C] Compiling $<" + $(Q) mkdir -p `dirname $@` + $(Q) $(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< + + $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc + $(E) "[CXX] Compiling $<" + $(Q) mkdir -p `dirname $@` + $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< + + $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc + $(E) "[HOSTCXX] Compiling $<" + $(Q) mkdir -p `dirname $@` + $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< + + $(OBJDIR)/$(CONFIG)/%.o : %.cc + $(E) "[CXX] Compiling $<" + $(Q) mkdir -p `dirname $@` + $(Q) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< + + install: install_c install_cxx install-plugins install-certs verify-install + + install_c: install-headers_c install-static_c install-shared_c + + install_cxx: install-headers_cxx install-static_cxx install-shared_cxx + + install_csharp: install-shared_csharp install_c + + install_grpc_csharp_ext: install_csharp + + install-headers: install-headers_c install-headers_cxx + + install-headers_c: + $(E) "[INSTALL] Installing public C headers" + $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1 + $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1 + + install-headers_cxx: + $(E) "[INSTALL] Installing public C++ headers" + $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1 + $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1 + + install-static: install-static_c install-static_cxx + + install-static_c: static_c strip-static_c install-pkg-config_c + % for lib in libs: + % if lib.language == "c": + % if lib.build == "all": + % if not lib.get('external_deps', None): + $(E) "[INSTALL] Installing lib${lib.name}.a" + $(Q) $(INSTALL) -d $(prefix)/lib + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a + % endif + % endif + % endif + % endfor + ifeq ($(HAS_ZOOKEEPER),true) + % for lib in libs: + % if lib.language == "c": + % if lib.build == "all": + % if 'zookeeper' in lib.get('external_deps', []): + $(E) "[INSTALL] Installing lib${lib.name}.a" + $(Q) $(INSTALL) -d $(prefix)/lib + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a + % endif + % endif + % endif + % endfor + endif + + install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx + % for lib in libs: + % if lib.language == "c++": + % if lib.build == "all": + $(E) "[INSTALL] Installing lib${lib.name}.a" + $(Q) $(INSTALL) -d $(prefix)/lib + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a + % endif + % endif + % endfor + + <%def name="install_shared(lang_filter)">\ + % for lib in libs: + % if lib.language == lang_filter: + % if lib.build == "all": + % if not lib.get('external_deps', None): + ifeq ($(SYSTEM),MINGW32) + $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)" + $(Q) $(INSTALL) -d $(prefix)/lib + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a + else + $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)" + $(Q) $(INSTALL) -d $(prefix)/lib + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT) + ifneq ($(SYSTEM),Darwin) + $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so.${settings.version.major} + $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so + endif + endif + % endif + % endif + % endif + % endfor + ifeq ($(HAS_ZOOKEEPER),true) + % for lib in libs: + % if lib.language == lang_filter: + % if lib.build == "all": + % if 'zookeeper' in lib.get('external_deps', []): + ifeq ($(SYSTEM),MINGW32) + $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)" + $(Q) $(INSTALL) -d $(prefix)/lib + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a + else + $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)" + $(Q) $(INSTALL) -d $(prefix)/lib + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT) + ifneq ($(SYSTEM),Darwin) + $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so.${settings.version.major} + $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so + endif + endif + % endif + % endif + % endif + % endfor + endif + ifneq ($(SYSTEM),MINGW32) + ifneq ($(SYSTEM),Darwin) + $(Q) ldconfig || true + endif + endif + + + install-shared_c: shared_c strip-shared_c install-pkg-config_c + ${install_shared("c")} + + install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx + ${install_shared("c++")} + + install-shared_csharp: shared_csharp strip-shared_csharp + ${install_shared("csharp")} + + install-plugins: $(PROTOC_PLUGINS) + ifeq ($(SYSTEM),MINGW32) + $(Q) false + else + $(E) "[INSTALL] Installing grpc protoc plugins" + % for tgt in targets: + % if tgt.build == 'protoc': + $(Q) $(INSTALL) -d $(prefix)/bin + $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name} + % endif + % endfor + endif + + install-pkg-config_c: pc_gpr pc_c pc_c_unsecure pc_c_zookeeper + $(E) "[INSTALL] Installing C pkg-config files" + $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc $(prefix)/lib/pkgconfig/gpr.pc + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(prefix)/lib/pkgconfig/grpc.pc + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(prefix)/lib/pkgconfig/grpc_unsecure.pc + ifeq ($(HAS_ZOOKEEPER),true) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_zookeeper.pc $(prefix)/lib/pkgconfig/grpc_zookeeper.pc + endif + + install-pkg-config_cxx: pc_cxx pc_cxx_unsecure + $(E) "[INSTALL] Installing C++ pkg-config files" + $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc $(prefix)/lib/pkgconfig/grpc++.pc + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc $(prefix)/lib/pkgconfig/grpc++_unsecure.pc + + install-certs: etc/roots.pem + $(E) "[INSTALL] Installing root certificates" + $(Q) $(INSTALL) -d $(prefix)/share/grpc + $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem + + verify-install: + ifeq ($(INSTALL_OK),true) + @echo "Your system looks ready to go." + @echo + else + @echo "We couldn't find protoc 3.0.0+ installed on your system. While this" + @echo "won't prevent grpc from working, you won't be able to compile" + @echo "and run any meaningful code with it." + @echo + @echo + @echo "Please download and install protobuf 3.0.0+ from:" + @echo + @echo " https://github.com/google/protobuf/releases" + @echo + @echo "Once you've done so, or if you think this message is in error," + @echo "you can re-run this check by doing:" + @echo + @echo " make verify-install" + endif + + clean: + $(E) "[CLEAN] Cleaning build directories." + $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk + + + # The various libraries + + % for lib in libs: + ${makelib(lib)} + % endfor + + + # All of the test targets, and protoc plugins + + % for tgt in targets: + ${maketarget(tgt)} + % endfor + + <%def name="makelib(lib)"> + LIB${lib.name.upper()}_SRC = \\ + + % for src in lib.src: + ${proto_to_cc(src)} \\ + + % endfor + + % if "public_headers" in lib: + % if lib.language == "c++": + PUBLIC_HEADERS_CXX += \\ + + % else: + PUBLIC_HEADERS_C += \\ + + % endif + % for hdr in lib.public_headers: + ${hdr} \\ + + % endfor + % endif + + LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC)))) + + ## If the library requires OpenSSL, let's add some restrictions. + % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check': + ifeq ($(NO_SECURE),true) + + # You can't build secure libraries if you don't have OpenSSL. + + $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error + + % if lib.build == "all": + ifeq ($(SYSTEM),MINGW32) + $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): openssl_dep_error + else + $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): openssl_dep_error + endif + % endif + + else + + % if lib.language == 'c++': + ifeq ($(NO_PROTOBUF),true) + + # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. + + $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error + + % if lib.build == "all": + ifeq ($(SYSTEM),MINGW32) + $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error + else + $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error + endif + % endif + + else + % endif + + $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP)\ + ## The else here corresponds to the if secure earlier. + % else: + % if lib.language == 'c++': + ifeq ($(NO_PROTOBUF),true) + + # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. + + $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error + + % if lib.build == "all": + ifeq ($(SYSTEM),MINGW32) + $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT): protobuf_dep_error + else + $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT): protobuf_dep_error + endif + % endif + + else + + % endif + $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP)\ + % endif + % if lib.language == 'c++': + $(PROTOBUF_DEP)\ + % endif + $(LIB${lib.name.upper()}_OBJS) + $(E) "[AR] Creating $@" + $(Q) mkdir -p `dirname $@` + $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a + $(Q) $(AR) rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) + % if lib.get('baselib', False): + % if lib.get('secure', 'check') == True: + $(Q) rm -rf tmp-merge-${lib.name} + $(Q) mkdir tmp-merge-${lib.name} + $(Q) ( cd tmp-merge-${lib.name} ; $(AR) x ../$(LIBDIR)/$(CONFIG)/lib${lib.name}.a ) + $(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge-${lib.name} ; <%text>ar x ../$${l} ) ; done + $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/__.SYMDEF* + $(Q) ar rcs $(LIBDIR)/$(CONFIG)/lib${lib.name}.a tmp-merge-${lib.name}/* + $(Q) rm -rf tmp-merge-${lib.name} + % endif + % endif + ifeq ($(SYSTEM),Darwin) + $(Q) ranlib $(LIBDIR)/$(CONFIG)/lib${lib.name}.a + endif + + <% + + if lib.language == 'c++': + ld = '$(LDXX)' + else: + ld = '$(LD)' + + out_base = '$(LIBDIR)/$(CONFIG)/' + lib.name + out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name + + common = '$(LIB' + lib.name.upper() + '_OBJS) $(LDLIBS)' + + libs = '' + lib_deps = ' $(ZLIB_DEP)' + mingw_libs = '' + mingw_lib_deps = ' $(ZLIB_DEP)' + if lib.language == 'c++': + lib_deps += ' $(PROTOBUF_DEP)' + mingw_lib_deps += ' $(PROTOBUF_DEP)' + for dep in lib.get('deps', []): + libs = libs + ' -l' + dep + lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT)' + mingw_libs = mingw_libs + ' -l' + dep + '-imp' + mingw_lib_deps = mingw_lib_deps + ' $(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)' + + security = lib.get('secure', 'check') + if security == True: + common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)' + + if security in [True, 'check']: + for src in lib.src: + if not proto_re.match(src): + sources_that_need_openssl.add(src) + else: + for src in lib.src: + sources_that_don_t_need_openssl.add(src) + + if 'zookeeper' in lib.get('external_deps', []): + libs = libs + ' -lzookeeper_mt' + + if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check': + lib_deps = lib_deps + ' $(OPENSSL_DEP)' + mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)' + + if lib.language == 'c++': + common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)' + %> + + % if lib.build == "all": + ifeq ($(SYSTEM),MINGW32) + ${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps} + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=${out_base}.def -Wl,--out-implib=${out_libbase}-imp.a -o ${out_base}.$(SHARED_EXT) ${common}${mingw_libs} + else + ${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps} + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + ifeq ($(SYSTEM),Darwin) + $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name lib${lib.name}.$(SHARED_EXT) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs} + else + $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} -o ${out_libbase}.$(SHARED_EXT) ${common}${libs} + $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major} + $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so + endif + endif + % endif + % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check': + ## If the lib was secure, we have to close the Makefile's if that tested + ## the presence of OpenSSL. + + endif + % endif + % if lib.language == 'c++': + ## If the lib was C++, we have to close the Makefile's if that tested + ## the presence of protobuf 3.0.0+ + + endif + % endif + + % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check': + ifneq ($(NO_SECURE),true) + % endif + ifneq ($(NO_DEPS),true) + -include $(LIB${lib.name.upper()}_OBJS:.o=.dep) + endif + % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check': + endif + % endif + % for src in lib.src: + % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src): + $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))} + % endif + % endfor + + + <%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %> + % if not has_no_sources: + ${tgt.name.upper()}_SRC = \\ + + % for src in tgt.src: + ${proto_to_cc(src)} \\ + + % endfor + + ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC)))) + % endif + % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check': + ifeq ($(NO_SECURE),true) + + # You can't build secure targets if you don't have OpenSSL. + + $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error + + else + + % endif + ## + ## We're not trying to add a dependency on building zlib and openssl here, + ## as it's already done in the libraries. We're assuming that the build + ## trickles down, and that a secure target requires a secure version of + ## a library. + ## + ## That simplifies the codegen a bit, but prevents a fully defined Makefile. + ## I can live with that. + ## + % if tgt.build == 'protoc' or tgt.language == 'c++': + + ifeq ($(NO_PROTOBUF),true) + + # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + + $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error + + else + + $(BINDIR)/$(CONFIG)/${tgt.name}: \ + % if not has_no_sources: + $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\ + % endif + % else: + $(BINDIR)/$(CONFIG)/${tgt.name}: \ + % if not has_no_sources: + $(${tgt.name.upper()}_OBJS)\ + % endif + % endif + % for dep in tgt.deps: + $(LIBDIR)/$(CONFIG)/lib${dep}.a\ + % endfor + + % if tgt.language == "c++": + ## C++ targets specificies. + % if tgt.build == 'protoc': + $(E) "[HOSTLD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \ + % if not has_no_sources: + $(${tgt.name.upper()}_OBJS)\ + % endif + % else: + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) \ + % if not has_no_sources: + $(${tgt.name.upper()}_OBJS)\ + % endif + % endif + % else: + ## C-only targets specificities. + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LD) $(LDFLAGS) \ + % if not has_no_sources: + $(${tgt.name.upper()}_OBJS)\ + % endif + % endif + % for dep in tgt.deps: + $(LIBDIR)/$(CONFIG)/lib${dep}.a\ + % endfor + % if 'zookeeper' in tgt.get('external_deps', []): + -lzookeeper_mt\ + % endif + % if tgt.language == "c++": + % if tgt.build == 'protoc': + $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\ + % else: + $(LDLIBSXX) $(LDLIBS_PROTOBUF)\ + % endif + % endif + % if tgt.build == 'protoc': + $(HOST_LDLIBS)\ + % else: + $(LDLIBS)\ + % endif + % if tgt.build == 'protoc': + $(HOST_LDLIBS_PROTOC)\ + % elif tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check': + $(LDLIBS_SECURE)\ + % endif + % if tgt.language == 'c++' and tgt.build == 'test': + $(GTEST_LIB)\ + % elif tgt.language == 'c++' and tgt.build == 'benchmark': + $(GTEST_LIB)\ + % endif + -o $(BINDIR)/$(CONFIG)/${tgt.name} + % if tgt.build == 'protoc' or tgt.language == 'c++': + + endif + % endif + % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check': + + endif + % endif + + % for src in tgt.src: + $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \ + % for dep in tgt.deps: + $(LIBDIR)/$(CONFIG)/lib${dep}.a\ + % endfor + + % endfor + % if not has_no_sources: + deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep) + % endif + + % if not has_no_sources: + % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check': + ifneq ($(NO_SECURE),true) + % endif + ifneq ($(NO_DEPS),true) + -include $(${tgt.name.upper()}_OBJS:.o=.dep) + endif + % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check': + endif + % endif + % endif + + + ifneq ($(OPENSSL_DEP),) + # This is to ensure the embedded OpenSSL is built beforehand, properly + # installing headers to their final destination on the drive. We need this + # otherwise parallel compilation will fail if a source is compiled first. + % for src in sorted(sources_that_need_openssl): + % if src not in sources_that_don_t_need_openssl: + ${src}: $(OPENSSL_DEP) + % endif + % endfor + endif + + .PHONY: all strip tools \ + dep_error openssl_dep_error openssl_dep_message git_update stop \ + buildtests buildtests_c buildtests_cxx \ + test test_c test_cxx \ + install install_c install_cxx \ + install-headers install-headers_c install-headers_cxx \ + install-shared install-shared_c install-shared_cxx \ + install-static install-static_c install-static_cxx \ + strip strip-shared strip-static \ + strip_c strip-shared_c strip-static_c \ + strip_cxx strip-shared_cxx strip-static_cxx \ + dep_c dep_cxx bins_dep_c bins_dep_cxx \ + clean From f96dfc3cf89f0e10a5356ca1bcfd4697410a75c4 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Sep 2015 14:43:18 -0700 Subject: [PATCH 27/32] First round of fixing up implicit 64->32 bit conversions --- Makefile | 7 ++ include/grpc/support/port_platform.h | 1 + include/grpc/support/slice_buffer.h | 2 +- src/core/channel/channel_args.c | 2 +- src/core/channel/compress_filter.c | 3 +- src/core/compression/message_compress.c | 10 ++- src/core/iomgr/alarm.c | 4 +- src/core/iomgr/alarm_heap.c | 4 +- src/core/iomgr/tcp_client_posix.c | 3 +- src/core/iomgr/tcp_server_posix.c | 7 +- src/core/iomgr/udp_server.c | 7 +- src/core/iomgr/wakeup_fd_pipe.c | 2 +- src/core/security/jwt_verifier.c | 8 ++- src/core/support/slice_buffer.c | 2 +- src/core/support/stack_lockfree.c | 8 +-- src/core/surface/call.c | 14 ++-- src/core/surface/server.c | 13 ++-- src/core/transport/chttp2/frame_goaway.c | 6 +- src/core/transport/chttp2/frame_settings.c | 2 +- src/core/transport/chttp2/hpack_parser.c | 3 +- src/core/transport/chttp2/parsing.c | 4 +- src/core/transport/chttp2/stream_encoder.c | 41 +++++++----- src/core/transport/chttp2/timeout_encoding.c | 2 +- src/core/transport/chttp2/writing.c | 18 ++++-- src/core/transport/chttp2_transport.c | 19 +++--- src/core/transport/transport.h | 2 +- src/core/tsi/fake_transport_security.c | 9 +-- src/core/tsi/ssl_transport_security.c | 64 +++++++++++++------ templates/Makefile.template | 7 ++ test/build/empty.c | 34 ++++++++++ test/core/compression/message_compress_test.c | 2 +- test/core/fling/server.c | 2 +- test/core/iomgr/fd_posix_test.c | 2 +- test/core/iomgr/udp_server_test.c | 2 +- test/core/support/murmur_hash_test.c | 4 +- test/core/support/stack_lockfree_test.c | 7 +- test/core/transport/chttp2/hpack_table_test.c | 2 +- .../transport/chttp2/stream_encoder_test.c | 4 +- test/core/transport/chttp2/stream_map_test.c | 40 ++++++------ tools/codegen/core/gen_hpack_tables.c | 33 +++++----- 40 files changed, 261 insertions(+), 145 deletions(-) create mode 100644 test/build/empty.c diff --git a/Makefile b/Makefile index 5a3f1ea7412..21f3011a6e2 100644 --- a/Makefile +++ b/Makefile @@ -231,6 +231,10 @@ endif CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false) +# Detect if -Wshorten-64-to-32 is a thing +SHORTEN_64_TO_32_CHECK_CMD = $(CC) -Wshorten-64-to-32 test/build/empty.c +HAS_SHORTEN_64_TO_32 = $(shell $(SHORTEN_64_TO_32_CHECK_CMD) 2> /dev/null && echo true || echo false) + # The HOST compiler settings are used to compile the protoc plugins. # In most cases, you won't have to change anything, but if you are # cross-compiling, you can override these variables from GNU make's @@ -246,6 +250,9 @@ DEFINES += $(EXTRA_DEFINES) endif CFLAGS += -std=c89 -pedantic -Wsign-conversion +ifeq ($(HAS_SHORTEN_64_TO_32),true) +CFLAGS += -Wshorten-64-to-32 +endif ifeq ($(HAS_CXX11),true) CXXFLAGS += -std=c++11 else diff --git a/include/grpc/support/port_platform.h b/include/grpc/support/port_platform.h index d09815557ec..69709f88502 100644 --- a/include/grpc/support/port_platform.h +++ b/include/grpc/support/port_platform.h @@ -318,6 +318,7 @@ typedef uintptr_t gpr_uintptr; /* INT64_MAX is unavailable on some platforms. */ #define GPR_INT64_MAX (gpr_int64)(~(gpr_uint64)0 >> 1) +#define GPR_UINT32_MAX (~(gpr_uint32)0) /* maximum alignment needed for any type on this platform, rounded up to a power of two */ diff --git a/include/grpc/support/slice_buffer.h b/include/grpc/support/slice_buffer.h index 04db003ac58..321ba288fd9 100644 --- a/include/grpc/support/slice_buffer.h +++ b/include/grpc/support/slice_buffer.h @@ -77,7 +77,7 @@ size_t gpr_slice_buffer_add_indexed(gpr_slice_buffer *sb, gpr_slice slice); void gpr_slice_buffer_addn(gpr_slice_buffer *sb, gpr_slice *slices, size_t n); /* add a very small (less than 8 bytes) amount of data to the end of a slice buffer: returns a pointer into which to add the data */ -gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, unsigned len); +gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, size_t len); /* pop the last buffer, but don't unref it */ void gpr_slice_buffer_pop(gpr_slice_buffer *sb); /* clear a slice buffer, unref all elements */ diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c index 31ce3a83fde..591135cd6f2 100644 --- a/src/core/channel/channel_args.c +++ b/src/core/channel/channel_args.c @@ -132,7 +132,7 @@ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( for (i = 0; i < a->num_args; ++i) { if (a->args[i].type == GRPC_ARG_INTEGER && !strcmp(GRPC_COMPRESSION_ALGORITHM_ARG, a->args[i].key)) { - return a->args[i].value.integer; + return (grpc_compression_algorithm)a->args[i].value.integer; break; } } diff --git a/src/core/channel/compress_filter.c b/src/core/channel/compress_filter.c index 0b85c7b4fa6..8e06094257d 100644 --- a/src/core/channel/compress_filter.c +++ b/src/core/channel/compress_filter.c @@ -142,8 +142,9 @@ static void finish_compressed_sopb(grpc_stream_op_buffer *send_ops, grpc_stream_op *sop = &send_ops->ops[i]; switch (sop->type) { case GRPC_OP_BEGIN_MESSAGE: + GPR_ASSERT(calld->slices.length <= GPR_UINT32_MAX); grpc_sopb_add_begin_message( - &new_send_ops, calld->slices.length, + &new_send_ops, (gpr_uint32)calld->slices.length, sop->data.begin_message.flags | GRPC_WRITE_INTERNAL_COMPRESS); break; case GRPC_OP_SLICE: diff --git a/src/core/compression/message_compress.c b/src/core/compression/message_compress.c index 7856f40dd18..01db7134c3c 100644 --- a/src/core/compression/message_compress.c +++ b/src/core/compression/message_compress.c @@ -49,19 +49,23 @@ static int zlib_body(z_stream *zs, gpr_slice_buffer *input, int flush; size_t i; gpr_slice outbuf = gpr_slice_malloc(OUTPUT_BLOCK_SIZE); + const uInt uint_max = ~(uInt)0; - zs->avail_out = GPR_SLICE_LENGTH(outbuf); + GPR_ASSERT(GPR_SLICE_LENGTH(outbuf) <= uint_max); + zs->avail_out = (uInt)GPR_SLICE_LENGTH(outbuf); zs->next_out = GPR_SLICE_START_PTR(outbuf); flush = Z_NO_FLUSH; for (i = 0; i < input->count; i++) { if (i == input->count - 1) flush = Z_FINISH; - zs->avail_in = GPR_SLICE_LENGTH(input->slices[i]); + GPR_ASSERT(GPR_SLICE_LENGTH(input->slices[i]) <= uint_max); + zs->avail_in = (uInt)GPR_SLICE_LENGTH(input->slices[i]); zs->next_in = GPR_SLICE_START_PTR(input->slices[i]); do { if (zs->avail_out == 0) { gpr_slice_buffer_add_indexed(output, outbuf); outbuf = gpr_slice_malloc(OUTPUT_BLOCK_SIZE); - zs->avail_out = GPR_SLICE_LENGTH(outbuf); + GPR_ASSERT(GPR_SLICE_LENGTH(outbuf) <= uint_max); + zs->avail_out = (uInt)GPR_SLICE_LENGTH(outbuf); zs->next_out = GPR_SLICE_START_PTR(outbuf); } r = flate(zs, flush); diff --git a/src/core/iomgr/alarm.c b/src/core/iomgr/alarm.c index e31793475fb..515b96ffc12 100644 --- a/src/core/iomgr/alarm.c +++ b/src/core/iomgr/alarm.c @@ -145,7 +145,7 @@ static void list_remove(grpc_alarm *alarm) { alarm->prev->next = alarm->next; } -static void swap_adjacent_shards_in_queue(size_t first_shard_queue_index) { +static void swap_adjacent_shards_in_queue(gpr_uint32 first_shard_queue_index) { shard_type *temp; temp = g_shard_queue[first_shard_queue_index]; g_shard_queue[first_shard_queue_index] = @@ -355,7 +355,7 @@ static int run_some_expired_alarms(gpr_mu *drop_mu, gpr_timespec now, gpr_mu_lock(drop_mu); } - return n; + return (int)n; } int grpc_alarm_check(gpr_mu *drop_mu, gpr_timespec now, gpr_timespec *next) { diff --git a/src/core/iomgr/alarm_heap.c b/src/core/iomgr/alarm_heap.c index 7bafdffcefd..769142e425d 100644 --- a/src/core/iomgr/alarm_heap.c +++ b/src/core/iomgr/alarm_heap.c @@ -45,7 +45,7 @@ its argument. */ static void adjust_upwards(grpc_alarm **first, gpr_uint32 i, grpc_alarm *t) { while (i > 0) { - gpr_uint32 parent = (i - 1u) / 2u; + gpr_uint32 parent = (gpr_uint32)(((int)i - 1) / 2); if (gpr_time_cmp(first[parent]->deadline, t->deadline) >= 0) break; first[i] = first[parent]; first[i]->heap_index = i; @@ -94,7 +94,7 @@ static void maybe_shrink(grpc_alarm_heap *heap) { static void note_changed_priority(grpc_alarm_heap *heap, grpc_alarm *alarm) { gpr_uint32 i = alarm->heap_index; - gpr_uint32 parent = (i - 1u) / 2u; + gpr_uint32 parent = (gpr_uint32)(((int)i - 1) / 2); if (gpr_time_cmp(heap->alarms[parent]->deadline, alarm->deadline) < 0) { adjust_upwards(heap->alarms, i, alarm); } else { diff --git a/src/core/iomgr/tcp_client_posix.c b/src/core/iomgr/tcp_client_posix.c index 7ca0a60c31e..c3668f6a920 100644 --- a/src/core/iomgr/tcp_client_posix.c +++ b/src/core/iomgr/tcp_client_posix.c @@ -229,7 +229,8 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *ep), } do { - err = connect(fd, addr, addr_len); + GPR_ASSERT(addr_len < ~(socklen_t)0); + err = connect(fd, addr, (socklen_t)addr_len); } while (err < 0 && errno == EINTR); addr_str = grpc_sockaddr_to_uri(addr); diff --git a/src/core/iomgr/tcp_server_posix.c b/src/core/iomgr/tcp_server_posix.c index 6b81090108f..bcbd0afe6b9 100644 --- a/src/core/iomgr/tcp_server_posix.c +++ b/src/core/iomgr/tcp_server_posix.c @@ -83,7 +83,7 @@ typedef struct { struct sockaddr sockaddr; struct sockaddr_un un; } addr; - int addr_len; + size_t addr_len; grpc_iomgr_closure read_closure; grpc_iomgr_closure destroyed_closure; } server_port; @@ -236,7 +236,7 @@ static void init_max_accept_queue_size(void) { char *end; long i = strtol(buf, &end, 10); if (i > 0 && i <= INT_MAX && end && *end == 0) { - n = i; + n = (int)i; } } fclose(fp); @@ -274,7 +274,8 @@ static int prepare_socket(int fd, const struct sockaddr *addr, goto error; } - if (bind(fd, addr, addr_len) < 0) { + GPR_ASSERT(addr_len < ~(socklen_t)0); + if (bind(fd, addr, (socklen_t)addr_len) < 0) { char *addr_str; grpc_sockaddr_to_string(&addr_str, addr, 0); gpr_log(GPR_ERROR, "bind addr=%s: %s", addr_str, strerror(errno)); diff --git a/src/core/iomgr/udp_server.c b/src/core/iomgr/udp_server.c index 95ae698781b..ed9eee8726b 100644 --- a/src/core/iomgr/udp_server.c +++ b/src/core/iomgr/udp_server.c @@ -78,7 +78,7 @@ typedef struct { struct sockaddr sockaddr; struct sockaddr_un un; } addr; - int addr_len; + size_t addr_len; grpc_iomgr_closure read_closure; grpc_iomgr_closure destroyed_closure; grpc_udp_server_read_cb read_cb; @@ -242,7 +242,8 @@ static int prepare_socket(int fd, const struct sockaddr *addr, #endif } - if (bind(fd, addr, addr_len) < 0) { + GPR_ASSERT(addr_len < ~(socklen_t)0); + if (bind(fd, addr, (socklen_t)addr_len) < 0) { char *addr_str; grpc_sockaddr_to_string(&addr_str, addr, 0); gpr_log(GPR_ERROR, "bind addr=%s: %s", addr_str, strerror(errno)); @@ -431,7 +432,7 @@ void grpc_udp_server_start(grpc_udp_server *s, grpc_pollset **pollsets, /* TODO(rjshade): Add a test for this method. */ void grpc_udp_server_write(server_port *sp, const char *buffer, size_t buf_len, const struct sockaddr *peer_address) { - int rc; + ssize_t rc; rc = sendto(sp->fd, buffer, buf_len, 0, peer_address, sizeof(peer_address)); if (rc < 0) { gpr_log(GPR_ERROR, "Unable to send data: %s", strerror(errno)); diff --git a/src/core/iomgr/wakeup_fd_pipe.c b/src/core/iomgr/wakeup_fd_pipe.c index bd643e80619..902034ee4b1 100644 --- a/src/core/iomgr/wakeup_fd_pipe.c +++ b/src/core/iomgr/wakeup_fd_pipe.c @@ -56,7 +56,7 @@ static void pipe_init(grpc_wakeup_fd *fd_info) { static void pipe_consume(grpc_wakeup_fd *fd_info) { char buf[128]; - int r; + ssize_t r; for (;;) { r = read(fd_info->read_fd, buf, sizeof(buf)); diff --git a/src/core/security/jwt_verifier.c b/src/core/security/jwt_verifier.c index 03f8c3783e9..790f2178dbe 100644 --- a/src/core/security/jwt_verifier.c +++ b/src/core/security/jwt_verifier.c @@ -33,6 +33,7 @@ #include "src/core/security/jwt_verifier.h" +#include #include #include "src/core/httpcli/httpcli.h" @@ -412,7 +413,9 @@ static EVP_PKEY *extract_pkey_from_x509(const char *x509_str) { X509 *x509 = NULL; EVP_PKEY *result = NULL; BIO *bio = BIO_new(BIO_s_mem()); - BIO_write(bio, x509_str, strlen(x509_str)); + size_t len = strlen(x509_str); + GPR_ASSERT(len < INT_MAX); + BIO_write(bio, x509_str, (int)len); x509 = PEM_read_bio_X509(bio, NULL, NULL, NULL); if (x509 == NULL) { gpr_log(GPR_ERROR, "Unable to parse x509 cert."); @@ -439,7 +442,8 @@ static BIGNUM *bignum_from_base64(const char *b64) { gpr_log(GPR_ERROR, "Invalid base64 for big num."); return NULL; } - result = BN_bin2bn(GPR_SLICE_START_PTR(bin), GPR_SLICE_LENGTH(bin), NULL); + result = + BN_bin2bn(GPR_SLICE_START_PTR(bin), (int)GPR_SLICE_LENGTH(bin), NULL); gpr_slice_unref(bin); return result; } diff --git a/src/core/support/slice_buffer.c b/src/core/support/slice_buffer.c index 6482ef9c9fe..8873d459d56 100644 --- a/src/core/support/slice_buffer.c +++ b/src/core/support/slice_buffer.c @@ -69,7 +69,7 @@ void gpr_slice_buffer_destroy(gpr_slice_buffer *sb) { } } -gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, unsigned n) { +gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, size_t n) { gpr_slice *back; gpr_uint8 *out; diff --git a/src/core/support/stack_lockfree.c b/src/core/support/stack_lockfree.c index 0d4b4bedd9a..180ba19c680 100644 --- a/src/core/support/stack_lockfree.c +++ b/src/core/support/stack_lockfree.c @@ -123,13 +123,13 @@ int gpr_stack_lockfree_push(gpr_stack_lockfree *stack, int entry) { #ifndef NDEBUG /* Check for double push */ { - int pushed_index = entry / (8 * sizeof(gpr_atm)); - int pushed_bit = entry % (8 * sizeof(gpr_atm)); + int pushed_index = entry / (int)(8 * sizeof(gpr_atm)); + int pushed_bit = entry % (int)(8 * sizeof(gpr_atm)); gpr_atm old_val; old_val = gpr_atm_no_barrier_fetch_add(&stack->pushed[pushed_index], (gpr_atm)(1UL << pushed_bit)); - GPR_ASSERT((old_val & (1UL << pushed_bit)) == 0); + GPR_ASSERT((old_val & (gpr_atm)(1UL << pushed_bit)) == 0); } #endif @@ -167,7 +167,7 @@ int gpr_stack_lockfree_pop(gpr_stack_lockfree *stack) { old_val = gpr_atm_no_barrier_fetch_add(&stack->pushed[pushed_index], -(gpr_atm)(1UL << pushed_bit)); - GPR_ASSERT((old_val & (1UL << pushed_bit)) != 0); + GPR_ASSERT((old_val & (gpr_atm)(1UL << pushed_bit)) != 0); } #endif diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 6ece56371b4..c96df77a98d 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -508,7 +508,7 @@ static void set_status_code(grpc_call *call, status_source source, if (call->status[source].is_set) return; call->status[source].is_set = 1; - call->status[source].code = status; + call->status[source].code = (grpc_status_code)status; call->error_status_set = status != GRPC_STATUS_OK; if (status != GRPC_STATUS_OK && !grpc_bbq_empty(&call->incoming_queue)) { @@ -604,7 +604,7 @@ static void unlock(grpc_call *call) { int completing_requests = 0; int start_op = 0; int i; - const gpr_uint32 MAX_RECV_PEEK_AHEAD = 65536; + const size_t MAX_RECV_PEEK_AHEAD = 65536; size_t buffered_bytes; int cancel_alarm = 0; @@ -1107,10 +1107,12 @@ static int fill_send_ops(grpc_call *call, grpc_transport_stream_op *op) { /* fall through intended */ case WRITE_STATE_STARTED: if (is_op_live(call, GRPC_IOREQ_SEND_MESSAGE)) { + size_t length; data = call->request_data[GRPC_IOREQ_SEND_MESSAGE]; flags = call->request_flags[GRPC_IOREQ_SEND_MESSAGE]; - grpc_sopb_add_begin_message( - &call->send_ops, grpc_byte_buffer_length(data.send_message), flags); + length = grpc_byte_buffer_length(data.send_message); + GPR_ASSERT(length <= GPR_UINT32_MAX); + grpc_sopb_add_begin_message(&call->send_ops, (gpr_uint32)length, flags); copy_byte_buffer_to_stream_ops(data.send_message, &call->send_ops); op->send_ops = &call->send_ops; call->last_send_contains |= 1 << GRPC_IOREQ_SEND_MESSAGE; @@ -1243,7 +1245,7 @@ static grpc_call_error start_ioreq(grpc_call *call, const grpc_ioreq *reqs, } if (op == GRPC_IOREQ_SEND_STATUS) { set_status_code(call, STATUS_FROM_SERVER_STATUS, - reqs[i].data.send_status.code); + (gpr_uint32)reqs[i].data.send_status.code); if (reqs[i].data.send_status.details) { set_status_details(call, STATUS_FROM_SERVER_STATUS, GRPC_MDSTR_REF(reqs[i].data.send_status.details)); @@ -1333,7 +1335,7 @@ static grpc_call_error cancel_with_status(grpc_call *c, grpc_status_code status, GPR_ASSERT(status != GRPC_STATUS_OK); - set_status_code(c, STATUS_FROM_API_OVERRIDE, status); + set_status_code(c, STATUS_FROM_API_OVERRIDE, (gpr_uint32)status); set_status_details(c, STATUS_FROM_API_OVERRIDE, details); c->cancel_with_status = status; diff --git a/src/core/surface/server.c b/src/core/surface/server.c index c3d80467872..3d404f78a4f 100644 --- a/src/core/surface/server.c +++ b/src/core/surface/server.c @@ -33,6 +33,7 @@ #include "src/core/surface/server.h" +#include #include #include @@ -804,7 +805,7 @@ grpc_server *grpc_server_create_from_filters( server->request_freelist = gpr_stack_lockfree_create(server->max_requested_calls); for (i = 0; i < (size_t)server->max_requested_calls; i++) { - gpr_stack_lockfree_push(server->request_freelist, i); + gpr_stack_lockfree_push(server->request_freelist, (int)i); } request_matcher_init(&server->unregistered_request_matcher, server->max_requested_calls); @@ -896,7 +897,7 @@ void grpc_server_setup_transport(grpc_server *s, grpc_transport *transport, grpc_mdstr *host; grpc_mdstr *method; gpr_uint32 hash; - gpr_uint32 slots; + size_t slots; gpr_uint32 probes; gpr_uint32 max_probes = 0; grpc_transport_op op; @@ -949,7 +950,8 @@ void grpc_server_setup_transport(grpc_server *s, grpc_transport *transport, crm->host = host; crm->method = method; } - chand->registered_method_slots = slots; + GPR_ASSERT(slots <= GPR_UINT32_MAX); + chand->registered_method_slots = (gpr_uint32)slots; chand->registered_method_max_probes = max_probes; } @@ -970,7 +972,7 @@ void grpc_server_setup_transport(grpc_server *s, grpc_transport *transport, op.set_accept_stream_user_data = chand; op.on_connectivity_state_change = &chand->channel_connectivity_changed; op.connectivity_state = &chand->connectivity_state; - op.disconnect = gpr_atm_acq_load(&s->shutdown_flag); + op.disconnect = gpr_atm_acq_load(&s->shutdown_flag) != 0; grpc_transport_perform_op(transport, &op); } @@ -1256,8 +1258,9 @@ static void done_request_event(void *req, grpc_cq_completion *c) { if (rc >= server->requested_calls && rc < server->requested_calls + server->max_requested_calls) { + GPR_ASSERT(rc - server->requested_calls <= INT_MAX); gpr_stack_lockfree_push(server->request_freelist, - rc - server->requested_calls); + (int)(rc - server->requested_calls)); } else { gpr_free(req); } diff --git a/src/core/transport/chttp2/frame_goaway.c b/src/core/transport/chttp2/frame_goaway.c index d40e6fd03a8..1a6d80da582 100644 --- a/src/core/transport/chttp2/frame_goaway.c +++ b/src/core/transport/chttp2/frame_goaway.c @@ -143,7 +143,7 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse( transport_parsing->goaway_received = 1; transport_parsing->goaway_last_stream_index = p->last_stream_id; gpr_slice_unref(transport_parsing->goaway_text); - transport_parsing->goaway_error = p->error_code; + transport_parsing->goaway_error = (grpc_status_code)p->error_code; transport_parsing->goaway_text = gpr_slice_new(p->debug_data, p->debug_length, gpr_free); p->debug_data = NULL; @@ -160,7 +160,9 @@ void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code, gpr_slice_buffer *slice_buffer) { gpr_slice header = gpr_slice_malloc(9 + 4 + 4); gpr_uint8 *p = GPR_SLICE_START_PTR(header); - gpr_uint32 frame_length = 4 + 4 + GPR_SLICE_LENGTH(debug_data); + gpr_uint32 frame_length; + GPR_ASSERT(GPR_SLICE_LENGTH(debug_data) < GPR_UINT32_MAX - 4 - 4); + frame_length = 4 + 4 + (gpr_uint32)GPR_SLICE_LENGTH(debug_data); /* frame header: length */ *p++ = frame_length >> 16; diff --git a/src/core/transport/chttp2/frame_settings.c b/src/core/transport/chttp2/frame_settings.c index 927ae55996f..f70776bf4cb 100644 --- a/src/core/transport/chttp2/frame_settings.c +++ b/src/core/transport/chttp2/frame_settings.c @@ -76,7 +76,7 @@ static gpr_uint8 *fill_header(gpr_uint8 *out, gpr_uint32 length, gpr_slice grpc_chttp2_settings_create(gpr_uint32 *old, const gpr_uint32 *new, gpr_uint32 force_mask, size_t count) { size_t i; - size_t n = 0; + gpr_uint32 n = 0; gpr_slice output; gpr_uint8 *p; diff --git a/src/core/transport/chttp2/hpack_parser.c b/src/core/transport/chttp2/hpack_parser.c index f806f59ed73..93a452f1fd2 100644 --- a/src/core/transport/chttp2/hpack_parser.c +++ b/src/core/transport/chttp2/hpack_parser.c @@ -1085,7 +1085,8 @@ static int parse_string_prefix(grpc_chttp2_hpack_parser *p, static void append_bytes(grpc_chttp2_hpack_parser_string *str, const gpr_uint8 *data, size_t length) { if (length + str->length > str->capacity) { - str->capacity = str->length + length; + GPR_ASSERT(str->length + length <= GPR_UINT32_MAX); + str->capacity = (gpr_uint32)(str->length + length); str->str = gpr_realloc(str->str, str->capacity); } memcpy(str->str + str->length, data, length); diff --git a/src/core/transport/chttp2/parsing.c b/src/core/transport/chttp2/parsing.c index b0f884e2581..a29987a05ad 100644 --- a/src/core/transport/chttp2/parsing.c +++ b/src/core/transport/chttp2/parsing.c @@ -131,7 +131,7 @@ void grpc_chttp2_publish_reads( published later */ if (transport_parsing->goaway_received) { grpc_chttp2_add_incoming_goaway(transport_global, - transport_parsing->goaway_error, + (gpr_uint32)transport_parsing->goaway_error, transport_parsing->goaway_text); transport_parsing->goaway_text = gpr_empty_slice(); transport_parsing->goaway_received = 0; @@ -212,7 +212,7 @@ void grpc_chttp2_publish_reads( if (stream_parsing->saw_rst_stream) { stream_global->cancelled = 1; stream_global->cancelled_status = grpc_chttp2_http2_error_to_grpc_status( - stream_parsing->rst_stream_reason); + (grpc_chttp2_error_code)stream_parsing->rst_stream_reason); if (stream_parsing->rst_stream_reason == GRPC_CHTTP2_NO_ERROR) { stream_global->published_cancelled = 1; } diff --git a/src/core/transport/chttp2/stream_encoder.c b/src/core/transport/chttp2/stream_encoder.c index bcae93dc7a2..8c30af652fc 100644 --- a/src/core/transport/chttp2/stream_encoder.c +++ b/src/core/transport/chttp2/stream_encoder.c @@ -74,8 +74,9 @@ typedef struct { } framer_state; /* fills p (which is expected to be 9 bytes long) with a data frame header */ -static void fill_header(gpr_uint8 *p, gpr_uint8 type, gpr_uint32 id, - gpr_uint32 len, gpr_uint8 flags) { +static void fill_header(gpr_uint8 *p, gpr_uint8 type, gpr_uint32 id, size_t len, + gpr_uint8 flags) { + GPR_ASSERT(len < 16777316); *p++ = len >> 16; *p++ = len >> 8; *p++ = len; @@ -185,8 +186,8 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c, gpr_uint32 key_hash = elem->key->hash; gpr_uint32 elem_hash = GRPC_MDSTR_KV_HASH(key_hash, elem->value->hash); gpr_uint32 new_index = c->tail_remote_index + c->table_elems + 1; - gpr_uint32 elem_size = 32 + GPR_SLICE_LENGTH(elem->key->slice) + - GPR_SLICE_LENGTH(elem->value->slice); + size_t elem_size = 32 + GPR_SLICE_LENGTH(elem->key->slice) + + GPR_SLICE_LENGTH(elem->value->slice); grpc_mdelem *elem_to_unref; /* Reserve space for this element in the remote table: if this overflows @@ -270,7 +271,7 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c, static void emit_indexed(grpc_chttp2_hpack_compressor *c, gpr_uint32 index, framer_state *st) { - size_t len = GRPC_CHTTP2_VARINT_LENGTH(index, 1); + gpr_uint32 len = GRPC_CHTTP2_VARINT_LENGTH(index, 1); GRPC_CHTTP2_WRITE_VARINT(index, 1, 0x80, add_tiny_header_data(st, len), len); } @@ -291,11 +292,13 @@ static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c, gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 2); gpr_uint8 huffman_prefix; gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice); - gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); + size_t len_val = GPR_SLICE_LENGTH(value_slice); + gpr_uint32 len_val_len; + GPR_ASSERT(len_val <= GPR_UINT32_MAX); + len_val_len = GRPC_CHTTP2_VARINT_LENGTH((gpr_uint32)len_val, 1); GRPC_CHTTP2_WRITE_VARINT(key_index, 2, 0x40, add_tiny_header_data(st, len_pfx), len_pfx); - GRPC_CHTTP2_WRITE_VARINT(len_val, 1, 0x00, + GRPC_CHTTP2_WRITE_VARINT((gpr_uint32)len_val, 1, 0x00, add_tiny_header_data(st, len_val_len), len_val_len); add_header_data(st, gpr_slice_ref(value_slice)); } @@ -306,23 +309,27 @@ static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c, gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 4); gpr_uint8 huffman_prefix; gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice); - gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); + size_t len_val = GPR_SLICE_LENGTH(value_slice); + gpr_uint32 len_val_len; + GPR_ASSERT(len_val <= GPR_UINT32_MAX); + len_val_len = GRPC_CHTTP2_VARINT_LENGTH((gpr_uint32)len_val, 1); GRPC_CHTTP2_WRITE_VARINT(key_index, 4, 0x00, add_tiny_header_data(st, len_pfx), len_pfx); - GRPC_CHTTP2_WRITE_VARINT(len_val, 1, 0x00, + GRPC_CHTTP2_WRITE_VARINT((gpr_uint32)len_val, 1, 0x00, add_tiny_header_data(st, len_val_len), len_val_len); add_header_data(st, gpr_slice_ref(value_slice)); } static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem, framer_state *st) { - gpr_uint32 len_key = GPR_SLICE_LENGTH(elem->key->slice); + gpr_uint32 len_key = (gpr_uint32)GPR_SLICE_LENGTH(elem->key->slice); gpr_uint8 huffman_prefix; gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice); + gpr_uint32 len_val = (gpr_uint32)GPR_SLICE_LENGTH(value_slice); gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); + GPR_ASSERT(len_key <= GPR_UINT32_MAX); + GPR_ASSERT(GPR_SLICE_LENGTH(value_slice) <= GPR_UINT32_MAX); *add_tiny_header_data(st, 1) = 0x40; GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00, add_tiny_header_data(st, len_key_len), len_key_len); @@ -334,12 +341,14 @@ static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c, static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem, framer_state *st) { - gpr_uint32 len_key = GPR_SLICE_LENGTH(elem->key->slice); + gpr_uint32 len_key = (gpr_uint32)GPR_SLICE_LENGTH(elem->key->slice); gpr_uint8 huffman_prefix; gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice); + gpr_uint32 len_val = (gpr_uint32)GPR_SLICE_LENGTH(value_slice); gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); + GPR_ASSERT(len_key <= GPR_UINT32_MAX); + GPR_ASSERT(GPR_SLICE_LENGTH(value_slice) <= GPR_UINT32_MAX); *add_tiny_header_data(st, 1) = 0x00; GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00, add_tiny_header_data(st, len_key_len), len_key_len); @@ -565,7 +574,7 @@ void grpc_chttp2_encode(grpc_stream_op *ops, size_t ops_count, int eof, framer_state st; gpr_slice slice; grpc_stream_op *op; - gpr_uint32 max_take_size; + size_t max_take_size; gpr_uint32 curop = 0; gpr_uint32 unref_op; grpc_mdctx *mdctx = compressor->mdctx; diff --git a/src/core/transport/chttp2/timeout_encoding.c b/src/core/transport/chttp2/timeout_encoding.c index 40fcdc26dca..8a9b290ecb9 100644 --- a/src/core/transport/chttp2/timeout_encoding.c +++ b/src/core/transport/chttp2/timeout_encoding.c @@ -123,7 +123,7 @@ void grpc_chttp2_encode_timeout(gpr_timespec timeout, char *buffer) { enc_nanos(buffer, timeout.tv_nsec); } else if (timeout.tv_sec < 1000 && timeout.tv_nsec != 0) { enc_micros(buffer, - timeout.tv_sec * 1000000 + + (int)(timeout.tv_sec * 1000000) + (timeout.tv_nsec / 1000 + (timeout.tv_nsec % 1000 != 0))); } else { enc_seconds(buffer, timeout.tv_sec + (timeout.tv_nsec != 0)); diff --git a/src/core/transport/chttp2/writing.c b/src/core/transport/chttp2/writing.c index ac79044e08f..c015e82931d 100644 --- a/src/core/transport/chttp2/writing.c +++ b/src/core/transport/chttp2/writing.c @@ -32,10 +32,13 @@ */ #include "src/core/transport/chttp2/internal.h" -#include "src/core/transport/chttp2/http2_errors.h" + +#include #include +#include "src/core/transport/chttp2/http2_errors.h" + static void finalize_outbuf(grpc_chttp2_transport_writing *transport_writing); int grpc_chttp2_unlocking_check_writes( @@ -78,12 +81,13 @@ int grpc_chttp2_unlocking_check_writes( stream_writing->send_closed = GRPC_DONT_SEND_CLOSED; if (stream_global->outgoing_sopb) { - window_delta = - grpc_chttp2_preencode(stream_global->outgoing_sopb->ops, - &stream_global->outgoing_sopb->nops, - GPR_MIN(transport_global->outgoing_window, - stream_global->outgoing_window), - &stream_writing->sopb); + window_delta = grpc_chttp2_preencode( + stream_global->outgoing_sopb->ops, + &stream_global->outgoing_sopb->nops, + (gpr_uint32)GPR_MIN(GPR_MIN(transport_global->outgoing_window, + stream_global->outgoing_window), + GPR_UINT32_MAX), + &stream_writing->sopb); GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT( "write", transport_global, outgoing_window, -(gpr_int64)window_delta); GRPC_CHTTP2_FLOWCTL_TRACE_STREAM("write", transport_global, stream_global, diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c index c1a3c0436f2..c80330527e5 100644 --- a/src/core/transport/chttp2_transport.c +++ b/src/core/transport/chttp2_transport.c @@ -692,7 +692,8 @@ static void perform_stream_op_locked( op->max_recv_bytes - stream_global->max_recv_bytes); stream_global->unannounced_incoming_window += op->max_recv_bytes - stream_global->max_recv_bytes; - stream_global->max_recv_bytes = op->max_recv_bytes; + stream_global->max_recv_bytes = + (gpr_uint32)(GPR_MIN(op->max_recv_bytes, GPR_UINT32_MAX)); } grpc_chttp2_incoming_metadata_live_op_buffer_end( &stream_global->outstanding_metadata); @@ -761,7 +762,7 @@ static void perform_transport_op(grpc_transport *gt, grpc_transport_op *op) { t->global.sent_goaway = 1; grpc_chttp2_goaway_append( t->global.last_incoming_stream_id, - grpc_chttp2_grpc_status_to_http2_error(op->goaway_status), + (gpr_uint32)grpc_chttp2_grpc_status_to_http2_error(op->goaway_status), gpr_slice_ref(*op->goaway_message), &t->global.qbuf); close_transport = !grpc_chttp2_has_streams(t); } @@ -829,8 +830,9 @@ static void remove_stream(grpc_chttp2_transport *t, gpr_uint32 id) { new_stream_count = grpc_chttp2_stream_map_size(&t->parsing_stream_map) + grpc_chttp2_stream_map_size(&t->new_stream_map); + GPR_ASSERT(new_stream_count <= GPR_UINT32_MAX); if (new_stream_count != t->global.concurrent_stream_count) { - t->global.concurrent_stream_count = new_stream_count; + t->global.concurrent_stream_count = (gpr_uint32)new_stream_count; maybe_start_some_streams(&t->global); } } @@ -943,7 +945,8 @@ static void cancel_from_api(grpc_chttp2_transport_global *transport_global, gpr_slice_buffer_add( &transport_global->qbuf, grpc_chttp2_rst_stream_create( - stream_global->id, grpc_chttp2_grpc_status_to_http2_error(status))); + stream_global->id, + (gpr_uint32)grpc_chttp2_grpc_status_to_http2_error(status))); } grpc_chttp2_list_add_read_write_state_changed(transport_global, stream_global); @@ -989,11 +992,11 @@ static void close_from_api(grpc_chttp2_transport_global *transport_global, *p++ = 's'; if (status < 10) { *p++ = 1; - *p++ = '0' + status; + *p++ = (gpr_uint8)('0' + status); } else { *p++ = 2; - *p++ = '0' + (status / 10); - *p++ = '0' + (status % 10); + *p++ = (gpr_uint8)('0' + (status / 10)); + *p++ = (gpr_uint8)('0' + (status % 10)); } GPR_ASSERT(p == GPR_SLICE_END_PTR(status_hdr)); len += GPR_SLICE_LENGTH(status_hdr); @@ -1121,7 +1124,7 @@ static int recv_data_loop(grpc_chttp2_transport *t, int *success) { grpc_chttp2_stream_map_move_into(&t->new_stream_map, &t->parsing_stream_map); t->global.concurrent_stream_count = - grpc_chttp2_stream_map_size(&t->parsing_stream_map); + (gpr_uint32)grpc_chttp2_stream_map_size(&t->parsing_stream_map); if (t->parsing.initial_window_update != 0) { grpc_chttp2_stream_map_for_each(&t->parsing_stream_map, update_global_window, t); diff --git a/src/core/transport/transport.h b/src/core/transport/transport.h index 92c1f38c5ea..6e1ec2f64cd 100644 --- a/src/core/transport/transport.h +++ b/src/core/transport/transport.h @@ -75,7 +75,7 @@ typedef struct grpc_transport_stream_op { /** The number of bytes this peer is currently prepared to receive. These bytes will be eventually used to replenish per-stream flow control windows. */ - gpr_uint32 max_recv_bytes; + size_t max_recv_bytes; grpc_iomgr_closure *on_done_recv; grpc_pollset *bind_pollset; diff --git a/src/core/tsi/fake_transport_security.c b/src/core/tsi/fake_transport_security.c index a813c302213..b1a975155a7 100644 --- a/src/core/tsi/fake_transport_security.c +++ b/src/core/tsi/fake_transport_security.c @@ -100,7 +100,7 @@ static const char* tsi_fake_handshake_message_to_string(int msg) { static tsi_result tsi_fake_handshake_message_from_string( const char* msg_string, tsi_fake_handshake_message* msg) { - int i; + tsi_fake_handshake_message i; for (i = 0; i < TSI_FAKE_HANDSHAKE_MESSAGE_MAX; i++) { if (strncmp(msg_string, tsi_fake_handshake_message_strings[i], strlen(tsi_fake_handshake_message_strings[i])) == 0) { @@ -219,7 +219,7 @@ static tsi_result bytes_to_frame(unsigned char* bytes, size_t bytes_size, frame->offset = 0; frame->size = bytes_size + TSI_FAKE_FRAME_HEADER_SIZE; if (!tsi_fake_frame_ensure_size(frame)) return TSI_OUT_OF_RESOURCES; - store32_little_endian(frame->size, frame->data); + store32_little_endian((gpr_uint32)frame->size, frame->data); memcpy(frame->data + TSI_FAKE_FRAME_HEADER_SIZE, bytes, bytes_size); tsi_fake_frame_reset(frame, 1 /* needs draining */); return TSI_OK; @@ -266,7 +266,7 @@ static tsi_result fake_protector_protect(tsi_frame_protector* self, if (frame->size == 0) { /* New frame, create a header. */ size_t written_in_frame_size = 0; - store32_little_endian(impl->max_frame_size, frame_header); + store32_little_endian((gpr_uint32)impl->max_frame_size, frame_header); written_in_frame_size = TSI_FAKE_FRAME_HEADER_SIZE; result = fill_frame_from_bytes(frame_header, &written_in_frame_size, frame); if (result != TSI_INCOMPLETE_DATA) { @@ -303,7 +303,8 @@ static tsi_result fake_protector_protect_flush( frame->size = frame->offset; frame->offset = 0; frame->needs_draining = 1; - store32_little_endian(frame->size, frame->data); /* Overwrite header. */ + store32_little_endian((gpr_uint32)frame->size, + frame->data); /* Overwrite header. */ } result = drain_frame_to_bytes(protected_output_frames, protected_output_frames_size, frame); diff --git a/src/core/tsi/ssl_transport_security.c b/src/core/tsi/ssl_transport_security.c index 6add4928658..99ce7ecadf6 100644 --- a/src/core/tsi/ssl_transport_security.c +++ b/src/core/tsi/ssl_transport_security.c @@ -291,7 +291,7 @@ static tsi_result add_subject_alt_names_properties_to_peer( for (i = 0; i < subject_alt_name_count; i++) { GENERAL_NAME* subject_alt_name = - sk_GENERAL_NAME_value(subject_alt_names, i); + sk_GENERAL_NAME_value(subject_alt_names, (int)i); /* Filter out the non-dns entries names. */ if (subject_alt_name->type == GEN_DNS) { unsigned char* dns_name = NULL; @@ -366,7 +366,10 @@ static void log_ssl_error_stack(void) { /* Performs an SSL_read and handle errors. */ static tsi_result do_ssl_read(SSL* ssl, unsigned char* unprotected_bytes, size_t* unprotected_bytes_size) { - int read_from_ssl = SSL_read(ssl, unprotected_bytes, *unprotected_bytes_size); + int read_from_ssl; + GPR_ASSERT(*unprotected_bytes_size <= INT_MAX); + read_from_ssl = + SSL_read(ssl, unprotected_bytes, (int)*unprotected_bytes_size); if (read_from_ssl == 0) { gpr_log(GPR_ERROR, "SSL_read returned 0 unexpectedly."); return TSI_INTERNAL_ERROR; @@ -400,8 +403,10 @@ static tsi_result do_ssl_read(SSL* ssl, unsigned char* unprotected_bytes, /* Performs an SSL_write and handle errors. */ static tsi_result do_ssl_write(SSL* ssl, unsigned char* unprotected_bytes, size_t unprotected_bytes_size) { - int ssl_write_result = - SSL_write(ssl, unprotected_bytes, unprotected_bytes_size); + int ssl_write_result; + GPR_ASSERT(unprotected_bytes_size <= INT_MAX); + ssl_write_result = + SSL_write(ssl, unprotected_bytes, (int)unprotected_bytes_size); if (ssl_write_result < 0) { ssl_write_result = SSL_get_error(ssl, ssl_write_result); if (ssl_write_result == SSL_ERROR_WANT_READ) { @@ -423,7 +428,9 @@ static tsi_result ssl_ctx_use_certificate_chain( size_t pem_cert_chain_size) { tsi_result result = TSI_OK; X509* certificate = NULL; - BIO* pem = BIO_new_mem_buf((void*)pem_cert_chain, pem_cert_chain_size); + BIO* pem; + GPR_ASSERT(pem_cert_chain_size <= INT_MAX); + pem = BIO_new_mem_buf((void*)pem_cert_chain, (int)pem_cert_chain_size); if (pem == NULL) return TSI_OUT_OF_RESOURCES; do { @@ -464,7 +471,9 @@ static tsi_result ssl_ctx_use_private_key(SSL_CTX* context, size_t pem_key_size) { tsi_result result = TSI_OK; EVP_PKEY* private_key = NULL; - BIO* pem = BIO_new_mem_buf((void*)pem_key, pem_key_size); + BIO* pem; + GPR_ASSERT(pem_key_size <= INT_MAX); + pem = BIO_new_mem_buf((void*)pem_key, (int)pem_key_size); if (pem == NULL) return TSI_OUT_OF_RESOURCES; do { private_key = PEM_read_bio_PrivateKey(pem, NULL, NULL, ""); @@ -491,8 +500,11 @@ static tsi_result ssl_ctx_load_verification_certs( size_t num_roots = 0; X509* root = NULL; X509_NAME* root_name = NULL; - BIO* pem = BIO_new_mem_buf((void*)pem_roots, pem_roots_size); - X509_STORE* root_store = SSL_CTX_get_cert_store(context); + BIO* pem; + X509_STORE* root_store; + GPR_ASSERT(pem_roots_size <= INT_MAX); + pem = BIO_new_mem_buf((void*)pem_roots, (int)pem_roots_size); + root_store = SSL_CTX_get_cert_store(context); if (root_store == NULL) return TSI_INVALID_ARGUMENT; if (pem == NULL) return TSI_OUT_OF_RESOURCES; if (root_names != NULL) { @@ -592,7 +604,9 @@ static tsi_result extract_x509_subject_names_from_pem_cert( const unsigned char* pem_cert, size_t pem_cert_size, tsi_peer* peer) { tsi_result result = TSI_OK; X509* cert = NULL; - BIO* pem = BIO_new_mem_buf((void*)pem_cert, pem_cert_size); + BIO* pem; + GPR_ASSERT(pem_cert_size <= INT_MAX); + pem = BIO_new_mem_buf((void*)pem_cert, (int)pem_cert_size); if (pem == NULL) return TSI_OUT_OF_RESOURCES; cert = PEM_read_bio_X509(pem, NULL, NULL, ""); @@ -657,8 +671,9 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self, int pending_in_ssl = BIO_pending(impl->from_ssl); if (pending_in_ssl > 0) { *unprotected_bytes_size = 0; + GPR_ASSERT(*protected_output_frames_size <= INT_MAX); read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames, - *protected_output_frames_size); + (int)*protected_output_frames_size); if (read_from_ssl < 0) { gpr_log(GPR_ERROR, "Could not read from BIO even though some data is pending"); @@ -684,8 +699,9 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self, result = do_ssl_write(impl->ssl, impl->buffer, impl->buffer_size); if (result != TSI_OK) return result; + GPR_ASSERT(*protected_output_frames_size <= INT_MAX); read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames, - *protected_output_frames_size); + (int)*protected_output_frames_size); if (read_from_ssl < 0) { gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); return TSI_INTERNAL_ERROR; @@ -715,8 +731,9 @@ static tsi_result ssl_protector_protect_flush( *still_pending_size = (size_t)pending; if (*still_pending_size == 0) return TSI_OK; + GPR_ASSERT(*protected_output_frames_size <= INT_MAX); read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames, - *protected_output_frames_size); + (int)*protected_output_frames_size); if (read_from_ssl <= 0) { gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); return TSI_INTERNAL_ERROR; @@ -751,8 +768,9 @@ static tsi_result ssl_protector_unprotect( *unprotected_bytes_size = output_bytes_size - output_bytes_offset; /* Then, try to write some data to ssl. */ + GPR_ASSERT(*protected_frames_bytes_size <= INT_MAX); written_into_ssl = BIO_write(impl->into_ssl, protected_frames_bytes, - *protected_frames_bytes_size); + (int)*protected_frames_bytes_size); if (written_into_ssl < 0) { gpr_log(GPR_ERROR, "Sending protected frame to ssl failed with %d", written_into_ssl); @@ -792,7 +810,8 @@ static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, *bytes_size > INT_MAX) { return TSI_INVALID_ARGUMENT; } - bytes_read_from_ssl = BIO_read(impl->from_ssl, bytes, *bytes_size); + GPR_ASSERT(*bytes_size <= INT_MAX); + bytes_read_from_ssl = BIO_read(impl->from_ssl, bytes, (int)*bytes_size); if (bytes_read_from_ssl < 0) { *bytes_size = 0; if (!BIO_should_retry(impl->from_ssl)) { @@ -822,7 +841,9 @@ static tsi_result ssl_handshaker_process_bytes_from_peer( if (bytes == NULL || bytes_size == 0 || *bytes_size > INT_MAX) { return TSI_INVALID_ARGUMENT; } - bytes_written_into_ssl_size = BIO_write(impl->into_ssl, bytes, *bytes_size); + GPR_ASSERT(*bytes_size <= INT_MAX); + bytes_written_into_ssl_size = + BIO_write(impl->into_ssl, bytes, (int)*bytes_size); if (bytes_written_into_ssl_size < 0) { gpr_log(GPR_ERROR, "Could not write to memory BIO."); impl->result = TSI_INTERNAL_ERROR; @@ -1044,9 +1065,9 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client, static int select_protocol_list(const unsigned char** out, unsigned char* outlen, const unsigned char* client_list, - unsigned int client_list_len, + size_t client_list_len, const unsigned char* server_list, - unsigned int server_list_len) { + size_t server_list_len) { const unsigned char* client_current = client_list; while ((unsigned int)(client_current - client_list) < client_list_len) { unsigned char client_current_len = *(client_current++); @@ -1219,7 +1240,8 @@ static int server_handshaker_factory_npn_advertised_callback( tsi_ssl_server_handshaker_factory* factory = (tsi_ssl_server_handshaker_factory*)arg; *out = factory->alpn_protocol_list; - *outlen = factory->alpn_protocol_list_length; + GPR_ASSERT(factory->alpn_protocol_list_length <= UINT_MAX); + *outlen = (unsigned int)factory->alpn_protocol_list_length; return SSL_TLSEXT_ERR_OK; } @@ -1277,8 +1299,10 @@ tsi_result tsi_create_ssl_client_handshaker_factory( break; } #if TSI_OPENSSL_ALPN_SUPPORT - if (SSL_CTX_set_alpn_protos(ssl_context, impl->alpn_protocol_list, - impl->alpn_protocol_list_length)) { + GPR_ASSERT(impl->alpn_protocol_list_length < UINT_MAX); + if (SSL_CTX_set_alpn_protos( + ssl_context, impl->alpn_protocol_list, + (unsigned int)impl->alpn_protocol_list_length)) { gpr_log(GPR_ERROR, "Could not set alpn protocol list to context."); result = TSI_INVALID_ARGUMENT; break; diff --git a/templates/Makefile.template b/templates/Makefile.template index 79640180f68..d6bcb54bac4 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -247,6 +247,10 @@ CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false) + # Detect if -Wshorten-64-to-32 is a thing + SHORTEN_64_TO_32_CHECK_CMD = $(CC) -Wshorten-64-to-32 test/build/empty.c + HAS_SHORTEN_64_TO_32 = $(shell $(SHORTEN_64_TO_32_CHECK_CMD) 2> /dev/null && echo true || echo false) + # The HOST compiler settings are used to compile the protoc plugins. # In most cases, you won't have to change anything, but if you are # cross-compiling, you can override these variables from GNU make's @@ -262,6 +266,9 @@ endif CFLAGS += -std=c89 -pedantic -Wsign-conversion + ifeq ($(HAS_SHORTEN_64_TO_32),true) + CFLAGS += -Wshorten-64-to-32 + endif ifeq ($(HAS_CXX11),true) CXXFLAGS += -std=c++11 else diff --git a/test/build/empty.c b/test/build/empty.c new file mode 100644 index 00000000000..58e4698aee2 --- /dev/null +++ b/test/build/empty.c @@ -0,0 +1,34 @@ +/* + * + * 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. + * + */ + +int main(void) {} diff --git a/test/core/compression/message_compress_test.c b/test/core/compression/message_compress_test.c index 495841c79f5..98da6a1eaab 100644 --- a/test/core/compression/message_compress_test.c +++ b/test/core/compression/message_compress_test.c @@ -149,7 +149,7 @@ static gpr_slice create_test_value(test_value id) { static void test_bad_data(void) { gpr_slice_buffer input; gpr_slice_buffer output; - int i; + grpc_compression_algorithm i; gpr_slice_buffer_init(&input); gpr_slice_buffer_init(&output); diff --git a/test/core/fling/server.c b/test/core/fling/server.c index 64f95730848..5aace03520b 100644 --- a/test/core/fling/server.c +++ b/test/core/fling/server.c @@ -197,7 +197,7 @@ int main(int argc, char **argv) { grpc_test_init(1, fake_argv); grpc_init(); - srand(clock()); + srand((unsigned)clock()); cl = gpr_cmdline_create("fling server"); gpr_cmdline_add_string(cl, "bind", "Bind host:port", &addr); diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index 8bba87d61fc..af66ef0997f 100644 --- a/test/core/iomgr/fd_posix_test.c +++ b/test/core/iomgr/fd_posix_test.c @@ -419,7 +419,7 @@ static void test_grpc_fd_change(void) { int flags; int sv[2]; char data; - int result; + ssize_t result; grpc_iomgr_closure first_closure; grpc_iomgr_closure second_closure; diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c index c91752b9373..8c964246c79 100644 --- a/test/core/iomgr/udp_server_test.c +++ b/test/core/iomgr/udp_server_test.c @@ -53,7 +53,7 @@ static void on_connect(void *arg, grpc_endpoint *udp) {} static void on_read(int fd, grpc_udp_server_cb new_transport_cb, void *cb_arg) { char read_buffer[512]; - int byte_count; + ssize_t byte_count; gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); byte_count = recv(fd, read_buffer, sizeof(read_buffer), 0); diff --git a/test/core/support/murmur_hash_test.c b/test/core/support/murmur_hash_test.c index 1e5279f4629..1762486776f 100644 --- a/test/core/support/murmur_hash_test.c +++ b/test/core/support/murmur_hash_test.c @@ -57,8 +57,8 @@ static void verification_test(hash_func hash, gpr_uint32 expected) { the seed */ for (i = 0; i < 256; i++) { - key[i] = (uint8_t)i; - hashes[i] = hash(key, i, 256u - i); + key[i] = (gpr_uint8)i; + hashes[i] = hash(key, i, (gpr_uint32)(256u - i)); } /* Then hash the result array */ diff --git a/test/core/support/stack_lockfree_test.c b/test/core/support/stack_lockfree_test.c index 4a2a0532d8a..0f49e6fa52a 100644 --- a/test/core/support/stack_lockfree_test.c +++ b/test/core/support/stack_lockfree_test.c @@ -62,7 +62,7 @@ static void test_serial_sized(size_t size) { /* Now add repeatedly more items and check them */ for (i = 1; i < size; i *= 2) { for (j = 0; j <= i; j++) { - GPR_ASSERT(gpr_stack_lockfree_push(stack, j) == (j == 0)); + GPR_ASSERT(gpr_stack_lockfree_push(stack, (int)j) == (j == 0)); } for (j = 0; j <= i; j++) { GPR_ASSERT(gpr_stack_lockfree_pop(stack) == (int)(i - j)); @@ -118,7 +118,7 @@ static void test_mt_sized(size_t size, int nth) { stack = gpr_stack_lockfree_create(size); for (i = 0; i < nth; i++) { args[i].stack = stack; - args[i].stack_size = size; + args[i].stack_size = (int)size; args[i].nthreads = nth; args[i].rank = i; args[i].sum = 0; @@ -137,7 +137,8 @@ static void test_mt_sized(size_t size, int nth) { } static void test_mt() { - size_t size, nth; + size_t size; + int nth; for (nth = 1; nth < MAX_THREADS; nth++) { for (size = 128; size < MAX_STACK_SIZE; size *= 2) { test_mt_sized(size, nth); diff --git a/test/core/transport/chttp2/hpack_table_test.c b/test/core/transport/chttp2/hpack_table_test.c index ec0a569371a..aa3e273a6c9 100644 --- a/test/core/transport/chttp2/hpack_table_test.c +++ b/test/core/transport/chttp2/hpack_table_test.c @@ -49,7 +49,7 @@ static void assert_str(const grpc_chttp2_hptbl *tbl, grpc_mdstr *mdstr, GPR_ASSERT(gpr_slice_str_cmp(mdstr->slice, str) == 0); } -static void assert_index(const grpc_chttp2_hptbl *tbl, size_t idx, +static void assert_index(const grpc_chttp2_hptbl *tbl, gpr_uint32 idx, const char *key, const char *value) { grpc_mdelem *md = grpc_chttp2_hptbl_lookup(tbl, idx); assert_str(tbl, md->key, key); diff --git a/test/core/transport/chttp2/stream_encoder_test.c b/test/core/transport/chttp2/stream_encoder_test.c index 4bb503b4e9f..a723b90084d 100644 --- a/test/core/transport/chttp2/stream_encoder_test.c +++ b/test/core/transport/chttp2/stream_encoder_test.c @@ -75,8 +75,8 @@ static void verify_sopb(size_t window_available, int eof, gpr_slice_buffer_init(&output); grpc_sopb_init(&encops); GPR_ASSERT(expect_window_used == - grpc_chttp2_preencode(g_sopb.ops, &g_sopb.nops, window_available, - &encops)); + grpc_chttp2_preencode(g_sopb.ops, &g_sopb.nops, + (gpr_uint32)window_available, &encops)); grpc_chttp2_encode(encops.ops, encops.nops, eof, 0xdeadbeef, &g_compressor, &output); encops.nops = 0; diff --git a/test/core/transport/chttp2/stream_map_test.c b/test/core/transport/chttp2/stream_map_test.c index 72aaafd18d7..81fb80f84f1 100644 --- a/test/core/transport/chttp2/stream_map_test.c +++ b/test/core/transport/chttp2/stream_map_test.c @@ -82,9 +82,9 @@ static void test_double_deletion(void) { } /* test add & lookup */ -static void test_basic_add_find(size_t n) { +static void test_basic_add_find(gpr_uint32 n) { grpc_chttp2_stream_map map; - size_t i; + gpr_uint32 i; size_t got; LOG_TEST("test_basic_add_find"); @@ -107,15 +107,15 @@ static void test_basic_add_find(size_t n) { /* verify that for_each gets the right values during test_delete_evens_XXX */ static void verify_for_each(void *user_data, gpr_uint32 stream_id, void *ptr) { - size_t *for_each_check = user_data; + gpr_uint32 *for_each_check = user_data; GPR_ASSERT(ptr); GPR_ASSERT(*for_each_check == stream_id); *for_each_check += 2; } -static void check_delete_evens(grpc_chttp2_stream_map *map, size_t n) { - size_t for_each_check = 1; - size_t i; +static void check_delete_evens(grpc_chttp2_stream_map *map, gpr_uint32 n) { + gpr_uint32 for_each_check = 1; + gpr_uint32 i; size_t got; GPR_ASSERT(NULL == grpc_chttp2_stream_map_find(map, 0)); @@ -139,9 +139,9 @@ static void check_delete_evens(grpc_chttp2_stream_map *map, size_t n) { /* add a bunch of keys, delete the even ones, and make sure the map is consistent */ -static void test_delete_evens_sweep(size_t n) { +static void test_delete_evens_sweep(gpr_uint32 n) { grpc_chttp2_stream_map map; - size_t i; + gpr_uint32 i; LOG_TEST("test_delete_evens_sweep"); gpr_log(GPR_INFO, "n = %d", n); @@ -152,7 +152,8 @@ static void test_delete_evens_sweep(size_t n) { } for (i = 1; i <= n; i++) { if ((i & 1) == 0) { - GPR_ASSERT((void *)i == grpc_chttp2_stream_map_delete(&map, i)); + GPR_ASSERT((void *)(gpr_uintptr)i == + grpc_chttp2_stream_map_delete(&map, i)); } } check_delete_evens(&map, n); @@ -161,9 +162,9 @@ static void test_delete_evens_sweep(size_t n) { /* add a bunch of keys, delete the even ones immediately, and make sure the map is consistent */ -static void test_delete_evens_incremental(size_t n) { +static void test_delete_evens_incremental(gpr_uint32 n) { grpc_chttp2_stream_map map; - size_t i; + gpr_uint32 i; LOG_TEST("test_delete_evens_incremental"); gpr_log(GPR_INFO, "n = %d", n); @@ -181,10 +182,10 @@ static void test_delete_evens_incremental(size_t n) { /* add a bunch of keys, delete old ones after some time, ensure the backing array does not grow */ -static void test_periodic_compaction(size_t n) { +static void test_periodic_compaction(gpr_uint32 n) { grpc_chttp2_stream_map map; - size_t i; - size_t del; + gpr_uint32 i; + gpr_uint32 del; LOG_TEST("test_periodic_compaction"); gpr_log(GPR_INFO, "n = %d", n); @@ -192,10 +193,11 @@ static void test_periodic_compaction(size_t n) { grpc_chttp2_stream_map_init(&map, 16); GPR_ASSERT(map.capacity == 16); for (i = 1; i <= n; i++) { - grpc_chttp2_stream_map_add(&map, i, (void *)i); + grpc_chttp2_stream_map_add(&map, i, (void *)(gpr_uintptr)i); if (i > 8) { del = i - 8; - GPR_ASSERT((void *)del == grpc_chttp2_stream_map_delete(&map, del)); + GPR_ASSERT((void *)(gpr_uintptr)del == + grpc_chttp2_stream_map_delete(&map, del)); } } GPR_ASSERT(map.capacity == 16); @@ -203,9 +205,9 @@ static void test_periodic_compaction(size_t n) { } int main(int argc, char **argv) { - size_t n = 1; - size_t prev = 1; - size_t tmp; + gpr_uint32 n = 1; + gpr_uint32 prev = 1; + gpr_uint32 tmp; grpc_test_init(argc, argv); diff --git a/tools/codegen/core/gen_hpack_tables.c b/tools/codegen/core/gen_hpack_tables.c index 555f1e71c56..dec0e2f3fef 100644 --- a/tools/codegen/core/gen_hpack_tables.c +++ b/tools/codegen/core/gen_hpack_tables.c @@ -127,7 +127,9 @@ static void generate_first_byte_lut(void) { /* represents a set of symbols as an array of booleans indicating inclusion */ typedef struct { char included[GRPC_CHTTP2_NUM_HUFFSYMS]; } symset; /* represents a lookup table indexed by a nibble */ -typedef struct { int values[16]; } nibblelut; +typedef struct { unsigned values[16]; } nibblelut; + +#define NOT_SET (~(unsigned)0) /* returns a symset that includes all possible symbols */ static symset symset_all(void) { @@ -148,7 +150,7 @@ static nibblelut nibblelut_empty(void) { nibblelut x; int i; for (i = 0; i < 16; i++) { - x.values[i] = -1; + x.values[i] = NOT_SET; } return x; } @@ -168,7 +170,7 @@ static int nsyms(symset s) { /* global table of discovered huffman decoding states */ static struct { /* the bit offset that this state starts at */ - int bitofs; + unsigned bitofs; /* the set of symbols that this state started with */ symset syms; @@ -177,13 +179,13 @@ static struct { /* lookup table for what to emit */ nibblelut emit; } huffstates[MAXHUFFSTATES]; -static int nhuffstates = 0; +static unsigned nhuffstates = 0; /* given a number of decoded bits and a set of symbols that are live, return the index into the decoder table for this state. set isnew to 1 if this state was previously undiscovered */ -static int state_index(int bitofs, symset syms, int *isnew) { - int i; +static unsigned state_index(unsigned bitofs, symset syms, unsigned *isnew) { + unsigned i; for (i = 0; i < nhuffstates; i++) { if (huffstates[i].bitofs != bitofs) continue; if (0 != memcmp(huffstates[i].syms.included, syms.included, @@ -211,24 +213,24 @@ static int state_index(int bitofs, symset syms, int *isnew) { emit - the symbol to emit on this nibble (or -1 if no symbol has been found) syms - the set of symbols that could be matched */ -static void build_dec_tbl(int state, int nibble, int nibbits, unsigned bitofs, - int emit, symset syms) { - int i; +static void build_dec_tbl(unsigned state, unsigned nibble, int nibbits, + unsigned bitofs, unsigned emit, symset syms) { + unsigned i; unsigned bit; /* If we have four bits in the nibble we're looking at, then we can fill in a slot in the lookup tables. */ if (nibbits == 4) { - int isnew; + unsigned isnew; /* Find the state that we are in: this may be a new state, in which case we recurse to fill it in, or we may have already seen this state, in which case the recursion terminates */ - int st = state_index(bitofs, syms, &isnew); - GPR_ASSERT(huffstates[state].next.values[nibble] == -1); + unsigned st = state_index(bitofs, syms, &isnew); + GPR_ASSERT(huffstates[state].next.values[nibble] == NOT_SET); huffstates[state].next.values[nibble] = st; huffstates[state].emit.values[nibble] = emit; if (isnew) { - build_dec_tbl(st, 0, 0, bitofs, -1, syms); + build_dec_tbl(st, 0, 0, bitofs, NOT_SET, syms); } return; } @@ -290,8 +292,9 @@ static void dump_ctbl(const char *name) { } static void generate_huff_tables(void) { - int i; - build_dec_tbl(state_index(0, symset_all(), &i), 0, 0, 0, -1, symset_all()); + unsigned i; + build_dec_tbl(state_index(0, symset_all(), &i), 0, 0, 0, NOT_SET, + symset_all()); nctbl = 0; printf("static const gpr_uint8 next_tbl[%d] = {", nhuffstates); From 2ed498151da3b68107312b6397dbff4b4f60e475 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Sep 2015 14:54:26 -0700 Subject: [PATCH 28/32] Fix typo --- src/core/transport/chttp2/parsing.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/transport/chttp2/parsing.c b/src/core/transport/chttp2/parsing.c index a29987a05ad..5d3dfe2286c 100644 --- a/src/core/transport/chttp2/parsing.c +++ b/src/core/transport/chttp2/parsing.c @@ -194,8 +194,9 @@ void grpc_chttp2_publish_reads( GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( "parsed", transport_parsing, stream_parsing, outgoing_window_update, -(gpr_int64)stream_parsing->outgoing_window_update); + GPR_ASSERT(stream_parsing->outgoing_window_update <= GPR_UINT32_MAX); stream_global->outgoing_window += - (gpr_uint32)stream_global->outgoing_window; + (gpr_uint32)stream_parsing->outgoing_window_update; stream_parsing->outgoing_window_update = 0; is_zero = stream_global->outgoing_window <= 0; if (was_zero && !is_zero) { From 6a6b36c50300bcc33d761598591c4d1bd4f1f6aa Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Sep 2015 16:00:22 -0700 Subject: [PATCH 29/32] Enable -Wconversion --- Makefile | 9 +--- src/core/channel/compress_filter.c | 5 +- .../resolvers/sockaddr_resolver.c | 4 +- src/core/iomgr/alarm.c | 6 +-- .../pollset_multipoller_with_poll_posix.c | 4 +- src/core/iomgr/pollset_posix.c | 2 +- src/core/iomgr/sockaddr_utils.c | 12 +++-- src/core/surface/call.c | 11 +++-- src/core/transport/chttp2/bin_encoder.c | 23 +++++---- src/core/transport/chttp2/frame_data.c | 3 +- src/core/transport/chttp2/frame_goaway.c | 25 +++++----- src/core/transport/chttp2/frame_rst_stream.c | 16 +++--- src/core/transport/chttp2/frame_settings.c | 22 ++++----- .../transport/chttp2/frame_window_update.c | 16 +++--- src/core/transport/chttp2/hpack_parser.c | 18 ++++--- src/core/transport/chttp2/hpack_table.c | 31 +++++++----- src/core/transport/chttp2/internal.h | 4 +- src/core/transport/chttp2/parsing.c | 8 +-- src/core/transport/chttp2/stream_encoder.c | 49 ++++++++++--------- src/core/transport/chttp2/varint.h | 2 +- src/core/transport/chttp2_transport.c | 49 ++++++++++--------- src/core/transport/metadata.c | 4 +- templates/Makefile.template | 9 +--- test/core/fling/client.c | 2 +- test/core/iomgr/endpoint_tests.c | 6 +-- test/core/iomgr/fd_posix_test.c | 3 +- test/core/iomgr/tcp_posix_test.c | 10 ++-- test/core/iomgr/udp_server_test.c | 2 +- test/core/json/json_rewrite.c | 6 ++- test/core/json/json_rewrite_test.c | 3 +- test/core/support/slice_test.c | 6 +-- .../transport/chttp2/stream_encoder_test.c | 8 +-- test/core/util/parse_hexstring.c | 4 +- test/core/util/port_posix.c | 2 +- test/core/util/reconnect_server.c | 2 +- test/core/util/test_config.h | 18 ++++--- tools/codegen/core/gen_hpack_tables.c | 8 +-- .../core/gen_legal_metadata_characters.c | 2 +- 38 files changed, 216 insertions(+), 198 deletions(-) diff --git a/Makefile b/Makefile index 21f3011a6e2..b705129a7bd 100644 --- a/Makefile +++ b/Makefile @@ -231,10 +231,6 @@ endif CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false) -# Detect if -Wshorten-64-to-32 is a thing -SHORTEN_64_TO_32_CHECK_CMD = $(CC) -Wshorten-64-to-32 test/build/empty.c -HAS_SHORTEN_64_TO_32 = $(shell $(SHORTEN_64_TO_32_CHECK_CMD) 2> /dev/null && echo true || echo false) - # The HOST compiler settings are used to compile the protoc plugins. # In most cases, you won't have to change anything, but if you are # cross-compiling, you can override these variables from GNU make's @@ -249,10 +245,7 @@ ifdef EXTRA_DEFINES DEFINES += $(EXTRA_DEFINES) endif -CFLAGS += -std=c89 -pedantic -Wsign-conversion -ifeq ($(HAS_SHORTEN_64_TO_32),true) -CFLAGS += -Wshorten-64-to-32 -endif +CFLAGS += -std=c89 -pedantic -Wsign-conversion -Wconversion ifeq ($(HAS_CXX11),true) CXXFLAGS += -std=c++11 else diff --git a/src/core/channel/compress_filter.c b/src/core/channel/compress_filter.c index 8e06094257d..c47b91bc58e 100644 --- a/src/core/channel/compress_filter.c +++ b/src/core/channel/compress_filter.c @@ -230,7 +230,10 @@ static void process_send_ops(grpc_call_element *elem, GPR_ASSERT(calld->remaining_slice_bytes > 0); /* Increase input ref count, gpr_slice_buffer_add takes ownership. */ gpr_slice_buffer_add(&calld->slices, gpr_slice_ref(sop->data.slice)); - calld->remaining_slice_bytes -= GPR_SLICE_LENGTH(sop->data.slice); + GPR_ASSERT(GPR_SLICE_LENGTH(sop->data.slice) > + calld->remaining_slice_bytes); + calld->remaining_slice_bytes -= + (gpr_uint32)GPR_SLICE_LENGTH(sop->data.slice); if (calld->remaining_slice_bytes == 0) { did_compress = compress_send_sb(calld->compression_algorithm, &calld->slices); diff --git a/src/core/client_config/resolvers/sockaddr_resolver.c b/src/core/client_config/resolvers/sockaddr_resolver.c index 4a3c14545ad..85b1bf28498 100644 --- a/src/core/client_config/resolvers/sockaddr_resolver.c +++ b/src/core/client_config/resolvers/sockaddr_resolver.c @@ -218,7 +218,7 @@ static int parse_ipv4(grpc_uri *uri, struct sockaddr_storage *addr, gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port); goto done; } - in->sin_port = htons(port_num); + in->sin_port = htons((gpr_uint16)port_num); } else { gpr_log(GPR_ERROR, "no port given for ipv4 scheme"); goto done; @@ -259,7 +259,7 @@ static int parse_ipv6(grpc_uri *uri, struct sockaddr_storage *addr, gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port); goto done; } - in6->sin6_port = htons(port_num); + in6->sin6_port = htons((gpr_uint16)port_num); } else { gpr_log(GPR_ERROR, "no port given for ipv6 scheme"); goto done; diff --git a/src/core/iomgr/alarm.c b/src/core/iomgr/alarm.c index 515b96ffc12..7b67fe3b1d0 100644 --- a/src/core/iomgr/alarm.c +++ b/src/core/iomgr/alarm.c @@ -123,13 +123,13 @@ static size_t shard_idx(const grpc_alarm *info) { } static double ts_to_dbl(gpr_timespec ts) { - return ts.tv_sec + 1e-9 * ts.tv_nsec; + return (double)ts.tv_sec + 1e-9 * ts.tv_nsec; } static gpr_timespec dbl_to_ts(double d) { gpr_timespec ts; - ts.tv_sec = d; - ts.tv_nsec = 1e9 * (d - ts.tv_sec); + ts.tv_sec = (time_t)d; + ts.tv_nsec = (int)(1e9 * (d - (double)ts.tv_sec)); ts.clock_type = GPR_TIMESPAN; return ts; } diff --git a/src/core/iomgr/pollset_multipoller_with_poll_posix.c b/src/core/iomgr/pollset_multipoller_with_poll_posix.c index 30ee6e24db4..f1bc60ba4e9 100644 --- a/src/core/iomgr/pollset_multipoller_with_poll_posix.c +++ b/src/core/iomgr/pollset_multipoller_with_poll_posix.c @@ -140,8 +140,8 @@ static void multipoll_with_poll_pollset_maybe_work( gpr_mu_unlock(&pollset->mu); for (i = 1; i < pfd_count; i++) { - pfds[i].events = grpc_fd_begin_poll(watchers[i].fd, pollset, POLLIN, - POLLOUT, &watchers[i]); + pfds[i].events = (short)grpc_fd_begin_poll(watchers[i].fd, pollset, POLLIN, + POLLOUT, &watchers[i]); } r = grpc_poll_function(pfds, pfd_count, timeout); diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c index 93aa3ad662c..dec2f5490ff 100644 --- a/src/core/iomgr/pollset_posix.c +++ b/src/core/iomgr/pollset_posix.c @@ -443,7 +443,7 @@ static void basic_pollset_maybe_work(grpc_pollset *pollset, pfd[1].revents = 0; gpr_mu_unlock(&pollset->mu); pfd[1].events = - grpc_fd_begin_poll(fd, pollset, POLLIN, POLLOUT, &fd_watcher); + (short)grpc_fd_begin_poll(fd, pollset, POLLIN, POLLOUT, &fd_watcher); if (pfd[1].events != 0) { nfds++; } diff --git a/src/core/iomgr/sockaddr_utils.c b/src/core/iomgr/sockaddr_utils.c index efdc4803654..0e4bf245498 100644 --- a/src/core/iomgr/sockaddr_utils.c +++ b/src/core/iomgr/sockaddr_utils.c @@ -123,15 +123,17 @@ void grpc_sockaddr_make_wildcards(int port, struct sockaddr_in *wild4_out, } void grpc_sockaddr_make_wildcard4(int port, struct sockaddr_in *wild_out) { + GPR_ASSERT(port >= 0 && port < 65536); memset(wild_out, 0, sizeof(*wild_out)); wild_out->sin_family = AF_INET; - wild_out->sin_port = htons(port); + wild_out->sin_port = htons((gpr_uint16)port); } void grpc_sockaddr_make_wildcard6(int port, struct sockaddr_in6 *wild_out) { + GPR_ASSERT(port >= 0 && port < 65536); memset(wild_out, 0, sizeof(*wild_out)); wild_out->sin6_family = AF_INET6; - wild_out->sin6_port = htons(port); + wild_out->sin6_port = htons((gpr_uint16)port); } int grpc_sockaddr_to_string(char **out, const struct sockaddr *addr, @@ -215,10 +217,12 @@ int grpc_sockaddr_get_port(const struct sockaddr *addr) { int grpc_sockaddr_set_port(const struct sockaddr *addr, int port) { switch (addr->sa_family) { case AF_INET: - ((struct sockaddr_in *)addr)->sin_port = htons(port); + GPR_ASSERT(port >= 0 && port < 65536); + ((struct sockaddr_in *)addr)->sin_port = htons((gpr_uint16)port); return 1; case AF_INET6: - ((struct sockaddr_in6 *)addr)->sin6_port = htons(port); + GPR_ASSERT(port >= 0 && port < 65536); + ((struct sockaddr_in6 *)addr)->sin6_port = htons((gpr_uint16)port); return 1; default: gpr_log(GPR_ERROR, "Unknown socket family %d in grpc_sockaddr_set_port", diff --git a/src/core/surface/call.c b/src/core/surface/call.c index c96df77a98d..16a7d2ec358 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -421,7 +421,7 @@ static grpc_cq_completion *allocate_completion(grpc_call *call) { if (call->allocated_completions & (1u << i)) { continue; } - call->allocated_completions |= 1u << i; + call->allocated_completions |= (gpr_uint8)(1u << i); gpr_mu_unlock(&call->completion_mu); return &call->completions[i]; } @@ -432,7 +432,8 @@ static grpc_cq_completion *allocate_completion(grpc_call *call) { static void done_completion(void *call, grpc_cq_completion *completion) { grpc_call *c = call; gpr_mu_lock(&c->completion_mu); - c->allocated_completions &= ~(1u << (completion - c->completions)); + c->allocated_completions &= + (gpr_uint8) ~(1u << (completion - c->completions)); gpr_mu_unlock(&c->completion_mu); GRPC_CALL_INTERNAL_UNREF(c, "completion", 1); } @@ -743,7 +744,7 @@ static void finish_live_ioreq_op(grpc_call *call, grpc_ioreq_op op, size_t i; /* ioreq is live: we need to do something */ master = &call->masters[master_set]; - master->complete_mask |= 1u << op; + master->complete_mask |= (gpr_uint16)(1u << op); if (!success) { master->success = 0; } @@ -1214,7 +1215,7 @@ static grpc_call_error start_ioreq(grpc_call *call, const grpc_ioreq *reqs, grpc_ioreq_completion_func completion, void *user_data) { size_t i; - gpr_uint32 have_ops = 0; + gpr_uint16 have_ops = 0; grpc_ioreq_op op; reqinfo_master *master; grpc_ioreq_data data; @@ -1251,7 +1252,7 @@ static grpc_call_error start_ioreq(grpc_call *call, const grpc_ioreq *reqs, GRPC_MDSTR_REF(reqs[i].data.send_status.details)); } } - have_ops |= 1u << op; + have_ops |= (gpr_uint16)(1u << op); call->request_data[op] = data; call->request_flags[op] = reqs[i].flags; diff --git a/src/core/transport/chttp2/bin_encoder.c b/src/core/transport/chttp2/bin_encoder.c index b87d4de04b4..e21d8000832 100644 --- a/src/core/transport/chttp2/bin_encoder.c +++ b/src/core/transport/chttp2/bin_encoder.c @@ -128,12 +128,13 @@ gpr_slice grpc_chttp2_huffman_compress(gpr_slice input) { while (temp_length > 8) { temp_length -= 8; - *out++ = temp >> temp_length; + *out++ = (gpr_uint8)(temp >> temp_length); } } if (temp_length) { - *out++ = (temp << (8u - temp_length)) | (0xffu >> temp_length); + *out++ = (gpr_uint8)(temp << (8u - temp_length)) | + (gpr_uint8)(0xffu >> temp_length); } GPR_ASSERT(out == GPR_SLICE_END_PTR(output)); @@ -150,7 +151,7 @@ typedef struct { static void enc_flush_some(huff_out *out) { while (out->temp_length > 8) { out->temp_length -= 8; - *out->out++ = out->temp >> out->temp_length; + *out->out++ = (gpr_uint8)(out->temp >> out->temp_length); } } @@ -189,8 +190,9 @@ gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input) { /* encode full triplets */ for (i = 0; i < input_triplets; i++) { - enc_add2(&out, in[0] >> 2, ((in[0] & 0x3) << 4) | (in[1] >> 4)); - enc_add2(&out, ((in[1] & 0xf) << 2) | (in[2] >> 6), in[2] & 0x3f); + enc_add2(&out, in[0] >> 2, (gpr_uint8)((in[0] & 0x3) << 4) | (in[1] >> 4)); + enc_add2(&out, (gpr_uint8)((in[1] & 0xf) << 2) | (in[2] >> 6), + (gpr_uint8)(in[2] & 0x3f)); in += 3; } @@ -199,19 +201,20 @@ gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input) { case 0: break; case 1: - enc_add2(&out, in[0] >> 2, (in[0] & 0x3) << 4); + enc_add2(&out, in[0] >> 2, (gpr_uint8)((in[0] & 0x3) << 4)); in += 1; break; case 2: - enc_add2(&out, in[0] >> 2, ((in[0] & 0x3) << 4) | (in[1] >> 4)); - enc_add1(&out, (in[1] & 0xf) << 2); + enc_add2(&out, in[0] >> 2, + (gpr_uint8)((in[0] & 0x3) << 4) | (gpr_uint8)(in[1] >> 4)); + enc_add1(&out, (gpr_uint8)((in[1] & 0xf) << 2)); in += 2; break; } if (out.temp_length) { - *out.out++ = - (out.temp << (8u - out.temp_length)) | (0xffu >> out.temp_length); + *out.out++ = (gpr_uint8)(out.temp << (8u - out.temp_length)) | + (gpr_uint8)(0xffu >> out.temp_length); } GPR_ASSERT(out.out <= GPR_SLICE_END_PTR(output)); diff --git a/src/core/transport/chttp2/frame_data.c b/src/core/transport/chttp2/frame_data.c index 29d19b4e945..403358016d3 100644 --- a/src/core/transport/chttp2/frame_data.c +++ b/src/core/transport/chttp2/frame_data.c @@ -161,7 +161,8 @@ grpc_chttp2_parse_error grpc_chttp2_data_parser_parse( grpc_sopb_add_slice( &p->incoming_sopb, gpr_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg))); - p->frame_size -= (end - cur); + GPR_ASSERT(end - cur <= p->frame_size); + p->frame_size -= (gpr_uint32)(end - cur); return GRPC_CHTTP2_PARSE_OK; } } diff --git a/src/core/transport/chttp2/frame_goaway.c b/src/core/transport/chttp2/frame_goaway.c index 1a6d80da582..09d4da234c5 100644 --- a/src/core/transport/chttp2/frame_goaway.c +++ b/src/core/transport/chttp2/frame_goaway.c @@ -137,7 +137,8 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse( /* fallthrough */ case GRPC_CHTTP2_GOAWAY_DEBUG: memcpy(p->debug_data + p->debug_pos, cur, (size_t)(end - cur)); - p->debug_pos += end - cur; + GPR_ASSERT(end - cur < GPR_UINT32_MAX - p->debug_pos); + p->debug_pos += (gpr_uint32)(end - cur); p->state = GRPC_CHTTP2_GOAWAY_DEBUG; if (is_last) { transport_parsing->goaway_received = 1; @@ -165,9 +166,9 @@ void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code, frame_length = 4 + 4 + (gpr_uint32)GPR_SLICE_LENGTH(debug_data); /* frame header: length */ - *p++ = frame_length >> 16; - *p++ = frame_length >> 8; - *p++ = frame_length; + *p++ = (gpr_uint8)(frame_length >> 16); + *p++ = (gpr_uint8)(frame_length >> 8); + *p++ = (gpr_uint8)(frame_length); /* frame header: type */ *p++ = GRPC_CHTTP2_FRAME_GOAWAY; /* frame header: flags */ @@ -178,15 +179,15 @@ void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code, *p++ = 0; *p++ = 0; /* payload: last stream id */ - *p++ = last_stream_id >> 24; - *p++ = last_stream_id >> 16; - *p++ = last_stream_id >> 8; - *p++ = last_stream_id; + *p++ = (gpr_uint8)(last_stream_id >> 24); + *p++ = (gpr_uint8)(last_stream_id >> 16); + *p++ = (gpr_uint8)(last_stream_id >> 8); + *p++ = (gpr_uint8)(last_stream_id); /* payload: error code */ - *p++ = error_code >> 24; - *p++ = error_code >> 16; - *p++ = error_code >> 8; - *p++ = error_code; + *p++ = (gpr_uint8)(error_code >> 24); + *p++ = (gpr_uint8)(error_code >> 16); + *p++ = (gpr_uint8)(error_code >> 8); + *p++ = (gpr_uint8)(error_code); GPR_ASSERT(p == GPR_SLICE_END_PTR(header)); gpr_slice_buffer_add(slice_buffer, header); gpr_slice_buffer_add(slice_buffer, debug_data); diff --git a/src/core/transport/chttp2/frame_rst_stream.c b/src/core/transport/chttp2/frame_rst_stream.c index a878d936c1e..67da245239c 100644 --- a/src/core/transport/chttp2/frame_rst_stream.c +++ b/src/core/transport/chttp2/frame_rst_stream.c @@ -47,14 +47,14 @@ gpr_slice grpc_chttp2_rst_stream_create(gpr_uint32 id, gpr_uint32 code) { *p++ = 4; *p++ = GRPC_CHTTP2_FRAME_RST_STREAM; *p++ = 0; - *p++ = id >> 24; - *p++ = id >> 16; - *p++ = id >> 8; - *p++ = id; - *p++ = code >> 24; - *p++ = code >> 16; - *p++ = code >> 8; - *p++ = code; + *p++ = (gpr_uint8)(id >> 24); + *p++ = (gpr_uint8)(id >> 16); + *p++ = (gpr_uint8)(id >> 8); + *p++ = (gpr_uint8)(id); + *p++ = (gpr_uint8)(code >> 24); + *p++ = (gpr_uint8)(code >> 16); + *p++ = (gpr_uint8)(code >> 8); + *p++ = (gpr_uint8)(code); return slice; } diff --git a/src/core/transport/chttp2/frame_settings.c b/src/core/transport/chttp2/frame_settings.c index f70776bf4cb..54d3694a5c3 100644 --- a/src/core/transport/chttp2/frame_settings.c +++ b/src/core/transport/chttp2/frame_settings.c @@ -61,9 +61,9 @@ const grpc_chttp2_setting_parameters static gpr_uint8 *fill_header(gpr_uint8 *out, gpr_uint32 length, gpr_uint8 flags) { - *out++ = length >> 16; - *out++ = length >> 8; - *out++ = length; + *out++ = (gpr_uint8)(length >> 16); + *out++ = (gpr_uint8)(length >> 8); + *out++ = (gpr_uint8)(length); *out++ = GRPC_CHTTP2_FRAME_SETTINGS; *out++ = flags; *out++ = 0; @@ -90,12 +90,12 @@ gpr_slice grpc_chttp2_settings_create(gpr_uint32 *old, const gpr_uint32 *new, for (i = 0; i < count; i++) { if (new[i] != old[i] || (force_mask & (1u << i)) != 0) { GPR_ASSERT(i); - *p++ = i >> 8; - *p++ = i; - *p++ = new[i] >> 24; - *p++ = new[i] >> 16; - *p++ = new[i] >> 8; - *p++ = new[i]; + *p++ = (gpr_uint8)(i >> 8); + *p++ = (gpr_uint8)(i); + *p++ = (gpr_uint8)(new[i] >> 24); + *p++ = (gpr_uint8)(new[i] >> 16); + *p++ = (gpr_uint8)(new[i] >> 8); + *p++ = (gpr_uint8)(new[i]); old[i] = new[i]; } } @@ -162,7 +162,7 @@ grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse( } return GRPC_CHTTP2_PARSE_OK; } - parser->id = ((gpr_uint16)*cur) << 8; + parser->id = (gpr_uint16)(((gpr_uint16)*cur) << 8); cur++; /* fallthrough */ case GRPC_CHTTP2_SPS_ID1: @@ -170,7 +170,7 @@ grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse( parser->state = GRPC_CHTTP2_SPS_ID1; return GRPC_CHTTP2_PARSE_OK; } - parser->id |= (*cur); + parser->id = (gpr_uint16)(parser->id | (*cur)); cur++; /* fallthrough */ case GRPC_CHTTP2_SPS_VAL0: diff --git a/src/core/transport/chttp2/frame_window_update.c b/src/core/transport/chttp2/frame_window_update.c index d624298ad2a..ea13969e8cc 100644 --- a/src/core/transport/chttp2/frame_window_update.c +++ b/src/core/transport/chttp2/frame_window_update.c @@ -48,14 +48,14 @@ gpr_slice grpc_chttp2_window_update_create(gpr_uint32 id, *p++ = 4; *p++ = GRPC_CHTTP2_FRAME_WINDOW_UPDATE; *p++ = 0; - *p++ = id >> 24; - *p++ = id >> 16; - *p++ = id >> 8; - *p++ = id; - *p++ = window_update >> 24; - *p++ = window_update >> 16; - *p++ = window_update >> 8; - *p++ = window_update; + *p++ = (gpr_uint8)(id >> 24); + *p++ = (gpr_uint8)(id >> 16); + *p++ = (gpr_uint8)(id >> 8); + *p++ = (gpr_uint8)(id); + *p++ = (gpr_uint8)(window_update >> 24); + *p++ = (gpr_uint8)(window_update >> 16); + *p++ = (gpr_uint8)(window_update >> 8); + *p++ = (gpr_uint8)(window_update); return slice; } diff --git a/src/core/transport/chttp2/hpack_parser.c b/src/core/transport/chttp2/hpack_parser.c index 93a452f1fd2..9c40e8a4e60 100644 --- a/src/core/transport/chttp2/hpack_parser.c +++ b/src/core/transport/chttp2/hpack_parser.c @@ -1090,7 +1090,8 @@ static void append_bytes(grpc_chttp2_hpack_parser_string *str, str->str = gpr_realloc(str->str, str->capacity); } memcpy(str->str + str->length, data, length); - str->length += length; + GPR_ASSERT(length <= GPR_UINT32_MAX - str->length); + str->length += (gpr_uint32)length; } static int append_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, @@ -1158,9 +1159,9 @@ static int append_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, goto b64_byte3; p->base64_buffer |= bits; bits = p->base64_buffer; - decoded[0] = bits >> 16; - decoded[1] = bits >> 8; - decoded[2] = bits; + decoded[0] = (gpr_uint8)(bits >> 16); + decoded[1] = (gpr_uint8)(bits >> 8); + decoded[2] = (gpr_uint8)(bits); append_bytes(str, decoded, 3); goto b64_byte0; } @@ -1190,7 +1191,7 @@ static int finish_str(grpc_chttp2_hpack_parser *p) { bits & 0xffff); return 0; } - decoded[0] = bits >> 16; + decoded[0] = (gpr_uint8)(bits >> 16); append_bytes(str, decoded, 1); break; case B64_BYTE3: @@ -1200,8 +1201,8 @@ static int finish_str(grpc_chttp2_hpack_parser *p) { bits & 0xff); return 0; } - decoded[0] = bits >> 16; - decoded[1] = bits >> 8; + decoded[0] = (gpr_uint8)(bits >> 16); + decoded[1] = (gpr_uint8)(bits >> 8); append_bytes(str, decoded, 2); break; } @@ -1256,7 +1257,8 @@ static int parse_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, parse_next(p, cur + remaining, end); } else { if (!add_str_bytes(p, cur, cur + given)) return 0; - p->strgot += given; + GPR_ASSERT(given <= GPR_UINT32_MAX - p->strgot); + p->strgot += (gpr_uint32)given; p->state = parse_string; return 1; } diff --git a/src/core/transport/chttp2/hpack_table.c b/src/core/transport/chttp2/hpack_table.c index 3aeb4dae94e..e18778ab0b7 100644 --- a/src/core/transport/chttp2/hpack_table.c +++ b/src/core/transport/chttp2/hpack_table.c @@ -150,19 +150,22 @@ grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, /* Evict one element from the table */ static void evict1(grpc_chttp2_hptbl *tbl) { grpc_mdelem *first_ent = tbl->ents[tbl->first_ent]; - tbl->mem_used -= GPR_SLICE_LENGTH(first_ent->key->slice) + - GPR_SLICE_LENGTH(first_ent->value->slice) + - GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; - tbl->first_ent = (tbl->first_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT; + size_t elem_bytes = GPR_SLICE_LENGTH(first_ent->key->slice) + + GPR_SLICE_LENGTH(first_ent->value->slice) + + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; + GPR_ASSERT(elem_bytes <= tbl->mem_used); + tbl->mem_used = (gpr_uint16)(tbl->mem_used - elem_bytes); + tbl->first_ent = + (gpr_uint16)((tbl->first_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT); tbl->num_ents--; GRPC_MDELEM_UNREF(first_ent); } void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { /* determine how many bytes of buffer this entry represents */ - gpr_uint16 elem_bytes = GPR_SLICE_LENGTH(md->key->slice) + - GPR_SLICE_LENGTH(md->value->slice) + - GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; + size_t elem_bytes = GPR_SLICE_LENGTH(md->key->slice) + + GPR_SLICE_LENGTH(md->value->slice) + + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; /* we can't add elements bigger than the max table size */ if (elem_bytes > tbl->max_bytes) { @@ -182,7 +185,7 @@ void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { } /* evict entries to ensure no overflow */ - while (elem_bytes > tbl->max_bytes - tbl->mem_used) { + while (elem_bytes > (size_t)tbl->max_bytes - tbl->mem_used) { evict1(tbl); } @@ -190,28 +193,30 @@ void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { tbl->ents[tbl->last_ent] = md; /* update accounting values */ - tbl->last_ent = (tbl->last_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT; + tbl->last_ent = + (gpr_uint16)((tbl->last_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT); tbl->num_ents++; - tbl->mem_used += elem_bytes; + tbl->mem_used = (gpr_uint16)(tbl->mem_used + elem_bytes); } grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( const grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { grpc_chttp2_hptbl_find_result r = {0, 0}; - int i; + gpr_uint16 i; /* See if the string is in the static table */ for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { grpc_mdelem *ent = tbl->static_ents[i]; if (md->key != ent->key) continue; - r.index = i + 1; + r.index = (gpr_uint16)(i + 1); r.has_value = md->value == ent->value; if (r.has_value) return r; } /* Scan the dynamic table */ for (i = 0; i < tbl->num_ents; i++) { - int idx = tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY; + gpr_uint16 idx = + (gpr_uint16)(tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY); grpc_mdelem *ent = tbl->ents[(tbl->first_ent + i) % GRPC_CHTTP2_MAX_TABLE_COUNT]; if (md->key != ent->key) continue; diff --git a/src/core/transport/chttp2/internal.h b/src/core/transport/chttp2/internal.h index 125cd744b7d..c8c1abb7508 100644 --- a/src/core/transport/chttp2/internal.h +++ b/src/core/transport/chttp2/internal.h @@ -168,7 +168,7 @@ typedef struct { grpc_iomgr_closure *pending_closures_tail; /** window available for us to send to peer */ - gpr_uint32 outgoing_window; + gpr_int64 outgoing_window; /** window available for peer to send to us - updated after parse */ gpr_uint32 incoming_window; /** how much window would we like to have for incoming_window */ @@ -280,7 +280,7 @@ struct grpc_chttp2_transport_parsing { gpr_uint32 goaway_last_stream_index; gpr_slice goaway_text; - gpr_uint64 outgoing_window_update; + gpr_int64 outgoing_window_update; /** pings awaiting responses */ grpc_chttp2_outstanding_ping pings; diff --git a/src/core/transport/chttp2/parsing.c b/src/core/transport/chttp2/parsing.c index 5d3dfe2286c..a592ce7d28b 100644 --- a/src/core/transport/chttp2/parsing.c +++ b/src/core/transport/chttp2/parsing.c @@ -411,7 +411,7 @@ int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, 0)) { return 0; } - transport_parsing->incoming_frame_size -= (end - cur); + transport_parsing->incoming_frame_size -= (gpr_uint32)(end - cur); return 1; } gpr_log(GPR_ERROR, "should never reach here"); @@ -479,7 +479,7 @@ static void skip_header(void *tp, grpc_mdelem *md) { GRPC_MDELEM_UNREF(md); } static int init_skip_frame_parser( grpc_chttp2_transport_parsing *transport_parsing, int is_header) { if (is_header) { - int is_eoh = transport_parsing->expect_continuation_stream_id != 0; + gpr_uint8 is_eoh = transport_parsing->expect_continuation_stream_id != 0; transport_parsing->parser = grpc_chttp2_header_parser_parse; transport_parsing->parser_data = &transport_parsing->hpack_parser; transport_parsing->hpack_parser.on_header = skip_header; @@ -622,8 +622,8 @@ static void on_header(void *tp, grpc_mdelem *md) { static int init_header_frame_parser( grpc_chttp2_transport_parsing *transport_parsing, int is_continuation) { - int is_eoh = (transport_parsing->incoming_frame_flags & - GRPC_CHTTP2_DATA_FLAG_END_HEADERS) != 0; + gpr_uint8 is_eoh = (transport_parsing->incoming_frame_flags & + GRPC_CHTTP2_DATA_FLAG_END_HEADERS) != 0; int via_accept = 0; grpc_chttp2_stream_parsing *stream_parsing; diff --git a/src/core/transport/chttp2/stream_encoder.c b/src/core/transport/chttp2/stream_encoder.c index 8c30af652fc..6a22532bc2c 100644 --- a/src/core/transport/chttp2/stream_encoder.c +++ b/src/core/transport/chttp2/stream_encoder.c @@ -77,15 +77,15 @@ typedef struct { static void fill_header(gpr_uint8 *p, gpr_uint8 type, gpr_uint32 id, size_t len, gpr_uint8 flags) { GPR_ASSERT(len < 16777316); - *p++ = len >> 16; - *p++ = len >> 8; - *p++ = len; + *p++ = (gpr_uint8)(len >> 16); + *p++ = (gpr_uint8)(len >> 8); + *p++ = (gpr_uint8)(len); *p++ = type; *p++ = flags; - *p++ = id >> 24; - *p++ = id >> 16; - *p++ = id >> 8; - *p++ = id; + *p++ = (gpr_uint8)(id >> 24); + *p++ = (gpr_uint8)(id >> 16); + *p++ = (gpr_uint8)(id >> 8); + *p++ = (gpr_uint8)(id); } /* finish a frame - fill in the previously reserved header */ @@ -106,11 +106,12 @@ static void finish_frame(framer_state *st, int is_header_boundary, case NONE: return; } - fill_header(GPR_SLICE_START_PTR(st->output->slices[st->header_idx]), type, - st->stream_id, - st->output->length - st->output_length_at_start_of_frame, - (is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) | - (is_header_boundary ? GRPC_CHTTP2_DATA_FLAG_END_HEADERS : 0)); + fill_header( + GPR_SLICE_START_PTR(st->output->slices[st->header_idx]), type, + st->stream_id, st->output->length - st->output_length_at_start_of_frame, + (gpr_uint8)( + (is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) | + (is_header_boundary ? GRPC_CHTTP2_DATA_FLAG_END_HEADERS : 0))); st->cur_frame_type = NONE; } @@ -190,6 +191,8 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c, GPR_SLICE_LENGTH(elem->value->slice); grpc_mdelem *elem_to_unref; + GPR_ASSERT(elem_size < 65536); + /* Reserve space for this element in the remote table: if this overflows the current table, drop elements until it fits, matching the decompressor algorithm */ @@ -201,14 +204,16 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c, c->table_elem_size[c->tail_remote_index % GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]); GPR_ASSERT(c->table_elems > 0); - c->table_size -= c->table_elem_size[c->tail_remote_index % - GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]; + c->table_size = + (gpr_uint16)(c->table_size - + c->table_elem_size[c->tail_remote_index % + GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]); c->table_elems--; } GPR_ASSERT(c->table_elems < GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS); c->table_elem_size[new_index % GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS] = - elem_size; - c->table_size += elem_size; + (gpr_uint16)elem_size; + c->table_size = (gpr_uint16)(c->table_size + elem_size); c->table_elems++; /* Store this element into {entries,indices}_elem */ @@ -497,7 +502,7 @@ gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count, gpr_uint32 flow_controlled_bytes_taken = 0; gpr_uint32 curop = 0; gpr_uint8 *p; - int compressed_flag_set = 0; + gpr_uint8 compressed_flag_set = 0; while (curop < *inops_count) { GPR_ASSERT(flow_controlled_bytes_taken <= max_flow_controlled_bytes); @@ -523,10 +528,10 @@ gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count, p = GPR_SLICE_START_PTR(slice); p[0] = compressed_flag_set; - p[1] = op->data.begin_message.length >> 24; - p[2] = op->data.begin_message.length >> 16; - p[3] = op->data.begin_message.length >> 8; - p[4] = op->data.begin_message.length; + p[1] = (gpr_uint8)(op->data.begin_message.length >> 24); + p[2] = (gpr_uint8)(op->data.begin_message.length >> 16); + p[3] = (gpr_uint8)(op->data.begin_message.length >> 8); + p[4] = (gpr_uint8)(op->data.begin_message.length); op->type = GRPC_OP_SLICE; op->data.slice = slice; /* fallthrough */ @@ -550,7 +555,7 @@ gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count, grpc_sopb_append(outops, op, 1); curop++; } - flow_controlled_bytes_taken += GPR_SLICE_LENGTH(slice); + flow_controlled_bytes_taken += (gpr_uint32)GPR_SLICE_LENGTH(slice); break; } } diff --git a/src/core/transport/chttp2/varint.h b/src/core/transport/chttp2/varint.h index 37856913f82..4dfcc76773e 100644 --- a/src/core/transport/chttp2/varint.h +++ b/src/core/transport/chttp2/varint.h @@ -63,7 +63,7 @@ void grpc_chttp2_hpack_write_varint_tail(gpr_uint32 tail_value, do { \ gpr_uint8* tgt = target; \ if ((length) == 1u) { \ - (tgt)[0] = (prefix_or) | (n); \ + (tgt)[0] = (gpr_uint8)((prefix_or) | (n)); \ } else { \ (tgt)[0] = (prefix_or) | GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits); \ grpc_chttp2_hpack_write_varint_tail( \ diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c index c80330527e5..deb2fedf0c4 100644 --- a/src/core/transport/chttp2_transport.c +++ b/src/core/transport/chttp2_transport.c @@ -209,7 +209,7 @@ static void ref_transport(grpc_chttp2_transport *t) { gpr_ref(&t->refs); } static void init_transport(grpc_chttp2_transport *t, const grpc_channel_args *channel_args, grpc_endpoint *ep, grpc_mdctx *mdctx, - int is_client) { + gpr_uint8 is_client) { size_t i; int j; @@ -683,6 +683,8 @@ static void perform_stream_op_locked( stream_global->publish_sopb = op->recv_ops; stream_global->publish_sopb->nops = 0; stream_global->publish_state = op->recv_state; + /* clamp max recv bytes */ + op->max_recv_bytes = GPR_MIN(op->max_recv_bytes, GPR_UINT32_MAX); if (stream_global->max_recv_bytes < op->max_recv_bytes) { GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( "op", transport_global, stream_global, max_recv_bytes, @@ -691,9 +693,8 @@ static void perform_stream_op_locked( "op", transport_global, stream_global, unannounced_incoming_window, op->max_recv_bytes - stream_global->max_recv_bytes); stream_global->unannounced_incoming_window += - op->max_recv_bytes - stream_global->max_recv_bytes; - stream_global->max_recv_bytes = - (gpr_uint32)(GPR_MIN(op->max_recv_bytes, GPR_UINT32_MAX)); + (gpr_uint32)op->max_recv_bytes - stream_global->max_recv_bytes; + stream_global->max_recv_bytes = (gpr_uint32)op->max_recv_bytes; } grpc_chttp2_incoming_metadata_live_op_buffer_end( &stream_global->outstanding_metadata); @@ -730,14 +731,14 @@ static void send_ping_locked(grpc_chttp2_transport *t, p->next = &t->global.pings; p->prev = p->next->prev; p->prev->next = p->next->prev = p; - p->id[0] = (t->global.ping_counter >> 56) & 0xff; - p->id[1] = (t->global.ping_counter >> 48) & 0xff; - p->id[2] = (t->global.ping_counter >> 40) & 0xff; - p->id[3] = (t->global.ping_counter >> 32) & 0xff; - p->id[4] = (t->global.ping_counter >> 24) & 0xff; - p->id[5] = (t->global.ping_counter >> 16) & 0xff; - p->id[6] = (t->global.ping_counter >> 8) & 0xff; - p->id[7] = t->global.ping_counter & 0xff; + p->id[0] = (gpr_uint8)((t->global.ping_counter >> 56) & 0xff); + p->id[1] = (gpr_uint8)((t->global.ping_counter >> 48) & 0xff); + p->id[2] = (gpr_uint8)((t->global.ping_counter >> 40) & 0xff); + p->id[3] = (gpr_uint8)((t->global.ping_counter >> 32) & 0xff); + p->id[4] = (gpr_uint8)((t->global.ping_counter >> 24) & 0xff); + p->id[5] = (gpr_uint8)((t->global.ping_counter >> 16) & 0xff); + p->id[6] = (gpr_uint8)((t->global.ping_counter >> 8) & 0xff); + p->id[7] = (gpr_uint8)(t->global.ping_counter & 0xff); p->on_recv = on_recv; gpr_slice_buffer_add(&t->global.qbuf, grpc_chttp2_ping_create(0, p->id)); } @@ -999,7 +1000,7 @@ static void close_from_api(grpc_chttp2_transport_global *transport_global, *p++ = (gpr_uint8)('0' + (status % 10)); } GPR_ASSERT(p == GPR_SLICE_END_PTR(status_hdr)); - len += GPR_SLICE_LENGTH(status_hdr); + len += (gpr_uint32)GPR_SLICE_LENGTH(status_hdr); if (optional_message) { GPR_ASSERT(GPR_SLICE_LENGTH(*optional_message) < 127); @@ -1019,23 +1020,23 @@ static void close_from_api(grpc_chttp2_transport_global *transport_global, *p++ = 'a'; *p++ = 'g'; *p++ = 'e'; - *p++ = GPR_SLICE_LENGTH(*optional_message); + *p++ = (gpr_uint8)GPR_SLICE_LENGTH(*optional_message); GPR_ASSERT(p == GPR_SLICE_END_PTR(message_pfx)); - len += GPR_SLICE_LENGTH(message_pfx); - len += GPR_SLICE_LENGTH(*optional_message); + len += (gpr_uint32)GPR_SLICE_LENGTH(message_pfx); + len += (gpr_uint32)GPR_SLICE_LENGTH(*optional_message); } hdr = gpr_slice_malloc(9); p = GPR_SLICE_START_PTR(hdr); - *p++ = len >> 16; - *p++ = len >> 8; - *p++ = len; + *p++ = (gpr_uint8)(len >> 16); + *p++ = (gpr_uint8)(len >> 8); + *p++ = (gpr_uint8)(len); *p++ = GRPC_CHTTP2_FRAME_HEADER; *p++ = GRPC_CHTTP2_DATA_FLAG_END_STREAM | GRPC_CHTTP2_DATA_FLAG_END_HEADERS; - *p++ = stream_global->id >> 24; - *p++ = stream_global->id >> 16; - *p++ = stream_global->id >> 8; - *p++ = stream_global->id; + *p++ = (gpr_uint8)(stream_global->id >> 24); + *p++ = (gpr_uint8)(stream_global->id >> 16); + *p++ = (gpr_uint8)(stream_global->id >> 8); + *p++ = (gpr_uint8)(stream_global->id); GPR_ASSERT(p == GPR_SLICE_END_PTR(hdr)); gpr_slice_buffer_add(&transport_global->qbuf, hdr); @@ -1281,7 +1282,7 @@ grpc_transport *grpc_create_chttp2_transport( const grpc_channel_args *channel_args, grpc_endpoint *ep, grpc_mdctx *mdctx, int is_client) { grpc_chttp2_transport *t = gpr_malloc(sizeof(grpc_chttp2_transport)); - init_transport(t, channel_args, ep, mdctx, is_client); + init_transport(t, channel_args, ep, mdctx, is_client != 0); return &t->base; } diff --git a/src/core/transport/metadata.c b/src/core/transport/metadata.c index 9b07b980b7c..9d135f43560 100644 --- a/src/core/transport/metadata.c +++ b/src/core/transport/metadata.c @@ -334,7 +334,7 @@ grpc_mdstr *grpc_mdstr_from_string(grpc_mdctx *ctx, const char *str, grpc_mdstr *ret; for (i = 0; i < len; i++) { if (str[i] >= 'A' && str[i] <= 'Z') { - copy[i] = str[i] - 'A' + 'a'; + copy[i] = (char)(str[i] - 'A' + 'a'); } else { copy[i] = str[i]; } @@ -379,7 +379,7 @@ grpc_mdstr *grpc_mdstr_from_buffer(grpc_mdctx *ctx, const gpr_uint8 *buf, s->slice.refcount = NULL; memcpy(s->slice.data.inlined.bytes, buf, length); s->slice.data.inlined.bytes[length] = 0; - s->slice.data.inlined.length = length; + s->slice.data.inlined.length = (gpr_uint8)length; } else { /* string data goes after the internal_string header, and we +1 for null terminator */ diff --git a/templates/Makefile.template b/templates/Makefile.template index d6bcb54bac4..346b4f438ce 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -247,10 +247,6 @@ CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false) - # Detect if -Wshorten-64-to-32 is a thing - SHORTEN_64_TO_32_CHECK_CMD = $(CC) -Wshorten-64-to-32 test/build/empty.c - HAS_SHORTEN_64_TO_32 = $(shell $(SHORTEN_64_TO_32_CHECK_CMD) 2> /dev/null && echo true || echo false) - # The HOST compiler settings are used to compile the protoc plugins. # In most cases, you won't have to change anything, but if you are # cross-compiling, you can override these variables from GNU make's @@ -265,10 +261,7 @@ DEFINES += $(EXTRA_DEFINES) endif - CFLAGS += -std=c89 -pedantic -Wsign-conversion - ifeq ($(HAS_SHORTEN_64_TO_32),true) - CFLAGS += -Wshorten-64-to-32 - endif + CFLAGS += -std=c89 -pedantic -Wsign-conversion -Wconversion ifeq ($(HAS_CXX11),true) CXXFLAGS += -std=c++11 else diff --git a/test/core/fling/client.c b/test/core/fling/client.c index ed80544e3c7..a53411c2f56 100644 --- a/test/core/fling/client.c +++ b/test/core/fling/client.c @@ -130,7 +130,7 @@ static void step_ping_pong_stream(void) { static double now(void) { gpr_timespec tv = gpr_now(GPR_CLOCK_REALTIME); - return 1e9 * tv.tv_sec + tv.tv_nsec; + return 1e9 * (double)tv.tv_sec + tv.tv_nsec; } typedef struct { diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c index 27123eb216b..853b9a32c2c 100644 --- a/test/core/iomgr/endpoint_tests.c +++ b/test/core/iomgr/endpoint_tests.c @@ -86,7 +86,7 @@ static grpc_endpoint_test_fixture begin_test(grpc_endpoint_test_config config, static void end_test(grpc_endpoint_test_config config) { config.clean_up(); } static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size, - size_t *num_blocks, int *current_data) { + size_t *num_blocks, gpr_uint8 *current_data) { size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1 : 0); gpr_slice *slices = malloc(sizeof(gpr_slice) * nslices); size_t num_bytes_left = num_bytes; @@ -102,7 +102,7 @@ static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size, buf = GPR_SLICE_START_PTR(slices[i]); for (j = 0; j < GPR_SLICE_LENGTH(slices[i]); ++j) { buf[j] = *current_data; - *current_data = (*current_data + 1) % 256; + (*current_data)++; } } GPR_ASSERT(num_bytes_left == 0); @@ -117,7 +117,7 @@ struct read_and_write_test_state { size_t current_write_size; size_t bytes_written; int current_read_data; - int current_write_data; + gpr_uint8 current_write_data; int read_done; int write_done; gpr_slice_buffer incoming; diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index af66ef0997f..75959069c0f 100644 --- a/test/core/iomgr/fd_posix_test.c +++ b/test/core/iomgr/fd_posix_test.c @@ -83,7 +83,8 @@ static void create_test_socket(int port, int *socket_fd, /* Use local address for test */ sin->sin_family = AF_INET; sin->sin_addr.s_addr = htonl(0x7f000001); - sin->sin_port = htons(port); + GPR_ASSERT(port >= 0 && port < 65536); + sin->sin_port = htons((gpr_uint16)port); } /* Dummy gRPC callback */ diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c index b94f5987cae..59c498edff1 100644 --- a/test/core/iomgr/tcp_posix_test.c +++ b/test/core/iomgr/tcp_posix_test.c @@ -81,7 +81,7 @@ static ssize_t fill_socket(int fd) { int i; unsigned char buf[256]; for (i = 0; i < 256; ++i) { - buf[i] = i; + buf[i] = (gpr_uint8)i; } do { write_bytes = write(fd, buf, 256); @@ -99,7 +99,7 @@ static size_t fill_socket_partial(int fd, size_t bytes) { unsigned char *buf = malloc(bytes); unsigned i; for (i = 0; i < bytes; ++i) { - buf[i] = i % 256; + buf[i] = (gpr_uint8)(i % 256); } do { @@ -276,7 +276,7 @@ struct write_socket_state { }; static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size, - size_t *num_blocks, int *current_data) { + size_t *num_blocks, gpr_uint8 *current_data) { size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1u : 0u); gpr_slice *slices = gpr_malloc(sizeof(gpr_slice) * nslices); size_t num_bytes_left = num_bytes; @@ -291,7 +291,7 @@ static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size, buf = GPR_SLICE_START_PTR(slices[i]); for (j = 0; j < GPR_SLICE_LENGTH(slices[i]); ++j) { buf[j] = *current_data; - *current_data = (*current_data + 1) % 256; + (*current_data)++; } } GPR_ASSERT(num_bytes_left == 0); @@ -373,7 +373,7 @@ static void write_test(size_t num_bytes, size_t slice_size) { ssize_t read_bytes; size_t num_blocks; gpr_slice *slices; - int current_data = 0; + gpr_uint8 current_data = 0; gpr_slice_buffer outgoing; grpc_iomgr_closure write_done_closure; gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c index 8c964246c79..c4f1896ba6a 100644 --- a/test/core/iomgr/udp_server_test.c +++ b/test/core/iomgr/udp_server_test.c @@ -59,7 +59,7 @@ static void on_read(int fd, grpc_udp_server_cb new_transport_cb, void *cb_arg) { byte_count = recv(fd, read_buffer, sizeof(read_buffer), 0); g_number_of_reads++; - g_number_of_bytes_read += byte_count; + g_number_of_bytes_read += (int)byte_count; grpc_pollset_kick(&g_pollset, NULL); gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); diff --git a/test/core/json/json_rewrite.c b/test/core/json/json_rewrite.c index 561bf487b9f..82cc4090f3e 100644 --- a/test/core/json/json_rewrite.c +++ b/test/core/json/json_rewrite.c @@ -34,8 +34,9 @@ #include #include -#include #include +#include +#include #include "src/core/json/json_reader.h" #include "src/core/json/json_writer.h" @@ -96,7 +97,8 @@ static void json_reader_string_clear(void* userdata) { static void json_reader_string_add_char(void* userdata, gpr_uint32 c) { json_reader_userdata* state = userdata; check_string(state, 1); - state->scratchpad[state->string_len++] = c; + GPR_ASSERT(c < 256); + state->scratchpad[state->string_len++] = (char)c; } static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) { diff --git a/test/core/json/json_rewrite_test.c b/test/core/json/json_rewrite_test.c index 7cf184950e8..d26ef53b2d7 100644 --- a/test/core/json/json_rewrite_test.c +++ b/test/core/json/json_rewrite_test.c @@ -108,7 +108,8 @@ static void json_reader_string_clear(void* userdata) { static void json_reader_string_add_char(void* userdata, gpr_uint32 c) { json_reader_userdata* state = userdata; check_string(state, 1); - state->scratchpad[state->string_len++] = c; + GPR_ASSERT(c <= 256); + state->scratchpad[state->string_len++] = (char)c; } static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) { diff --git a/test/core/support/slice_test.c b/test/core/support/slice_test.c index a84ad50cf3b..1d202f06186 100644 --- a/test/core/support/slice_test.c +++ b/test/core/support/slice_test.c @@ -116,7 +116,7 @@ static void test_slice_sub_works(unsigned length) { beginning of the slice. */ slice = gpr_slice_malloc(length); for (i = 0; i < length; i++) { - GPR_SLICE_START_PTR(slice)[i] = i; + GPR_SLICE_START_PTR(slice)[i] = (gpr_uint8)i; } /* Ensure that for all subsets length is correct and that we start on the @@ -155,7 +155,7 @@ static void test_slice_split_head_works(size_t length) { beginning of the slice. */ slice = gpr_slice_malloc(length); for (i = 0; i < length; i++) { - GPR_SLICE_START_PTR(slice)[i] = i; + GPR_SLICE_START_PTR(slice)[i] = (gpr_uint8)i; } /* Ensure that for all subsets length is correct and that we start on the @@ -183,7 +183,7 @@ static void test_slice_split_tail_works(size_t length) { beginning of the slice. */ slice = gpr_slice_malloc(length); for (i = 0; i < length; i++) { - GPR_SLICE_START_PTR(slice)[i] = i; + GPR_SLICE_START_PTR(slice)[i] = (gpr_uint8)i; } /* Ensure that for all subsets length is correct and that we start on the diff --git a/test/core/transport/chttp2/stream_encoder_test.c b/test/core/transport/chttp2/stream_encoder_test.c index a723b90084d..71db98c69e2 100644 --- a/test/core/transport/chttp2/stream_encoder_test.c +++ b/test/core/transport/chttp2/stream_encoder_test.c @@ -59,7 +59,7 @@ static gpr_slice create_test_slice(size_t length) { gpr_slice slice = gpr_slice_malloc(length); size_t i; for (i = 0; i < length; i++) { - GPR_SLICE_START_PTR(slice)[i] = i; + GPR_SLICE_START_PTR(slice)[i] = (gpr_uint8)i; } return slice; } @@ -196,10 +196,10 @@ static void test_basic_headers(void) { } static void encode_int_to_str(int i, char *p) { - p[0] = 'a' + i % 26; + p[0] = (char)('a' + i % 26); i /= 26; GPR_ASSERT(i < 26); - p[1] = 'a' + i; + p[1] = (char)('a' + i); p[2] = 0; } @@ -246,7 +246,7 @@ static void randstr(char *p, int bufsz) { int i; int len = 1 + rand() % bufsz; for (i = 0; i < len; i++) { - p[i] = 'a' + rand() % 26; + p[i] = (char)('a' + rand() % 26); } p[len] = 0; } diff --git a/test/core/util/parse_hexstring.c b/test/core/util/parse_hexstring.c index 0bac8fef329..eced3173d16 100644 --- a/test/core/util/parse_hexstring.c +++ b/test/core/util/parse_hexstring.c @@ -54,10 +54,10 @@ gpr_slice parse_hexstring(const char *hexstring) { temp = 0; for (p = hexstring; *p; p++) { if (*p >= '0' && *p <= '9') { - temp = (temp << 4) | (*p - '0'); + temp = (gpr_uint8)(temp << 4) | (gpr_uint8)(*p - '0'); nibbles++; } else if (*p >= 'a' && *p <= 'f') { - temp = (temp << 4) | (*p - 'a' + 10); + temp = (gpr_uint8)(temp << 4) | (gpr_uint8)(*p - 'a' + 10); nibbles++; } if (nibbles == 2) { diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c index 4781d334e23..be45bae4960 100644 --- a/test/core/util/port_posix.c +++ b/test/core/util/port_posix.c @@ -102,7 +102,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((gpr_uint16)*port); if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { gpr_log(GPR_DEBUG, "bind(port=%d) failed: %s", *port, strerror(errno)); close(fd); diff --git a/test/core/util/reconnect_server.c b/test/core/util/reconnect_server.c index aa7f77eadf1..71fb69b54fc 100644 --- a/test/core/util/reconnect_server.c +++ b/test/core/util/reconnect_server.c @@ -116,7 +116,7 @@ void reconnect_server_start(reconnect_server *server, int port) { int port_added; addr.sin_family = AF_INET; - addr.sin_port = htons(port); + addr.sin_port = htons((gpr_uint16)port); memset(&addr.sin_addr, 0, sizeof(addr.sin_addr)); server->tcp_server = grpc_tcp_server_create(); diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h index ccef8620c13..15b71747fb5 100644 --- a/test/core/util/test_config.h +++ b/test/core/util/test_config.h @@ -54,15 +54,17 @@ extern double g_fixture_slowdown_factor; (GRPC_TEST_SLOWDOWN_BUILD_FACTOR * GRPC_TEST_SLOWDOWN_MACHINE_FACTOR * \ g_fixture_slowdown_factor) -#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \ - gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), \ - gpr_time_from_millis(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x), \ - GPR_TIMESPAN)) +#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \ + gpr_time_add( \ + gpr_now(GPR_CLOCK_MONOTONIC), \ + gpr_time_from_millis((long)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \ + GPR_TIMESPAN)) -#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \ - gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), \ - gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x), \ - GPR_TIMESPAN)) +#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \ + gpr_time_add( \ + gpr_now(GPR_CLOCK_MONOTONIC), \ + gpr_time_from_micros((long)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \ + GPR_TIMESPAN)) #ifndef GRPC_TEST_CUSTOM_PICK_PORT #define GRPC_TEST_PICK_PORT diff --git a/tools/codegen/core/gen_hpack_tables.c b/tools/codegen/core/gen_hpack_tables.c index dec0e2f3fef..d924aba6022 100644 --- a/tools/codegen/core/gen_hpack_tables.c +++ b/tools/codegen/core/gen_hpack_tables.c @@ -71,13 +71,13 @@ static unsigned char prefix_mask(unsigned char prefix_len) { unsigned char i; unsigned char out = 0; for (i = 0; i < prefix_len; i++) { - out |= 1 << (7 - i); + out |= (unsigned char)(1 << (7 - i)); } return out; } static unsigned char suffix_mask(unsigned char prefix_len) { - return ~prefix_mask(prefix_len); + return (unsigned char)~prefix_mask(prefix_len); } static void generate_first_byte_lut(void) { @@ -92,7 +92,7 @@ static void generate_first_byte_lut(void) { chrspec = NULL; for (j = 0; j < num_fields; j++) { if ((prefix_mask(fields[j].prefix_length) & i) == fields[j].prefix) { - suffix = suffix_mask(fields[j].prefix_length) & i; + suffix = suffix_mask(fields[j].prefix_length) & (unsigned char)i; if (suffix == suffix_mask(fields[j].prefix_length)) { if (fields[j].index != 2) continue; } else if (suffix == 0) { @@ -336,7 +336,7 @@ static void generate_base64_inverse_table(void) { memset(inverse, 255, sizeof(inverse)); for (i = 0; i < strlen(alphabet); i++) { - inverse[(unsigned char)alphabet[i]] = i; + inverse[(unsigned char)alphabet[i]] = (unsigned char)i; } printf("static const gpr_uint8 inverse_base64[256] = {"); diff --git a/tools/codegen/core/gen_legal_metadata_characters.c b/tools/codegen/core/gen_legal_metadata_characters.c index 0fbc545d8d1..2ffda54a21f 100644 --- a/tools/codegen/core/gen_legal_metadata_characters.c +++ b/tools/codegen/core/gen_legal_metadata_characters.c @@ -41,7 +41,7 @@ static unsigned char legal_bits[256 / 8]; static void legal(int x) { int byte = x / 8; int bit = x % 8; - legal_bits[byte] |= 1 << bit; + legal_bits[byte] |= (unsigned char)(1 << bit); } static void dump(void) { From 6b8046375e15702493094598803c22ed3b8e1e65 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Sep 2015 16:06:05 -0700 Subject: [PATCH 30/32] Fix typo --- src/core/channel/compress_filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/channel/compress_filter.c b/src/core/channel/compress_filter.c index c47b91bc58e..17b48f31c18 100644 --- a/src/core/channel/compress_filter.c +++ b/src/core/channel/compress_filter.c @@ -230,7 +230,7 @@ static void process_send_ops(grpc_call_element *elem, GPR_ASSERT(calld->remaining_slice_bytes > 0); /* Increase input ref count, gpr_slice_buffer_add takes ownership. */ gpr_slice_buffer_add(&calld->slices, gpr_slice_ref(sop->data.slice)); - GPR_ASSERT(GPR_SLICE_LENGTH(sop->data.slice) > + GPR_ASSERT(GPR_SLICE_LENGTH(sop->data.slice) >= calld->remaining_slice_bytes); calld->remaining_slice_bytes -= (gpr_uint32)GPR_SLICE_LENGTH(sop->data.slice); From ebc7ef268ca9536af6a4c5be1c80bcc79665d4e9 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Sep 2015 22:19:25 -0700 Subject: [PATCH 31/32] Mac build fixes --- include/grpc/support/port_platform.h | 1 + src/core/iomgr/pollset_multipoller_with_poll_posix.c | 3 ++- src/core/iomgr/tcp_posix.c | 10 ++++++++-- src/core/support/cpu_posix.c | 8 ++++---- src/core/support/log_posix.c | 2 +- src/core/support/time_posix.c | 4 ++-- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/grpc/support/port_platform.h b/include/grpc/support/port_platform.h index 69709f88502..93291a174da 100644 --- a/include/grpc/support/port_platform.h +++ b/include/grpc/support/port_platform.h @@ -179,6 +179,7 @@ #ifndef _BSD_SOURCE #define _BSD_SOURCE #endif +#define GPR_MSG_IOVLEN_TYPE int #if TARGET_OS_IPHONE #define GPR_PLATFORM_STRING "ios" #define GPR_CPU_IPHONE 1 diff --git a/src/core/iomgr/pollset_multipoller_with_poll_posix.c b/src/core/iomgr/pollset_multipoller_with_poll_posix.c index f1bc60ba4e9..cae260cab0b 100644 --- a/src/core/iomgr/pollset_multipoller_with_poll_posix.c +++ b/src/core/iomgr/pollset_multipoller_with_poll_posix.c @@ -101,7 +101,8 @@ static void multipoll_with_poll_pollset_maybe_work( gpr_timespec now, int allow_synchronous_callback) { int timeout; int r; - size_t i, j, pfd_count, fd_count; + size_t i, j, fd_count; + nfds_t pfd_count; pollset_hdr *h; /* TODO(ctiller): inline some elements to avoid an allocation */ grpc_fd_watcher *watchers; diff --git a/src/core/iomgr/tcp_posix.c b/src/core/iomgr/tcp_posix.c index 81f04494eb5..68f469c3681 100644 --- a/src/core/iomgr/tcp_posix.c +++ b/src/core/iomgr/tcp_posix.c @@ -61,6 +61,12 @@ #define SENDMSG_FLAGS 0 #endif +#ifdef GPR_MSG_IOVLEN_TYPE +typedef GPR_MSG_IOVLEN_TYPE msg_iovlen_type; +#else +typedef size_t msg_iovlen_type; +#endif + int grpc_tcp_trace = 0; typedef struct { @@ -68,7 +74,7 @@ typedef struct { grpc_fd *em_fd; int fd; int finished_edge; - size_t iov_size; /* Number of slices to allocate per read attempt */ + msg_iovlen_type iov_size; /* Number of slices to allocate per read attempt */ size_t slice_size; gpr_refcount refcount; @@ -265,7 +271,7 @@ static grpc_endpoint_op_status tcp_read(grpc_endpoint *ep, static grpc_endpoint_op_status tcp_flush(grpc_tcp *tcp) { struct msghdr msg; struct iovec iov[MAX_WRITE_IOVEC]; - size_t iov_size; + msg_iovlen_type iov_size; ssize_t sent_length; size_t sending_length; size_t trailing; diff --git a/src/core/support/cpu_posix.c b/src/core/support/cpu_posix.c index 99484e37fbc..55d92c0555f 100644 --- a/src/core/support/cpu_posix.c +++ b/src/core/support/cpu_posix.c @@ -44,11 +44,11 @@ static __thread char magic_thread_local; -static int ncpus = 0; +static long ncpus = 0; static void init_ncpus() { ncpus = sysconf(_SC_NPROCESSORS_ONLN); - if (ncpus < 1) { + if (ncpus < 1 || ncpus > GPR_UINT32_MAX) { gpr_log(GPR_ERROR, "Cannot determine number of CPUs: assuming 1"); ncpus = 1; } @@ -57,7 +57,7 @@ static void init_ncpus() { unsigned gpr_cpu_num_cores(void) { static gpr_once once = GPR_ONCE_INIT; gpr_once_init(&once, init_ncpus); - return ncpus; + return (unsigned)ncpus; } /* This is a cheap, but good enough, pointer hash for sharding things: */ @@ -71,7 +71,7 @@ unsigned gpr_cpu_current_cpu(void) { most code that's using this is using it to shard across work queues though, so here we use thread identity instead to achieve a similar though not identical effect */ - return shard_ptr(&magic_thread_local); + return (unsigned)shard_ptr(&magic_thread_local); } #endif /* GPR_CPU_POSIX */ diff --git a/src/core/support/log_posix.c b/src/core/support/log_posix.c index 940ee20f151..021c4666d41 100644 --- a/src/core/support/log_posix.c +++ b/src/core/support/log_posix.c @@ -62,7 +62,7 @@ void gpr_log(const char *file, int line, gpr_log_severity severity, } else if ((size_t)ret <= sizeof(buf) - 1) { message = buf; } else { - message = allocated = gpr_malloc(ret + 1); + message = allocated = gpr_malloc((size_t)ret + 1); va_start(args, format); vsnprintf(message, ret + 1, format, args); va_end(args); diff --git a/src/core/support/time_posix.c b/src/core/support/time_posix.c index a2744002437..dcecff0d05d 100644 --- a/src/core/support/time_posix.c +++ b/src/core/support/time_posix.c @@ -108,8 +108,8 @@ gpr_timespec gpr_now(gpr_clock_type clock) { break; case GPR_CLOCK_MONOTONIC: now_dbl = (mach_absolute_time() - g_time_start) * g_time_scale; - now.tv_sec = now_dbl * 1e-9; - now.tv_nsec = now_dbl - now.tv_sec * 1e9; + now.tv_sec = (time_t)(now_dbl * 1e-9); + now.tv_nsec = (int)(now_dbl - ((double)now.tv_sec) * 1e9); break; case GPR_CLOCK_PRECISE: gpr_precise_clock_now(&now); From 8cf0ed03d188a053606c74bc340e0b04fd24710a Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Sep 2015 22:37:25 -0700 Subject: [PATCH 32/32] Fix mac build --- test/cpp/qps/server_async.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc index 1251679ba21..516598a0e22 100644 --- a/test/cpp/qps/server_async.cc +++ b/test/cpp/qps/server_async.cc @@ -98,7 +98,7 @@ class AsyncQpsServerTest : public Server { } } ~AsyncQpsServerTest() { - auto deadline = std::chrono::high_resolution_clock::now() + + auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(10); server_->Shutdown(deadline); for (auto ss = shutdown_state_.begin(); ss != shutdown_state_.end(); ++ss) {