diff options
182 files changed, 2546 insertions, 2546 deletions
diff --git a/src/core/ext/census/grpc_context.cc b/src/core/ext/census/grpc_context.cc index fb4fcb34a8..ffe7c51ff8 100644 --- a/src/core/ext/census/grpc_context.cc +++ b/src/core/ext/census/grpc_context.cc @@ -24,8 +24,8 @@ void grpc_census_call_set_context(grpc_call* call, census_context* context) { GRPC_API_TRACE("grpc_census_call_set_context(call=%p, census_context=%p)", 2, (call, context)); - if (context != NULL) { - grpc_call_context_set(call, GRPC_CONTEXT_TRACING, context, NULL); + if (context != nullptr) { + grpc_call_context_set(call, GRPC_CONTEXT_TRACING, context, nullptr); } } diff --git a/src/core/ext/filters/client_channel/backup_poller.cc b/src/core/ext/filters/client_channel/backup_poller.cc index c3795c35c1..ed437d255c 100644 --- a/src/core/ext/filters/client_channel/backup_poller.cc +++ b/src/core/ext/filters/client_channel/backup_poller.cc @@ -46,7 +46,7 @@ typedef struct backup_poller { static gpr_once g_once = GPR_ONCE_INIT; static gpr_mu g_poller_mu; -static backup_poller* g_poller = NULL; // guarded by g_poller_mu +static backup_poller* g_poller = nullptr; // guarded by g_poller_mu // g_poll_interval_ms is set only once at the first time // grpc_client_channel_start_backup_polling() is called, after that it is // treated as const. @@ -55,7 +55,7 @@ static int g_poll_interval_ms = DEFAULT_POLL_INTERVAL_MS; static void init_globals() { gpr_mu_init(&g_poller_mu); char* env = gpr_getenv("GRPC_CLIENT_CHANNEL_BACKUP_POLL_INTERVAL_MS"); - if (env != NULL) { + if (env != nullptr) { int poll_interval_ms = gpr_parse_nonnegative_int(env); if (poll_interval_ms == -1) { gpr_log(GPR_ERROR, @@ -86,7 +86,7 @@ static void g_poller_unref(grpc_exec_ctx* exec_ctx) { if (gpr_unref(&g_poller->refs)) { gpr_mu_lock(&g_poller_mu); backup_poller* p = g_poller; - g_poller = NULL; + g_poller = nullptr; gpr_mu_unlock(&g_poller_mu); gpr_mu_lock(p->pollset_mu); p->shutting_down = true; @@ -113,7 +113,7 @@ static void run_poller(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { backup_poller_shutdown_unref(exec_ctx, p); return; } - grpc_error* err = grpc_pollset_work(exec_ctx, p->pollset, NULL, + grpc_error* err = grpc_pollset_work(exec_ctx, p->pollset, nullptr, grpc_exec_ctx_now(exec_ctx)); gpr_mu_unlock(p->pollset_mu); GRPC_LOG_IF_ERROR("Run client channel backup poller", err); @@ -129,7 +129,7 @@ void grpc_client_channel_start_backup_polling( return; } gpr_mu_lock(&g_poller_mu); - if (g_poller == NULL) { + if (g_poller == nullptr) { g_poller = (backup_poller*)gpr_zalloc(sizeof(backup_poller)); g_poller->pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); g_poller->shutting_down = false; diff --git a/src/core/ext/filters/client_channel/channel_connectivity.cc b/src/core/ext/filters/client_channel/channel_connectivity.cc index 82a5edca93..0538e00a6f 100644 --- a/src/core/ext/filters/client_channel/channel_connectivity.cc +++ b/src/core/ext/filters/client_channel/channel_connectivity.cc @@ -115,8 +115,8 @@ static void partly_done(grpc_exec_ctx* exec_ctx, state_watcher* w, grpc_channel_get_channel_stack(w->channel)); grpc_client_channel_watch_connectivity_state( exec_ctx, client_channel_elem, - grpc_polling_entity_create_from_pollset(grpc_cq_pollset(w->cq)), NULL, - &w->on_complete, NULL); + grpc_polling_entity_create_from_pollset(grpc_cq_pollset(w->cq)), nullptr, + &w->on_complete, nullptr); } gpr_mu_lock(&w->mu); @@ -229,7 +229,7 @@ void grpc_channel_watch_connectivity_state( w->cq = cq; w->tag = tag; w->channel = channel; - w->error = NULL; + w->error = nullptr; watcher_timer_init_arg* wa = (watcher_timer_init_arg*)gpr_malloc(sizeof(watcher_timer_init_arg)); diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 584872bfc1..075c569f61 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -115,7 +115,7 @@ static bool parse_timeout(grpc_json* field, grpc_millis* timeout) { buf[len - 1] = '\0'; // Remove trailing 's'. char* decimal_point = strchr(buf, '.'); int nanos = 0; - if (decimal_point != NULL) { + if (decimal_point != nullptr) { *decimal_point = '\0'; nanos = gpr_parse_nonnegative_int(decimal_point + 1); if (nanos == -1) { @@ -141,14 +141,14 @@ static bool parse_timeout(grpc_json* field, grpc_millis* timeout) { static void* method_parameters_create_from_json(const grpc_json* json) { wait_for_ready_value wait_for_ready = WAIT_FOR_READY_UNSET; grpc_millis timeout = 0; - for (grpc_json* field = json->child; field != NULL; field = field->next) { - if (field->key == NULL) continue; + for (grpc_json* field = json->child; field != nullptr; field = field->next) { + if (field->key == nullptr) continue; if (strcmp(field->key, "waitForReady") == 0) { - if (wait_for_ready != WAIT_FOR_READY_UNSET) return NULL; // Duplicate. - if (!parse_wait_for_ready(field, &wait_for_ready)) return NULL; + if (wait_for_ready != WAIT_FOR_READY_UNSET) return nullptr; // Duplicate. + if (!parse_wait_for_ready(field, &wait_for_ready)) return nullptr; } else if (strcmp(field->key, "timeout") == 0) { - if (timeout > 0) return NULL; // Duplicate. - if (!parse_timeout(field, &timeout)) return NULL; + if (timeout > 0) return nullptr; // Duplicate. + if (!parse_timeout(field, &timeout)) return nullptr; } } method_parameters* value = @@ -234,7 +234,7 @@ static void set_channel_connectivity_state_locked(grpc_exec_ctx* exec_ctx, * - Make it possible for policies to return GRPC_CHANNEL_TRANSIENT_FAILURE. * - Hand over pending picks from old policies during the switch that happens * when resolver provides an update. */ - if (chand->lb_policy != NULL) { + if (chand->lb_policy != nullptr) { if (state == GRPC_CHANNEL_TRANSIENT_FAILURE) { /* cancel picks with wait_for_ready=false */ grpc_lb_policy_cancel_picks_locked( @@ -266,11 +266,11 @@ static void on_lb_policy_state_changed_locked(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, "chand=%p: lb_policy=%p state changed to %s", w->chand, w->lb_policy, grpc_connectivity_state_name(w->state)); } - if (publish_state == GRPC_CHANNEL_SHUTDOWN && w->chand->resolver != NULL) { + if (publish_state == GRPC_CHANNEL_SHUTDOWN && w->chand->resolver != nullptr) { publish_state = GRPC_CHANNEL_TRANSIENT_FAILURE; grpc_resolver_channel_saw_error_locked(exec_ctx, w->chand->resolver); GRPC_LB_POLICY_UNREF(exec_ctx, w->chand->lb_policy, "channel"); - w->chand->lb_policy = NULL; + w->chand->lb_policy = nullptr; } set_channel_connectivity_state_locked(exec_ctx, w->chand, publish_state, GRPC_ERROR_REF(error), "lb_changed"); @@ -318,13 +318,13 @@ static void parse_retry_throttle_params(const grpc_json* field, void* arg) { service_config_parsing_state* parsing_state = (service_config_parsing_state*)arg; if (strcmp(field->key, "retryThrottling") == 0) { - if (parsing_state->retry_throttle_data != NULL) return; // Duplicate. + if (parsing_state->retry_throttle_data != nullptr) return; // Duplicate. if (field->type != GRPC_JSON_OBJECT) return; int max_milli_tokens = 0; int milli_token_ratio = 0; - for (grpc_json* sub_field = field->child; sub_field != NULL; + for (grpc_json* sub_field = field->child; sub_field != nullptr; sub_field = sub_field->next) { - if (sub_field->key == NULL) return; + if (sub_field->key == nullptr) return; if (strcmp(sub_field->key, "maxTokens") == 0) { if (max_milli_tokens != 0) return; // Duplicate. if (sub_field->type != GRPC_JSON_NUMBER) return; @@ -339,7 +339,7 @@ static void parse_retry_throttle_params(const grpc_json* field, void* arg) { uint32_t multiplier = 1; uint32_t decimal_value = 0; const char* decimal_point = strchr(sub_field->value, '.'); - if (decimal_point != NULL) { + if (decimal_point != nullptr) { whole_len = (size_t)(decimal_point - sub_field->value); multiplier = 1000; size_t decimal_len = strlen(decimal_point + 1); @@ -378,18 +378,18 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, } // Extract the following fields from the resolver result, if non-NULL. bool lb_policy_updated = false; - char* lb_policy_name_dup = NULL; + char* lb_policy_name_dup = nullptr; bool lb_policy_name_changed = false; - grpc_lb_policy* new_lb_policy = NULL; - char* service_config_json = NULL; - grpc_server_retry_throttle_data* retry_throttle_data = NULL; - grpc_slice_hash_table* method_params_table = NULL; - if (chand->resolver_result != NULL) { + grpc_lb_policy* new_lb_policy = nullptr; + char* service_config_json = nullptr; + grpc_server_retry_throttle_data* retry_throttle_data = nullptr; + grpc_slice_hash_table* method_params_table = nullptr; + if (chand->resolver_result != nullptr) { // Find LB policy name. - const char* lb_policy_name = NULL; + const char* lb_policy_name = nullptr; const grpc_arg* channel_arg = grpc_channel_args_find(chand->resolver_result, GRPC_ARG_LB_POLICY_NAME); - if (channel_arg != NULL) { + if (channel_arg != nullptr) { GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); lb_policy_name = channel_arg->value.string; } @@ -397,7 +397,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, // the grpclb policy, regardless of what the resolver actually specified. channel_arg = grpc_channel_args_find(chand->resolver_result, GRPC_ARG_LB_ADDRESSES); - if (channel_arg != NULL && channel_arg->type == GRPC_ARG_POINTER) { + if (channel_arg != nullptr && channel_arg->type == GRPC_ARG_POINTER) { grpc_lb_addresses* addresses = (grpc_lb_addresses*)channel_arg->value.pointer.p; bool found_balancer_address = false; @@ -408,7 +408,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, } } if (found_balancer_address) { - if (lb_policy_name != NULL && strcmp(lb_policy_name, "grpclb") != 0) { + if (lb_policy_name != nullptr && strcmp(lb_policy_name, "grpclb") != 0) { gpr_log(GPR_INFO, "resolver requested LB policy %s but provided at least one " "balancer address -- forcing use of grpclb LB policy", @@ -419,7 +419,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, } // Use pick_first if nothing was specified and we didn't select grpclb // above. - if (lb_policy_name == NULL) lb_policy_name = "pick_first"; + if (lb_policy_name == nullptr) lb_policy_name = "pick_first"; grpc_lb_policy_args lb_policy_args; lb_policy_args.args = chand->resolver_result; lb_policy_args.client_channel_factory = chand->client_channel_factory; @@ -430,9 +430,9 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, // only thing that modifies its value, and it can only be invoked // once at any given time. lb_policy_name_changed = - chand->info_lb_policy_name == NULL || + chand->info_lb_policy_name == nullptr || strcmp(chand->info_lb_policy_name, lb_policy_name) != 0; - if (chand->lb_policy != NULL && !lb_policy_name_changed) { + if (chand->lb_policy != nullptr && !lb_policy_name_changed) { // Continue using the same LB policy. Update with new addresses. lb_policy_updated = true; grpc_lb_policy_update_locked(exec_ctx, chand->lb_policy, &lb_policy_args); @@ -440,22 +440,22 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, // Instantiate new LB policy. new_lb_policy = grpc_lb_policy_create(exec_ctx, lb_policy_name, &lb_policy_args); - if (new_lb_policy == NULL) { + if (new_lb_policy == nullptr) { gpr_log(GPR_ERROR, "could not create LB policy \"%s\"", lb_policy_name); } } // Find service config. channel_arg = grpc_channel_args_find(chand->resolver_result, GRPC_ARG_SERVICE_CONFIG); - if (channel_arg != NULL) { + if (channel_arg != nullptr) { GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); service_config_json = gpr_strdup(channel_arg->value.string); grpc_service_config* service_config = grpc_service_config_create(service_config_json); - if (service_config != NULL) { + if (service_config != nullptr) { channel_arg = grpc_channel_args_find(chand->resolver_result, GRPC_ARG_SERVER_URI); - GPR_ASSERT(channel_arg != NULL); + GPR_ASSERT(channel_arg != nullptr); GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); grpc_uri* uri = grpc_uri_parse(exec_ctx, channel_arg->value.string, true); @@ -479,7 +479,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, // The copy will be saved in chand->lb_policy_name below. lb_policy_name_dup = gpr_strdup(lb_policy_name); grpc_channel_args_destroy(exec_ctx, chand->resolver_result); - chand->resolver_result = NULL; + chand->resolver_result = nullptr; } if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, @@ -494,22 +494,22 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, // // First, swap out the data used by cc_get_channel_info(). gpr_mu_lock(&chand->info_mu); - if (lb_policy_name_dup != NULL) { + if (lb_policy_name_dup != nullptr) { gpr_free(chand->info_lb_policy_name); chand->info_lb_policy_name = lb_policy_name_dup; } - if (service_config_json != NULL) { + if (service_config_json != nullptr) { gpr_free(chand->info_service_config_json); chand->info_service_config_json = service_config_json; } gpr_mu_unlock(&chand->info_mu); // Swap out the retry throttle data. - if (chand->retry_throttle_data != NULL) { + if (chand->retry_throttle_data != nullptr) { grpc_server_retry_throttle_data_unref(chand->retry_throttle_data); } chand->retry_throttle_data = retry_throttle_data; // Swap out the method params table. - if (chand->method_params_table != NULL) { + if (chand->method_params_table != nullptr) { grpc_slice_hash_table_unref(exec_ctx, chand->method_params_table); } chand->method_params_table = method_params_table; @@ -519,9 +519,9 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, // Note that we do NOT do this if either (a) we updated the existing // LB policy above or (b) we failed to create the new LB policy (in // which case we want to continue using the most recent one we had). - if (new_lb_policy != NULL || error != GRPC_ERROR_NONE || - chand->resolver == NULL) { - if (chand->lb_policy != NULL) { + if (new_lb_policy != nullptr || error != GRPC_ERROR_NONE || + chand->resolver == nullptr) { + if (chand->lb_policy != nullptr) { if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p: unreffing lb_policy=%p", chand, chand->lb_policy); @@ -535,17 +535,17 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, } // Now that we've swapped out the relevant fields of chand, check for // error or shutdown. - if (error != GRPC_ERROR_NONE || chand->resolver == NULL) { + if (error != GRPC_ERROR_NONE || chand->resolver == nullptr) { if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p: shutting down", chand); } - if (chand->resolver != NULL) { + if (chand->resolver != nullptr) { if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p: shutting down resolver", chand); } grpc_resolver_shutdown_locked(exec_ctx, chand->resolver); GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); - chand->resolver = NULL; + chand->resolver = nullptr; } set_channel_connectivity_state_locked( exec_ctx, chand, GRPC_CHANNEL_SHUTDOWN, @@ -562,7 +562,7 @@ static void on_resolver_result_changed_locked(grpc_exec_ctx* exec_ctx, grpc_connectivity_state state = GRPC_CHANNEL_TRANSIENT_FAILURE; grpc_error* state_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("No load balancing policy"); - if (new_lb_policy != NULL) { + if (new_lb_policy != nullptr) { if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p: initializing new LB policy", chand); } @@ -599,46 +599,46 @@ static void start_transport_op_locked(grpc_exec_ctx* exec_ctx, void* arg, (grpc_channel_element*)op->handler_private.extra_arg; channel_data* chand = (channel_data*)elem->channel_data; - if (op->on_connectivity_state_change != NULL) { + if (op->on_connectivity_state_change != nullptr) { grpc_connectivity_state_notify_on_state_change( exec_ctx, &chand->state_tracker, op->connectivity_state, op->on_connectivity_state_change); - op->on_connectivity_state_change = NULL; - op->connectivity_state = NULL; + op->on_connectivity_state_change = nullptr; + op->connectivity_state = nullptr; } - if (op->send_ping != NULL) { - if (chand->lb_policy == NULL) { + if (op->send_ping != nullptr) { + if (chand->lb_policy == nullptr) { GRPC_CLOSURE_SCHED( exec_ctx, op->send_ping, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Ping with no load balancing")); } else { grpc_lb_policy_ping_one_locked(exec_ctx, chand->lb_policy, op->send_ping); - op->bind_pollset = NULL; + op->bind_pollset = nullptr; } - op->send_ping = NULL; + op->send_ping = nullptr; } if (op->disconnect_with_error != GRPC_ERROR_NONE) { - if (chand->resolver != NULL) { + if (chand->resolver != nullptr) { set_channel_connectivity_state_locked( exec_ctx, chand, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(op->disconnect_with_error), "disconnect"); grpc_resolver_shutdown_locked(exec_ctx, chand->resolver); GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel"); - chand->resolver = NULL; + chand->resolver = nullptr; if (!chand->started_resolving) { grpc_closure_list_fail_all(&chand->waiting_for_resolver_result_closures, GRPC_ERROR_REF(op->disconnect_with_error)); GRPC_CLOSURE_LIST_SCHED(exec_ctx, &chand->waiting_for_resolver_result_closures); } - if (chand->lb_policy != NULL) { + if (chand->lb_policy != nullptr) { grpc_pollset_set_del_pollset_set(exec_ctx, chand->lb_policy->interested_parties, chand->interested_parties); GRPC_LB_POLICY_UNREF(exec_ctx, chand->lb_policy, "channel"); - chand->lb_policy = NULL; + chand->lb_policy = nullptr; } } GRPC_ERROR_UNREF(op->disconnect_with_error); @@ -654,7 +654,7 @@ static void cc_start_transport_op(grpc_exec_ctx* exec_ctx, channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(op->set_accept_stream == false); - if (op->bind_pollset != NULL) { + if (op->bind_pollset != nullptr) { grpc_pollset_set_add_pollset(exec_ctx, chand->interested_parties, op->bind_pollset); } @@ -673,15 +673,15 @@ static void cc_get_channel_info(grpc_exec_ctx* exec_ctx, const grpc_channel_info* info) { channel_data* chand = (channel_data*)elem->channel_data; gpr_mu_lock(&chand->info_mu); - if (info->lb_policy_name != NULL) { - *info->lb_policy_name = chand->info_lb_policy_name == NULL - ? NULL + if (info->lb_policy_name != nullptr) { + *info->lb_policy_name = chand->info_lb_policy_name == nullptr + ? nullptr : gpr_strdup(chand->info_lb_policy_name); } - if (info->service_config_json != NULL) { + if (info->service_config_json != nullptr) { *info->service_config_json = - chand->info_service_config_json == NULL - ? NULL + chand->info_service_config_json == nullptr + ? nullptr : gpr_strdup(chand->info_service_config_json); } gpr_mu_unlock(&chand->info_mu); @@ -700,7 +700,7 @@ static grpc_error* cc_init_channel_elem(grpc_exec_ctx* exec_ctx, gpr_mu_init(&chand->external_connectivity_watcher_list_mu); gpr_mu_lock(&chand->external_connectivity_watcher_list_mu); - chand->external_connectivity_watcher_list_head = NULL; + chand->external_connectivity_watcher_list_head = nullptr; gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu); chand->owning_stack = args->channel_stack; @@ -714,7 +714,7 @@ static grpc_error* cc_init_channel_elem(grpc_exec_ctx* exec_ctx, // Record client channel factory. const grpc_arg* arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_CLIENT_CHANNEL_FACTORY); - if (arg == NULL) { + if (arg == nullptr) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Missing client channel factory in args for client channel filter"); } @@ -728,7 +728,7 @@ static grpc_error* cc_init_channel_elem(grpc_exec_ctx* exec_ctx, (grpc_client_channel_factory*)arg->value.pointer.p; // Get server name to resolve, using proxy mapper if needed. arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVER_URI); - if (arg == NULL) { + if (arg == nullptr) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Missing server uri in args for client channel filter"); } @@ -736,18 +736,18 @@ static grpc_error* cc_init_channel_elem(grpc_exec_ctx* exec_ctx, return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "server uri arg must be a string"); } - char* proxy_name = NULL; - grpc_channel_args* new_args = NULL; + char* proxy_name = nullptr; + grpc_channel_args* new_args = nullptr; grpc_proxy_mappers_map_name(exec_ctx, arg->value.string, args->channel_args, &proxy_name, &new_args); // Instantiate resolver. chand->resolver = grpc_resolver_create( - exec_ctx, proxy_name != NULL ? proxy_name : arg->value.string, - new_args != NULL ? new_args : args->channel_args, + exec_ctx, proxy_name != nullptr ? proxy_name : arg->value.string, + new_args != nullptr ? new_args : args->channel_args, chand->interested_parties, chand->combiner); - if (proxy_name != NULL) gpr_free(proxy_name); - if (new_args != NULL) grpc_channel_args_destroy(exec_ctx, new_args); - if (chand->resolver == NULL) { + if (proxy_name != nullptr) gpr_free(proxy_name); + if (new_args != nullptr) grpc_channel_args_destroy(exec_ctx, new_args); + if (chand->resolver == nullptr) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING("resolver creation failed"); } chand->deadline_checking_enabled = @@ -766,17 +766,17 @@ static void shutdown_resolver_locked(grpc_exec_ctx* exec_ctx, void* arg, static void cc_destroy_channel_elem(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem) { channel_data* chand = (channel_data*)elem->channel_data; - if (chand->resolver != NULL) { + if (chand->resolver != nullptr) { GRPC_CLOSURE_SCHED( exec_ctx, GRPC_CLOSURE_CREATE(shutdown_resolver_locked, chand->resolver, grpc_combiner_scheduler(chand->combiner)), GRPC_ERROR_NONE); } - if (chand->client_channel_factory != NULL) { + if (chand->client_channel_factory != nullptr) { grpc_client_channel_factory_unref(exec_ctx, chand->client_channel_factory); } - if (chand->lb_policy != NULL) { + if (chand->lb_policy != nullptr) { grpc_pollset_set_del_pollset_set(exec_ctx, chand->lb_policy->interested_parties, chand->interested_parties); @@ -784,10 +784,10 @@ static void cc_destroy_channel_elem(grpc_exec_ctx* exec_ctx, } gpr_free(chand->info_lb_policy_name); gpr_free(chand->info_service_config_json); - if (chand->retry_throttle_data != NULL) { + if (chand->retry_throttle_data != nullptr) { grpc_server_retry_throttle_data_unref(chand->retry_throttle_data); } - if (chand->method_params_table != NULL) { + if (chand->method_params_table != nullptr) { grpc_slice_hash_table_unref(exec_ctx, chand->method_params_table); } grpc_client_channel_stop_backup_polling(exec_ctx, chand->interested_parties); @@ -870,7 +870,7 @@ grpc_subchannel_call* grpc_client_channel_get_subchannel_call( static void waiting_for_pick_batches_add( call_data* calld, grpc_transport_stream_op_batch* batch) { if (batch->send_initial_metadata) { - GPR_ASSERT(calld->initial_metadata_batch == NULL); + GPR_ASSERT(calld->initial_metadata_batch == nullptr); calld->initial_metadata_batch = batch; } else { GPR_ASSERT(calld->waiting_for_pick_batches_count < MAX_WAITING_BATCHES); @@ -912,7 +912,7 @@ static void waiting_for_pick_batches_fail(grpc_exec_ctx* exec_ctx, GRPC_ERROR_REF(error), "waiting_for_pick_batches_fail"); } - if (calld->initial_metadata_batch != NULL) { + if (calld->initial_metadata_batch != nullptr) { grpc_transport_stream_op_batch_finish_with_failure( exec_ctx, calld->initial_metadata_batch, GRPC_ERROR_REF(error), calld->call_combiner); @@ -956,7 +956,7 @@ static void waiting_for_pick_batches_resume(grpc_exec_ctx* exec_ctx, GRPC_ERROR_NONE, "waiting_for_pick_batches_resume"); } - GPR_ASSERT(calld->initial_metadata_batch != NULL); + GPR_ASSERT(calld->initial_metadata_batch != nullptr); grpc_subchannel_call_process_op(exec_ctx, calld->subchannel_call, calld->initial_metadata_batch); } @@ -971,14 +971,14 @@ static void apply_service_config_to_call_locked(grpc_exec_ctx* exec_ctx, gpr_log(GPR_DEBUG, "chand=%p calld=%p: applying service config to call", chand, calld); } - if (chand->retry_throttle_data != NULL) { + if (chand->retry_throttle_data != nullptr) { calld->retry_throttle_data = grpc_server_retry_throttle_data_ref(chand->retry_throttle_data); } - if (chand->method_params_table != NULL) { + if (chand->method_params_table != nullptr) { calld->method_params = (method_parameters*)grpc_method_config_table_get( exec_ctx, chand->method_params_table, calld->path); - if (calld->method_params != NULL) { + if (calld->method_params != nullptr) { method_parameters_ref(calld->method_params); // If the deadline from the service config is shorter than the one // from the client API, reset the deadline timer. @@ -1031,7 +1031,7 @@ static void pick_done_locked(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_error* error) { call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; - if (calld->connected_subchannel == NULL) { + if (calld->connected_subchannel == nullptr) { // Failed to create subchannel. GRPC_ERROR_UNREF(calld->error); calld->error = error == GRPC_ERROR_NONE @@ -1072,7 +1072,7 @@ static void pick_callback_cancel_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_call_element* elem = (grpc_call_element*)arg; channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; - if (calld->lb_policy != NULL) { + if (calld->lb_policy != nullptr) { if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: cancelling pick from LB policy %p", chand, calld, calld->lb_policy); @@ -1095,9 +1095,9 @@ static void pick_callback_done_locked(grpc_exec_ctx* exec_ctx, void* arg, gpr_log(GPR_DEBUG, "chand=%p calld=%p: pick completed asynchronously", chand, calld); } - GPR_ASSERT(calld->lb_policy != NULL); + GPR_ASSERT(calld->lb_policy != nullptr); GRPC_LB_POLICY_UNREF(exec_ctx, calld->lb_policy, "pick_subchannel"); - calld->lb_policy = NULL; + calld->lb_policy = nullptr; async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_REF(error)); } @@ -1123,7 +1123,7 @@ static bool pick_callback_start_locked(grpc_exec_ctx* exec_ctx, initial_metadata_flags & GRPC_INITIAL_METADATA_WAIT_FOR_READY_EXPLICITLY_SET; const bool wait_for_ready_set_from_service_config = - calld->method_params != NULL && + calld->method_params != nullptr && calld->method_params->wait_for_ready != WAIT_FOR_READY_UNSET; if (!wait_for_ready_set_from_api && wait_for_ready_set_from_service_config) { if (calld->method_params->wait_for_ready == WAIT_FOR_READY_TRUE) { @@ -1143,7 +1143,7 @@ static bool pick_callback_start_locked(grpc_exec_ctx* exec_ctx, grpc_combiner_scheduler(chand->combiner)); const bool pick_done = grpc_lb_policy_pick_locked( exec_ctx, chand->lb_policy, &inputs, &calld->connected_subchannel, - calld->subchannel_call_context, NULL, &calld->lb_pick_closure); + calld->subchannel_call_context, nullptr, &calld->lb_pick_closure); if (pick_done) { /* synchronous grpc_lb_policy_pick call. Unref the LB policy. */ if (GRPC_TRACER_ON(grpc_client_channel_trace)) { @@ -1151,7 +1151,7 @@ static bool pick_callback_start_locked(grpc_exec_ctx* exec_ctx, chand, calld); } GRPC_LB_POLICY_UNREF(exec_ctx, calld->lb_policy, "pick_subchannel"); - calld->lb_policy = NULL; + calld->lb_policy = nullptr; } else { GRPC_CALL_STACK_REF(calld->owning_call, "pick_callback_cancel"); grpc_call_combiner_set_notify_on_cancel( @@ -1231,7 +1231,7 @@ static void pick_after_resolver_result_done_locked(grpc_exec_ctx* exec_ctx, chand, calld); } async_pick_done_locked(exec_ctx, elem, GRPC_ERROR_REF(error)); - } else if (chand->lb_policy != NULL) { + } else if (chand->lb_policy != nullptr) { if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: resolver returned, doing pick", chand, calld); @@ -1252,7 +1252,7 @@ static void pick_after_resolver_result_done_locked(grpc_exec_ctx* exec_ctx, // removed in https://github.com/grpc/grpc/pull/12297. Need to figure // out what is actually causing this to occur and then figure out the // right way to deal with it. - else if (chand->resolver != NULL) { + else if (chand->resolver != nullptr) { // No LB policy, so try again. if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, @@ -1299,8 +1299,8 @@ static void start_pick_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; channel_data* chand = (channel_data*)elem->channel_data; - GPR_ASSERT(calld->connected_subchannel == NULL); - if (chand->lb_policy != NULL) { + GPR_ASSERT(calld->connected_subchannel == nullptr); + if (chand->lb_policy != nullptr) { // We already have an LB policy, so ask it for a pick. if (pick_callback_start_locked(exec_ctx, elem)) { // Pick completed synchronously. @@ -1309,7 +1309,7 @@ static void start_pick_locked(grpc_exec_ctx* exec_ctx, void* arg, } } else { // We do not yet have an LB policy, so wait for a resolver result. - if (chand->resolver == NULL) { + if (chand->resolver == nullptr) { pick_done_locked(exec_ctx, elem, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Disconnected")); return; @@ -1331,7 +1331,7 @@ static void start_pick_locked(grpc_exec_ctx* exec_ctx, void* arg, static void on_complete(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)arg; call_data* calld = (call_data*)elem->call_data; - if (calld->retry_throttle_data != NULL) { + if (calld->retry_throttle_data != nullptr) { if (error == GRPC_ERROR_NONE) { grpc_server_retry_throttle_data_record_success( calld->retry_throttle_data); @@ -1382,7 +1382,7 @@ static void cc_start_transport_stream_op_batch( } // If we have a subchannel call, send the cancellation batch down. // Otherwise, fail all pending batches. - if (calld->subchannel_call != NULL) { + if (calld->subchannel_call != nullptr) { grpc_subchannel_call_process_op(exec_ctx, calld->subchannel_call, batch); } else { waiting_for_pick_batches_add(calld, batch); @@ -1394,7 +1394,7 @@ static void cc_start_transport_stream_op_batch( // Intercept on_complete for recv_trailing_metadata so that we can // check retry throttle status. if (batch->recv_trailing_metadata) { - GPR_ASSERT(batch->on_complete != NULL); + GPR_ASSERT(batch->on_complete != nullptr); calld->original_on_complete = batch->on_complete; GRPC_CLOSURE_INIT(&calld->on_complete, on_complete, elem, grpc_schedule_on_exec_ctx); @@ -1404,7 +1404,7 @@ static void cc_start_transport_stream_op_batch( // Note that once we have completed the pick, we do not need to enter // the channel combiner, which is more efficient (especially for // streaming calls). - if (calld->subchannel_call != NULL) { + if (calld->subchannel_call != nullptr) { if (GRPC_TRACER_ON(grpc_client_channel_trace)) { gpr_log(GPR_DEBUG, "chand=%p calld=%p: sending batch to subchannel_call=%p", chand, @@ -1473,25 +1473,25 @@ static void cc_destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_deadline_state_destroy(exec_ctx, elem); } grpc_slice_unref_internal(exec_ctx, calld->path); - if (calld->method_params != NULL) { + if (calld->method_params != nullptr) { method_parameters_unref(calld->method_params); } GRPC_ERROR_UNREF(calld->error); - if (calld->subchannel_call != NULL) { + if (calld->subchannel_call != nullptr) { grpc_subchannel_call_set_cleanup_closure(calld->subchannel_call, then_schedule_closure); - then_schedule_closure = NULL; + then_schedule_closure = nullptr; GRPC_SUBCHANNEL_CALL_UNREF(exec_ctx, calld->subchannel_call, "client_channel_destroy_call"); } - GPR_ASSERT(calld->lb_policy == NULL); + GPR_ASSERT(calld->lb_policy == nullptr); GPR_ASSERT(calld->waiting_for_pick_batches_count == 0); - if (calld->connected_subchannel != NULL) { + if (calld->connected_subchannel != nullptr) { GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, calld->connected_subchannel, "picked"); } for (size_t i = 0; i < GRPC_CONTEXT_COUNT; ++i) { - if (calld->subchannel_call_context[i].value != NULL) { + if (calld->subchannel_call_context[i].value != nullptr) { calld->subchannel_call_context[i].destroy( calld->subchannel_call_context[i].value); } @@ -1527,11 +1527,11 @@ const grpc_channel_filter grpc_client_channel_filter = { static void try_to_connect_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error_ignored) { channel_data* chand = (channel_data*)arg; - if (chand->lb_policy != NULL) { + if (chand->lb_policy != nullptr) { grpc_lb_policy_exit_idle_locked(exec_ctx, chand->lb_policy); } else { chand->exit_idle_when_lb_policy_arrives = true; - if (!chand->started_resolving && chand->resolver != NULL) { + if (!chand->started_resolving && chand->resolver != nullptr) { start_resolving_locked(exec_ctx, chand); } } @@ -1569,7 +1569,7 @@ static external_connectivity_watcher* lookup_external_connectivity_watcher( gpr_mu_lock(&chand->external_connectivity_watcher_list_mu); external_connectivity_watcher* w = chand->external_connectivity_watcher_list_head; - while (w != NULL && w->on_complete != on_complete) { + while (w != nullptr && w->on_complete != on_complete) { w = w->next; } gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu); @@ -1599,7 +1599,7 @@ static void external_connectivity_watcher_list_remove( } external_connectivity_watcher* w = chand->external_connectivity_watcher_list_head; - while (w != NULL) { + while (w != nullptr) { if (w->next == too_remove) { w->next = w->next->next; gpr_mu_unlock(&chand->external_connectivity_watcher_list_mu); @@ -1618,7 +1618,7 @@ int grpc_client_channel_num_external_connectivity_watchers( gpr_mu_lock(&chand->external_connectivity_watcher_list_mu); external_connectivity_watcher* w = chand->external_connectivity_watcher_list_head; - while (w != NULL) { + while (w != nullptr) { count++; w = w->next; } @@ -1643,8 +1643,8 @@ static void on_external_watch_complete_locked(grpc_exec_ctx* exec_ctx, static void watch_connectivity_state_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error_ignored) { external_connectivity_watcher* w = (external_connectivity_watcher*)arg; - external_connectivity_watcher* found = NULL; - if (w->state != NULL) { + external_connectivity_watcher* found = nullptr; + if (w->state != nullptr) { external_connectivity_watcher_list_append(w->chand, w); GRPC_CLOSURE_RUN(exec_ctx, w->watcher_timer_init, GRPC_ERROR_NONE); GRPC_CLOSURE_INIT(&w->my_closure, on_external_watch_complete_locked, w, @@ -1652,12 +1652,12 @@ static void watch_connectivity_state_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_connectivity_state_notify_on_state_change( exec_ctx, &w->chand->state_tracker, w->state, &w->my_closure); } else { - GPR_ASSERT(w->watcher_timer_init == NULL); + GPR_ASSERT(w->watcher_timer_init == nullptr); found = lookup_external_connectivity_watcher(w->chand, w->on_complete); if (found) { GPR_ASSERT(found->on_complete == w->on_complete); grpc_connectivity_state_notify_on_state_change( - exec_ctx, &found->chand->state_tracker, NULL, &found->my_closure); + exec_ctx, &found->chand->state_tracker, nullptr, &found->my_closure); } grpc_polling_entity_del_from_pollset_set(exec_ctx, &w->pollent, w->chand->interested_parties); diff --git a/src/core/ext/filters/client_channel/client_channel_plugin.cc b/src/core/ext/filters/client_channel/client_channel_plugin.cc index 0db894913c..eebef6827c 100644 --- a/src/core/ext/filters/client_channel/client_channel_plugin.cc +++ b/src/core/ext/filters/client_channel/client_channel_plugin.cc @@ -37,7 +37,7 @@ static bool append_filter(grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_append_filter( - builder, (const grpc_channel_filter*)arg, NULL, NULL); + builder, (const grpc_channel_filter*)arg, nullptr, nullptr); } static bool set_default_host_if_unset(grpc_exec_ctx* exec_ctx, @@ -53,7 +53,7 @@ static bool set_default_host_if_unset(grpc_exec_ctx* exec_ctx, } char* default_authority = grpc_get_default_authority( exec_ctx, grpc_channel_stack_builder_get_target(builder)); - if (default_authority != NULL) { + if (default_authority != nullptr) { grpc_arg arg = grpc_channel_arg_string_create( (char*)GRPC_ARG_DEFAULT_AUTHORITY, default_authority); grpc_channel_args* new_args = grpc_channel_args_copy_and_add(args, &arg, 1); @@ -73,7 +73,7 @@ extern "C" void grpc_client_channel_init(void) { grpc_register_http_proxy_mapper(); grpc_subchannel_index_init(); grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MIN, - set_default_host_if_unset, NULL); + set_default_host_if_unset, nullptr); grpc_channel_init_register_stage( GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter, (void*)&grpc_client_channel_filter); diff --git a/src/core/ext/filters/client_channel/http_connect_handshaker.cc b/src/core/ext/filters/client_channel/http_connect_handshaker.cc index 418bb41ef6..b7cb2e3eba 100644 --- a/src/core/ext/filters/client_channel/http_connect_handshaker.cc +++ b/src/core/ext/filters/client_channel/http_connect_handshaker.cc @@ -65,10 +65,10 @@ static void http_connect_handshaker_unref(grpc_exec_ctx* exec_ctx, http_connect_handshaker* handshaker) { if (gpr_unref(&handshaker->refcount)) { gpr_mu_destroy(&handshaker->mu); - if (handshaker->endpoint_to_destroy != NULL) { + if (handshaker->endpoint_to_destroy != nullptr) { grpc_endpoint_destroy(exec_ctx, handshaker->endpoint_to_destroy); } - if (handshaker->read_buffer_to_destroy != NULL) { + if (handshaker->read_buffer_to_destroy != nullptr) { grpc_slice_buffer_destroy_internal(exec_ctx, handshaker->read_buffer_to_destroy); gpr_free(handshaker->read_buffer_to_destroy); @@ -85,11 +85,11 @@ static void http_connect_handshaker_unref(grpc_exec_ctx* exec_ctx, static void cleanup_args_for_failure_locked( grpc_exec_ctx* exec_ctx, http_connect_handshaker* handshaker) { handshaker->endpoint_to_destroy = handshaker->args->endpoint; - handshaker->args->endpoint = NULL; + handshaker->args->endpoint = nullptr; handshaker->read_buffer_to_destroy = handshaker->args->read_buffer; - handshaker->args->read_buffer = NULL; + handshaker->args->read_buffer = nullptr; grpc_channel_args_destroy(exec_ctx, handshaker->args->args); - handshaker->args->args = NULL; + handshaker->args->args = nullptr; } // If the handshake failed or we're shutting down, clean up and invoke the @@ -260,7 +260,7 @@ static void http_connect_handshaker_do_handshake( // If not found, invoke on_handshake_done without doing anything. const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_HTTP_CONNECT_SERVER); - if (arg == NULL) { + if (arg == nullptr) { // Set shutdown to true so that subsequent calls to // http_connect_handshaker_shutdown() do nothing. gpr_mu_lock(&handshaker->mu); @@ -273,11 +273,11 @@ static void http_connect_handshaker_do_handshake( char* server_name = arg->value.string; // Get headers from channel args. arg = grpc_channel_args_find(args->args, GRPC_ARG_HTTP_CONNECT_HEADERS); - grpc_http_header* headers = NULL; + grpc_http_header* headers = nullptr; size_t num_headers = 0; - char** header_strings = NULL; + char** header_strings = nullptr; size_t num_header_strings = 0; - if (arg != NULL) { + if (arg != nullptr) { GPR_ASSERT(arg->type == GRPC_ARG_STRING); gpr_string_split(arg->value.string, "\n", &header_strings, &num_header_strings); @@ -285,7 +285,7 @@ static void http_connect_handshaker_do_handshake( num_header_strings); for (size_t i = 0; i < num_header_strings; ++i) { char* sep = strchr(header_strings[i], ':'); - if (sep == NULL) { + if (sep == nullptr) { gpr_log(GPR_ERROR, "skipping unparseable HTTP CONNECT header: %s", header_strings[i]); continue; diff --git a/src/core/ext/filters/client_channel/http_proxy.cc b/src/core/ext/filters/client_channel/http_proxy.cc index a16b44d3dc..405d8c0e55 100644 --- a/src/core/ext/filters/client_channel/http_proxy.cc +++ b/src/core/ext/filters/client_channel/http_proxy.cc @@ -41,15 +41,15 @@ * responsibility to gpr_free user_cred. */ static char* get_http_proxy_server(grpc_exec_ctx* exec_ctx, char** user_cred) { - GPR_ASSERT(user_cred != NULL); - char* proxy_name = NULL; + GPR_ASSERT(user_cred != nullptr); + char* proxy_name = nullptr; char* uri_str = gpr_getenv("http_proxy"); - char** authority_strs = NULL; + char** authority_strs = nullptr; size_t authority_nstrs; - if (uri_str == NULL) return NULL; + if (uri_str == nullptr) return nullptr; grpc_uri* uri = grpc_uri_parse(exec_ctx, uri_str, false /* suppress_errors */); - if (uri == NULL || uri->authority == NULL) { + if (uri == nullptr || uri->authority == nullptr) { gpr_log(GPR_ERROR, "cannot parse value of 'http_proxy' env var"); goto done; } @@ -73,7 +73,7 @@ static char* get_http_proxy_server(grpc_exec_ctx* exec_ctx, char** user_cred) { for (size_t i = 0; i < authority_nstrs; i++) { gpr_free(authority_strs[i]); } - proxy_name = NULL; + proxy_name = nullptr; } gpr_free(authority_strs); done: @@ -88,13 +88,13 @@ static bool proxy_mapper_map_name(grpc_exec_ctx* exec_ctx, const grpc_channel_args* args, char** name_to_resolve, grpc_channel_args** new_args) { - char* user_cred = NULL; + char* user_cred = nullptr; *name_to_resolve = get_http_proxy_server(exec_ctx, &user_cred); - if (*name_to_resolve == NULL) return false; - char* no_proxy_str = NULL; + if (*name_to_resolve == nullptr) return false; + char* no_proxy_str = nullptr; grpc_uri* uri = grpc_uri_parse(exec_ctx, server_uri, false /* suppress_errors */); - if (uri == NULL || uri->path[0] == '\0') { + if (uri == nullptr || uri->path[0] == '\0') { gpr_log(GPR_ERROR, "'http_proxy' environment variable set, but cannot " "parse server URI '%s' -- not using proxy", @@ -107,7 +107,7 @@ static bool proxy_mapper_map_name(grpc_exec_ctx* exec_ctx, goto no_use_proxy; } no_proxy_str = gpr_getenv("no_proxy"); - if (no_proxy_str != NULL) { + if (no_proxy_str != nullptr) { static const char* NO_PROXY_SEPARATOR = ","; bool use_proxy = true; char* server_host; @@ -149,7 +149,7 @@ static bool proxy_mapper_map_name(grpc_exec_ctx* exec_ctx, args_to_add[0] = grpc_channel_arg_string_create( (char*)GRPC_ARG_HTTP_CONNECT_SERVER, uri->path[0] == '/' ? uri->path + 1 : uri->path); - if (user_cred != NULL) { + if (user_cred != nullptr) { /* Use base64 encoding for user credentials as stated in RFC 7617 */ char* encoded_user_cred = grpc_base64_encode(user_cred, strlen(user_cred), 0, 0); @@ -167,9 +167,9 @@ static bool proxy_mapper_map_name(grpc_exec_ctx* exec_ctx, gpr_free(user_cred); return true; no_use_proxy: - if (uri != NULL) grpc_uri_destroy(uri); + if (uri != nullptr) grpc_uri_destroy(uri); gpr_free(*name_to_resolve); - *name_to_resolve = NULL; + *name_to_resolve = nullptr; gpr_free(user_cred); return false; } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc index d93a9c3710..6d9fadaf30 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc @@ -72,8 +72,8 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; // Get stats object from context and take a ref. - GPR_ASSERT(args->context != NULL); - GPR_ASSERT(args->context[GRPC_GRPCLB_CLIENT_STATS].value != NULL); + GPR_ASSERT(args->context != nullptr); + GPR_ASSERT(args->context[GRPC_GRPCLB_CLIENT_STATS].value != nullptr); calld->client_stats = grpc_grpclb_client_stats_ref( (grpc_grpclb_client_stats*)args->context[GRPC_GRPCLB_CLIENT_STATS].value); // Record call started. diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index 01b243bc3e..a3282b5d93 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -133,7 +133,7 @@ grpc_tracer_flag grpc_lb_glb_trace = GRPC_TRACER_INITIALIZER(false, "glb"); static grpc_error* initial_metadata_add_lb_token( grpc_exec_ctx* exec_ctx, grpc_metadata_batch* initial_metadata, grpc_linked_mdelem* lb_token_mdelem_storage, grpc_mdelem lb_token) { - GPR_ASSERT(lb_token_mdelem_storage != NULL); + GPR_ASSERT(lb_token_mdelem_storage != nullptr); GPR_ASSERT(!GRPC_MDISNULL(lb_token)); return grpc_metadata_batch_add_tail(exec_ctx, initial_metadata, lb_token_mdelem_storage, lb_token); @@ -186,14 +186,14 @@ static void wrapped_rr_closure(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { wrapped_rr_closure_arg* wc_arg = (wrapped_rr_closure_arg*)arg; - GPR_ASSERT(wc_arg->wrapped_closure != NULL); + GPR_ASSERT(wc_arg->wrapped_closure != nullptr); GRPC_CLOSURE_SCHED(exec_ctx, wc_arg->wrapped_closure, GRPC_ERROR_REF(error)); - if (wc_arg->rr_policy != NULL) { + if (wc_arg->rr_policy != nullptr) { /* if *target is NULL, no pick has been made by the RR policy (eg, all * addresses failed to connect). There won't be any user_data/token * available */ - if (*wc_arg->target != NULL) { + if (*wc_arg->target != nullptr) { if (!GRPC_MDISNULL(wc_arg->lb_token)) { initial_metadata_add_lb_token(exec_ctx, wc_arg->initial_metadata, wc_arg->lb_token_mdelem_storage, @@ -206,7 +206,7 @@ static void wrapped_rr_closure(grpc_exec_ctx* exec_ctx, void* arg, abort(); } // Pass on client stats via context. Passes ownership of the reference. - GPR_ASSERT(wc_arg->client_stats != NULL); + GPR_ASSERT(wc_arg->client_stats != nullptr); wc_arg->context[GRPC_GRPCLB_CLIENT_STATS].value = wc_arg->client_stats; wc_arg->context[GRPC_GRPCLB_CLIENT_STATS].destroy = destroy_client_stats; } else { @@ -217,7 +217,7 @@ static void wrapped_rr_closure(grpc_exec_ctx* exec_ctx, void* arg, } GRPC_LB_POLICY_UNREF(exec_ctx, wc_arg->rr_policy, "wrapped_rr_closure"); } - GPR_ASSERT(wc_arg->free_when_done != NULL); + GPR_ASSERT(wc_arg->free_when_done != nullptr); gpr_free(wc_arg->free_when_done); } @@ -454,7 +454,7 @@ static void* lb_token_copy(void* token) { : (void*)GRPC_MDELEM_REF(grpc_mdelem{(uintptr_t)token}).payload; } static void lb_token_destroy(grpc_exec_ctx* exec_ctx, void* token) { - if (token != NULL) { + if (token != nullptr) { GRPC_MDELEM_UNREF(exec_ctx, grpc_mdelem{(uintptr_t)token}); } } @@ -537,7 +537,7 @@ static grpc_lb_addresses* process_serverlist_locked( grpc_lb_addresses_set_address(lb_addresses, addr_idx, &addr.addr, addr.len, false /* is_balancer */, - NULL /* balancer_name */, user_data); + nullptr /* balancer_name */, user_data); ++addr_idx; } GPR_ASSERT(addr_idx == num_valid); @@ -637,7 +637,7 @@ static bool pick_from_internal_rr_locked( const grpc_lb_policy_pick_args* pick_args, bool force_async, grpc_connected_subchannel** target, wrapped_rr_closure_arg* wc_arg) { // Check for drops if we are not using fallback backend addresses. - if (glb_policy->serverlist != NULL) { + if (glb_policy->serverlist != nullptr) { // Look at the index into the serverlist to see if we should drop this call. grpc_grpclb_server* server = glb_policy->serverlist->servers[glb_policy->serverlist_index++]; @@ -660,7 +660,7 @@ static bool pick_from_internal_rr_locked( server->load_balance_token, wc_arg->client_stats); grpc_grpclb_client_stats_unref(wc_arg->client_stats); if (force_async) { - GPR_ASSERT(wc_arg->wrapped_closure != NULL); + GPR_ASSERT(wc_arg->wrapped_closure != nullptr); GRPC_CLOSURE_SCHED(exec_ctx, wc_arg->wrapped_closure, GRPC_ERROR_NONE); gpr_free(wc_arg->free_when_done); return false; @@ -685,11 +685,11 @@ static bool pick_from_internal_rr_locked( pick_args->lb_token_mdelem_storage, GRPC_MDELEM_REF(wc_arg->lb_token)); // Pass on client stats via context. Passes ownership of the reference. - GPR_ASSERT(wc_arg->client_stats != NULL); + GPR_ASSERT(wc_arg->client_stats != nullptr); wc_arg->context[GRPC_GRPCLB_CLIENT_STATS].value = wc_arg->client_stats; wc_arg->context[GRPC_GRPCLB_CLIENT_STATS].destroy = destroy_client_stats; if (force_async) { - GPR_ASSERT(wc_arg->wrapped_closure != NULL); + GPR_ASSERT(wc_arg->wrapped_closure != nullptr); GRPC_CLOSURE_SCHED(exec_ctx, wc_arg->wrapped_closure, GRPC_ERROR_NONE); gpr_free(wc_arg->free_when_done); return false; @@ -706,7 +706,7 @@ static bool pick_from_internal_rr_locked( static grpc_lb_policy_args* lb_policy_args_create(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy) { grpc_lb_addresses* addresses; - if (glb_policy->serverlist != NULL) { + if (glb_policy->serverlist != nullptr) { GPR_ASSERT(glb_policy->serverlist->num_servers > 0); addresses = process_serverlist_locked(exec_ctx, glb_policy->serverlist); } else { @@ -714,10 +714,10 @@ static grpc_lb_policy_args* lb_policy_args_create(grpc_exec_ctx* exec_ctx, // serverlist from the balancer, we use the fallback backends returned by // the resolver. Note that the fallback backend list may be empty, in which // case the new round_robin policy will keep the requested picks pending. - GPR_ASSERT(glb_policy->fallback_backend_addresses != NULL); + GPR_ASSERT(glb_policy->fallback_backend_addresses != nullptr); addresses = grpc_lb_addresses_copy(glb_policy->fallback_backend_addresses); } - GPR_ASSERT(addresses != NULL); + GPR_ASSERT(addresses != nullptr); grpc_lb_policy_args* args = (grpc_lb_policy_args*)gpr_zalloc(sizeof(*args)); args->client_channel_factory = glb_policy->cc_factory; args->combiner = glb_policy->base.combiner; @@ -742,11 +742,11 @@ static void glb_rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error); static void create_rr_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, grpc_lb_policy_args* args) { - GPR_ASSERT(glb_policy->rr_policy == NULL); + GPR_ASSERT(glb_policy->rr_policy == nullptr); grpc_lb_policy* new_rr_policy = grpc_lb_policy_create(exec_ctx, "round_robin", args); - if (new_rr_policy == NULL) { + if (new_rr_policy == nullptr) { gpr_log(GPR_ERROR, "Failure creating a RoundRobin policy for serverlist update with " "%lu entries. The previous RR instance (%p), if any, will continue " @@ -757,7 +757,7 @@ static void create_rr_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, return; } glb_policy->rr_policy = new_rr_policy; - grpc_error* rr_state_error = NULL; + grpc_error* rr_state_error = nullptr; const grpc_connectivity_state rr_state = grpc_lb_policy_check_connectivity_locked(exec_ctx, glb_policy->rr_policy, &rr_state_error); @@ -824,8 +824,8 @@ static void rr_handover_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy) { if (glb_policy->shutting_down) return; grpc_lb_policy_args* args = lb_policy_args_create(exec_ctx, glb_policy); - GPR_ASSERT(args != NULL); - if (glb_policy->rr_policy != NULL) { + GPR_ASSERT(args != nullptr); + if (glb_policy->rr_policy != nullptr) { if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log(GPR_DEBUG, "Updating Round Robin policy (%p)", (void*)glb_policy->rr_policy); @@ -857,7 +857,7 @@ static void glb_rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, * sink, policies can't transition back from it. .*/ GRPC_LB_POLICY_UNREF(exec_ctx, glb_policy->rr_policy, "rr_connectivity_shutdown"); - glb_policy->rr_policy = NULL; + glb_policy->rr_policy = nullptr; GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, "glb_rr_connectivity_cb"); gpr_free(rr_connectivity); @@ -912,7 +912,7 @@ static grpc_channel_args* build_lb_channel_args( * instantiated and used in that case. Otherwise, something has gone wrong. */ GPR_ASSERT(num_grpclb_addrs > 0); grpc_lb_addresses* lb_addresses = - grpc_lb_addresses_create(num_grpclb_addrs, NULL); + grpc_lb_addresses_create(num_grpclb_addrs, nullptr); grpc_slice_hash_table_entry* targets_info_entries = (grpc_slice_hash_table_entry*)gpr_zalloc(sizeof(*targets_info_entries) * num_grpclb_addrs); @@ -920,7 +920,7 @@ static grpc_channel_args* build_lb_channel_args( size_t lb_addresses_idx = 0; for (size_t i = 0; i < addresses->num_addresses; ++i) { if (!addresses->addresses[i].is_balancer) continue; - if (addresses->addresses[i].user_data != NULL) { + if (addresses->addresses[i].user_data != nullptr) { gpr_log(GPR_ERROR, "This LB policy doesn't support user data. It will be ignored"); } @@ -934,7 +934,7 @@ static grpc_channel_args* build_lb_channel_args( grpc_lb_addresses_set_address( lb_addresses, lb_addresses_idx++, addresses->addresses[i].address.addr, addresses->addresses[i].address.len, false /* is balancer */, - addresses->addresses[i].balancer_name, NULL /* user data */); + addresses->addresses[i].balancer_name, nullptr /* user data */); } GPR_ASSERT(num_grpclb_addrs == lb_addresses_idx); grpc_slice_hash_table* targets_info = @@ -959,18 +959,18 @@ static grpc_channel_args* build_lb_channel_args( static void glb_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; - GPR_ASSERT(glb_policy->pending_picks == NULL); - GPR_ASSERT(glb_policy->pending_pings == NULL); + GPR_ASSERT(glb_policy->pending_picks == nullptr); + GPR_ASSERT(glb_policy->pending_pings == nullptr); gpr_free((void*)glb_policy->server_name); grpc_channel_args_destroy(exec_ctx, glb_policy->args); - if (glb_policy->client_stats != NULL) { + if (glb_policy->client_stats != nullptr) { grpc_grpclb_client_stats_unref(glb_policy->client_stats); } grpc_connectivity_state_destroy(exec_ctx, &glb_policy->state_tracker); - if (glb_policy->serverlist != NULL) { + if (glb_policy->serverlist != nullptr) { grpc_grpclb_destroy_serverlist(glb_policy->serverlist); } - if (glb_policy->fallback_backend_addresses != NULL) { + if (glb_policy->fallback_backend_addresses != nullptr) { grpc_lb_addresses_destroy(exec_ctx, glb_policy->fallback_backend_addresses); } grpc_fake_resolver_response_generator_unref(glb_policy->response_generator); @@ -991,8 +991,8 @@ static void glb_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { * because glb_policy->lb_call is only assigned in lb_call_init_locked as part * of query_for_backends_locked, which can only be invoked while * glb_policy->shutting_down is false. */ - if (lb_call != NULL) { - grpc_call_cancel(lb_call, NULL); + if (lb_call != nullptr) { + grpc_call_cancel(lb_call, nullptr); /* lb_on_server_status_received will pick up the cancel and clean up */ } if (glb_policy->retry_timer_active) { @@ -1005,27 +1005,27 @@ static void glb_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { } pending_pick* pp = glb_policy->pending_picks; - glb_policy->pending_picks = NULL; + glb_policy->pending_picks = nullptr; pending_ping* pping = glb_policy->pending_pings; - glb_policy->pending_pings = NULL; - if (glb_policy->rr_policy != NULL) { + glb_policy->pending_pings = nullptr; + if (glb_policy->rr_policy != nullptr) { GRPC_LB_POLICY_UNREF(exec_ctx, glb_policy->rr_policy, "glb_shutdown"); } // We destroy the LB channel here because // glb_lb_channel_on_connectivity_changed_cb needs a valid glb_policy // instance. Destroying the lb channel in glb_destroy would likely result in // a callback invocation without a valid glb_policy arg. - if (glb_policy->lb_channel != NULL) { + if (glb_policy->lb_channel != nullptr) { grpc_channel_destroy(glb_policy->lb_channel); - glb_policy->lb_channel = NULL; + glb_policy->lb_channel = nullptr; } grpc_connectivity_state_set( exec_ctx, &glb_policy->state_tracker, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel Shutdown"), "glb_shutdown"); - while (pp != NULL) { + while (pp != nullptr) { pending_pick* next = pp->next; - *pp->target = NULL; + *pp->target = nullptr; GRPC_CLOSURE_SCHED( exec_ctx, &pp->wrapped_on_complete_arg.wrapper_closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel Shutdown")); @@ -1033,7 +1033,7 @@ static void glb_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { pp = next; } - while (pping != NULL) { + while (pping != nullptr) { pending_ping* next = pping->next; GRPC_CLOSURE_SCHED( exec_ctx, &pping->wrapped_notify_arg.wrapper_closure, @@ -1058,11 +1058,11 @@ static void glb_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; pending_pick* pp = glb_policy->pending_picks; - glb_policy->pending_picks = NULL; - while (pp != NULL) { + glb_policy->pending_picks = nullptr; + while (pp != nullptr) { pending_pick* next = pp->next; if (pp->target == target) { - *target = NULL; + *target = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, &pp->wrapped_on_complete_arg.wrapper_closure, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick Cancelled", &error, 1)); @@ -1072,7 +1072,7 @@ static void glb_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, } pp = next; } - if (glb_policy->rr_policy != NULL) { + if (glb_policy->rr_policy != nullptr) { grpc_lb_policy_cancel_pick_locked(exec_ctx, glb_policy->rr_policy, target, GRPC_ERROR_REF(error)); } @@ -1096,8 +1096,8 @@ static void glb_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)pol; pending_pick* pp = glb_policy->pending_picks; - glb_policy->pending_picks = NULL; - while (pp != NULL) { + glb_policy->pending_picks = nullptr; + while (pp != nullptr) { pending_pick* next = pp->next; if ((pp->pick_args.initial_metadata_flags & initial_metadata_flags_mask) == initial_metadata_flags_eq) { @@ -1110,7 +1110,7 @@ static void glb_cancel_picks_locked(grpc_exec_ctx* exec_ctx, } pp = next; } - if (glb_policy->rr_policy != NULL) { + if (glb_policy->rr_policy != nullptr) { grpc_lb_policy_cancel_picks_locked( exec_ctx, glb_policy->rr_policy, initial_metadata_flags_mask, initial_metadata_flags_eq, GRPC_ERROR_REF(error)); @@ -1126,7 +1126,7 @@ static void start_picking_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy) { /* start a timer to fall back */ if (glb_policy->lb_fallback_timeout_ms > 0 && - glb_policy->serverlist == NULL && !glb_policy->fallback_timer_active) { + glb_policy->serverlist == nullptr && !glb_policy->fallback_timer_active) { grpc_millis deadline = grpc_exec_ctx_now(exec_ctx) + glb_policy->lb_fallback_timeout_ms; GRPC_LB_POLICY_WEAK_REF(&glb_policy->base, "grpclb_fallback_timer"); @@ -1155,8 +1155,8 @@ static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_connected_subchannel** target, grpc_call_context_element* context, void** user_data, grpc_closure* on_complete) { - if (pick_args->lb_token_mdelem_storage == NULL) { - *target = NULL; + if (pick_args->lb_token_mdelem_storage == nullptr) { + *target = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, on_complete, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "No mdelem storage for the LB token. Load reporting " @@ -1165,10 +1165,10 @@ static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, } glb_lb_policy* glb_policy = (glb_lb_policy*)pol; bool pick_done = false; - if (glb_policy->rr_policy != NULL) { + if (glb_policy->rr_policy != nullptr) { const grpc_connectivity_state rr_connectivity_state = grpc_lb_policy_check_connectivity_locked(exec_ctx, - glb_policy->rr_policy, NULL); + glb_policy->rr_policy, nullptr); // The glb_policy->rr_policy may have transitioned to SHUTDOWN but the // callback registered to capture this event // (glb_rr_connectivity_changed_locked) may not have been invoked yet. We @@ -1197,7 +1197,7 @@ static int glb_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, wc_arg->rr_policy = glb_policy->rr_policy; wc_arg->target = target; wc_arg->context = context; - GPR_ASSERT(glb_policy->client_stats != NULL); + GPR_ASSERT(glb_policy->client_stats != nullptr); wc_arg->client_stats = grpc_grpclb_client_stats_ref(glb_policy->client_stats); wc_arg->wrapped_closure = on_complete; @@ -1264,7 +1264,7 @@ static void lb_call_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, gpr_log(GPR_INFO, "Restaring call to LB server (grpclb %p)", (void*)glb_policy); } - GPR_ASSERT(glb_policy->lb_call == NULL); + GPR_ASSERT(glb_policy->lb_call == nullptr); query_for_backends_locked(exec_ctx, glb_policy); } GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, "grpclb_retry_timer"); @@ -1325,8 +1325,8 @@ static void client_load_report_done_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; grpc_byte_buffer_destroy(glb_policy->client_load_report_payload); - glb_policy->client_load_report_payload = NULL; - if (error != GRPC_ERROR_NONE || glb_policy->lb_call == NULL) { + glb_policy->client_load_report_payload = nullptr; + if (error != GRPC_ERROR_NONE || glb_policy->lb_call == nullptr) { glb_policy->client_load_report_timer_pending = false; GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, "client_load_report"); @@ -1344,23 +1344,23 @@ static bool load_report_counters_are_zero(grpc_grpclb_request* request) { request->client_stats.num_calls_finished_with_client_failed_to_send == 0 && request->client_stats.num_calls_finished_known_received == 0 && - (drop_entries == NULL || drop_entries->num_entries == 0); + (drop_entries == nullptr || drop_entries->num_entries == 0); } static void send_client_load_report_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; - if (error == GRPC_ERROR_CANCELLED || glb_policy->lb_call == NULL) { + if (error == GRPC_ERROR_CANCELLED || glb_policy->lb_call == nullptr) { glb_policy->client_load_report_timer_pending = false; GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, &glb_policy->base, "client_load_report"); - if (glb_policy->lb_call == NULL) { + if (glb_policy->lb_call == nullptr) { maybe_restart_lb_call(exec_ctx, glb_policy); } return; } // Construct message payload. - GPR_ASSERT(glb_policy->client_load_report_payload == NULL); + GPR_ASSERT(glb_policy->client_load_report_payload == nullptr); grpc_grpclb_request* request = grpc_grpclb_load_report_request_create_locked(glb_policy->client_stats); // Skip client load report if the counters were all zero in the last @@ -1403,9 +1403,9 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error); static void lb_call_init_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy) { - GPR_ASSERT(glb_policy->server_name != NULL); + GPR_ASSERT(glb_policy->server_name != nullptr); GPR_ASSERT(glb_policy->server_name[0] != '\0'); - GPR_ASSERT(glb_policy->lb_call == NULL); + GPR_ASSERT(glb_policy->lb_call == nullptr); GPR_ASSERT(!glb_policy->shutting_down); /* Note the following LB call progresses every time there's activity in \a @@ -1417,13 +1417,13 @@ static void lb_call_init_locked(grpc_exec_ctx* exec_ctx, ? GRPC_MILLIS_INF_FUTURE : grpc_exec_ctx_now(exec_ctx) + glb_policy->lb_call_timeout_ms; glb_policy->lb_call = grpc_channel_create_pollset_set_call( - exec_ctx, glb_policy->lb_channel, NULL, GRPC_PROPAGATE_DEFAULTS, + exec_ctx, glb_policy->lb_channel, nullptr, GRPC_PROPAGATE_DEFAULTS, glb_policy->base.interested_parties, GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD, - &host, deadline, NULL); + &host, deadline, nullptr); grpc_slice_unref_internal(exec_ctx, host); - if (glb_policy->client_stats != NULL) { + if (glb_policy->client_stats != nullptr) { grpc_grpclb_client_stats_unref(glb_policy->client_stats); } glb_policy->client_stats = grpc_grpclb_client_stats_create(); @@ -1459,9 +1459,9 @@ static void lb_call_init_locked(grpc_exec_ctx* exec_ctx, static void lb_call_destroy_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy) { - GPR_ASSERT(glb_policy->lb_call != NULL); + GPR_ASSERT(glb_policy->lb_call != nullptr); grpc_call_unref(glb_policy->lb_call); - glb_policy->lb_call = NULL; + glb_policy->lb_call = nullptr; grpc_metadata_array_destroy(&glb_policy->lb_initial_metadata_recv); grpc_metadata_array_destroy(&glb_policy->lb_trailing_metadata_recv); @@ -1479,7 +1479,7 @@ static void lb_call_destroy_locked(grpc_exec_ctx* exec_ctx, */ static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy) { - GPR_ASSERT(glb_policy->lb_channel != NULL); + GPR_ASSERT(glb_policy->lb_channel != nullptr); if (glb_policy->shutting_down) return; lb_call_init_locked(exec_ctx, glb_policy); @@ -1490,7 +1490,7 @@ static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, (void*)glb_policy, (void*)glb_policy->lb_channel, (void*)glb_policy->lb_call); } - GPR_ASSERT(glb_policy->lb_call != NULL); + GPR_ASSERT(glb_policy->lb_call != nullptr); grpc_call_error call_error; grpc_op ops[3]; @@ -1500,22 +1500,22 @@ static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; op++; op->op = GRPC_OP_RECV_INITIAL_METADATA; op->data.recv_initial_metadata.recv_initial_metadata = &glb_policy->lb_initial_metadata_recv; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; op++; - GPR_ASSERT(glb_policy->lb_request_payload != NULL); + GPR_ASSERT(glb_policy->lb_request_payload != nullptr); op->op = GRPC_OP_SEND_MESSAGE; op->data.send_message.send_message = glb_policy->lb_request_payload; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; op++; call_error = grpc_call_start_batch_and_execute(exec_ctx, glb_policy->lb_call, - ops, (size_t)(op - ops), NULL); + ops, (size_t)(op - ops), nullptr); GPR_ASSERT(GRPC_CALL_OK == call_error); op = ops; @@ -1526,7 +1526,7 @@ static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, op->data.recv_status_on_client.status_details = &glb_policy->lb_call_status_details; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; op++; /* take a weak ref (won't prevent calling of \a glb_shutdown if the strong ref * count goes to zero) to be unref'd in lb_on_server_status_received_locked */ @@ -1541,7 +1541,7 @@ static void query_for_backends_locked(grpc_exec_ctx* exec_ctx, op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &glb_policy->lb_response_payload; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; op++; /* take another weak ref to be unref'd/reused in * lb_on_response_received_locked */ @@ -1558,7 +1558,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_op ops[2]; memset(ops, 0, sizeof(ops)); grpc_op* op = ops; - if (glb_policy->lb_response_payload != NULL) { + if (glb_policy->lb_response_payload != nullptr) { grpc_backoff_reset(&glb_policy->lb_call_backoff_state); /* Received data from the LB server. Look inside * glb_policy->lb_response_payload, for a serverlist. */ @@ -1568,10 +1568,10 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_byte_buffer_reader_destroy(&bbr); grpc_byte_buffer_destroy(glb_policy->lb_response_payload); - grpc_grpclb_initial_response* response = NULL; + grpc_grpclb_initial_response* response = nullptr; if (!glb_policy->seen_initial_response && (response = grpc_grpclb_initial_response_parse(response_slice)) != - NULL) { + nullptr) { if (response->has_client_stats_report_interval) { glb_policy->client_stats_report_interval = GPR_MAX( GPR_MS_PER_SEC, grpc_grpclb_duration_to_millis( @@ -1598,8 +1598,8 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, } else { grpc_grpclb_serverlist* serverlist = grpc_grpclb_response_parse_serverlist(response_slice); - if (serverlist != NULL) { - GPR_ASSERT(glb_policy->lb_call != NULL); + if (serverlist != nullptr) { + GPR_ASSERT(glb_policy->lb_call != nullptr); if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log(GPR_INFO, "Serverlist with %lu servers received", (unsigned long)serverlist->num_servers); @@ -1622,14 +1622,14 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, } grpc_grpclb_destroy_serverlist(serverlist); } else { /* new serverlist */ - if (glb_policy->serverlist != NULL) { + if (glb_policy->serverlist != nullptr) { /* dispose of the old serverlist */ grpc_grpclb_destroy_serverlist(glb_policy->serverlist); } else { /* or dispose of the fallback */ grpc_lb_addresses_destroy(exec_ctx, glb_policy->fallback_backend_addresses); - glb_policy->fallback_backend_addresses = NULL; + glb_policy->fallback_backend_addresses = nullptr; if (glb_policy->fallback_timer_active) { grpc_timer_cancel(exec_ctx, &glb_policy->lb_fallback_timer); glb_policy->fallback_timer_active = false; @@ -1659,7 +1659,7 @@ static void lb_on_response_received_locked(grpc_exec_ctx* exec_ctx, void* arg, op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message.recv_message = &glb_policy->lb_response_payload; op->flags = 0; - op->reserved = NULL; + op->reserved = nullptr; op++; /* reuse the "lb_on_response_received_locked" weak ref taken in * query_for_backends_locked() */ @@ -1685,14 +1685,14 @@ static void lb_on_fallback_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, glb_policy->fallback_timer_active = false; /* If we receive a serverlist after the timer fires but before this callback * actually runs, don't fall back. */ - if (glb_policy->serverlist == NULL) { + if (glb_policy->serverlist == nullptr) { if (!glb_policy->shutting_down && error == GRPC_ERROR_NONE) { if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { gpr_log(GPR_INFO, "Falling back to use backends from resolver (grpclb %p)", (void*)glb_policy); } - GPR_ASSERT(glb_policy->fallback_backend_addresses != NULL); + GPR_ASSERT(glb_policy->fallback_backend_addresses != nullptr); rr_handover_locked(exec_ctx, glb_policy); } } @@ -1703,7 +1703,7 @@ static void lb_on_fallback_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, static void lb_on_server_status_received_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { glb_lb_policy* glb_policy = (glb_lb_policy*)arg; - GPR_ASSERT(glb_policy->lb_call != NULL); + GPR_ASSERT(glb_policy->lb_call != nullptr); if (GRPC_TRACER_ON(grpc_lb_glb_trace)) { char* status_details = grpc_slice_to_c_string(glb_policy->lb_call_status_details); @@ -1727,7 +1727,7 @@ static void lb_on_server_status_received_locked(grpc_exec_ctx* exec_ctx, static void fallback_update_locked(grpc_exec_ctx* exec_ctx, glb_lb_policy* glb_policy, const grpc_lb_addresses* addresses) { - GPR_ASSERT(glb_policy->fallback_backend_addresses != NULL); + GPR_ASSERT(glb_policy->fallback_backend_addresses != nullptr); grpc_lb_addresses_destroy(exec_ctx, glb_policy->fallback_backend_addresses); glb_policy->fallback_backend_addresses = extract_backend_addresses_locked(exec_ctx, addresses); @@ -1742,8 +1742,8 @@ static void glb_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, glb_lb_policy* glb_policy = (glb_lb_policy*)policy; const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); - if (arg == NULL || arg->type != GRPC_ARG_POINTER) { - if (glb_policy->lb_channel == NULL) { + if (arg == nullptr || arg->type != GRPC_ARG_POINTER) { + if (glb_policy->lb_channel == nullptr) { // If we don't have a current channel to the LB, go into TRANSIENT // FAILURE. grpc_connectivity_state_set( @@ -1763,10 +1763,10 @@ static void glb_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, (const grpc_lb_addresses*)arg->value.pointer.p; // If a non-empty serverlist hasn't been received from the balancer, // propagate the update to fallback_backend_addresses. - if (glb_policy->serverlist == NULL) { + if (glb_policy->serverlist == nullptr) { fallback_update_locked(exec_ctx, glb_policy, addresses); } - GPR_ASSERT(glb_policy->lb_channel != NULL); + GPR_ASSERT(glb_policy->lb_channel != nullptr); // Propagate updates to the LB channel (pick_first) through the fake // resolver. grpc_channel_args* lb_channel_args = build_lb_channel_args( @@ -1789,7 +1789,7 @@ static void glb_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, grpc_polling_entity_create_from_pollset_set( glb_policy->base.interested_parties), &glb_policy->lb_channel_connectivity, - &glb_policy->lb_channel_on_connectivity_changed, NULL); + &glb_policy->lb_channel_on_connectivity_changed, nullptr); } } @@ -1817,7 +1817,7 @@ static void glb_lb_channel_on_connectivity_changed_cb(grpc_exec_ctx* exec_ctx, grpc_polling_entity_create_from_pollset_set( glb_policy->base.interested_parties), &glb_policy->lb_channel_connectivity, - &glb_policy->lb_channel_on_connectivity_changed, NULL); + &glb_policy->lb_channel_on_connectivity_changed, nullptr); break; } case GRPC_CHANNEL_IDLE: @@ -1825,9 +1825,9 @@ static void glb_lb_channel_on_connectivity_changed_cb(grpc_exec_ctx* exec_ctx, // call to kick the lb channel into gear. /* fallthrough */ case GRPC_CHANNEL_READY: - if (glb_policy->lb_call != NULL) { + if (glb_policy->lb_call != nullptr) { glb_policy->updating_lb_call = true; - grpc_call_cancel(glb_policy->lb_call, NULL); + grpc_call_cancel(glb_policy->lb_call, nullptr); // lb_on_server_status_received() will pick up the cancel and reinit // lb_call. } else if (glb_policy->started_picking && !glb_policy->shutting_down) { @@ -1866,21 +1866,21 @@ static grpc_lb_policy* glb_create(grpc_exec_ctx* exec_ctx, /* Count the number of gRPC-LB addresses. There must be at least one. */ const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); - if (arg == NULL || arg->type != GRPC_ARG_POINTER) { - return NULL; + if (arg == nullptr || arg->type != GRPC_ARG_POINTER) { + return nullptr; } grpc_lb_addresses* addresses = (grpc_lb_addresses*)arg->value.pointer.p; size_t num_grpclb_addrs = 0; for (size_t i = 0; i < addresses->num_addresses; ++i) { if (addresses->addresses[i].is_balancer) ++num_grpclb_addrs; } - if (num_grpclb_addrs == 0) return NULL; + if (num_grpclb_addrs == 0) return nullptr; glb_lb_policy* glb_policy = (glb_lb_policy*)gpr_zalloc(sizeof(*glb_policy)); /* Get server name. */ arg = grpc_channel_args_find(args->args, GRPC_ARG_SERVER_URI); - GPR_ASSERT(arg != NULL); + GPR_ASSERT(arg != nullptr); GPR_ASSERT(arg->type == GRPC_ARG_STRING); grpc_uri* uri = grpc_uri_parse(exec_ctx, arg->value.string, true); GPR_ASSERT(uri->path[0] != '\0'); @@ -1893,7 +1893,7 @@ static grpc_lb_policy* glb_create(grpc_exec_ctx* exec_ctx, grpc_uri_destroy(uri); glb_policy->cc_factory = args->client_channel_factory; - GPR_ASSERT(glb_policy->cc_factory != NULL); + GPR_ASSERT(glb_policy->cc_factory != nullptr); arg = grpc_channel_args_find(args->args, GRPC_ARG_GRPCLB_CALL_TIMEOUT_MS); glb_policy->lb_call_timeout_ms = @@ -1931,11 +1931,11 @@ static grpc_lb_policy* glb_create(grpc_exec_ctx* exec_ctx, exec_ctx, glb_policy->response_generator, lb_channel_args); grpc_channel_args_destroy(exec_ctx, lb_channel_args); gpr_free(uri_str); - if (glb_policy->lb_channel == NULL) { + if (glb_policy->lb_channel == nullptr) { gpr_free((void*)glb_policy->server_name); grpc_channel_args_destroy(exec_ctx, glb_policy->args); gpr_free(glb_policy); - return NULL; + return nullptr; } grpc_subchannel_index_ref(); GRPC_CLOSURE_INIT(&glb_policy->lb_channel_on_connectivity_changed, @@ -1969,10 +1969,10 @@ static bool maybe_add_client_load_reporting_filter( grpc_channel_stack_builder_get_channel_arguments(builder); const grpc_arg* channel_arg = grpc_channel_args_find(args, GRPC_ARG_LB_POLICY_NAME); - if (channel_arg != NULL && channel_arg->type == GRPC_ARG_STRING && + if (channel_arg != nullptr && channel_arg->type == GRPC_ARG_STRING && strcmp(channel_arg->value.string, "grpclb") == 0) { return grpc_channel_stack_builder_append_filter( - builder, (const grpc_channel_filter*)arg, NULL, NULL); + builder, (const grpc_channel_filter*)arg, nullptr, nullptr); } return true; } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc index 2dcf29fe0e..8eaa90e97b 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc @@ -35,7 +35,7 @@ grpc_channel* grpc_lb_policy_grpclb_create_lb_channel( grpc_channel_args* new_args = args; grpc_channel_credentials* channel_credentials = grpc_channel_credentials_find_in_args(args); - if (channel_credentials != NULL) { + if (channel_credentials != nullptr) { /* Substitute the channel credentials with a version without call * credentials: the load balancer is not necessarily trusted to handle * bearer token credentials */ @@ -43,7 +43,7 @@ grpc_channel* grpc_lb_policy_grpclb_create_lb_channel( grpc_channel_credentials* creds_sans_call_creds = grpc_channel_credentials_duplicate_without_call_credentials( channel_credentials); - GPR_ASSERT(creds_sans_call_creds != NULL); + GPR_ASSERT(creds_sans_call_creds != nullptr); grpc_arg args_to_add[] = { grpc_channel_credentials_to_arg(creds_sans_call_creds)}; /* Create the new set of channel args */ @@ -55,7 +55,7 @@ grpc_channel* grpc_lb_policy_grpclb_create_lb_channel( grpc_channel* lb_channel = grpc_client_channel_factory_create_channel( exec_ctx, client_channel_factory, lb_service_target_addresses, GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, new_args); - if (channel_credentials != NULL) { + if (channel_credentials != nullptr) { grpc_channel_args_destroy(exec_ctx, new_args); } return lb_channel; diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc index 903120ca7d..e19a6a71aa 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc @@ -87,7 +87,7 @@ void grpc_grpclb_client_stats_add_call_dropped_locked( gpr_atm_full_fetch_add(&client_stats->num_calls_started, (gpr_atm)1); gpr_atm_full_fetch_add(&client_stats->num_calls_finished, (gpr_atm)1); // Record the drop. - if (client_stats->drop_token_counts == NULL) { + if (client_stats->drop_token_counts == nullptr) { client_stats->drop_token_counts = (grpc_grpclb_dropped_call_counts*)gpr_zalloc( sizeof(grpc_grpclb_dropped_call_counts)); @@ -136,12 +136,12 @@ void grpc_grpclb_client_stats_get_locked( num_calls_finished_known_received, &client_stats->num_calls_finished_known_received); *drop_token_counts = client_stats->drop_token_counts; - client_stats->drop_token_counts = NULL; + client_stats->drop_token_counts = nullptr; } void grpc_grpclb_dropped_call_counts_destroy( grpc_grpclb_dropped_call_counts* drop_entries) { - if (drop_entries != NULL) { + if (drop_entries != nullptr) { for (size_t i = 0; i < drop_entries->num_entries; ++i) { gpr_free(drop_entries->token_counts[i].token); } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc index 87d7336b0c..2c8d7f4291 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc @@ -89,7 +89,7 @@ static bool encode_drops(pb_ostream_t* stream, const pb_field_t* field, void* const* arg) { grpc_grpclb_dropped_call_counts* drop_entries = (grpc_grpclb_dropped_call_counts*)*arg; - if (drop_entries == NULL) return true; + if (drop_entries == nullptr) return true; for (size_t i = 0; i < drop_entries->num_entries; ++i) { if (!pb_encode_tag_for_field(stream, field)) return false; grpc_lb_v1_ClientStatsPerToken drop_message; @@ -165,10 +165,10 @@ grpc_grpclb_initial_response* grpc_grpclb_initial_response_parse( memset(&res, 0, sizeof(grpc_grpclb_response)); if (!pb_decode(&stream, grpc_lb_v1_LoadBalanceResponse_fields, &res)) { gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); - return NULL; + return nullptr; } - if (!res.has_initial_response) return NULL; + if (!res.has_initial_response) return nullptr; grpc_grpclb_initial_response* initial_res = (grpc_grpclb_initial_response*)gpr_malloc( @@ -196,7 +196,7 @@ grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist( if (!status) { gpr_free(sl); gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); - return NULL; + return nullptr; } // Second pass: populate servers. if (sl->num_servers > 0) { @@ -212,7 +212,7 @@ grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist( if (!status) { grpc_grpclb_destroy_serverlist(sl); gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream)); - return NULL; + return nullptr; } } if (res.server_list.has_expiration_interval) { @@ -222,7 +222,7 @@ grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist( } void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist* serverlist) { - if (serverlist == NULL) { + if (serverlist == nullptr) { return; } for (size_t i = 0; i < serverlist->num_servers; i++) { @@ -251,7 +251,7 @@ grpc_grpclb_serverlist* grpc_grpclb_serverlist_copy( bool grpc_grpclb_serverlist_equals(const grpc_grpclb_serverlist* lhs, const grpc_grpclb_serverlist* rhs) { - if (lhs == NULL || rhs == NULL) { + if (lhs == nullptr || rhs == nullptr) { return false; } if (lhs->num_servers != rhs->num_servers) { diff --git a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc index 125a4186aa..a6a9a2645f 100644 --- a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +++ b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc @@ -60,9 +60,9 @@ typedef struct { static void pf_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; - GPR_ASSERT(p->subchannel_list == NULL); - GPR_ASSERT(p->latest_pending_subchannel_list == NULL); - GPR_ASSERT(p->pending_picks == NULL); + GPR_ASSERT(p->subchannel_list == nullptr); + GPR_ASSERT(p->latest_pending_subchannel_list == nullptr); + GPR_ASSERT(p->pending_picks == nullptr); grpc_connectivity_state_destroy(exec_ctx, &p->state_tracker); gpr_free(p); grpc_subchannel_index_unref(); @@ -78,24 +78,24 @@ static void shutdown_locked(grpc_exec_ctx* exec_ctx, pick_first_lb_policy* p, } p->shutdown = true; pending_pick* pp; - while ((pp = p->pending_picks) != NULL) { + while ((pp = p->pending_picks) != nullptr) { p->pending_picks = pp->next; - *pp->target = NULL; + *pp->target = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_REF(error)); gpr_free(pp); } grpc_connectivity_state_set(exec_ctx, &p->state_tracker, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(error), "shutdown"); - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "pf_shutdown"); - p->subchannel_list = NULL; + p->subchannel_list = nullptr; } - if (p->latest_pending_subchannel_list != NULL) { + if (p->latest_pending_subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->latest_pending_subchannel_list, "pf_shutdown"); - p->latest_pending_subchannel_list = NULL; + p->latest_pending_subchannel_list = nullptr; } GRPC_ERROR_UNREF(error); } @@ -110,11 +110,11 @@ static void pf_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error* error) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; pending_pick* pp = p->pending_picks; - p->pending_picks = NULL; - while (pp != NULL) { + p->pending_picks = nullptr; + while (pp != nullptr) { pending_pick* next = pp->next; if (pp->target == target) { - *target = NULL; + *target = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick Cancelled", &error, 1)); @@ -134,8 +134,8 @@ static void pf_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error* error) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; pending_pick* pp = p->pending_picks; - p->pending_picks = NULL; - while (pp != NULL) { + p->pending_picks = nullptr; + while (pp != nullptr) { pending_pick* next = pp->next; if ((pp->initial_metadata_flags & initial_metadata_flags_mask) == initial_metadata_flags_eq) { @@ -155,7 +155,7 @@ static void pf_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, static void start_picking_locked(grpc_exec_ctx* exec_ctx, pick_first_lb_policy* p) { p->started_picking = true; - if (p->subchannel_list != NULL && p->subchannel_list->num_subchannels > 0) { + if (p->subchannel_list != nullptr && p->subchannel_list->num_subchannels > 0) { p->subchannel_list->checking_subchannel = 0; grpc_lb_subchannel_list_ref_for_connectivity_watch( p->subchannel_list, "connectivity_watch+start_picking"); @@ -178,7 +178,7 @@ static int pf_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_closure* on_complete) { pick_first_lb_policy* p = (pick_first_lb_policy*)pol; // If we have a selected subchannel already, return synchronously. - if (p->selected != NULL) { + if (p->selected != nullptr) { *target = GRPC_CONNECTED_SUBCHANNEL_REF(p->selected->connected_subchannel, "picked"); return 1; @@ -242,8 +242,8 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, pick_first_lb_policy* p = (pick_first_lb_policy*)policy; const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); - if (arg == NULL || arg->type != GRPC_ARG_POINTER) { - if (p->subchannel_list == NULL) { + if (arg == nullptr || arg->type != GRPC_ARG_POINTER) { + if (p->subchannel_list == nullptr) { // If we don't have a current subchannel list, go into TRANSIENT FAILURE. grpc_connectivity_state_set( exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, @@ -274,18 +274,18 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"), "pf_update_empty"); - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "sl_shutdown_empty_update"); } p->subchannel_list = subchannel_list; // Empty list. - p->selected = NULL; + p->selected = nullptr; return; } - if (p->selected == NULL) { + if (p->selected == nullptr) { // We don't yet have a selected subchannel, so replace the current // subchannel list immediately. - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "pf_update_before_selected"); } @@ -307,12 +307,12 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, grpc_lb_subchannel_list_ref_for_connectivity_watch( subchannel_list, "connectivity_watch+replace_selected"); grpc_lb_subchannel_data_start_connectivity_watch(exec_ctx, sd); - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->subchannel_list, "pf_update_includes_selected"); } p->subchannel_list = subchannel_list; - if (p->selected->connected_subchannel != NULL) { + if (p->selected->connected_subchannel != nullptr) { sd->connected_subchannel = GRPC_CONNECTED_SUBCHANNEL_REF( p->selected->connected_subchannel, "pf_update_includes_selected"); } @@ -321,11 +321,11 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, // If there was a previously pending update (which may or may // not have contained the currently selected subchannel), drop // it, so that it doesn't override what we've done here. - if (p->latest_pending_subchannel_list != NULL) { + if (p->latest_pending_subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->latest_pending_subchannel_list, "pf_update_includes_selected+outdated"); - p->latest_pending_subchannel_list = NULL; + p->latest_pending_subchannel_list = nullptr; } return; } @@ -334,7 +334,7 @@ static void pf_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, // pending subchannel list to the new subchannel list. We will wait // for it to report READY before swapping it into the current // subchannel list. - if (p->latest_pending_subchannel_list != NULL) { + if (p->latest_pending_subchannel_list != nullptr) { if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { gpr_log(GPR_DEBUG, "Pick First %p Shutting down latest pending subchannel list " @@ -402,12 +402,12 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, // If the new state is anything other than READY and there is a // pending update, switch to the pending update. if (sd->curr_connectivity_state != GRPC_CHANNEL_READY && - p->latest_pending_subchannel_list != NULL) { - p->selected = NULL; + p->latest_pending_subchannel_list != nullptr) { + p->selected = nullptr; grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->subchannel_list, "selected_not_ready+switch_to_update"); p->subchannel_list = p->latest_pending_subchannel_list; - p->latest_pending_subchannel_list = NULL; + p->latest_pending_subchannel_list = nullptr; grpc_connectivity_state_set( exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_REF(error), "selected_not_ready+switch_to_update"); @@ -450,11 +450,11 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, // Case 2. Promote p->latest_pending_subchannel_list to // p->subchannel_list. if (sd->subchannel_list == p->latest_pending_subchannel_list) { - GPR_ASSERT(p->subchannel_list != NULL); + GPR_ASSERT(p->subchannel_list != nullptr); grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->subchannel_list, "finish_update"); p->subchannel_list = p->latest_pending_subchannel_list; - p->latest_pending_subchannel_list = NULL; + p->latest_pending_subchannel_list = nullptr; } // Cases 1 and 2. grpc_connectivity_state_set(exec_ctx, &p->state_tracker, @@ -495,7 +495,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, sd->subchannel_list->num_subchannels; sd = &sd->subchannel_list ->subchannels[sd->subchannel_list->checking_subchannel]; - } while (sd->subchannel == NULL); + } while (sd->subchannel == nullptr); // Case 1: Only set state to TRANSIENT_FAILURE if we've tried // all subchannels. if (sd->subchannel_list->checking_subchannel == 0 && @@ -537,7 +537,7 @@ static void pf_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, sd->subchannel_list->num_subchannels; sd = &sd->subchannel_list ->subchannels[sd->subchannel_list->checking_subchannel]; - } while (sd->subchannel == NULL && sd != original_sd); + } while (sd->subchannel == nullptr && sd != original_sd); if (sd == original_sd) { grpc_lb_subchannel_list_unref_for_connectivity_watch( exec_ctx, sd->subchannel_list, "pf_candidate_shutdown"); @@ -585,7 +585,7 @@ static void pick_first_factory_unref(grpc_lb_policy_factory* factory) {} static grpc_lb_policy* create_pick_first(grpc_exec_ctx* exec_ctx, grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { - GPR_ASSERT(args->client_channel_factory != NULL); + GPR_ASSERT(args->client_channel_factory != nullptr); pick_first_lb_policy* p = (pick_first_lb_policy*)gpr_zalloc(sizeof(*p)); if (GRPC_TRACER_ON(grpc_lb_pick_first_trace)) { gpr_log(GPR_DEBUG, "Pick First %p created.", (void*)p); diff --git a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc index df235922c8..6ea1f025df 100644 --- a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +++ b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc @@ -100,7 +100,7 @@ typedef struct round_robin_lb_policy { * The caller must do that if it returns a pick. */ static size_t get_next_ready_subchannel_index_locked( const round_robin_lb_policy* p) { - GPR_ASSERT(p->subchannel_list != NULL); + GPR_ASSERT(p->subchannel_list != nullptr); if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { gpr_log(GPR_INFO, "[RR %p] getting next ready subchannel (out of %lu), " @@ -161,8 +161,8 @@ static void rr_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol) { gpr_log(GPR_DEBUG, "[RR %p] Destroying Round Robin policy at %p", (void*)pol, (void*)pol); } - GPR_ASSERT(p->subchannel_list == NULL); - GPR_ASSERT(p->latest_pending_subchannel_list == NULL); + GPR_ASSERT(p->subchannel_list == nullptr); + GPR_ASSERT(p->latest_pending_subchannel_list == nullptr); grpc_connectivity_state_destroy(exec_ctx, &p->state_tracker); grpc_subchannel_index_unref(); gpr_free(p); @@ -175,25 +175,25 @@ static void shutdown_locked(grpc_exec_ctx* exec_ctx, round_robin_lb_policy* p, } p->shutdown = true; pending_pick* pp; - while ((pp = p->pending_picks) != NULL) { + while ((pp = p->pending_picks) != nullptr) { p->pending_picks = pp->next; - *pp->target = NULL; + *pp->target = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_REF(error)); gpr_free(pp); } grpc_connectivity_state_set(exec_ctx, &p->state_tracker, GRPC_CHANNEL_SHUTDOWN, GRPC_ERROR_REF(error), "rr_shutdown"); - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "sl_shutdown_rr_shutdown"); - p->subchannel_list = NULL; + p->subchannel_list = nullptr; } - if (p->latest_pending_subchannel_list != NULL) { + if (p->latest_pending_subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->latest_pending_subchannel_list, "sl_shutdown_pending_rr_shutdown"); - p->latest_pending_subchannel_list = NULL; + p->latest_pending_subchannel_list = nullptr; } GRPC_ERROR_UNREF(error); } @@ -209,11 +209,11 @@ static void rr_cancel_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error* error) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; pending_pick* pp = p->pending_picks; - p->pending_picks = NULL; - while (pp != NULL) { + p->pending_picks = nullptr; + while (pp != nullptr) { pending_pick* next = pp->next; if (pp->target == target) { - *target = NULL; + *target = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick cancelled", &error, 1)); @@ -233,12 +233,12 @@ static void rr_cancel_picks_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, grpc_error* error) { round_robin_lb_policy* p = (round_robin_lb_policy*)pol; pending_pick* pp = p->pending_picks; - p->pending_picks = NULL; - while (pp != NULL) { + p->pending_picks = nullptr; + while (pp != nullptr) { pending_pick* next = pp->next; if ((pp->initial_metadata_flags & initial_metadata_flags_mask) == initial_metadata_flags_eq) { - *pp->target = NULL; + *pp->target = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, pp->on_complete, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Pick cancelled", &error, 1)); @@ -281,7 +281,7 @@ static int rr_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, p->shutdown); } GPR_ASSERT(!p->shutdown); - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { const size_t next_ready_index = get_next_ready_subchannel_index_locked(p); if (next_ready_index < p->subchannel_list->num_subchannels) { /* readily available, report right away */ @@ -289,7 +289,7 @@ static int rr_pick_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* pol, &p->subchannel_list->subchannels[next_ready_index]; *target = GRPC_CONNECTED_SUBCHANNEL_REF(sd->connected_subchannel, "rr_picked"); - if (user_data != NULL) { + if (user_data != nullptr) { *user_data = sd->user_data; } if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { @@ -472,7 +472,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, } } else { // sd not in SHUTDOWN if (sd->curr_connectivity_state == GRPC_CHANNEL_READY) { - if (sd->connected_subchannel == NULL) { + if (sd->connected_subchannel == nullptr) { sd->connected_subchannel = GRPC_CONNECTED_SUBCHANNEL_REF( grpc_subchannel_get_connected_subchannel(sd->subchannel), "connected"); @@ -486,7 +486,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, GPR_ASSERT(!sd->subchannel_list->shutting_down); if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { const unsigned long num_subchannels = - p->subchannel_list != NULL + p->subchannel_list != nullptr ? (unsigned long)p->subchannel_list->num_subchannels : 0; gpr_log(GPR_DEBUG, @@ -495,13 +495,13 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, (void*)p, (void*)p->subchannel_list, num_subchannels, (void*)sd->subchannel_list, num_subchannels); } - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { // dispose of the current subchannel_list grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->subchannel_list, "sl_phase_out_shutdown"); } p->subchannel_list = p->latest_pending_subchannel_list; - p->latest_pending_subchannel_list = NULL; + p->latest_pending_subchannel_list = nullptr; } /* at this point we know there's at least one suitable subchannel. Go * ahead and pick one and notify the pending suitors in @@ -510,7 +510,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, GPR_ASSERT(next_ready_index < p->subchannel_list->num_subchannels); grpc_lb_subchannel_data* selected = &p->subchannel_list->subchannels[next_ready_index]; - if (p->pending_picks != NULL) { + if (p->pending_picks != nullptr) { // if the selected subchannel is going to be used for the pending // picks, update the last picked pointer update_last_ready_subchannel_index_locked(p, next_ready_index); @@ -520,7 +520,7 @@ static void rr_connectivity_changed_locked(grpc_exec_ctx* exec_ctx, void* arg, p->pending_picks = pp->next; *pp->target = GRPC_CONNECTED_SUBCHANNEL_REF( selected->connected_subchannel, "rr_picked"); - if (pp->user_data != NULL) { + if (pp->user_data != nullptr) { *pp->user_data = selected->user_data; } if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { @@ -577,11 +577,11 @@ static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, round_robin_lb_policy* p = (round_robin_lb_policy*)policy; const grpc_arg* arg = grpc_channel_args_find(args->args, GRPC_ARG_LB_ADDRESSES); - if (arg == NULL || arg->type != GRPC_ARG_POINTER) { + if (arg == nullptr || arg->type != GRPC_ARG_POINTER) { gpr_log(GPR_ERROR, "[RR %p] update provided no addresses; ignoring", p); // If we don't have a current subchannel list, go into TRANSIENT_FAILURE. // Otherwise, keep using the current subchannel list (ignore this update). - if (p->subchannel_list == NULL) { + if (p->subchannel_list == nullptr) { grpc_connectivity_state_set( exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Missing update in args"), @@ -602,7 +602,7 @@ static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, exec_ctx, &p->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty update"), "rr_update_empty"); - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref(exec_ctx, p->subchannel_list, "sl_shutdown_empty_update"); } @@ -610,7 +610,7 @@ static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, return; } if (p->started_picking) { - if (p->latest_pending_subchannel_list != NULL) { + if (p->latest_pending_subchannel_list != nullptr) { if (GRPC_TRACER_ON(grpc_lb_round_robin_trace)) { gpr_log(GPR_DEBUG, "[RR %p] Shutting down latest pending subchannel list %p, " @@ -635,7 +635,7 @@ static void rr_update_locked(grpc_exec_ctx* exec_ctx, grpc_lb_policy* policy, } else { // The policy isn't picking yet. Save the update for later, disposing of // previous version if any. - if (p->subchannel_list != NULL) { + if (p->subchannel_list != nullptr) { grpc_lb_subchannel_list_shutdown_and_unref( exec_ctx, p->subchannel_list, "rr_update_before_started_picking"); } @@ -662,7 +662,7 @@ static void round_robin_factory_unref(grpc_lb_policy_factory* factory) {} static grpc_lb_policy* round_robin_create(grpc_exec_ctx* exec_ctx, grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { - GPR_ASSERT(args->client_channel_factory != NULL); + GPR_ASSERT(args->client_channel_factory != nullptr); round_robin_lb_policy* p = (round_robin_lb_policy*)gpr_zalloc(sizeof(*p)); grpc_lb_policy_init(&p->base, &round_robin_lb_policy_vtable, args->combiner); grpc_subchannel_index_ref(); diff --git a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc index db38ef5305..f53abb7d96 100644 --- a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc +++ b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc @@ -31,7 +31,7 @@ void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx* exec_ctx, grpc_lb_subchannel_data* sd, const char* reason) { - if (sd->subchannel != NULL) { + if (sd->subchannel != nullptr) { if (GRPC_TRACER_ON(*sd->subchannel_list->tracer)) { gpr_log(GPR_DEBUG, "[%s %p] subchannel list %p index %" PRIuPTR " of %" PRIuPTR @@ -42,16 +42,16 @@ void grpc_lb_subchannel_data_unref_subchannel(grpc_exec_ctx* exec_ctx, sd->subchannel_list->num_subchannels, sd->subchannel); } GRPC_SUBCHANNEL_UNREF(exec_ctx, sd->subchannel, reason); - sd->subchannel = NULL; - if (sd->connected_subchannel != NULL) { + sd->subchannel = nullptr; + if (sd->connected_subchannel != nullptr) { GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, sd->connected_subchannel, reason); - sd->connected_subchannel = NULL; + sd->connected_subchannel = nullptr; } - if (sd->user_data != NULL) { - GPR_ASSERT(sd->user_data_vtable != NULL); + if (sd->user_data != nullptr) { + GPR_ASSERT(sd->user_data_vtable != nullptr); sd->user_data_vtable->destroy(exec_ctx, sd->user_data); - sd->user_data = NULL; + sd->user_data = nullptr; } } } @@ -126,7 +126,7 @@ grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( grpc_subchannel* subchannel = grpc_client_channel_factory_create_subchannel( exec_ctx, args->client_channel_factory, &sc_args); grpc_channel_args_destroy(exec_ctx, new_args); - if (subchannel == NULL) { + if (subchannel == nullptr) { // Subchannel could not be created. if (GRPC_TRACER_ON(*tracer)) { char* address_uri = @@ -162,7 +162,7 @@ grpc_lb_subchannel_list* grpc_lb_subchannel_list_create( sd->curr_connectivity_state = GRPC_CHANNEL_IDLE; sd->pending_connectivity_state_unsafe = GRPC_CHANNEL_IDLE; sd->user_data_vtable = addresses->user_data_vtable; - if (sd->user_data_vtable != NULL) { + if (sd->user_data_vtable != nullptr) { sd->user_data = sd->user_data_vtable->copy(addresses->addresses[i].user_data); } @@ -240,7 +240,7 @@ static void subchannel_data_cancel_connectivity_watch( (size_t)(sd - sd->subchannel_list->subchannels), sd->subchannel_list->num_subchannels, sd->subchannel, reason); } - grpc_subchannel_notify_on_state_change(exec_ctx, sd->subchannel, NULL, NULL, + grpc_subchannel_notify_on_state_change(exec_ctx, sd->subchannel, nullptr, nullptr, &sd->connectivity_changed_closure); } @@ -261,7 +261,7 @@ void grpc_lb_subchannel_list_shutdown_and_unref( // Otherwise, unref the subchannel directly. if (sd->connectivity_notification_pending) { subchannel_data_cancel_connectivity_watch(exec_ctx, sd, reason); - } else if (sd->subchannel != NULL) { + } else if (sd->subchannel != nullptr) { grpc_lb_subchannel_data_unref_subchannel(exec_ctx, sd, reason); } } diff --git a/src/core/ext/filters/client_channel/lb_policy_factory.cc b/src/core/ext/filters/client_channel/lb_policy_factory.cc index 05ab43d0b6..d43f9fd1b9 100644 --- a/src/core/ext/filters/client_channel/lb_policy_factory.cc +++ b/src/core/ext/filters/client_channel/lb_policy_factory.cc @@ -43,11 +43,11 @@ grpc_lb_addresses* grpc_lb_addresses_copy(const grpc_lb_addresses* addresses) { memcpy(new_addresses->addresses, addresses->addresses, sizeof(grpc_lb_address) * addresses->num_addresses); for (size_t i = 0; i < addresses->num_addresses; ++i) { - if (new_addresses->addresses[i].balancer_name != NULL) { + if (new_addresses->addresses[i].balancer_name != nullptr) { new_addresses->addresses[i].balancer_name = gpr_strdup(new_addresses->addresses[i].balancer_name); } - if (new_addresses->addresses[i].user_data != NULL) { + if (new_addresses->addresses[i].user_data != nullptr) { new_addresses->addresses[i].user_data = addresses->user_data_vtable->copy( new_addresses->addresses[i].user_data); } @@ -60,7 +60,7 @@ void grpc_lb_addresses_set_address(grpc_lb_addresses* addresses, size_t index, bool is_balancer, const char* balancer_name, void* user_data) { GPR_ASSERT(index < addresses->num_addresses); - if (user_data != NULL) GPR_ASSERT(addresses->user_data_vtable != NULL); + if (user_data != nullptr) GPR_ASSERT(addresses->user_data_vtable != nullptr); grpc_lb_address* target = &addresses->addresses[index]; memcpy(target->address.addr, address, address_len); target->address.len = address_len; @@ -98,12 +98,12 @@ int grpc_lb_addresses_cmp(const grpc_lb_addresses* addresses1, if (target1->is_balancer > target2->is_balancer) return 1; if (target1->is_balancer < target2->is_balancer) return -1; const char* balancer_name1 = - target1->balancer_name != NULL ? target1->balancer_name : ""; + target1->balancer_name != nullptr ? target1->balancer_name : ""; const char* balancer_name2 = - target2->balancer_name != NULL ? target2->balancer_name : ""; + target2->balancer_name != nullptr ? target2->balancer_name : ""; retval = strcmp(balancer_name1, balancer_name2); if (retval != 0) return retval; - if (addresses1->user_data_vtable != NULL) { + if (addresses1->user_data_vtable != nullptr) { retval = addresses1->user_data_vtable->cmp(target1->user_data, target2->user_data); if (retval != 0) return retval; @@ -116,7 +116,7 @@ void grpc_lb_addresses_destroy(grpc_exec_ctx* exec_ctx, grpc_lb_addresses* addresses) { for (size_t i = 0; i < addresses->num_addresses; ++i) { gpr_free(addresses->addresses[i].balancer_name); - if (addresses->addresses[i].user_data != NULL) { + if (addresses->addresses[i].user_data != nullptr) { addresses->user_data_vtable->destroy(exec_ctx, addresses->addresses[i].user_data); } @@ -148,8 +148,8 @@ grpc_lb_addresses* grpc_lb_addresses_find_channel_arg( const grpc_channel_args* channel_args) { const grpc_arg* lb_addresses_arg = grpc_channel_args_find(channel_args, GRPC_ARG_LB_ADDRESSES); - if (lb_addresses_arg == NULL || lb_addresses_arg->type != GRPC_ARG_POINTER) - return NULL; + if (lb_addresses_arg == nullptr || lb_addresses_arg->type != GRPC_ARG_POINTER) + return nullptr; return (grpc_lb_addresses*)lb_addresses_arg->value.pointer.p; } @@ -164,6 +164,6 @@ void grpc_lb_policy_factory_unref(grpc_lb_policy_factory* factory) { grpc_lb_policy* grpc_lb_policy_factory_create_lb_policy( grpc_exec_ctx* exec_ctx, grpc_lb_policy_factory* factory, grpc_lb_policy_args* args) { - if (factory == NULL) return NULL; + if (factory == nullptr) return nullptr; return factory->vtable->create_lb_policy(exec_ctx, factory, args); } diff --git a/src/core/ext/filters/client_channel/lb_policy_registry.cc b/src/core/ext/filters/client_channel/lb_policy_registry.cc index 7b0a926a1b..6e710e86d9 100644 --- a/src/core/ext/filters/client_channel/lb_policy_registry.cc +++ b/src/core/ext/filters/client_channel/lb_policy_registry.cc @@ -50,7 +50,7 @@ void grpc_register_lb_policy(grpc_lb_policy_factory* factory) { static grpc_lb_policy_factory* lookup_factory(const char* name) { int i; - if (name == NULL) return NULL; + if (name == nullptr) return nullptr; for (i = 0; i < g_number_of_lb_policies; i++) { if (0 == gpr_stricmp(name, g_all_of_the_lb_policies[i]->vtable->name)) { @@ -58,7 +58,7 @@ static grpc_lb_policy_factory* lookup_factory(const char* name) { } } - return NULL; + return nullptr; } grpc_lb_policy* grpc_lb_policy_create(grpc_exec_ctx* exec_ctx, const char* name, diff --git a/src/core/ext/filters/client_channel/parse_address.cc b/src/core/ext/filters/client_channel/parse_address.cc index 6cf77f13bc..39b1237c77 100644 --- a/src/core/ext/filters/client_channel/parse_address.cc +++ b/src/core/ext/filters/client_channel/parse_address.cc @@ -75,7 +75,7 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr, goto done; } // Parse port. - if (port == NULL) { + if (port == nullptr) { if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv4 scheme"); goto done; } @@ -118,7 +118,7 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr, in6->sin6_family = AF_INET6; // Handle the RFC6874 syntax for IPv6 zone identifiers. char* host_end = (char*)gpr_memrchr(host, '%', strlen(host)); - if (host_end != NULL) { + if (host_end != nullptr) { GPR_ASSERT(host_end >= host); char host_without_scope[INET6_ADDRSTRLEN]; size_t host_without_scope_len = (size_t)(host_end - host); @@ -144,7 +144,7 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr, } } // Parse port. - if (port == NULL) { + if (port == nullptr) { if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv6 scheme"); goto done; } diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc index 76f08281f7..5f91fe05af 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc @@ -121,15 +121,15 @@ static void dns_ares_shutdown_locked(grpc_exec_ctx* exec_ctx, if (r->have_retry_timer) { grpc_timer_cancel(exec_ctx, &r->retry_timer); } - if (r->pending_request != NULL) { + if (r->pending_request != nullptr) { grpc_cancel_ares_request(exec_ctx, r->pending_request); } - if (r->next_completion != NULL) { - *r->target_result = NULL; + if (r->next_completion != nullptr) { + *r->target_result = nullptr; GRPC_CLOSURE_SCHED( exec_ctx, r->next_completion, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resolver Shutdown")); - r->next_completion = NULL; + r->next_completion = nullptr; } } @@ -155,7 +155,7 @@ static void dns_ares_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, } static bool value_in_json_array(grpc_json* array, const char* value) { - for (grpc_json* entry = array->child; entry != NULL; entry = entry->next) { + for (grpc_json* entry = array->child; entry != nullptr; entry = entry->next) { if (entry->type == GRPC_JSON_STRING && strcmp(entry->value, value) == 0) { return true; } @@ -165,47 +165,47 @@ static bool value_in_json_array(grpc_json* array, const char* value) { static char* choose_service_config(char* service_config_choice_json) { grpc_json* choices_json = grpc_json_parse_string(service_config_choice_json); - if (choices_json == NULL || choices_json->type != GRPC_JSON_ARRAY) { + if (choices_json == nullptr || choices_json->type != GRPC_JSON_ARRAY) { gpr_log(GPR_ERROR, "cannot parse service config JSON string"); - return NULL; + return nullptr; } - char* service_config = NULL; - for (grpc_json* choice = choices_json->child; choice != NULL; + char* service_config = nullptr; + for (grpc_json* choice = choices_json->child; choice != nullptr; choice = choice->next) { if (choice->type != GRPC_JSON_OBJECT) { gpr_log(GPR_ERROR, "cannot parse service config JSON string"); break; } - grpc_json* service_config_json = NULL; - for (grpc_json* field = choice->child; field != NULL; field = field->next) { + grpc_json* service_config_json = nullptr; + for (grpc_json* field = choice->child; field != nullptr; field = field->next) { // Check client language, if specified. if (strcmp(field->key, "clientLanguage") == 0) { if (field->type != GRPC_JSON_ARRAY || !value_in_json_array(field, "c++")) { - service_config_json = NULL; + service_config_json = nullptr; break; } } // Check client hostname, if specified. if (strcmp(field->key, "clientHostname") == 0) { char* hostname = grpc_gethostname(); - if (hostname == NULL || field->type != GRPC_JSON_ARRAY || + if (hostname == nullptr || field->type != GRPC_JSON_ARRAY || !value_in_json_array(field, hostname)) { - service_config_json = NULL; + service_config_json = nullptr; break; } } // Check percentage, if specified. if (strcmp(field->key, "percentage") == 0) { if (field->type != GRPC_JSON_NUMBER) { - service_config_json = NULL; + service_config_json = nullptr; break; } int random_pct = rand() % 100; int percentage; if (sscanf(field->value, "%d", &percentage) != 1 || random_pct > percentage || percentage == 0) { - service_config_json = NULL; + service_config_json = nullptr; break; } } @@ -216,7 +216,7 @@ static char* choose_service_config(char* service_config_choice_json) { } } } - if (service_config_json != NULL) { + if (service_config_json != nullptr) { service_config = grpc_json_dump_to_string(service_config_json, 0); break; } @@ -228,33 +228,33 @@ static char* choose_service_config(char* service_config_choice_json) { static void dns_ares_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { ares_dns_resolver* r = (ares_dns_resolver*)arg; - grpc_channel_args* result = NULL; + grpc_channel_args* result = nullptr; GPR_ASSERT(r->resolving); r->resolving = false; - r->pending_request = NULL; - if (r->lb_addresses != NULL) { + r->pending_request = nullptr; + if (r->lb_addresses != nullptr) { static const char* args_to_remove[2]; size_t num_args_to_remove = 0; grpc_arg new_args[3]; size_t num_args_to_add = 0; new_args[num_args_to_add++] = grpc_lb_addresses_create_channel_arg(r->lb_addresses); - grpc_service_config* service_config = NULL; - char* service_config_string = NULL; - if (r->service_config_json != NULL) { + grpc_service_config* service_config = nullptr; + char* service_config_string = nullptr; + if (r->service_config_json != nullptr) { service_config_string = choose_service_config(r->service_config_json); gpr_free(r->service_config_json); - if (service_config_string != NULL) { + if (service_config_string != nullptr) { gpr_log(GPR_INFO, "selected service config choice: %s", service_config_string); args_to_remove[num_args_to_remove++] = GRPC_ARG_SERVICE_CONFIG; new_args[num_args_to_add++] = grpc_channel_arg_string_create( (char*)GRPC_ARG_SERVICE_CONFIG, service_config_string); service_config = grpc_service_config_create(service_config_string); - if (service_config != NULL) { + if (service_config != nullptr) { const char* lb_policy_name = grpc_service_config_get_lb_policy_name(service_config); - if (lb_policy_name != NULL) { + if (lb_policy_name != nullptr) { args_to_remove[num_args_to_remove++] = GRPC_ARG_LB_POLICY_NAME; new_args[num_args_to_add++] = grpc_channel_arg_string_create( (char*)GRPC_ARG_LB_POLICY_NAME, (char*)lb_policy_name); @@ -265,7 +265,7 @@ static void dns_ares_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, result = grpc_channel_args_copy_and_add_and_remove( r->channel_args, args_to_remove, num_args_to_remove, new_args, num_args_to_add); - if (service_config != NULL) grpc_service_config_destroy(service_config); + if (service_config != nullptr) grpc_service_config_destroy(service_config); gpr_free(service_config_string); grpc_lb_addresses_destroy(exec_ctx, r->lb_addresses); } else { @@ -287,7 +287,7 @@ static void dns_ares_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_timer_init(exec_ctx, &r->retry_timer, next_try, &r->dns_ares_on_retry_timer_locked); } - if (r->resolved_result != NULL) { + if (r->resolved_result != nullptr) { grpc_channel_args_destroy(exec_ctx, r->resolved_result); } r->resolved_result = result; @@ -318,25 +318,25 @@ static void dns_ares_start_resolving_locked(grpc_exec_ctx* exec_ctx, GRPC_RESOLVER_REF(&r->base, "dns-resolving"); GPR_ASSERT(!r->resolving); r->resolving = true; - r->lb_addresses = NULL; - r->service_config_json = NULL; + r->lb_addresses = nullptr; + r->service_config_json = nullptr; r->pending_request = grpc_dns_lookup_ares( exec_ctx, r->dns_server, r->name_to_resolve, r->default_port, r->interested_parties, &r->dns_ares_on_resolved_locked, &r->lb_addresses, true /* check_grpclb */, - r->request_service_config ? &r->service_config_json : NULL); + r->request_service_config ? &r->service_config_json : nullptr); } static void dns_ares_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, ares_dns_resolver* r) { - if (r->next_completion != NULL && + if (r->next_completion != nullptr && r->resolved_version != r->published_version) { - *r->target_result = r->resolved_result == NULL - ? NULL + *r->target_result = r->resolved_result == nullptr + ? nullptr : grpc_channel_args_copy(r->resolved_result); gpr_log(GPR_DEBUG, "dns_ares_maybe_finish_next_locked"); GRPC_CLOSURE_SCHED(exec_ctx, r->next_completion, GRPC_ERROR_NONE); - r->next_completion = NULL; + r->next_completion = nullptr; r->published_version = r->resolved_version; } } @@ -344,7 +344,7 @@ static void dns_ares_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, static void dns_ares_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { gpr_log(GPR_DEBUG, "dns_ares_destroy"); ares_dns_resolver* r = (ares_dns_resolver*)gr; - if (r->resolved_result != NULL) { + if (r->resolved_result != nullptr) { grpc_channel_args_destroy(exec_ctx, r->resolved_result); } grpc_pollset_set_destroy(exec_ctx, r->interested_parties); @@ -376,7 +376,7 @@ static grpc_resolver* dns_ares_create(grpc_exec_ctx* exec_ctx, r->request_service_config = !grpc_channel_arg_get_integer( arg, (grpc_integer_options){false, false, true}); r->interested_parties = grpc_pollset_set_create(); - if (args->pollset_set != NULL) { + if (args->pollset_set != nullptr) { grpc_pollset_set_add_pollset_set(exec_ctx, r->interested_parties, args->pollset_set); } @@ -428,7 +428,7 @@ extern "C" void grpc_resolver_dns_ares_init(void) { char* resolver = gpr_getenv("GRPC_DNS_RESOLVER"); /* TODO(zyc): Turn on c-ares based resolver by default after the address sorter and the CNAME support are added. */ - if (resolver != NULL && gpr_stricmp(resolver, "ares") == 0) { + if (resolver != nullptr && gpr_stricmp(resolver, "ares") == 0) { grpc_error* error = grpc_ares_init(); if (error != GRPC_ERROR_NONE) { GRPC_LOG_IF_ERROR("ares_library_init() failed", error); @@ -442,7 +442,7 @@ extern "C" void grpc_resolver_dns_ares_init(void) { extern "C" void grpc_resolver_dns_ares_shutdown(void) { char* resolver = gpr_getenv("GRPC_DNS_RESOLVER"); - if (resolver != NULL && gpr_stricmp(resolver, "ares") == 0) { + if (resolver != nullptr && gpr_stricmp(resolver, "ares") == 0) { grpc_ares_cleanup(); } gpr_free(resolver); diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc index 2bb98c1a3f..92c72c1bcb 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc @@ -91,7 +91,7 @@ static void grpc_ares_ev_driver_unref(grpc_ares_ev_driver* ev_driver) { gpr_log(GPR_DEBUG, "Unref ev_driver %" PRIuPTR, (uintptr_t)ev_driver); if (gpr_unref(&ev_driver->refs)) { gpr_log(GPR_DEBUG, "destroy ev_driver %" PRIuPTR, (uintptr_t)ev_driver); - GPR_ASSERT(ev_driver->fds == NULL); + GPR_ASSERT(ev_driver->fds == nullptr); gpr_mu_destroy(&ev_driver->mu); ares_destroy(ev_driver->channel); gpr_free(ev_driver); @@ -106,7 +106,7 @@ static void fd_node_destroy(grpc_exec_ctx* exec_ctx, fd_node* fdn) { /* c-ares library has closed the fd inside grpc_fd. This fd may be picked up immediately by another thread, and should not be closed by the following grpc_fd_orphan. */ - grpc_fd_orphan(exec_ctx, fdn->fd, NULL, NULL, true /* already_closed */, + grpc_fd_orphan(exec_ctx, fdn->fd, nullptr, nullptr, true /* already_closed */, "c-ares query finished"); gpr_free(fdn); } @@ -142,7 +142,7 @@ grpc_error* grpc_ares_ev_driver_create(grpc_ares_ev_driver** ev_driver, gpr_mu_init(&(*ev_driver)->mu); gpr_ref_init(&(*ev_driver)->refs, 1); (*ev_driver)->pollset_set = pollset_set; - (*ev_driver)->fds = NULL; + (*ev_driver)->fds = nullptr; (*ev_driver)->working = false; (*ev_driver)->shutting_down = false; return GRPC_ERROR_NONE; @@ -165,7 +165,7 @@ void grpc_ares_ev_driver_shutdown(grpc_exec_ctx* exec_ctx, gpr_mu_lock(&ev_driver->mu); ev_driver->shutting_down = true; fd_node* fn = ev_driver->fds; - while (fn != NULL) { + while (fn != nullptr) { grpc_fd_shutdown( exec_ctx, fn->fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("grpc_ares_ev_driver_shutdown")); @@ -180,7 +180,7 @@ static fd_node* pop_fd_node(fd_node** head, int fd) { fd_node dummy_head; dummy_head.next = *head; fd_node* node = &dummy_head; - while (node->next != NULL) { + while (node->next != nullptr) { if (grpc_fd_wrapped_fd(node->next->fd) == fd) { fd_node* ret = node->next; node->next = node->next->next; @@ -189,7 +189,7 @@ static fd_node* pop_fd_node(fd_node** head, int fd) { } node = node->next; } - return NULL; + return nullptr; } /* Check if \a fd is still readable */ @@ -275,7 +275,7 @@ ares_channel* grpc_ares_ev_driver_get_channel(grpc_ares_ev_driver* ev_driver) { // driver_closure with these filedescriptors. static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx, grpc_ares_ev_driver* ev_driver) { - fd_node* new_list = NULL; + fd_node* new_list = nullptr; if (!ev_driver->shutting_down) { ares_socket_t socks[ARES_GETSOCK_MAXNUM]; int socks_bitmask = @@ -332,14 +332,14 @@ static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx, // Any remaining fds in ev_driver->fds were not returned by ares_getsock() and // are therefore no longer in use, so they can be shut down and removed from // the list. - while (ev_driver->fds != NULL) { + while (ev_driver->fds != nullptr) { fd_node* cur = ev_driver->fds; ev_driver->fds = ev_driver->fds->next; fd_node_shutdown(exec_ctx, cur); } ev_driver->fds = new_list; // If the ev driver has no working fd, all the tasks are done. - if (new_list == NULL) { + if (new_list == nullptr) { ev_driver->working = false; gpr_log(GPR_DEBUG, "ev driver stop working"); } diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc index 9408b9d81d..af4493389d 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc @@ -102,7 +102,7 @@ static void grpc_ares_request_unref(grpc_exec_ctx* exec_ctx, request */ if (gpr_unref(&r->pending_queries)) { /* TODO(zyc): Sort results with RFC6724 before invoking on_done. */ - if (exec_ctx == NULL) { + if (exec_ctx == nullptr) { /* A new exec_ctx is created here, as the c-ares interface does not provide one in ares_host_callback. It's safe to schedule on_done with the newly created exec_ctx, since the caller has been warned not to @@ -150,12 +150,12 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, r->error = GRPC_ERROR_NONE; r->success = true; grpc_lb_addresses** lb_addresses = r->lb_addrs_out; - if (*lb_addresses == NULL) { - *lb_addresses = grpc_lb_addresses_create(0, NULL); + if (*lb_addresses == nullptr) { + *lb_addresses = grpc_lb_addresses_create(0, nullptr); } size_t prev_naddr = (*lb_addresses)->num_addresses; size_t i; - for (i = 0; hostent->h_addr_list[i] != NULL; i++) { + for (i = 0; hostent->h_addr_list[i] != nullptr; i++) { } (*lb_addresses)->num_addresses += i; (*lb_addresses)->addresses = (grpc_lb_address*)gpr_realloc( @@ -174,8 +174,8 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, grpc_lb_addresses_set_address( *lb_addresses, i, &addr, addr_len, hr->is_balancer /* is_balancer */, - hr->is_balancer ? hr->host : NULL /* balancer_name */, - NULL /* user_data */); + hr->is_balancer ? hr->host : nullptr /* balancer_name */, + nullptr /* user_data */); char output[INET6_ADDRSTRLEN]; ares_inet_ntop(AF_INET6, &addr.sin6_addr, output, INET6_ADDRSTRLEN); gpr_log(GPR_DEBUG, @@ -195,8 +195,8 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, grpc_lb_addresses_set_address( *lb_addresses, i, &addr, addr_len, hr->is_balancer /* is_balancer */, - hr->is_balancer ? hr->host : NULL /* balancer_name */, - NULL /* user_data */); + hr->is_balancer ? hr->host : nullptr /* balancer_name */, + nullptr /* user_data */); char output[INET_ADDRSTRLEN]; ares_inet_ntop(AF_INET, &addr.sin_addr, output, INET_ADDRSTRLEN); gpr_log(GPR_DEBUG, @@ -220,7 +220,7 @@ static void on_hostbyname_done_cb(void* arg, int status, int timeouts, } } gpr_mu_unlock(&r->mu); - destroy_hostbyname_request(NULL, hr); + destroy_hostbyname_request(nullptr, hr); } static void on_srv_query_done_cb(void* arg, int status, int timeouts, @@ -234,7 +234,7 @@ static void on_srv_query_done_cb(void* arg, int status, int timeouts, const int parse_status = ares_parse_srv_reply(abuf, alen, &reply); if (parse_status == ARES_SUCCESS) { ares_channel* channel = grpc_ares_ev_driver_get_channel(r->ev_driver); - for (struct ares_srv_reply* srv_it = reply; srv_it != NULL; + for (struct ares_srv_reply* srv_it = reply; srv_it != nullptr; srv_it = srv_it->next) { if (grpc_ipv6_loopback_available()) { grpc_ares_hostbyname_request* hr = create_hostbyname_request( @@ -249,7 +249,7 @@ static void on_srv_query_done_cb(void* arg, int status, int timeouts, grpc_ares_ev_driver_start(&exec_ctx, r->ev_driver); } } - if (reply != NULL) { + if (reply != nullptr) { ares_free_data(reply); } } else if (!r->success) { @@ -276,15 +276,15 @@ static void on_txt_done_cb(void* arg, int status, int timeouts, char* error_msg; grpc_ares_request* r = (grpc_ares_request*)arg; const size_t prefix_len = sizeof(g_service_config_attribute_prefix) - 1; - struct ares_txt_ext* result = NULL; - struct ares_txt_ext* reply = NULL; + struct ares_txt_ext* result = nullptr; + struct ares_txt_ext* reply = nullptr; grpc_error* error = GRPC_ERROR_NONE; gpr_mu_lock(&r->mu); if (status != ARES_SUCCESS) goto fail; status = ares_parse_txt_reply_ext(buf, len, &reply); if (status != ARES_SUCCESS) goto fail; // Find service config in TXT record. - for (result = reply; result != NULL; result = result->next) { + for (result = reply; result != nullptr; result = result->next) { if (result->record_start && memcmp(result->txt, g_service_config_attribute_prefix, prefix_len) == 0) { @@ -292,7 +292,7 @@ static void on_txt_done_cb(void* arg, int status, int timeouts, } } // Found a service config record. - if (result != NULL) { + if (result != nullptr) { size_t service_config_len = result->length - prefix_len; *r->service_config_json_out = (char*)gpr_malloc(service_config_len + 1); memcpy(*r->service_config_json_out, result->txt + prefix_len, @@ -323,7 +323,7 @@ fail: } done: gpr_mu_unlock(&r->mu); - grpc_ares_request_unref(NULL, r); + grpc_ares_request_unref(nullptr, r); } static grpc_ares_request* grpc_dns_lookup_ares_impl( @@ -332,8 +332,8 @@ static grpc_ares_request* grpc_dns_lookup_ares_impl( grpc_closure* on_done, grpc_lb_addresses** addrs, bool check_grpclb, char** service_config_json) { grpc_error* error = GRPC_ERROR_NONE; - grpc_ares_hostbyname_request* hr = NULL; - grpc_ares_request* r = NULL; + grpc_ares_hostbyname_request* hr = nullptr; + grpc_ares_request* r = nullptr; ares_channel* channel = NULL; /* TODO(zyc): Enable tracing after #9603 is checked in */ /* if (grpc_dns_trace) { @@ -345,13 +345,13 @@ static grpc_ares_request* grpc_dns_lookup_ares_impl( char* host; char* port; gpr_split_host_port(name, &host, &port); - if (host == NULL) { + if (host == nullptr) { error = grpc_error_set_str( GRPC_ERROR_CREATE_FROM_STATIC_STRING("unparseable host:port"), GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name)); goto error_cleanup; - } else if (port == NULL) { - if (default_port == NULL) { + } else if (port == nullptr) { + if (default_port == nullptr) { error = grpc_error_set_str( GRPC_ERROR_CREATE_FROM_STATIC_STRING("no port in name"), GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name)); @@ -375,7 +375,7 @@ static grpc_ares_request* grpc_dns_lookup_ares_impl( channel = grpc_ares_ev_driver_get_channel(r->ev_driver); // If dns_server is specified, use it. - if (dns_server != NULL) { + if (dns_server != nullptr) { gpr_log(GPR_INFO, "Using DNS server %s", dns_server); grpc_resolved_address addr; if (grpc_parse_ipv4_hostport(dns_server, &addr, false /* log_errors */)) { @@ -429,7 +429,7 @@ static grpc_ares_request* grpc_dns_lookup_ares_impl( r); gpr_free(service_name); } - if (service_config_json != NULL) { + if (service_config_json != nullptr) { grpc_ares_request_ref(r); ares_search(*channel, hr->host, ns_c_in, ns_t_txt, on_txt_done_cb, r); } @@ -444,7 +444,7 @@ error_cleanup: GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); gpr_free(host); gpr_free(port); - return NULL; + return nullptr; } grpc_ares_request* (*grpc_dns_lookup_ares)( @@ -503,8 +503,8 @@ static void on_dns_lookup_done_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_resolve_address_ares_request* r = (grpc_resolve_address_ares_request*)arg; grpc_resolved_addresses** resolved_addresses = r->addrs_out; - if (r->lb_addrs == NULL || r->lb_addrs->num_addresses == 0) { - *resolved_addresses = NULL; + if (r->lb_addrs == nullptr || r->lb_addrs->num_addresses == 0) { + *resolved_addresses = nullptr; } else { *resolved_addresses = (grpc_resolved_addresses*)gpr_zalloc(sizeof(grpc_resolved_addresses)); @@ -536,10 +536,10 @@ static void grpc_resolve_address_ares_impl(grpc_exec_ctx* exec_ctx, r->on_resolve_address_done = on_done; GRPC_CLOSURE_INIT(&r->on_dns_lookup_done, on_dns_lookup_done_cb, r, grpc_schedule_on_exec_ctx); - grpc_dns_lookup_ares(exec_ctx, NULL /* dns_server */, name, default_port, + grpc_dns_lookup_ares(exec_ctx, nullptr /* dns_server */, name, default_port, interested_parties, &r->on_dns_lookup_done, &r->lb_addrs, false /* check_grpclb */, - NULL /* service_config_json */); + nullptr /* service_config_json */); } void (*grpc_resolve_address_ares)( diff --git a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc index a57ab66118..589c74807f 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc @@ -100,12 +100,12 @@ static void dns_shutdown_locked(grpc_exec_ctx* exec_ctx, if (r->have_retry_timer) { grpc_timer_cancel(exec_ctx, &r->retry_timer); } - if (r->next_completion != NULL) { - *r->target_result = NULL; + if (r->next_completion != nullptr) { + *r->target_result = nullptr; GRPC_CLOSURE_SCHED( exec_ctx, r->next_completion, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resolver Shutdown")); - r->next_completion = NULL; + r->next_completion = nullptr; } } @@ -150,20 +150,20 @@ static void dns_on_retry_timer_locked(grpc_exec_ctx* exec_ctx, void* arg, static void dns_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { dns_resolver* r = (dns_resolver*)arg; - grpc_channel_args* result = NULL; + grpc_channel_args* result = nullptr; GPR_ASSERT(r->resolving); r->resolving = false; GRPC_ERROR_REF(error); error = grpc_error_set_str(error, GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(r->name_to_resolve)); - if (r->addresses != NULL) { + if (r->addresses != nullptr) { grpc_lb_addresses* addresses = grpc_lb_addresses_create( - r->addresses->naddrs, NULL /* user_data_vtable */); + r->addresses->naddrs, nullptr /* user_data_vtable */); for (size_t i = 0; i < r->addresses->naddrs; ++i) { grpc_lb_addresses_set_address( addresses, i, &r->addresses->addrs[i].addr, r->addresses->addrs[i].len, false /* is_balancer */, - NULL /* balancer_name */, NULL /* user_data */); + nullptr /* balancer_name */, nullptr /* user_data */); } grpc_arg new_arg = grpc_lb_addresses_create_channel_arg(addresses); result = grpc_channel_args_copy_and_add(r->channel_args, &new_arg, 1); @@ -187,7 +187,7 @@ static void dns_on_resolved_locked(grpc_exec_ctx* exec_ctx, void* arg, grpc_combiner_scheduler(r->base.combiner)); grpc_timer_init(exec_ctx, &r->retry_timer, next_try, &r->on_retry); } - if (r->resolved_result != NULL) { + if (r->resolved_result != nullptr) { grpc_channel_args_destroy(exec_ctx, r->resolved_result); } r->resolved_result = result; @@ -203,7 +203,7 @@ static void dns_start_resolving_locked(grpc_exec_ctx* exec_ctx, GRPC_RESOLVER_REF(&r->base, "dns-resolving"); GPR_ASSERT(!r->resolving); r->resolving = true; - r->addresses = NULL; + r->addresses = nullptr; grpc_resolve_address( exec_ctx, r->name_to_resolve, r->default_port, r->interested_parties, GRPC_CLOSURE_CREATE(dns_on_resolved_locked, r, @@ -213,20 +213,20 @@ static void dns_start_resolving_locked(grpc_exec_ctx* exec_ctx, static void dns_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, dns_resolver* r) { - if (r->next_completion != NULL && + if (r->next_completion != nullptr && r->resolved_version != r->published_version) { - *r->target_result = r->resolved_result == NULL - ? NULL + *r->target_result = r->resolved_result == nullptr + ? nullptr : grpc_channel_args_copy(r->resolved_result); GRPC_CLOSURE_SCHED(exec_ctx, r->next_completion, GRPC_ERROR_NONE); - r->next_completion = NULL; + r->next_completion = nullptr; r->published_version = r->resolved_version; } } static void dns_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { dns_resolver* r = (dns_resolver*)gr; - if (r->resolved_result != NULL) { + if (r->resolved_result != nullptr) { grpc_channel_args_destroy(exec_ctx, r->resolved_result); } grpc_pollset_set_destroy(exec_ctx, r->interested_parties); @@ -241,7 +241,7 @@ static grpc_resolver* dns_create(grpc_exec_ctx* exec_ctx, const char* default_port) { if (0 != strcmp(args->uri->authority, "")) { gpr_log(GPR_ERROR, "authority based dns uri's not supported"); - return NULL; + return nullptr; } // Get name from args. char* path = args->uri->path; @@ -253,7 +253,7 @@ static grpc_resolver* dns_create(grpc_exec_ctx* exec_ctx, r->default_port = gpr_strdup(default_port); r->channel_args = grpc_channel_args_copy(args->args); r->interested_parties = grpc_pollset_set_create(); - if (args->pollset_set != NULL) { + if (args->pollset_set != nullptr) { grpc_pollset_set_add_pollset_set(exec_ctx, r->interested_parties, args->pollset_set); } @@ -297,13 +297,13 @@ static grpc_resolver_factory* dns_resolver_factory_create() { extern "C" void grpc_resolver_dns_native_init(void) { char* resolver = gpr_getenv("GRPC_DNS_RESOLVER"); - if (resolver != NULL && gpr_stricmp(resolver, "native") == 0) { + if (resolver != nullptr && gpr_stricmp(resolver, "native") == 0) { gpr_log(GPR_DEBUG, "Using native dns resolver"); grpc_register_resolver_type(dns_resolver_factory_create()); } else { grpc_resolver_factory* existing_factory = grpc_resolver_factory_lookup("dns"); - if (existing_factory == NULL) { + if (existing_factory == nullptr) { gpr_log(GPR_DEBUG, "Using native dns resolver"); grpc_register_resolver_type(dns_resolver_factory_create()); } else { diff --git a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc index ed5b1011fb..85d7090144 100644 --- a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc @@ -78,31 +78,31 @@ static void fake_resolver_destroy(grpc_exec_ctx* exec_ctx, grpc_resolver* gr) { static void fake_resolver_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver) { fake_resolver* r = (fake_resolver*)resolver; - if (r->next_completion != NULL) { - *r->target_result = NULL; + if (r->next_completion != nullptr) { + *r->target_result = nullptr; GRPC_CLOSURE_SCHED( exec_ctx, r->next_completion, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resolver Shutdown")); - r->next_completion = NULL; + r->next_completion = nullptr; } } static void fake_resolver_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, fake_resolver* r) { - if (r->next_completion != NULL && r->next_results != NULL) { + if (r->next_completion != nullptr && r->next_results != nullptr) { *r->target_result = grpc_channel_args_union(r->next_results, r->channel_args); grpc_channel_args_destroy(exec_ctx, r->next_results); - r->next_results = NULL; + r->next_results = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, r->next_completion, GRPC_ERROR_NONE); - r->next_completion = NULL; + r->next_completion = nullptr; } } static void fake_resolver_channel_saw_error_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver) { fake_resolver* r = (fake_resolver*)resolver; - if (r->next_results == NULL && r->results_upon_error != NULL) { + if (r->next_results == nullptr && r->results_upon_error != nullptr) { // Pretend we re-resolved. r->next_results = grpc_channel_args_copy(r->results_upon_error); } @@ -162,11 +162,11 @@ static void set_response_closure_fn(grpc_exec_ctx* exec_ctx, void* arg, set_response_closure_arg* closure_arg = (set_response_closure_arg*)arg; grpc_fake_resolver_response_generator* generator = closure_arg->generator; fake_resolver* r = generator->resolver; - if (r->next_results != NULL) { + if (r->next_results != nullptr) { grpc_channel_args_destroy(exec_ctx, r->next_results); } r->next_results = closure_arg->next_response; - if (r->results_upon_error != NULL) { + if (r->results_upon_error != nullptr) { grpc_channel_args_destroy(exec_ctx, r->results_upon_error); } r->results_upon_error = grpc_channel_args_copy(closure_arg->next_response); @@ -177,7 +177,7 @@ static void set_response_closure_fn(grpc_exec_ctx* exec_ctx, void* arg, void grpc_fake_resolver_response_generator_set_response( grpc_exec_ctx* exec_ctx, grpc_fake_resolver_response_generator* generator, grpc_channel_args* next_response) { - GPR_ASSERT(generator->resolver != NULL); + GPR_ASSERT(generator->resolver != nullptr); set_response_closure_arg* closure_arg = (set_response_closure_arg*)gpr_zalloc(sizeof(*closure_arg)); closure_arg->generator = generator; @@ -220,7 +220,7 @@ grpc_fake_resolver_response_generator* grpc_fake_resolver_get_response_generator(const grpc_channel_args* args) { const grpc_arg* arg = grpc_channel_args_find(args, GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR); - if (arg == NULL || arg->type != GRPC_ARG_POINTER) return NULL; + if (arg == nullptr || arg->type != GRPC_ARG_POINTER) return nullptr; return (grpc_fake_resolver_response_generator*)arg->value.pointer.p; } @@ -240,7 +240,7 @@ static grpc_resolver* fake_resolver_create(grpc_exec_ctx* exec_ctx, grpc_resolver_init(&r->base, &fake_resolver_vtable, args->combiner); grpc_fake_resolver_response_generator* response_generator = grpc_fake_resolver_get_response_generator(args->args); - if (response_generator != NULL) response_generator->resolver = r; + if (response_generator != nullptr) response_generator->resolver = r; return &r->base; } diff --git a/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc b/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc index 9fc8dffea3..82afd1d8b7 100644 --- a/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc @@ -71,12 +71,12 @@ static const grpc_resolver_vtable sockaddr_resolver_vtable = { static void sockaddr_shutdown_locked(grpc_exec_ctx* exec_ctx, grpc_resolver* resolver) { sockaddr_resolver* r = (sockaddr_resolver*)resolver; - if (r->next_completion != NULL) { - *r->target_result = NULL; + if (r->next_completion != nullptr) { + *r->target_result = nullptr; GRPC_CLOSURE_SCHED( exec_ctx, r->next_completion, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Resolver Shutdown")); - r->next_completion = NULL; + r->next_completion = nullptr; } } @@ -100,13 +100,13 @@ static void sockaddr_next_locked(grpc_exec_ctx* exec_ctx, static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx* exec_ctx, sockaddr_resolver* r) { - if (r->next_completion != NULL && !r->published) { + if (r->next_completion != nullptr && !r->published) { r->published = true; grpc_arg arg = grpc_lb_addresses_create_channel_arg(r->addresses); *r->target_result = grpc_channel_args_copy_and_add(r->channel_args, &arg, 1); GRPC_CLOSURE_SCHED(exec_ctx, r->next_completion, GRPC_ERROR_NONE); - r->next_completion = NULL; + r->next_completion = nullptr; } } @@ -149,7 +149,7 @@ static grpc_resolver* sockaddr_create(grpc_exec_ctx* exec_ctx, if (0 != strcmp(args->uri->authority, "")) { gpr_log(GPR_ERROR, "authority based uri's not supported by the %s scheme", args->uri->scheme); - return NULL; + return nullptr; } /* Construct addresses. */ grpc_slice path_slice = @@ -158,7 +158,7 @@ static grpc_resolver* sockaddr_create(grpc_exec_ctx* exec_ctx, grpc_slice_buffer_init(&path_parts); grpc_slice_split(path_slice, ",", &path_parts); grpc_lb_addresses* addresses = - grpc_lb_addresses_create(path_parts.count, NULL /* user_data_vtable */); + grpc_lb_addresses_create(path_parts.count, nullptr /* user_data_vtable */); bool errors_found = false; for (size_t i = 0; i < addresses->num_addresses; i++) { grpc_uri ith_uri = *args->uri; @@ -174,7 +174,7 @@ static grpc_resolver* sockaddr_create(grpc_exec_ctx* exec_ctx, grpc_slice_unref_internal(exec_ctx, path_slice); if (errors_found) { grpc_lb_addresses_destroy(exec_ctx, addresses); - return NULL; + return nullptr; } /* Instantiate resolver. */ sockaddr_resolver* r = diff --git a/src/core/ext/filters/client_channel/resolver_factory.cc b/src/core/ext/filters/client_channel/resolver_factory.cc index 6f0a7c1e36..1a289d9771 100644 --- a/src/core/ext/filters/client_channel/resolver_factory.cc +++ b/src/core/ext/filters/client_channel/resolver_factory.cc @@ -30,12 +30,12 @@ void grpc_resolver_factory_unref(grpc_resolver_factory* factory) { grpc_resolver* grpc_resolver_factory_create_resolver( grpc_exec_ctx* exec_ctx, grpc_resolver_factory* factory, grpc_resolver_args* args) { - if (factory == NULL) return NULL; + if (factory == nullptr) return nullptr; return factory->vtable->create_resolver(exec_ctx, factory, args); } char* grpc_resolver_factory_get_default_authority( grpc_resolver_factory* factory, grpc_uri* uri) { - if (factory == NULL) return NULL; + if (factory == nullptr) return nullptr; return factory->vtable->get_default_authority(factory, uri); } diff --git a/src/core/ext/filters/client_channel/resolver_registry.cc b/src/core/ext/filters/client_channel/resolver_registry.cc index 9e45887f35..5da6114a3d 100644 --- a/src/core/ext/filters/client_channel/resolver_registry.cc +++ b/src/core/ext/filters/client_channel/resolver_registry.cc @@ -78,7 +78,7 @@ static grpc_resolver_factory* lookup_factory(const char* name) { return g_all_of_the_resolvers[i]; } } - return NULL; + return nullptr; } grpc_resolver_factory* grpc_resolver_factory_lookup(const char* name) { @@ -88,7 +88,7 @@ grpc_resolver_factory* grpc_resolver_factory_lookup(const char* name) { } static grpc_resolver_factory* lookup_factory_by_uri(grpc_uri* uri) { - if (!uri) return NULL; + if (!uri) return nullptr; return lookup_factory(uri->scheme); } @@ -96,17 +96,17 @@ static grpc_resolver_factory* resolve_factory(grpc_exec_ctx* exec_ctx, const char* target, grpc_uri** uri, char** canonical_target) { - grpc_resolver_factory* factory = NULL; + grpc_resolver_factory* factory = nullptr; - GPR_ASSERT(uri != NULL); + GPR_ASSERT(uri != nullptr); *uri = grpc_uri_parse(exec_ctx, target, 1); factory = lookup_factory_by_uri(*uri); - if (factory == NULL) { + if (factory == nullptr) { grpc_uri_destroy(*uri); gpr_asprintf(canonical_target, "%s%s", g_default_resolver_prefix, target); *uri = grpc_uri_parse(exec_ctx, *canonical_target, 1); factory = lookup_factory_by_uri(*uri); - if (factory == NULL) { + if (factory == nullptr) { grpc_uri_destroy(grpc_uri_parse(exec_ctx, target, 0)); grpc_uri_destroy(grpc_uri_parse(exec_ctx, *canonical_target, 0)); gpr_log(GPR_ERROR, "don't know how to resolve '%s' or '%s'", target, @@ -120,8 +120,8 @@ grpc_resolver* grpc_resolver_create(grpc_exec_ctx* exec_ctx, const char* target, const grpc_channel_args* args, grpc_pollset_set* pollset_set, grpc_combiner* combiner) { - grpc_uri* uri = NULL; - char* canonical_target = NULL; + grpc_uri* uri = nullptr; + char* canonical_target = nullptr; grpc_resolver_factory* factory = resolve_factory(exec_ctx, target, &uri, &canonical_target); grpc_resolver* resolver; @@ -139,8 +139,8 @@ grpc_resolver* grpc_resolver_create(grpc_exec_ctx* exec_ctx, const char* target, } char* grpc_get_default_authority(grpc_exec_ctx* exec_ctx, const char* target) { - grpc_uri* uri = NULL; - char* canonical_target = NULL; + grpc_uri* uri = nullptr; + char* canonical_target = nullptr; grpc_resolver_factory* factory = resolve_factory(exec_ctx, target, &uri, &canonical_target); char* authority = grpc_resolver_factory_get_default_authority(factory, uri); @@ -151,9 +151,9 @@ char* grpc_get_default_authority(grpc_exec_ctx* exec_ctx, const char* target) { char* grpc_resolver_factory_add_default_prefix_if_needed( grpc_exec_ctx* exec_ctx, const char* target) { - grpc_uri* uri = NULL; - char* canonical_target = NULL; + grpc_uri* uri = nullptr; + char* canonical_target = nullptr; resolve_factory(exec_ctx, target, &uri, &canonical_target); grpc_uri_destroy(uri); - return canonical_target == NULL ? gpr_strdup(target) : canonical_target; + return canonical_target == nullptr ? gpr_strdup(target) : canonical_target; } diff --git a/src/core/ext/filters/client_channel/retry_throttle.cc b/src/core/ext/filters/client_channel/retry_throttle.cc index 09dcade089..867d775151 100644 --- a/src/core/ext/filters/client_channel/retry_throttle.cc +++ b/src/core/ext/filters/client_channel/retry_throttle.cc @@ -48,7 +48,7 @@ static void get_replacement_throttle_data_if_needed( grpc_server_retry_throttle_data* new_throttle_data = (grpc_server_retry_throttle_data*)gpr_atm_acq_load( &(*throttle_data)->replacement); - if (new_throttle_data == NULL) return; + if (new_throttle_data == nullptr) return; *throttle_data = new_throttle_data; } } @@ -88,7 +88,7 @@ void grpc_server_retry_throttle_data_unref( grpc_server_retry_throttle_data* replacement = (grpc_server_retry_throttle_data*)gpr_atm_acq_load( &throttle_data->replacement); - if (replacement != NULL) { + if (replacement != nullptr) { grpc_server_retry_throttle_data_unref(replacement); } gpr_free(throttle_data); @@ -109,7 +109,7 @@ static grpc_server_retry_throttle_data* grpc_server_retry_throttle_data_create( // the token count by scaling proportionately to the old data. This // ensures that if we're already throttling retries on the old scale, // we will start out doing the same thing on the new one. - if (old_throttle_data != NULL) { + if (old_throttle_data != nullptr) { double token_fraction = (int)gpr_atm_acq_load(&old_throttle_data->milli_tokens) / (double)old_throttle_data->max_milli_tokens; @@ -119,7 +119,7 @@ static grpc_server_retry_throttle_data* grpc_server_retry_throttle_data_create( (gpr_atm)initial_milli_tokens); // If there was a pre-existing entry, mark it as stale and give it a // pointer to the new entry, which is its replacement. - if (old_throttle_data != NULL) { + if (old_throttle_data != nullptr) { grpc_server_retry_throttle_data_ref(throttle_data); gpr_atm_rel_store(&old_throttle_data->replacement, (gpr_atm)throttle_data); } @@ -170,7 +170,7 @@ void grpc_retry_throttle_map_init() { void grpc_retry_throttle_map_shutdown() { gpr_mu_destroy(&g_mu); - gpr_avl_unref(g_avl, NULL); + gpr_avl_unref(g_avl, nullptr); } grpc_server_retry_throttle_data* grpc_retry_throttle_map_get_data_for_server( @@ -178,12 +178,12 @@ grpc_server_retry_throttle_data* grpc_retry_throttle_map_get_data_for_server( gpr_mu_lock(&g_mu); grpc_server_retry_throttle_data* throttle_data = (grpc_server_retry_throttle_data*)gpr_avl_get(g_avl, (char*)server_name, - NULL); - if (throttle_data == NULL) { + nullptr); + if (throttle_data == nullptr) { // Entry not found. Create a new one. throttle_data = grpc_server_retry_throttle_data_create( - max_milli_tokens, milli_token_ratio, NULL); - g_avl = gpr_avl_add(g_avl, (char*)server_name, throttle_data, NULL); + max_milli_tokens, milli_token_ratio, nullptr); + g_avl = gpr_avl_add(g_avl, (char*)server_name, throttle_data, nullptr); } else { if (throttle_data->max_milli_tokens != max_milli_tokens || throttle_data->milli_token_ratio != milli_token_ratio) { @@ -191,7 +191,7 @@ grpc_server_retry_throttle_data* grpc_retry_throttle_map_get_data_for_server( // the original one. throttle_data = grpc_server_retry_throttle_data_create( max_milli_tokens, milli_token_ratio, throttle_data); - g_avl = gpr_avl_add(g_avl, (char*)server_name, throttle_data, NULL); + g_avl = gpr_avl_add(g_avl, (char*)server_name, throttle_data, nullptr); } else { // Entry found. Increase refcount. grpc_server_retry_throttle_data_ref(throttle_data); diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index 427df743d6..f0d61e2893 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -227,7 +227,7 @@ grpc_subchannel* grpc_subchannel_weak_ref( grpc_subchannel* grpc_subchannel_ref_from_weak_ref( grpc_subchannel* c GRPC_SUBCHANNEL_REF_EXTRA_ARGS) { - if (!c) return NULL; + if (!c) return nullptr; for (;;) { gpr_atm old_refs = gpr_atm_acq_load(&c->ref_pair); if (old_refs >= (1 << INTERNAL_REF_BITS)) { @@ -236,7 +236,7 @@ grpc_subchannel* grpc_subchannel_ref_from_weak_ref( return c; } } else { - return NULL; + return nullptr; } } } @@ -251,7 +251,7 @@ static void disconnect(grpc_exec_ctx* exec_ctx, grpc_subchannel* c) { exec_ctx, c->connector, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Subchannel disconnected")); con = GET_CONNECTED_SUBCHANNEL(c, no_barrier); - if (con != NULL) { + if (con != nullptr) { GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, con, "connection"); gpr_atm_no_barrier_store(&c->connected_subchannel, (gpr_atm)0xdeadbeef); } @@ -306,17 +306,17 @@ grpc_subchannel* grpc_subchannel_create(grpc_exec_ctx* exec_ctx, memcpy((void*)c->filters, args->filters, sizeof(grpc_channel_filter*) * c->num_filters); } else { - c->filters = NULL; + c->filters = nullptr; } c->pollset_set = grpc_pollset_set_create(); grpc_resolved_address* addr = (grpc_resolved_address*)gpr_malloc(sizeof(*addr)); grpc_get_subchannel_address_arg(exec_ctx, args->args, addr); - grpc_resolved_address* new_address = NULL; - grpc_channel_args* new_args = NULL; + grpc_resolved_address* new_address = nullptr; + grpc_channel_args* new_args = nullptr; if (grpc_proxy_mappers_map_address(exec_ctx, addr, args->args, &new_address, &new_args)) { - GPR_ASSERT(new_address != NULL); + GPR_ASSERT(new_address != nullptr); gpr_free(addr); addr = new_address; } @@ -324,10 +324,10 @@ grpc_subchannel* grpc_subchannel_create(grpc_exec_ctx* exec_ctx, grpc_arg new_arg = grpc_create_subchannel_address_arg(addr); gpr_free(addr); c->args = grpc_channel_args_copy_and_add_and_remove( - new_args != NULL ? new_args : args->args, keys_to_remove, + new_args != nullptr ? new_args : args->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), &new_arg, 1); gpr_free(new_arg.value.string); - if (new_args != NULL) grpc_channel_args_destroy(exec_ctx, new_args); + if (new_args != nullptr) grpc_channel_args_destroy(exec_ctx, new_args); c->root_external_state_watcher.next = c->root_external_state_watcher.prev = &c->root_external_state_watcher; GRPC_CLOSURE_INIT(&c->connected, subchannel_connected, c, @@ -404,7 +404,7 @@ static void on_external_state_watcher_done(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { external_state_watcher* w = (external_state_watcher*)arg; grpc_closure* follow_up = w->notify; - if (w->pollset_set != NULL) { + if (w->pollset_set != nullptr) { grpc_pollset_set_del_pollset_set(exec_ctx, w->subchannel->pollset_set, w->pollset_set); } @@ -451,7 +451,7 @@ static void maybe_start_connecting_locked(grpc_exec_ctx* exec_ctx, return; } - if (GET_CONNECTED_SUBCHANNEL(c, no_barrier) != NULL) { + if (GET_CONNECTED_SUBCHANNEL(c, no_barrier) != nullptr) { /* Already connected: don't restart */ return; } @@ -490,13 +490,13 @@ void grpc_subchannel_notify_on_state_change( grpc_closure* notify) { external_state_watcher* w; - if (state == NULL) { + if (state == nullptr) { gpr_mu_lock(&c->mu); for (w = c->root_external_state_watcher.next; w != &c->root_external_state_watcher; w = w->next) { if (w->notify == notify) { grpc_connectivity_state_notify_on_state_change( - exec_ctx, &c->state_tracker, NULL, &w->closure); + exec_ctx, &c->state_tracker, nullptr, &w->closure); } } gpr_mu_unlock(&c->mu); @@ -507,7 +507,7 @@ void grpc_subchannel_notify_on_state_change( w->notify = notify; GRPC_CLOSURE_INIT(&w->closure, on_external_state_watcher_done, w, grpc_schedule_on_exec_ctx); - if (interested_parties != NULL) { + if (interested_parties != nullptr) { grpc_pollset_set_add_pollset_set(exec_ctx, c->pollset_set, interested_parties); } @@ -549,10 +549,10 @@ static void subchannel_on_child_state_changed(grpc_exec_ctx* exec_ctx, void* p, "reflect_child"); if (sw->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { grpc_connected_subchannel_notify_on_state_change( - exec_ctx, GET_CONNECTED_SUBCHANNEL(c, no_barrier), NULL, + exec_ctx, GET_CONNECTED_SUBCHANNEL(c, no_barrier), nullptr, &sw->connectivity_state, &sw->closure); GRPC_SUBCHANNEL_WEAK_REF(c, "state_watcher"); - sw = NULL; + sw = nullptr; } gpr_mu_unlock(mu); @@ -565,7 +565,7 @@ static void connected_subchannel_state_op(grpc_exec_ctx* exec_ctx, grpc_pollset_set* interested_parties, grpc_connectivity_state* state, grpc_closure* closure) { - grpc_transport_op* op = grpc_make_transport_op(NULL); + grpc_transport_op* op = grpc_make_transport_op(nullptr); grpc_channel_element* elem; op->connectivity_state = state; op->on_connectivity_state_change = closure; @@ -585,7 +585,7 @@ void grpc_connected_subchannel_notify_on_state_change( void grpc_connected_subchannel_ping(grpc_exec_ctx* exec_ctx, grpc_connected_subchannel* con, grpc_closure* closure) { - grpc_transport_op* op = grpc_make_transport_op(NULL); + grpc_transport_op* op = grpc_make_transport_op(nullptr); grpc_channel_element* elem; op->send_ping = closure; elem = grpc_channel_stack_element(CHANNEL_STACK_FROM_CONNECTION(con), 0); @@ -611,7 +611,7 @@ static bool publish_transport_locked(grpc_exec_ctx* exec_ctx, return false; } grpc_error* error = grpc_channel_stack_builder_finish( - exec_ctx, builder, 0, 1, connection_destroy, NULL, (void**)&con); + exec_ctx, builder, 0, 1, connection_destroy, nullptr, (void**)&con); if (error != GRPC_ERROR_NONE) { grpc_transport_destroy(exec_ctx, c->connecting_result.transport); gpr_log(GPR_ERROR, "error initializing subchannel stack: %s", @@ -666,7 +666,7 @@ static void subchannel_connected(grpc_exec_ctx* exec_ctx, void* arg, GRPC_SUBCHANNEL_WEAK_REF(c, "connected"); gpr_mu_lock(&c->mu); c->connecting = false; - if (c->connecting_result.transport != NULL && + if (c->connecting_result.transport != nullptr && publish_transport_locked(exec_ctx, c)) { /* do nothing, transport was published */ } else if (c->disconnected) { @@ -697,10 +697,10 @@ static void subchannel_connected(grpc_exec_ctx* exec_ctx, void* arg, static void subchannel_call_destroy(grpc_exec_ctx* exec_ctx, void* call, grpc_error* error) { grpc_subchannel_call* c = (grpc_subchannel_call*)call; - GPR_ASSERT(c->schedule_closure_after_destroy != NULL); + GPR_ASSERT(c->schedule_closure_after_destroy != nullptr); GPR_TIMER_BEGIN("grpc_subchannel_call_unref.destroy", 0); grpc_connected_subchannel* connection = c->connection; - grpc_call_stack_destroy(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), NULL, + grpc_call_stack_destroy(exec_ctx, SUBCHANNEL_CALL_TO_CALL_STACK(c), nullptr, c->schedule_closure_after_destroy); GRPC_CONNECTED_SUBCHANNEL_UNREF(exec_ctx, connection, "subchannel_call"); GPR_TIMER_END("grpc_subchannel_call_unref.destroy", 0); @@ -708,8 +708,8 @@ static void subchannel_call_destroy(grpc_exec_ctx* exec_ctx, void* call, void grpc_subchannel_call_set_cleanup_closure(grpc_subchannel_call* call, grpc_closure* closure) { - GPR_ASSERT(call->schedule_closure_after_destroy == NULL); - GPR_ASSERT(closure != NULL); + GPR_ASSERT(call->schedule_closure_after_destroy == nullptr); + GPR_ASSERT(closure != nullptr); call->schedule_closure_after_destroy = closure; } @@ -756,7 +756,7 @@ grpc_error* grpc_connected_subchannel_create_call( (*call)->connection = GRPC_CONNECTED_SUBCHANNEL_REF(con, "subchannel_call"); const grpc_call_element_args call_args = { callstk, /* call_stack */ - NULL, /* server_transport_data */ + nullptr, /* server_transport_data */ args->context, /* context */ args->path, /* path */ args->start_time, /* start_time */ @@ -783,7 +783,7 @@ grpc_call_stack* grpc_subchannel_call_get_call_stack( static void grpc_uri_to_sockaddr(grpc_exec_ctx* exec_ctx, const char* uri_str, grpc_resolved_address* addr) { grpc_uri* uri = grpc_uri_parse(exec_ctx, uri_str, 0 /* suppress_errors */); - GPR_ASSERT(uri != NULL); + GPR_ASSERT(uri != nullptr); if (!grpc_parse_uri(uri, addr)) memset(addr, 0, sizeof(*addr)); grpc_uri_destroy(uri); } @@ -801,7 +801,7 @@ void grpc_get_subchannel_address_arg(grpc_exec_ctx* exec_ctx, const char* grpc_get_subchannel_address_uri_arg(const grpc_channel_args* args) { const grpc_arg* addr_arg = grpc_channel_args_find(args, GRPC_ARG_SUBCHANNEL_ADDRESS); - GPR_ASSERT(addr_arg != NULL); // Should have been set by LB policy. + GPR_ASSERT(addr_arg != nullptr); // Should have been set by LB policy. GPR_ASSERT(addr_arg->type == GRPC_ARG_STRING); return addr_arg->value.string; } diff --git a/src/core/ext/filters/client_channel/subchannel_index.cc b/src/core/ext/filters/client_channel/subchannel_index.cc index 0c4213cf77..ae39ca394e 100644 --- a/src/core/ext/filters/client_channel/subchannel_index.cc +++ b/src/core/ext/filters/client_channel/subchannel_index.cc @@ -53,7 +53,7 @@ static grpc_subchannel_key* create_key( memcpy((grpc_channel_filter*)k->args.filters, args->filters, sizeof(*k->args.filters) * k->args.filter_count); } else { - k->args.filters = NULL; + k->args.filters = nullptr; } k->args.args = copy_channel_args(args->args); return k; @@ -162,10 +162,10 @@ grpc_subchannel* grpc_subchannel_index_find(grpc_exec_ctx* exec_ctx, grpc_subchannel* grpc_subchannel_index_register(grpc_exec_ctx* exec_ctx, grpc_subchannel_key* key, grpc_subchannel* constructed) { - grpc_subchannel* c = NULL; + grpc_subchannel* c = nullptr; bool need_to_unref_constructed; - while (c == NULL) { + while (c == nullptr) { need_to_unref_constructed = false; // Compare and swap loop: @@ -176,10 +176,10 @@ grpc_subchannel* grpc_subchannel_index_register(grpc_exec_ctx* exec_ctx, // - Check to see if a subchannel already exists c = (grpc_subchannel*)gpr_avl_get(index, key, exec_ctx); - if (c != NULL) { + if (c != nullptr) { c = GRPC_SUBCHANNEL_REF_FROM_WEAK_REF(c, "index_register"); } - if (c != NULL) { + if (c != nullptr) { // yes -> we're done need_to_unref_constructed = true; } else { diff --git a/src/core/ext/filters/client_channel/uri_parser.cc b/src/core/ext/filters/client_channel/uri_parser.cc index 1cc52dec12..b76dcbe4e3 100644 --- a/src/core/ext/filters/client_channel/uri_parser.cc +++ b/src/core/ext/filters/client_channel/uri_parser.cc @@ -52,7 +52,7 @@ static grpc_uri* bad_uri(const char* uri_text, size_t pos, const char* section, gpr_free(line_prefix); } - return NULL; + return nullptr; } /** Returns a copy of percent decoded \a src[begin, end) */ @@ -148,10 +148,10 @@ static int parse_fragment_or_query(const char* uri_text, size_t* i) { static void parse_query_parts(grpc_uri* uri) { static const char* QUERY_PARTS_SEPARATOR = "&"; static const char* QUERY_PARTS_VALUE_SEPARATOR = "="; - GPR_ASSERT(uri->query != NULL); + GPR_ASSERT(uri->query != nullptr); if (uri->query[0] == '\0') { - uri->query_parts = NULL; - uri->query_parts_values = NULL; + uri->query_parts = nullptr; + uri->query_parts_values = nullptr; uri->num_query_parts = 0; return; } @@ -174,7 +174,7 @@ static void parse_query_parts(grpc_uri* uri) { * be included, even if they include the separator. */ uri->query_parts_values[i] = query_param_parts[1]; } else { - uri->query_parts_values[i] = NULL; + uri->query_parts_values[i] = nullptr; } for (size_t j = 2; j < num_query_param_parts; j++) { gpr_free(query_param_parts[j]); @@ -289,15 +289,15 @@ grpc_uri* grpc_uri_parse(grpc_exec_ctx* exec_ctx, const char* uri_text, } const char* grpc_uri_get_query_arg(const grpc_uri* uri, const char* key) { - GPR_ASSERT(key != NULL); - if (key[0] == '\0') return NULL; + GPR_ASSERT(key != nullptr); + if (key[0] == '\0') return nullptr; for (size_t i = 0; i < uri->num_query_parts; ++i) { if (0 == strcmp(key, uri->query_parts[i])) { return uri->query_parts_values[i]; } } - return NULL; + return nullptr; } void grpc_uri_destroy(grpc_uri* uri) { diff --git a/src/core/ext/filters/deadline/deadline_filter.cc b/src/core/ext/filters/deadline/deadline_filter.cc index dc194ec068..849ce7153e 100644 --- a/src/core/ext/filters/deadline/deadline_filter.cc +++ b/src/core/ext/filters/deadline/deadline_filter.cc @@ -91,7 +91,7 @@ static void start_timer_if_needed(grpc_exec_ctx* exec_ctx, return; } grpc_deadline_state* deadline_state = (grpc_deadline_state*)elem->call_data; - grpc_closure* closure = NULL; + grpc_closure* closure = nullptr; switch (deadline_state->timer_state) { case GRPC_DEADLINE_STATE_PENDING: // Note: We do not start the timer if there is already a timer @@ -111,7 +111,7 @@ static void start_timer_if_needed(grpc_exec_ctx* exec_ctx, elem, grpc_schedule_on_exec_ctx); break; } - GPR_ASSERT(closure != NULL); + GPR_ASSERT(closure != nullptr); GRPC_CALL_STACK_REF(deadline_state->call_stack, "deadline_timer"); grpc_timer_init(exec_ctx, &deadline_state->timer, deadline, closure); } @@ -378,7 +378,7 @@ static bool maybe_add_deadline_filter(grpc_exec_ctx* exec_ctx, return grpc_deadline_checking_enabled( grpc_channel_stack_builder_get_channel_arguments(builder)) ? grpc_channel_stack_builder_prepend_filter( - builder, (const grpc_channel_filter*)arg, NULL, NULL) + builder, (const grpc_channel_filter*)arg, nullptr, nullptr) : true; } diff --git a/src/core/ext/filters/http/client/http_client_filter.cc b/src/core/ext/filters/http/client/http_client_filter.cc index 590bd22b1e..a625369b02 100644 --- a/src/core/ext/filters/http/client/http_client_filter.cc +++ b/src/core/ext/filters/http/client/http_client_filter.cc @@ -71,7 +71,7 @@ typedef struct channel_data { static grpc_error* client_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_metadata_batch* b) { - if (b->idx.named.status != NULL) { + if (b->idx.named.status != nullptr) { if (grpc_mdelem_eq(b->idx.named.status->md, GRPC_MDELEM_STATUS_200)) { grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.status); } else { @@ -93,7 +93,7 @@ static grpc_error* client_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, } } - if (b->idx.named.grpc_message != NULL) { + if (b->idx.named.grpc_message != nullptr) { grpc_slice pct_decoded_msg = grpc_permissive_percent_decode_slice( GRPC_MDVALUE(b->idx.named.grpc_message->md)); if (grpc_slice_is_equivalent(pct_decoded_msg, @@ -105,7 +105,7 @@ static grpc_error* client_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, } } - if (b->idx.named.content_type != NULL) { + if (b->idx.named.content_type != nullptr) { if (!grpc_mdelem_eq(b->idx.named.content_type->md, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)) { if (grpc_slice_buf_start_eq(GRPC_MDVALUE(b->idx.named.content_type->md), @@ -292,7 +292,7 @@ static grpc_error* update_path_for_get(grpc_exec_ctx* exec_ctx, static void remove_if_present(grpc_exec_ctx* exec_ctx, grpc_metadata_batch* batch, grpc_metadata_batch_callouts_index idx) { - if (batch->idx.array[idx] != NULL) { + if (batch->idx.array[idx] != nullptr) { grpc_metadata_batch_remove(exec_ctx, batch, batch->idx.array[idx]); } } @@ -450,7 +450,7 @@ static grpc_mdelem scheme_from_args(const grpc_channel_args* args) { size_t j; grpc_mdelem valid_schemes[] = {GRPC_MDELEM_SCHEME_HTTP, GRPC_MDELEM_SCHEME_HTTPS}; - if (args != NULL) { + if (args != nullptr) { for (i = 0; i < args->num_args; ++i) { if (args->args[i].type == GRPC_ARG_STRING && strcmp(args->args[i].key, GRPC_ARG_HTTP2_SCHEME) == 0) { @@ -467,7 +467,7 @@ static grpc_mdelem scheme_from_args(const grpc_channel_args* args) { } static size_t max_payload_size_from_args(const grpc_channel_args* args) { - if (args != NULL) { + if (args != nullptr) { for (size_t i = 0; i < args->num_args; ++i) { if (0 == strcmp(args->args[i].key, GRPC_ARG_MAX_PAYLOAD_SIZE_FOR_GET)) { if (args->args[i].type != GRPC_ARG_INTEGER) { @@ -524,7 +524,7 @@ static grpc_slice user_agent_from_args(const grpc_channel_args* args, } } - tmp = gpr_strvec_flatten(&v, NULL); + tmp = gpr_strvec_flatten(&v, nullptr); gpr_strvec_destroy(&v); result = grpc_slice_intern(grpc_slice_from_static_string(tmp)); gpr_free(tmp); @@ -538,7 +538,7 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, grpc_channel_element_args* args) { channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(!args->is_last); - GPR_ASSERT(args->optional_transport != NULL); + GPR_ASSERT(args->optional_transport != nullptr); chand->static_scheme = scheme_from_args(args->channel_args); chand->max_payload_size_for_get = max_payload_size_from_args(args->channel_args); diff --git a/src/core/ext/filters/http/http_filters_plugin.cc b/src/core/ext/filters/http/http_filters_plugin.cc index 064e66e323..69dbde409c 100644 --- a/src/core/ext/filters/http/http_filters_plugin.cc +++ b/src/core/ext/filters/http/http_filters_plugin.cc @@ -37,7 +37,7 @@ static optional_filter compress_filter = { static bool is_building_http_like_transport( grpc_channel_stack_builder* builder) { grpc_transport* t = grpc_channel_stack_builder_get_transport(builder); - return t != NULL && strstr(t->vtable->name, "http"); + return t != nullptr && strstr(t->vtable->name, "http"); } static bool maybe_add_optional_filter(grpc_exec_ctx* exec_ctx, @@ -51,7 +51,7 @@ static bool maybe_add_optional_filter(grpc_exec_ctx* exec_ctx, grpc_channel_args_find(channel_args, filtarg->control_channel_arg), !grpc_channel_args_want_minimal_stack(channel_args)); return enable ? grpc_channel_stack_builder_prepend_filter( - builder, filtarg->filter, NULL, NULL) + builder, filtarg->filter, nullptr, nullptr) : true; } @@ -60,7 +60,7 @@ static bool maybe_add_required_filter(grpc_exec_ctx* exec_ctx, void* arg) { return is_building_http_like_transport(builder) ? grpc_channel_stack_builder_prepend_filter( - builder, (const grpc_channel_filter*)arg, NULL, NULL) + builder, (const grpc_channel_filter*)arg, nullptr, nullptr) : true; } diff --git a/src/core/ext/filters/http/message_compress/message_compress_filter.cc b/src/core/ext/filters/http/message_compress/message_compress_filter.cc index 949ff917d6..8d95133d8f 100644 --- a/src/core/ext/filters/http/message_compress/message_compress_filter.cc +++ b/src/core/ext/filters/http/message_compress/message_compress_filter.cc @@ -112,7 +112,7 @@ static grpc_error* process_send_initial_metadata( grpc_stream_compression_algorithm stream_compression_algorithm = GRPC_STREAM_COMPRESS_NONE; if (initial_metadata->idx.named.grpc_internal_stream_encoding_request != - NULL) { + nullptr) { grpc_mdelem md = initial_metadata->idx.named.grpc_internal_stream_encoding_request->md; if (!grpc_stream_compression_algorithm_parse( @@ -141,13 +141,13 @@ static grpc_error* process_send_initial_metadata( initial_metadata->idx.named.grpc_internal_stream_encoding_request); /* Disable message-wise compression */ calld->compression_algorithm = GRPC_COMPRESS_NONE; - if (initial_metadata->idx.named.grpc_internal_encoding_request != NULL) { + if (initial_metadata->idx.named.grpc_internal_encoding_request != nullptr) { grpc_metadata_batch_remove( exec_ctx, initial_metadata, initial_metadata->idx.named.grpc_internal_encoding_request); } } else if (initial_metadata->idx.named.grpc_internal_encoding_request != - NULL) { + nullptr) { grpc_mdelem md = initial_metadata->idx.named.grpc_internal_encoding_request->md; if (!grpc_compression_algorithm_parse(GRPC_MDVALUE(md), @@ -228,7 +228,7 @@ static void send_message_batch_continue(grpc_exec_ctx* exec_ctx, // before we do that. grpc_transport_stream_op_batch* send_message_batch = calld->send_message_batch; - calld->send_message_batch = NULL; + calld->send_message_batch = nullptr; grpc_call_next_op(exec_ctx, elem, send_message_batch); } @@ -287,11 +287,11 @@ static void fail_send_message_batch_in_call_combiner(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { call_data* calld = (call_data*)arg; - if (calld->send_message_batch != NULL) { + if (calld->send_message_batch != nullptr) { grpc_transport_stream_op_batch_finish_with_failure( exec_ctx, calld->send_message_batch, GRPC_ERROR_REF(error), calld->call_combiner); - calld->send_message_batch = NULL; + calld->send_message_batch = nullptr; } } @@ -382,7 +382,7 @@ static void compress_start_transport_stream_op_batch( GRPC_ERROR_UNREF(calld->cancel_error); calld->cancel_error = GRPC_ERROR_REF(batch->payload->cancel_stream.cancel_error); - if (calld->send_message_batch != NULL) { + if (calld->send_message_batch != nullptr) { if (calld->send_initial_metadata_state == INITIAL_METADATA_UNSEEN) { GRPC_CALL_COMBINER_START( exec_ctx, calld->call_combiner, @@ -423,7 +423,7 @@ static void compress_start_transport_stream_op_batch( // for this, since we can't send two batches down while holding the // call combiner, since the connected_channel filter (at the bottom of // the call stack) will release the call combiner for each batch it sees. - if (calld->send_message_batch != NULL) { + if (calld->send_message_batch != nullptr) { GRPC_CALL_COMBINER_START( exec_ctx, calld->call_combiner, &calld->start_send_message_batch_in_call_combiner, GRPC_ERROR_NONE, @@ -432,7 +432,7 @@ static void compress_start_transport_stream_op_batch( } // Handle send_message. if (batch->send_message) { - GPR_ASSERT(calld->send_message_batch == NULL); + GPR_ASSERT(calld->send_message_batch == nullptr); calld->send_message_batch = batch; // If we have not yet seen send_initial_metadata, then we have to // wait. We save the batch in calld and then drop the call diff --git a/src/core/ext/filters/http/server/http_server_filter.cc b/src/core/ext/filters/http/server/http_server_filter.cc index 5cfe5acced..4f3897915c 100644 --- a/src/core/ext/filters/http/server/http_server_filter.cc +++ b/src/core/ext/filters/http/server/http_server_filter.cc @@ -69,7 +69,7 @@ typedef struct channel_data { static grpc_error* server_filter_outgoing_metadata(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_metadata_batch* b) { - if (b->idx.named.grpc_message != NULL) { + if (b->idx.named.grpc_message != nullptr) { grpc_slice pct_encoded_msg = grpc_percent_encode_slice( GRPC_MDVALUE(b->idx.named.grpc_message->md), grpc_compatible_percent_encoding_unreserved_bytes); @@ -100,7 +100,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, grpc_error* error = GRPC_ERROR_NONE; static const char* error_name = "Failed processing incoming headers"; - if (b->idx.named.method != NULL) { + if (b->idx.named.method != nullptr) { if (grpc_mdelem_eq(b->idx.named.method->md, GRPC_MDELEM_METHOD_POST)) { *calld->recv_initial_metadata_flags &= ~(GRPC_INITIAL_METADATA_CACHEABLE_REQUEST | @@ -132,7 +132,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, GRPC_ERROR_STR_KEY, grpc_slice_from_static_string(":method"))); } - if (b->idx.named.te != NULL) { + if (b->idx.named.te != nullptr) { if (!grpc_mdelem_eq(b->idx.named.te->md, GRPC_MDELEM_TE_TRAILERS)) { add_error(error_name, &error, grpc_attach_md_to_error( @@ -147,7 +147,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, GRPC_ERROR_STR_KEY, grpc_slice_from_static_string("te"))); } - if (b->idx.named.scheme != NULL) { + if (b->idx.named.scheme != nullptr) { if (!grpc_mdelem_eq(b->idx.named.scheme->md, GRPC_MDELEM_SCHEME_HTTP) && !grpc_mdelem_eq(b->idx.named.scheme->md, GRPC_MDELEM_SCHEME_HTTPS) && !grpc_mdelem_eq(b->idx.named.scheme->md, GRPC_MDELEM_SCHEME_GRPC)) { @@ -165,7 +165,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, GRPC_ERROR_STR_KEY, grpc_slice_from_static_string(":scheme"))); } - if (b->idx.named.content_type != NULL) { + if (b->idx.named.content_type != nullptr) { if (!grpc_mdelem_eq(b->idx.named.content_type->md, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)) { if (grpc_slice_buf_start_eq(GRPC_MDVALUE(b->idx.named.content_type->md), @@ -194,7 +194,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.content_type); } - if (b->idx.named.path == NULL) { + if (b->idx.named.path == nullptr) { add_error(error_name, &error, grpc_error_set_str( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Missing header"), @@ -239,7 +239,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, } } - if (b->idx.named.host != NULL && b->idx.named.authority == NULL) { + if (b->idx.named.host != nullptr && b->idx.named.authority == nullptr) { grpc_linked_mdelem* el = b->idx.named.host; grpc_mdelem md = GRPC_MDELEM_REF(el->md); grpc_metadata_batch_remove(exec_ctx, b, el); @@ -252,7 +252,7 @@ static grpc_error* server_filter_incoming_metadata(grpc_exec_ctx* exec_ctx, GRPC_MDELEM_UNREF(exec_ctx, md); } - if (b->idx.named.authority == NULL) { + if (b->idx.named.authority == nullptr) { add_error( error_name, &error, grpc_error_set_str( @@ -281,16 +281,16 @@ static void hs_on_complete(grpc_exec_ctx* exec_ctx, void* user_data, grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; /* Call recv_message_ready if we got the payload via the path field */ - if (calld->seen_path_with_query && calld->recv_message_ready != NULL) { + if (calld->seen_path_with_query && calld->recv_message_ready != nullptr) { *calld->pp_recv_message = calld->payload_bin_delivered - ? NULL + ? nullptr : (grpc_byte_stream*)&calld->read_stream; // Re-enter call combiner for recv_message_ready, since the surface // code will release the call combiner for each callback it receives. GRPC_CALL_COMBINER_START(exec_ctx, calld->call_combiner, calld->recv_message_ready, GRPC_ERROR_REF(err), "resuming recv_message_ready from on_complete"); - calld->recv_message_ready = NULL; + calld->recv_message_ready = nullptr; calld->payload_bin_delivered = true; } GRPC_CLOSURE_RUN(exec_ctx, calld->on_complete, GRPC_ERROR_REF(err)); @@ -341,7 +341,7 @@ static grpc_error* hs_mutate_op(grpc_exec_ctx* exec_ctx, if (op->recv_initial_metadata) { /* substitute our callback for the higher callback */ - GPR_ASSERT(op->payload->recv_initial_metadata.recv_flags != NULL); + GPR_ASSERT(op->payload->recv_initial_metadata.recv_flags != nullptr); calld->recv_initial_metadata = op->payload->recv_initial_metadata.recv_initial_metadata; calld->recv_initial_metadata_flags = diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc b/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc index 77b086c324..762198f034 100644 --- a/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc +++ b/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc @@ -60,7 +60,7 @@ static void on_initial_md_ready(grpc_exec_ctx* exec_ctx, void* user_data, call_data* calld = (call_data*)elem->call_data; if (err == GRPC_ERROR_NONE) { - if (calld->recv_initial_metadata->idx.named.path != NULL) { + if (calld->recv_initial_metadata->idx.named.path != nullptr) { calld->service_method = grpc_slice_ref_internal( GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.path->md)); calld->have_service_method = true; @@ -68,7 +68,7 @@ static void on_initial_md_ready(grpc_exec_ctx* exec_ctx, void* user_data, err = grpc_error_add_child( err, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Missing :path header")); } - if (calld->recv_initial_metadata->idx.named.lb_token != NULL) { + if (calld->recv_initial_metadata->idx.named.lb_token != nullptr) { calld->initial_md_string = grpc_slice_ref_internal( GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.lb_token->md)); calld->have_initial_md_string = true; diff --git a/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc b/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc index b26cbe3579..ab8387967c 100644 --- a/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc +++ b/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc @@ -48,8 +48,8 @@ static bool maybe_add_server_load_reporting_filter( !grpc_channel_stack_builder_iterator_is_end(it); grpc_channel_stack_builder_iterator_destroy(it); if (is_load_reporting_enabled(args) && !already_has_load_reporting_filter) { - return grpc_channel_stack_builder_prepend_filter(builder, filter, NULL, - NULL); + return grpc_channel_stack_builder_prepend_filter(builder, filter, nullptr, + nullptr); } return true; } diff --git a/src/core/ext/filters/max_age/max_age_filter.cc b/src/core/ext/filters/max_age/max_age_filter.cc index ade2e5bc82..001f9f3906 100644 --- a/src/core/ext/filters/max_age/max_age_filter.cc +++ b/src/core/ext/filters/max_age/max_age_filter.cc @@ -126,7 +126,7 @@ static void start_max_age_timer_after_init(grpc_exec_ctx* exec_ctx, void* arg, grpc_exec_ctx_now(exec_ctx) + chand->max_connection_age, &chand->close_max_age_channel); gpr_mu_unlock(&chand->max_age_timer_mu); - grpc_transport_op* op = grpc_make_transport_op(NULL); + grpc_transport_op* op = grpc_make_transport_op(nullptr); op->on_connectivity_state_change = &chand->channel_connectivity_changed, op->connectivity_state = &chand->connectivity_state; grpc_channel_next_op(exec_ctx, @@ -159,7 +159,7 @@ static void close_max_idle_channel(grpc_exec_ctx* exec_ctx, void* arg, if (error == GRPC_ERROR_NONE) { /* Prevent the max idle timer from being set again */ gpr_atm_no_barrier_fetch_add(&chand->call_count, 1); - grpc_transport_op* op = grpc_make_transport_op(NULL); + grpc_transport_op* op = grpc_make_transport_op(nullptr); op->goaway_error = grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("max_idle"), GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_NO_ERROR); @@ -204,7 +204,7 @@ static void force_close_max_age_channel(grpc_exec_ctx* exec_ctx, void* arg, chand->max_age_grace_timer_pending = false; gpr_mu_unlock(&chand->max_age_timer_mu); if (error == GRPC_ERROR_NONE) { - grpc_transport_op* op = grpc_make_transport_op(NULL); + grpc_transport_op* op = grpc_make_transport_op(nullptr); op->disconnect_with_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel reaches max age"); grpc_channel_element* elem = @@ -221,7 +221,7 @@ static void channel_connectivity_changed(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { channel_data* chand = (channel_data*)arg; if (chand->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { - grpc_transport_op* op = grpc_make_transport_op(NULL); + grpc_transport_op* op = grpc_make_transport_op(nullptr); op->on_connectivity_state_change = &chand->channel_connectivity_changed, op->connectivity_state = &chand->connectivity_state; grpc_channel_next_op( @@ -398,7 +398,7 @@ static bool maybe_add_max_age_filter(grpc_exec_ctx* exec_ctx, MAX_CONNECTION_IDLE_INTEGER_OPTIONS) != INT_MAX; if (enable) { return grpc_channel_stack_builder_prepend_filter( - builder, &grpc_max_age_filter, NULL, NULL); + builder, &grpc_max_age_filter, nullptr, nullptr); } else { return true; } @@ -407,7 +407,7 @@ static bool maybe_add_max_age_filter(grpc_exec_ctx* exec_ctx, extern "C" void grpc_max_age_filter_init(void) { grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - maybe_add_max_age_filter, NULL); + maybe_add_max_age_filter, nullptr); } extern "C" void grpc_max_age_filter_shutdown(void) {} diff --git a/src/core/ext/filters/message_size/message_size_filter.cc b/src/core/ext/filters/message_size/message_size_filter.cc index 9376d978b4..2e81d09961 100644 --- a/src/core/ext/filters/message_size/message_size_filter.cc +++ b/src/core/ext/filters/message_size/message_size_filter.cc @@ -60,22 +60,22 @@ static void* refcounted_message_size_limits_create_from_json( const grpc_json* json) { int max_request_message_bytes = -1; int max_response_message_bytes = -1; - for (grpc_json* field = json->child; field != NULL; field = field->next) { - if (field->key == NULL) continue; + for (grpc_json* field = json->child; field != nullptr; field = field->next) { + if (field->key == nullptr) continue; if (strcmp(field->key, "maxRequestMessageBytes") == 0) { - if (max_request_message_bytes >= 0) return NULL; // Duplicate. + if (max_request_message_bytes >= 0) return nullptr; // Duplicate. if (field->type != GRPC_JSON_STRING && field->type != GRPC_JSON_NUMBER) { - return NULL; + return nullptr; } max_request_message_bytes = gpr_parse_nonnegative_int(field->value); - if (max_request_message_bytes == -1) return NULL; + if (max_request_message_bytes == -1) return nullptr; } else if (strcmp(field->key, "maxResponseMessageBytes") == 0) { - if (max_response_message_bytes >= 0) return NULL; // Duplicate. + if (max_response_message_bytes >= 0) return nullptr; // Duplicate. if (field->type != GRPC_JSON_STRING && field->type != GRPC_JSON_NUMBER) { - return NULL; + return nullptr; } max_response_message_bytes = gpr_parse_nonnegative_int(field->value); - if (max_response_message_bytes == -1) return NULL; + if (max_response_message_bytes == -1) return nullptr; } } refcounted_message_size_limits* value = @@ -112,7 +112,7 @@ static void recv_message_ready(grpc_exec_ctx* exec_ctx, void* user_data, grpc_error* error) { grpc_call_element* elem = (grpc_call_element*)user_data; call_data* calld = (call_data*)elem->call_data; - if (*calld->recv_message != NULL && calld->limits.max_recv_size >= 0 && + if (*calld->recv_message != nullptr && calld->limits.max_recv_size >= 0 && (*calld->recv_message)->length > (size_t)calld->limits.max_recv_size) { char* message_string; gpr_asprintf(&message_string, @@ -175,7 +175,7 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, channel_data* chand = (channel_data*)elem->channel_data; call_data* calld = (call_data*)elem->call_data; calld->call_combiner = args->call_combiner; - calld->next_recv_message_ready = NULL; + calld->next_recv_message_ready = nullptr; GRPC_CLOSURE_INIT(&calld->recv_message_ready, recv_message_ready, elem, grpc_schedule_on_exec_ctx); // Get max sizes from channel data, then merge in per-method config values. @@ -183,11 +183,11 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, // apply the max request size to the send limit and the max response // size to the receive limit. calld->limits = chand->limits; - if (chand->method_limit_table != NULL) { + if (chand->method_limit_table != nullptr) { refcounted_message_size_limits* limits = (refcounted_message_size_limits*)grpc_method_config_table_get( exec_ctx, chand->method_limit_table, args->path); - if (limits != NULL) { + if (limits != nullptr) { if (limits->limits.max_send_size >= 0 && (limits->limits.max_send_size < calld->limits.max_send_size || calld->limits.max_send_size < 0)) { @@ -250,11 +250,11 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, // Get method config table from channel args. const grpc_arg* channel_arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVICE_CONFIG); - if (channel_arg != NULL) { + if (channel_arg != nullptr) { GPR_ASSERT(channel_arg->type == GRPC_ARG_STRING); grpc_service_config* service_config = grpc_service_config_create(channel_arg->value.string); - if (service_config != NULL) { + if (service_config != nullptr) { chand->method_limit_table = grpc_service_config_create_method_config_table( exec_ctx, service_config, @@ -299,12 +299,12 @@ static bool maybe_add_message_size_filter(grpc_exec_ctx* exec_ctx, } const grpc_arg* a = grpc_channel_args_find(channel_args, GRPC_ARG_SERVICE_CONFIG); - if (a != NULL) { + if (a != nullptr) { enable = true; } if (enable) { return grpc_channel_stack_builder_prepend_filter( - builder, &grpc_message_size_filter, NULL, NULL); + builder, &grpc_message_size_filter, nullptr, nullptr); } else { return true; } @@ -313,13 +313,13 @@ static bool maybe_add_message_size_filter(grpc_exec_ctx* exec_ctx, extern "C" void grpc_message_size_filter_init(void) { grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - maybe_add_message_size_filter, NULL); + maybe_add_message_size_filter, nullptr); grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - maybe_add_message_size_filter, NULL); + maybe_add_message_size_filter, nullptr); grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - maybe_add_message_size_filter, NULL); + maybe_add_message_size_filter, nullptr); } extern "C" void grpc_message_size_filter_shutdown(void) {} diff --git a/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc b/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc index f77ed02421..6bbb4d5739 100644 --- a/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +++ b/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc @@ -42,7 +42,7 @@ typedef struct call_data { // Find the user agent metadata element in the batch static bool get_user_agent_mdelem(const grpc_metadata_batch* batch, grpc_mdelem* md) { - if (batch->idx.named.user_agent != NULL) { + if (batch->idx.named.user_agent != nullptr) { *md = batch->idx.named.user_agent->md; return true; } @@ -104,7 +104,7 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, const grpc_call_element_args* args) { call_data* calld = (call_data*)elem->call_data; - calld->next_recv_initial_metadata_ready = NULL; + calld->next_recv_initial_metadata_ready = nullptr; calld->workaround_active = false; GRPC_CLOSURE_INIT(&calld->recv_initial_metadata_ready, recv_initial_metadata_ready, elem, @@ -142,7 +142,7 @@ static bool parse_user_agent(grpc_mdelem md) { long major_version, minor_version; char* head = strtok(user_agent_str, " "); - while (head != NULL) { + while (head != nullptr) { if (!grpc_objc_specifier_seen && 0 == strncmp(head, grpc_objc_specifier, grpc_objc_specifier_len)) { major_version_str = head + grpc_objc_specifier_len; @@ -153,11 +153,11 @@ static bool parse_user_agent(grpc_mdelem md) { break; } - head = strtok(NULL, " "); + head = strtok(nullptr, " "); } if (grpc_objc_specifier_seen) { major_version_str = strtok(major_version_str, "."); - minor_version_str = strtok(NULL, "."); + minor_version_str = strtok(nullptr, "."); major_version = atol(major_version_str); minor_version = atol(minor_version_str); } @@ -186,20 +186,20 @@ static bool register_workaround_cronet_compression( grpc_channel_stack_builder_get_channel_arguments(builder); const grpc_arg* a = grpc_channel_args_find( channel_args, GRPC_ARG_WORKAROUND_CRONET_COMPRESSION); - if (a == NULL) { + if (a == nullptr) { return true; } if (grpc_channel_arg_get_bool(a, false) == false) { return true; } return grpc_channel_stack_builder_prepend_filter( - builder, &grpc_workaround_cronet_compression_filter, NULL, NULL); + builder, &grpc_workaround_cronet_compression_filter, nullptr, nullptr); } extern "C" void grpc_workaround_cronet_compression_filter_init(void) { grpc_channel_init_register_stage( GRPC_SERVER_CHANNEL, GRPC_WORKAROUND_PRIORITY_HIGH, - register_workaround_cronet_compression, NULL); + register_workaround_cronet_compression, nullptr); grpc_register_workaround(GRPC_WORKAROUND_ID_CRONET_COMPRESSION, parse_user_agent); } diff --git a/src/core/ext/filters/workarounds/workaround_utils.cc b/src/core/ext/filters/workarounds/workaround_utils.cc index 9db42fbeee..9d76582ea2 100644 --- a/src/core/ext/filters/workarounds/workaround_utils.cc +++ b/src/core/ext/filters/workarounds/workaround_utils.cc @@ -30,7 +30,7 @@ grpc_workaround_user_agent_md* grpc_parse_user_agent(grpc_mdelem md) { (grpc_workaround_user_agent_md*)grpc_mdelem_get_user_data( md, destroy_user_agent_md); - if (NULL != user_agent_md) { + if (nullptr != user_agent_md) { return user_agent_md; } user_agent_md = (grpc_workaround_user_agent_md*)gpr_malloc( diff --git a/src/core/ext/transport/chttp2/client/chttp2_connector.cc b/src/core/ext/transport/chttp2/client/chttp2_connector.cc index 6cd476f4ca..77cc313480 100644 --- a/src/core/ext/transport/chttp2/client/chttp2_connector.cc +++ b/src/core/ext/transport/chttp2/client/chttp2_connector.cc @@ -68,7 +68,7 @@ static void chttp2_connector_unref(grpc_exec_ctx* exec_ctx, gpr_mu_destroy(&c->mu); // If handshaking is not yet in progress, destroy the endpoint. // Otherwise, the handshaker will do this for us. - if (c->endpoint != NULL) grpc_endpoint_destroy(exec_ctx, c->endpoint); + if (c->endpoint != nullptr) grpc_endpoint_destroy(exec_ctx, c->endpoint); gpr_free(c); } } @@ -78,13 +78,13 @@ static void chttp2_connector_shutdown(grpc_exec_ctx* exec_ctx, chttp2_connector* c = (chttp2_connector*)con; gpr_mu_lock(&c->mu); c->shutdown = true; - if (c->handshake_mgr != NULL) { + if (c->handshake_mgr != nullptr) { grpc_handshake_manager_shutdown(exec_ctx, c->handshake_mgr, GRPC_ERROR_REF(why)); } // If handshaking is not yet in progress, shutdown the endpoint. // Otherwise, the handshaker will do this for us. - if (!c->connecting && c->endpoint != NULL) { + if (!c->connecting && c->endpoint != nullptr) { grpc_endpoint_shutdown(exec_ctx, c->endpoint, GRPC_ERROR_REF(why)); } gpr_mu_unlock(&c->mu); @@ -125,10 +125,10 @@ static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, c->result->channel_args = args->args; } grpc_closure* notify = c->notify; - c->notify = NULL; + c->notify = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, notify, error); grpc_handshake_manager_destroy(exec_ctx, c->handshake_mgr); - c->handshake_mgr = NULL; + c->handshake_mgr = nullptr; gpr_mu_unlock(&c->mu); chttp2_connector_unref(exec_ctx, (grpc_connector*)c); } @@ -142,8 +142,8 @@ static void start_handshake_locked(grpc_exec_ctx* exec_ctx, c->args.interested_parties); grpc_handshake_manager_do_handshake( exec_ctx, c->handshake_mgr, c->endpoint, c->args.channel_args, - c->args.deadline, NULL /* acceptor */, on_handshake_done, c); - c->endpoint = NULL; // Endpoint handed off to handshake manager. + c->args.deadline, nullptr /* acceptor */, on_handshake_done, c); + c->endpoint = nullptr; // Endpoint handed off to handshake manager. } static void connected(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { @@ -159,15 +159,15 @@ static void connected(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { } memset(c->result, 0, sizeof(*c->result)); grpc_closure* notify = c->notify; - c->notify = NULL; + c->notify = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, notify, error); - if (c->endpoint != NULL) { + if (c->endpoint != nullptr) { grpc_endpoint_shutdown(exec_ctx, c->endpoint, GRPC_ERROR_REF(error)); } gpr_mu_unlock(&c->mu); chttp2_connector_unref(exec_ctx, (grpc_connector*)arg); } else { - GPR_ASSERT(c->endpoint != NULL); + GPR_ASSERT(c->endpoint != nullptr); start_handshake_locked(exec_ctx, c); gpr_mu_unlock(&c->mu); } @@ -182,11 +182,11 @@ static void chttp2_connector_connect(grpc_exec_ctx* exec_ctx, grpc_resolved_address addr; grpc_get_subchannel_address_arg(exec_ctx, args->channel_args, &addr); gpr_mu_lock(&c->mu); - GPR_ASSERT(c->notify == NULL); + GPR_ASSERT(c->notify == nullptr); c->notify = notify; c->args = *args; c->result = result; - GPR_ASSERT(c->endpoint == NULL); + GPR_ASSERT(c->endpoint == nullptr); chttp2_connector_ref(con); // Ref taken for callback. GRPC_CLOSURE_INIT(&c->connected, connected, c, grpc_schedule_on_exec_ctx); GPR_ASSERT(!c->connecting); diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc index 26c7f0debf..a5cd5d5294 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc @@ -49,9 +49,9 @@ static grpc_channel* client_channel_factory_create_channel( grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory, const char* target, grpc_client_channel_type type, const grpc_channel_args* args) { - if (target == NULL) { + if (target == nullptr) { gpr_log(GPR_ERROR, "cannot create channel with NULL target name"); - return NULL; + return nullptr; } // Add channel arg containing the server URI. grpc_arg arg = grpc_channel_arg_string_create( @@ -62,7 +62,7 @@ static grpc_channel* client_channel_factory_create_channel( grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1); gpr_free(arg.value.string); grpc_channel* channel = grpc_channel_create(exec_ctx, target, new_args, - GRPC_CLIENT_CHANNEL, NULL); + GRPC_CLIENT_CHANNEL, nullptr); grpc_channel_args_destroy(exec_ctx, new_args); return channel; } @@ -86,7 +86,7 @@ grpc_channel* grpc_insecure_channel_create(const char* target, GRPC_API_TRACE( "grpc_insecure_channel_create(target=%s, args=%p, reserved=%p)", 3, (target, args, reserved)); - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); // Add channel arg containing the client channel factory. grpc_arg arg = grpc_client_channel_factory_create_channel_arg(&client_channel_factory); @@ -98,7 +98,7 @@ grpc_channel* grpc_insecure_channel_create(const char* target, // Clean up. grpc_channel_args_destroy(&exec_ctx, new_args); grpc_exec_ctx_finish(&exec_ctx); - return channel != NULL ? channel + return channel != nullptr ? channel : grpc_lame_client_channel_create( target, GRPC_STATUS_INTERNAL, "Failed to create client channel"); diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc index 0974a7c393..aa3d0d1404 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc @@ -58,11 +58,11 @@ grpc_channel* grpc_insecure_channel_create_from_fd( grpc_channel* channel = grpc_channel_create( &exec_ctx, target, final_args, GRPC_CLIENT_DIRECT_CHANNEL, transport); grpc_channel_args_destroy(&exec_ctx, final_args); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr); grpc_exec_ctx_finish(&exec_ctx); - return channel != NULL ? channel + return channel != nullptr ? channel : grpc_lame_client_channel_create( target, GRPC_STATUS_INTERNAL, "Failed to create client channel"); diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc index 68c1e1868c..7e23c56643 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc @@ -47,51 +47,51 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( grpc_exec_ctx* exec_ctx, const grpc_subchannel_args* args) { grpc_channel_credentials* channel_credentials = grpc_channel_credentials_find_in_args(args->args); - if (channel_credentials == NULL) { + if (channel_credentials == nullptr) { gpr_log(GPR_ERROR, "Can't create subchannel: channel credentials missing for secure " "channel."); - return NULL; + return nullptr; } // Make sure security connector does not already exist in args. - if (grpc_security_connector_find_in_args(args->args) != NULL) { + if (grpc_security_connector_find_in_args(args->args) != nullptr) { gpr_log(GPR_ERROR, "Can't create subchannel: security connector already present in " "channel args."); - return NULL; + return nullptr; } // To which address are we connecting? By default, use the server URI. const grpc_arg* server_uri_arg = grpc_channel_args_find(args->args, GRPC_ARG_SERVER_URI); - GPR_ASSERT(server_uri_arg != NULL); + GPR_ASSERT(server_uri_arg != nullptr); GPR_ASSERT(server_uri_arg->type == GRPC_ARG_STRING); const char* server_uri_str = server_uri_arg->value.string; - GPR_ASSERT(server_uri_str != NULL); + GPR_ASSERT(server_uri_str != nullptr); grpc_uri* server_uri = grpc_uri_parse(exec_ctx, server_uri_str, true /* supress errors */); - GPR_ASSERT(server_uri != NULL); + GPR_ASSERT(server_uri != nullptr); const char* server_uri_path; server_uri_path = server_uri->path[0] == '/' ? server_uri->path + 1 : server_uri->path; const grpc_slice_hash_table* targets_info = grpc_lb_targets_info_find_in_args(args->args); - char* target_name_to_check = NULL; - if (targets_info != NULL) { // LB channel + char* target_name_to_check = nullptr; + if (targets_info != nullptr) { // LB channel // Find the balancer name for the target. const char* target_uri_str = grpc_get_subchannel_address_uri_arg(args->args); grpc_uri* target_uri = grpc_uri_parse(exec_ctx, target_uri_str, false /* suppress errors */); - GPR_ASSERT(target_uri != NULL); + GPR_ASSERT(target_uri != nullptr); if (target_uri->path[0] != '\0') { // "path" may be empty const grpc_slice key = grpc_slice_from_static_string( target_uri->path[0] == '/' ? target_uri->path + 1 : target_uri->path); const char* value = (const char*)grpc_slice_hash_table_get(targets_info, key); - if (value != NULL) target_name_to_check = gpr_strdup(value); + if (value != nullptr) target_name_to_check = gpr_strdup(value); grpc_slice_unref_internal(exec_ctx, key); } - if (target_name_to_check == NULL) { + if (target_name_to_check == nullptr) { // If the target name to check hasn't already been set, fall back to using // SERVER_URI target_name_to_check = gpr_strdup(server_uri_path); @@ -101,10 +101,10 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( target_name_to_check = gpr_strdup(server_uri_path); } grpc_uri_destroy(server_uri); - GPR_ASSERT(target_name_to_check != NULL); - grpc_channel_security_connector* subchannel_security_connector = NULL; + GPR_ASSERT(target_name_to_check != nullptr); + grpc_channel_security_connector* subchannel_security_connector = nullptr; // Create the security connector using the credentials and target name. - grpc_channel_args* new_args_from_connector = NULL; + grpc_channel_args* new_args_from_connector = nullptr; const grpc_security_status security_status = grpc_channel_credentials_create_security_connector( exec_ctx, channel_credentials, target_name_to_check, args->args, @@ -114,18 +114,18 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args( "Failed to create secure subchannel for secure name '%s'", target_name_to_check); gpr_free(target_name_to_check); - return NULL; + return nullptr; } gpr_free(target_name_to_check); grpc_arg new_security_connector_arg = grpc_security_connector_to_arg(&subchannel_security_connector->base); grpc_channel_args* new_args = grpc_channel_args_copy_and_add( - new_args_from_connector != NULL ? new_args_from_connector : args->args, + new_args_from_connector != nullptr ? new_args_from_connector : args->args, &new_security_connector_arg, 1); GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, &subchannel_security_connector->base, "lb_channel_create"); - if (new_args_from_connector != NULL) { + if (new_args_from_connector != nullptr) { grpc_channel_args_destroy(exec_ctx, new_args_from_connector); } grpc_subchannel_args* final_sc_args = @@ -140,11 +140,11 @@ static grpc_subchannel* client_channel_factory_create_subchannel( const grpc_subchannel_args* args) { grpc_subchannel_args* subchannel_args = get_secure_naming_subchannel_args(exec_ctx, args); - if (subchannel_args == NULL) { + if (subchannel_args == nullptr) { gpr_log( GPR_ERROR, "Failed to create subchannel arguments during subchannel creation."); - return NULL; + return nullptr; } grpc_connector* connector = grpc_chttp2_connector_create(); grpc_subchannel* s = @@ -160,9 +160,9 @@ static grpc_channel* client_channel_factory_create_channel( grpc_exec_ctx* exec_ctx, grpc_client_channel_factory* cc_factory, const char* target, grpc_client_channel_type type, const grpc_channel_args* args) { - if (target == NULL) { + if (target == nullptr) { gpr_log(GPR_ERROR, "cannot create channel with NULL target name"); - return NULL; + return nullptr; } // Add channel arg containing the server URI. grpc_arg arg = grpc_channel_arg_string_create( @@ -173,7 +173,7 @@ static grpc_channel* client_channel_factory_create_channel( grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1); gpr_free(arg.value.string); grpc_channel* channel = grpc_channel_create(exec_ctx, target, new_args, - GRPC_CLIENT_CHANNEL, NULL); + GRPC_CLIENT_CHANNEL, nullptr); grpc_channel_args_destroy(exec_ctx, new_args); return channel; } @@ -199,9 +199,9 @@ grpc_channel* grpc_secure_channel_create(grpc_channel_credentials* creds, "grpc_secure_channel_create(creds=%p, target=%s, args=%p, " "reserved=%p)", 4, ((void*)creds, target, (void*)args, (void*)reserved)); - GPR_ASSERT(reserved == NULL); - grpc_channel* channel = NULL; - if (creds != NULL) { + GPR_ASSERT(reserved == nullptr); + grpc_channel* channel = nullptr; + if (creds != nullptr) { // Add channel args containing the client channel factory and channel // credentials. grpc_arg args_to_add[] = { @@ -217,7 +217,7 @@ grpc_channel* grpc_secure_channel_create(grpc_channel_credentials* creds, grpc_channel_args_destroy(&exec_ctx, new_args); grpc_exec_ctx_finish(&exec_ctx); } - return channel != NULL ? channel + return channel != nullptr ? channel : grpc_lame_client_channel_create( target, GRPC_STATUS_INTERNAL, "Failed to create secure client channel"); diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.cc b/src/core/ext/transport/chttp2/server/chttp2_server.cc index 98683acc59..93be5e4081 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.cc +++ b/src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -69,7 +69,7 @@ static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, const char* error_str = grpc_error_string(error); gpr_log(GPR_DEBUG, "Handshaking failed: %s", error_str); - if (error == GRPC_ERROR_NONE && args->endpoint != NULL) { + if (error == GRPC_ERROR_NONE && args->endpoint != nullptr) { // We were shut down after handshaking completed successfully, so // destroy the endpoint here. // TODO(ctiller): It is currently necessary to shutdown endpoints @@ -86,7 +86,7 @@ static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, // If the handshaking succeeded but there is no endpoint, then the // handshaker may have handed off the connection to some external // code, so we can just clean up here without creating a transport. - if (args->endpoint != NULL) { + if (args->endpoint != nullptr) { grpc_transport* transport = grpc_create_chttp2_transport(exec_ctx, args->args, args->endpoint, 0); grpc_server_setup_transport( @@ -166,7 +166,7 @@ static void tcp_server_shutdown_complete(grpc_exec_ctx* exec_ctx, void* arg, // Flush queued work before destroying handshaker factory, since that // may do a synchronous unref. grpc_exec_ctx_flush(exec_ctx); - if (destroy_done != NULL) { + if (destroy_done != nullptr) { destroy_done->cb(exec_ctx, destroy_done->cb_arg, GRPC_ERROR_REF(error)); grpc_exec_ctx_flush(exec_ctx); } @@ -194,14 +194,14 @@ grpc_error* grpc_chttp2_server_add_port(grpc_exec_ctx* exec_ctx, grpc_server* server, const char* addr, grpc_channel_args* args, int* port_num) { - grpc_resolved_addresses* resolved = NULL; - grpc_tcp_server* tcp_server = NULL; + grpc_resolved_addresses* resolved = nullptr; + grpc_tcp_server* tcp_server = nullptr; size_t i; size_t count = 0; int port_temp; grpc_error* err = GRPC_ERROR_NONE; - server_state* state = NULL; - grpc_error** errors = NULL; + server_state* state = nullptr; + grpc_error** errors = nullptr; size_t naddrs = 0; *port_num = -1; @@ -284,7 +284,7 @@ error: *port_num = 0; done: - if (errors != NULL) { + if (errors != nullptr) { for (i = 0; i < naddrs; i++) { GRPC_ERROR_UNREF(errors[i]); } diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc index e37d69e5e9..2206e4a4f6 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc @@ -36,7 +36,7 @@ void grpc_server_add_insecure_channel_from_fd(grpc_server* server, void* reserved, int fd) { - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; char* name; @@ -60,8 +60,8 @@ void grpc_server_add_insecure_channel_from_fd(grpc_server* server, grpc_endpoint_add_to_pollset(&exec_ctx, server_endpoint, pollsets[i]); } - grpc_server_setup_transport(&exec_ctx, server, transport, NULL, server_args); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL); + grpc_server_setup_transport(&exec_ctx, server, transport, nullptr, server_args); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, nullptr); grpc_exec_ctx_finish(&exec_ctx); } diff --git a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc index 4b2e348780..ac3ea40f47 100644 --- a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +++ b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc @@ -38,16 +38,16 @@ int grpc_server_add_secure_http2_port(grpc_server* server, const char* addr, grpc_server_credentials* creds) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_error* err = GRPC_ERROR_NONE; - grpc_server_security_connector* sc = NULL; + grpc_server_security_connector* sc = nullptr; int port_num = 0; grpc_security_status status; - grpc_channel_args* args = NULL; + grpc_channel_args* args = nullptr; GRPC_API_TRACE( "grpc_server_add_secure_http2_port(" "server=%p, addr=%s, creds=%p)", 3, (server, addr, creds)); // Create security context. - if (creds == NULL) { + if (creds == nullptr) { err = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "No credentials specified for secure server port (creds==NULL)"); goto done; @@ -74,7 +74,7 @@ int grpc_server_add_secure_http2_port(grpc_server* server, const char* addr, // Add server port. err = grpc_chttp2_server_add_port(&exec_ctx, server, addr, args, &port_num); done: - if (sc != NULL) { + if (sc != nullptr) { GRPC_SECURITY_CONNECTOR_UNREF(&exec_ctx, &sc->base, "server"); } grpc_exec_ctx_finish(&exec_ctx); diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index a955ec2589..bd74e2e4b6 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -201,8 +201,8 @@ static void destruct_transport(grpc_exec_ctx* exec_ctx, grpc_chttp2_goaway_parser_destroy(&t->goaway_parser); for (i = 0; i < STREAM_LIST_COUNT; i++) { - GPR_ASSERT(t->lists[i].head == NULL); - GPR_ASSERT(t->lists[i].tail == NULL); + GPR_ASSERT(t->lists[i].head == nullptr); + GPR_ASSERT(t->lists[i].tail == nullptr); } GRPC_ERROR_UNREF(t->goaway_error); @@ -614,7 +614,7 @@ static void close_transport_locked(grpc_exec_ctx* exec_ctx, GRPC_STATUS_UNAVAILABLE); } if (t->write_state != GRPC_CHTTP2_WRITE_STATE_IDLE) { - if (t->close_transport_on_writes_finished == NULL) { + if (t->close_transport_on_writes_finished == nullptr) { t->close_transport_on_writes_finished = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Delayed close due to in-progress write"); @@ -729,7 +729,7 @@ static void destroy_stream_locked(grpc_exec_ctx* exec_ctx, void* sp, GPR_ASSERT((s->write_closed && s->read_closed) || s->id == 0); if (s->id != 0) { - GPR_ASSERT(grpc_chttp2_stream_map_find(&t->stream_map, s->id) == NULL); + GPR_ASSERT(grpc_chttp2_stream_map_find(&t->stream_map, s->id) == nullptr); } grpc_slice_buffer_destroy_internal(exec_ctx, @@ -749,12 +749,12 @@ static void destroy_stream_locked(grpc_exec_ctx* exec_ctx, void* sp, } } - GPR_ASSERT(s->send_initial_metadata_finished == NULL); - GPR_ASSERT(s->fetching_send_message == NULL); - GPR_ASSERT(s->send_trailing_metadata_finished == NULL); - GPR_ASSERT(s->recv_initial_metadata_ready == NULL); - GPR_ASSERT(s->recv_message_ready == NULL); - GPR_ASSERT(s->recv_trailing_metadata_finished == NULL); + GPR_ASSERT(s->send_initial_metadata_finished == nullptr); + GPR_ASSERT(s->fetching_send_message == nullptr); + GPR_ASSERT(s->send_trailing_metadata_finished == nullptr); + GPR_ASSERT(s->recv_initial_metadata_ready == nullptr); + GPR_ASSERT(s->recv_message_ready == nullptr); + GPR_ASSERT(s->recv_trailing_metadata_finished == nullptr); grpc_chttp2_data_parser_destroy(exec_ctx, &s->data_parser); grpc_chttp2_incoming_metadata_buffer_destroy(exec_ctx, &s->metadata_buffer[0]); @@ -781,13 +781,13 @@ static void destroy_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, grpc_chttp2_transport* t = (grpc_chttp2_transport*)gt; grpc_chttp2_stream* s = (grpc_chttp2_stream*)gs; - if (s->stream_compression_ctx != NULL) { + if (s->stream_compression_ctx != nullptr) { grpc_stream_compression_context_destroy(s->stream_compression_ctx); - s->stream_compression_ctx = NULL; + s->stream_compression_ctx = nullptr; } - if (s->stream_decompression_ctx != NULL) { + if (s->stream_decompression_ctx != nullptr) { grpc_stream_compression_context_destroy(s->stream_decompression_ctx); - s->stream_decompression_ctx = NULL; + s->stream_decompression_ctx = nullptr; } s->destroy_stream_arg = then_schedule_closure; @@ -807,16 +807,16 @@ grpc_chttp2_stream* grpc_chttp2_parsing_lookup_stream(grpc_chttp2_transport* t, grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, uint32_t id) { - if (t->channel_callback.accept_stream == NULL) { - return NULL; + if (t->channel_callback.accept_stream == nullptr) { + return nullptr; } grpc_chttp2_stream* accepting; - GPR_ASSERT(t->accepting_stream == NULL); + GPR_ASSERT(t->accepting_stream == nullptr); t->accepting_stream = &accepting; t->channel_callback.accept_stream(exec_ctx, t->channel_callback.accept_stream_user_data, &t->base, (void*)(uintptr_t)id); - t->accepting_stream = NULL; + t->accepting_stream = nullptr; return accepting; } @@ -845,9 +845,9 @@ static void set_write_state(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, t->write_state = st; if (st == GRPC_CHTTP2_WRITE_STATE_IDLE) { GRPC_CLOSURE_LIST_SCHED(exec_ctx, &t->run_after_write); - if (t->close_transport_on_writes_finished != NULL) { + if (t->close_transport_on_writes_finished != nullptr) { grpc_error* err = t->close_transport_on_writes_finished; - t->close_transport_on_writes_finished = NULL; + t->close_transport_on_writes_finished = nullptr; close_transport_locked(exec_ctx, t, err); } } @@ -987,7 +987,7 @@ static grpc_closure_scheduler* write_scheduler(grpc_chttp2_transport* t, case GRPC_CHTTP2_OPTIMIZE_FOR_LATENCY: return grpc_schedule_on_exec_ctx; } - GPR_UNREACHABLE_CODE(return NULL); + GPR_UNREACHABLE_CODE(return nullptr); } #define WRITE_STATE_TUPLE_TO_INT(p, i) (2 * (int)(p) + (int)(i)) @@ -1221,7 +1221,7 @@ static grpc_closure* add_closure_barrier(grpc_closure* closure) { static void null_then_run_closure(grpc_exec_ctx* exec_ctx, grpc_closure** closure, grpc_error* error) { grpc_closure* c = *closure; - *closure = NULL; + *closure = nullptr; GRPC_CLOSURE_RUN(exec_ctx, c, error); } @@ -1231,8 +1231,8 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx* exec_ctx, grpc_closure** pclosure, grpc_error* error, const char* desc) { grpc_closure* closure = *pclosure; - *pclosure = NULL; - if (closure == NULL) { + *pclosure = nullptr; + if (closure == nullptr) { GRPC_ERROR_UNREF(error); return; } @@ -1262,7 +1262,7 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx* exec_ctx, if (closure->next_data.scratch < CLOSURE_BARRIER_FIRST_REF_BIT) { if (closure->next_data.scratch & CLOSURE_BARRIER_STATS_BIT) { grpc_transport_move_stats(&s->stats, s->collecting_stats); - s->collecting_stats = NULL; + s->collecting_stats = nullptr; } if ((t->write_state == GRPC_CHTTP2_WRITE_STATE_IDLE) || !(closure->next_data.scratch & CLOSURE_BARRIER_MAY_COVER_WRITE)) { @@ -1275,7 +1275,7 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx* exec_ctx, } static bool contains_non_ok_status(grpc_metadata_batch* batch) { - if (batch->idx.named.grpc_status != NULL) { + if (batch->idx.named.grpc_status != nullptr) { return !grpc_mdelem_eq(batch->idx.named.grpc_status->md, GRPC_MDELEM_GRPC_STATUS_0); } @@ -1306,7 +1306,7 @@ static void continue_fetching_send_locked(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_chttp2_stream* s) { for (;;) { - if (s->fetching_send_message == NULL) { + if (s->fetching_send_message == nullptr) { /* Stream was cancelled before message fetch completed */ abort(); /* TODO(ctiller): what cleanup here? */ return; /* early out */ @@ -1320,14 +1320,14 @@ static void continue_fetching_send_locked(grpc_exec_ctx* exec_ctx, "fetching_send_message_finished"); } else { grpc_chttp2_write_cb* cb = t->write_cb_pool; - if (cb == NULL) { + if (cb == nullptr) { cb = (grpc_chttp2_write_cb*)gpr_malloc(sizeof(*cb)); } else { t->write_cb_pool = cb->next; } cb->call_at_byte = notify_offset; cb->closure = s->fetching_send_message_finished; - s->fetching_send_message_finished = NULL; + s->fetching_send_message_finished = nullptr; grpc_chttp2_write_cb** list = s->fetching_send_message->flags & GRPC_WRITE_THROUGH ? &s->on_write_finished_cbs @@ -1335,7 +1335,7 @@ static void continue_fetching_send_locked(grpc_exec_ctx* exec_ctx, cb->next = *list; *list = cb; } - s->fetching_send_message = NULL; + s->fetching_send_message = nullptr; return; /* early out */ } else if (grpc_byte_stream_next(exec_ctx, s->fetching_send_message, UINT32_MAX, &s->complete_fetch_locked)) { @@ -1373,7 +1373,7 @@ static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} static void log_metadata(const grpc_metadata_batch* md_batch, uint32_t id, bool is_client, bool is_initial) { - for (grpc_linked_mdelem* md = md_batch->list.head; md != NULL; + for (grpc_linked_mdelem* md = md_batch->list.head; md != nullptr; md = md->next) { char* key = grpc_slice_to_c_string(GRPC_MDKEY(md->md)); char* value = grpc_slice_to_c_string(GRPC_MDVALUE(md->md)); @@ -1412,9 +1412,9 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, } grpc_closure* on_complete = op->on_complete; - if (on_complete == NULL) { + if (on_complete == nullptr) { on_complete = - GRPC_CLOSURE_CREATE(do_nothing, NULL, grpc_schedule_on_exec_ctx); + GRPC_CLOSURE_CREATE(do_nothing, nullptr, grpc_schedule_on_exec_ctx); } /* use final_data as a barrier until enqueue time; the inital counter is @@ -1423,7 +1423,7 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, on_complete->error_data.error = GRPC_ERROR_NONE; if (op->collect_stats) { - GPR_ASSERT(s->collecting_stats == NULL); + GPR_ASSERT(s->collecting_stats == nullptr); s->collecting_stats = op_payload->collect_stats.collect_stats; on_complete->next_data.scratch |= CLOSURE_BARRIER_STATS_BIT; } @@ -1436,12 +1436,12 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, if (op->send_initial_metadata) { GRPC_STATS_INC_HTTP2_OP_SEND_INITIAL_METADATA(exec_ctx); - GPR_ASSERT(s->send_initial_metadata_finished == NULL); + GPR_ASSERT(s->send_initial_metadata_finished == nullptr); on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; /* Identify stream compression */ if (op_payload->send_initial_metadata.send_initial_metadata->idx.named - .content_encoding == NULL || + .content_encoding == nullptr || grpc_stream_compression_method_parse( GRPC_MDVALUE( op_payload->send_initial_metadata.send_initial_metadata->idx @@ -1502,7 +1502,7 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, } } } else { - s->send_initial_metadata = NULL; + s->send_initial_metadata = nullptr; grpc_chttp2_complete_closure_step( exec_ctx, t, s, &s->send_initial_metadata_finished, GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( @@ -1511,7 +1511,7 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, "send_initial_metadata_finished"); } } - if (op_payload->send_initial_metadata.peer_string != NULL) { + if (op_payload->send_initial_metadata.peer_string != nullptr) { gpr_atm_rel_store(op_payload->send_initial_metadata.peer_string, (gpr_atm)gpr_strdup(t->peer_string)); } @@ -1538,7 +1538,7 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, &s->write_closed_error, 1), "fetching_send_message_finished"); } else { - GPR_ASSERT(s->fetching_send_message == NULL); + GPR_ASSERT(s->fetching_send_message == nullptr); uint8_t* frame_hdr = grpc_slice_buffer_tiny_add( &s->flow_controlled_buffer, GRPC_HEADER_SIZE_IN_BYTES); uint32_t flags = op_payload->send_message.send_message->flags; @@ -1566,7 +1566,7 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, if (op->send_trailing_metadata) { GRPC_STATS_INC_HTTP2_OP_SEND_TRAILING_METADATA(exec_ctx); - GPR_ASSERT(s->send_trailing_metadata_finished == NULL); + GPR_ASSERT(s->send_trailing_metadata_finished == nullptr); on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; s->send_trailing_metadata_finished = add_closure_barrier(on_complete); s->send_trailing_metadata = @@ -1594,7 +1594,7 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, s->seen_error = true; } if (s->write_closed) { - s->send_trailing_metadata = NULL; + s->send_trailing_metadata = nullptr; grpc_chttp2_complete_closure_step( exec_ctx, t, s, &s->send_trailing_metadata_finished, grpc_metadata_batch_is_empty( @@ -1616,14 +1616,14 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, if (op->recv_initial_metadata) { GRPC_STATS_INC_HTTP2_OP_RECV_INITIAL_METADATA(exec_ctx); - GPR_ASSERT(s->recv_initial_metadata_ready == NULL); + GPR_ASSERT(s->recv_initial_metadata_ready == nullptr); s->recv_initial_metadata_ready = op_payload->recv_initial_metadata.recv_initial_metadata_ready; s->recv_initial_metadata = op_payload->recv_initial_metadata.recv_initial_metadata; s->trailing_metadata_available = op_payload->recv_initial_metadata.trailing_metadata_available; - if (op_payload->recv_initial_metadata.peer_string != NULL) { + if (op_payload->recv_initial_metadata.peer_string != nullptr) { gpr_atm_rel_store(op_payload->recv_initial_metadata.peer_string, (gpr_atm)gpr_strdup(t->peer_string)); } @@ -1633,7 +1633,7 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, if (op->recv_message) { GRPC_STATS_INC_HTTP2_OP_RECV_MESSAGE(exec_ctx); size_t already_received; - GPR_ASSERT(s->recv_message_ready == NULL); + GPR_ASSERT(s->recv_message_ready == nullptr); GPR_ASSERT(!s->pending_byte_stream); s->recv_message_ready = op_payload->recv_message.recv_message_ready; s->recv_message = op_payload->recv_message.recv_message; @@ -1651,7 +1651,7 @@ static void perform_stream_op_locked(grpc_exec_ctx* exec_ctx, void* stream_op, if (op->recv_trailing_metadata) { GRPC_STATS_INC_HTTP2_OP_RECV_TRAILING_METADATA(exec_ctx); - GPR_ASSERT(s->recv_trailing_metadata_finished == NULL); + GPR_ASSERT(s->recv_trailing_metadata_finished == nullptr); s->recv_trailing_metadata_finished = add_closure_barrier(on_complete); s->recv_trailing_metadata = op_payload->recv_trailing_metadata.recv_trailing_metadata; @@ -1761,7 +1761,7 @@ static void send_goaway(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED; grpc_http2_error_code http_error; grpc_slice slice; - grpc_error_get_status(exec_ctx, error, GRPC_MILLIS_INF_FUTURE, NULL, &slice, + grpc_error_get_status(exec_ctx, error, GRPC_MILLIS_INF_FUTURE, nullptr, &slice, &http_error); grpc_chttp2_goaway_append(t->last_new_stream_id, (uint32_t)http_error, grpc_slice_ref_internal(slice), &t->qbuf); @@ -1815,12 +1815,12 @@ static void perform_transport_op_locked(grpc_exec_ctx* exec_ctx, } if (op->send_ping) { - send_ping_locked(exec_ctx, t, NULL, op->send_ping); + send_ping_locked(exec_ctx, t, nullptr, op->send_ping); grpc_chttp2_initiate_write(exec_ctx, t, GRPC_CHTTP2_INITIATE_WRITE_APPLICATION_PING); } - if (op->on_connectivity_state_change != NULL) { + if (op->on_connectivity_state_change != nullptr) { grpc_connectivity_state_notify_on_state_change( exec_ctx, &t->channel_callback.state_tracker, op->connectivity_state, op->on_connectivity_state_change); @@ -1856,7 +1856,7 @@ static void perform_transport_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_chttp2_stream* s) { - if (s->recv_initial_metadata_ready != NULL && + if (s->recv_initial_metadata_ready != nullptr && s->published_metadata[0] != GRPC_METADATA_NOT_PUBLISHED) { if (s->seen_error) { grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &s->frame_storage); @@ -1876,8 +1876,8 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_chttp2_stream* s) { grpc_error* error = GRPC_ERROR_NONE; - if (s->recv_message_ready != NULL) { - *s->recv_message = NULL; + if (s->recv_message_ready != nullptr) { + *s->recv_message = nullptr; if (s->final_metadata_requested && s->seen_error) { grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &s->frame_storage); if (!s->pending_byte_stream) { @@ -1906,7 +1906,7 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx* exec_ctx, if (!grpc_stream_decompress( s->stream_decompression_ctx, &s->unprocessed_incoming_frames_buffer, - &s->decompressed_data_buffer, NULL, + &s->decompressed_data_buffer, nullptr, GRPC_HEADER_SIZE_IN_BYTES - s->decompressed_header_bytes, &end_of_context)) { grpc_slice_buffer_reset_and_unref_internal(exec_ctx, @@ -1922,17 +1922,17 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx* exec_ctx, } error = grpc_deframe_unprocessed_incoming_frames( exec_ctx, &s->data_parser, s, &s->decompressed_data_buffer, - NULL, s->recv_message); + nullptr, s->recv_message); if (end_of_context) { grpc_stream_compression_context_destroy( s->stream_decompression_ctx); - s->stream_decompression_ctx = NULL; + s->stream_decompression_ctx = nullptr; } } } else { error = grpc_deframe_unprocessed_incoming_frames( exec_ctx, &s->data_parser, s, - &s->unprocessed_incoming_frames_buffer, NULL, s->recv_message); + &s->unprocessed_incoming_frames_buffer, nullptr, s->recv_message); } if (error != GRPC_ERROR_NONE) { s->seen_error = true; @@ -1941,15 +1941,15 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx* exec_ctx, grpc_slice_buffer_reset_and_unref_internal( exec_ctx, &s->unprocessed_incoming_frames_buffer); break; - } else if (*s->recv_message != NULL) { + } else if (*s->recv_message != nullptr) { break; } } } - if (error == GRPC_ERROR_NONE && *s->recv_message != NULL) { + if (error == GRPC_ERROR_NONE && *s->recv_message != nullptr) { null_then_run_closure(exec_ctx, &s->recv_message_ready, GRPC_ERROR_NONE); } else if (s->published_metadata[1] != GRPC_METADATA_NOT_PUBLISHED) { - *s->recv_message = NULL; + *s->recv_message = nullptr; null_then_run_closure(exec_ctx, &s->recv_message_ready, GRPC_ERROR_NONE); } GRPC_ERROR_UNREF(error); @@ -1960,7 +1960,7 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_chttp2_stream* s) { grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); - if (s->recv_trailing_metadata_finished != NULL && s->read_closed && + if (s->recv_trailing_metadata_finished != nullptr && s->read_closed && s->write_closed) { if (s->seen_error) { grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &s->frame_storage); @@ -1972,7 +1972,7 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx* exec_ctx, bool pending_data = s->pending_byte_stream || s->unprocessed_incoming_frames_buffer.length > 0; if (s->read_closed && s->frame_storage.length > 0 && !pending_data && - !s->seen_error && s->recv_trailing_metadata_finished != NULL) { + !s->seen_error && s->recv_trailing_metadata_finished != nullptr) { /* Maybe some SYNC_FLUSH data is left in frame_storage. Consume them and * maybe decompress the next 5 bytes in the stream. */ bool end_of_context; @@ -1982,7 +1982,7 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx* exec_ctx, } if (!grpc_stream_decompress(s->stream_decompression_ctx, &s->frame_storage, - &s->unprocessed_incoming_frames_buffer, NULL, + &s->unprocessed_incoming_frames_buffer, nullptr, GRPC_HEADER_SIZE_IN_BYTES, &end_of_context)) { grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &s->frame_storage); grpc_slice_buffer_reset_and_unref_internal( @@ -1995,12 +1995,12 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx* exec_ctx, } if (end_of_context) { grpc_stream_compression_context_destroy(s->stream_decompression_ctx); - s->stream_decompression_ctx = NULL; + s->stream_decompression_ctx = nullptr; } } } if (s->read_closed && s->frame_storage.length == 0 && !pending_data && - s->recv_trailing_metadata_finished != NULL) { + s->recv_trailing_metadata_finished != nullptr) { grpc_chttp2_incoming_metadata_buffer_publish( exec_ctx, &s->metadata_buffer[1], s->recv_trailing_metadata); grpc_chttp2_complete_closure_step( @@ -2016,18 +2016,18 @@ static void remove_stream(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, (grpc_chttp2_stream*)grpc_chttp2_stream_map_delete(&t->stream_map, id); GPR_ASSERT(s); if (t->incoming_stream == s) { - t->incoming_stream = NULL; + t->incoming_stream = nullptr; grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); } if (s->pending_byte_stream) { - if (s->on_next != NULL) { + if (s->on_next != nullptr) { grpc_chttp2_incoming_byte_stream* bs = s->data_parser.parsing_frame; if (error == GRPC_ERROR_NONE) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Truncated message"); } incoming_byte_stream_publish_error(exec_ctx, bs, error); incoming_byte_stream_unref(exec_ctx, bs); - s->data_parser.parsing_frame = NULL; + s->data_parser.parsing_frame = nullptr; } else { GRPC_ERROR_UNREF(s->byte_stream_error); s->byte_stream_error = GRPC_ERROR_REF(error); @@ -2064,7 +2064,7 @@ void grpc_chttp2_cancel_stream(grpc_exec_ctx* exec_ctx, if (!s->read_closed || !s->write_closed) { if (s->id != 0) { grpc_http2_error_code http_error; - grpc_error_get_status(exec_ctx, due_to_error, s->deadline, NULL, NULL, + grpc_error_get_status(exec_ctx, due_to_error, s->deadline, nullptr, nullptr, &http_error); grpc_slice_buffer_add( &t->qbuf, grpc_chttp2_rst_stream_create(s->id, (uint32_t)http_error, @@ -2083,7 +2083,7 @@ void grpc_chttp2_fake_status(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_error* error) { grpc_status_code status; grpc_slice slice; - grpc_error_get_status(exec_ctx, error, s->deadline, &status, &slice, NULL); + grpc_error_get_status(exec_ctx, error, s->deadline, &status, &slice, nullptr); if (status != GRPC_STATUS_OK) { s->seen_error = true; } @@ -2094,7 +2094,7 @@ void grpc_chttp2_fake_status(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, what we want - which is safe because we haven't told anyone about the metadata yet */ if (s->published_metadata[1] == GRPC_METADATA_NOT_PUBLISHED || - s->recv_trailing_metadata_finished != NULL) { + s->recv_trailing_metadata_finished != nullptr) { char status_string[GPR_LTOA_MIN_BUFSIZE]; gpr_ltoa(status, status_string); GRPC_LOG_IF_ERROR("add_status", @@ -2165,17 +2165,17 @@ void grpc_chttp2_fail_pending_writes(grpc_exec_ctx* exec_ctx, grpc_chttp2_stream* s, grpc_error* error) { error = removal_error(error, s, "Pending writes failed due to stream closure"); - s->send_initial_metadata = NULL; + s->send_initial_metadata = nullptr; grpc_chttp2_complete_closure_step( exec_ctx, t, s, &s->send_initial_metadata_finished, GRPC_ERROR_REF(error), "send_initial_metadata_finished"); - s->send_trailing_metadata = NULL; + s->send_trailing_metadata = nullptr; grpc_chttp2_complete_closure_step( exec_ctx, t, s, &s->send_trailing_metadata_finished, GRPC_ERROR_REF(error), "send_trailing_metadata_finished"); - s->fetching_send_message = NULL; + s->fetching_send_message = nullptr; grpc_chttp2_complete_closure_step( exec_ctx, t, s, &s->fetching_send_message_finished, GRPC_ERROR_REF(error), "fetching_send_message_finished"); @@ -2248,7 +2248,7 @@ static void close_from_api(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_status_code grpc_status; grpc_slice slice; grpc_error_get_status(exec_ctx, error, s->deadline, &grpc_status, &slice, - NULL); + nullptr); GPR_ASSERT(grpc_status >= 0 && (int)grpc_status < 100); @@ -2472,7 +2472,7 @@ static grpc_error* try_http_parsing(grpc_exec_ctx* exec_ctx, grpc_error* parse_error = GRPC_ERROR_NONE; for (; i < t->read_buffer.count && parse_error == GRPC_ERROR_NONE; i++) { parse_error = - grpc_http_parser_parse(&parser, t->read_buffer.slices[i], NULL); + grpc_http_parser_parse(&parser, t->read_buffer.slices[i], nullptr); } if (parse_error == GRPC_ERROR_NONE && (parse_error = grpc_http_parser_eof(&parser)) == GRPC_ERROR_NONE) { @@ -2820,7 +2820,7 @@ static void reset_byte_stream(grpc_exec_ctx* exec_ctx, void* arg, } else { GPR_ASSERT(error != GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(exec_ctx, s->on_next, GRPC_ERROR_REF(error)); - s->on_next = NULL; + s->on_next = nullptr; GRPC_ERROR_UNREF(s->byte_stream_error); s->byte_stream_error = GRPC_ERROR_NONE; grpc_chttp2_cancel_stream(exec_ctx, s->t, s, GRPC_ERROR_REF(error)); @@ -2859,9 +2859,9 @@ static void incoming_byte_stream_next_locked(grpc_exec_ctx* exec_ctx, } else if (s->byte_stream_error != GRPC_ERROR_NONE) { GRPC_CLOSURE_SCHED(exec_ctx, bs->next_action.on_complete, GRPC_ERROR_REF(s->byte_stream_error)); - if (s->data_parser.parsing_frame != NULL) { + if (s->data_parser.parsing_frame != nullptr) { incoming_byte_stream_unref(exec_ctx, s->data_parser.parsing_frame); - s->data_parser.parsing_frame = NULL; + s->data_parser.parsing_frame = nullptr; } } else if (s->read_closed) { if (bs->remaining_bytes != 0) { @@ -2869,9 +2869,9 @@ static void incoming_byte_stream_next_locked(grpc_exec_ctx* exec_ctx, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Truncated message"); GRPC_CLOSURE_SCHED(exec_ctx, bs->next_action.on_complete, GRPC_ERROR_REF(s->byte_stream_error)); - if (s->data_parser.parsing_frame != NULL) { + if (s->data_parser.parsing_frame != nullptr) { incoming_byte_stream_unref(exec_ctx, s->data_parser.parsing_frame); - s->data_parser.parsing_frame = NULL; + s->data_parser.parsing_frame = nullptr; } } else { /* Should never reach here. */ @@ -2927,7 +2927,7 @@ static grpc_error* incoming_byte_stream_pull(grpc_exec_ctx* exec_ctx, } if (!grpc_stream_decompress(s->stream_decompression_ctx, &s->unprocessed_incoming_frames_buffer, - &s->decompressed_data_buffer, NULL, + &s->decompressed_data_buffer, nullptr, MAX_SIZE_T, &end_of_context)) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Stream decompression error."); @@ -2939,7 +2939,7 @@ static grpc_error* incoming_byte_stream_pull(grpc_exec_ctx* exec_ctx, s->unprocessed_incoming_frames_decompressed = true; if (end_of_context) { grpc_stream_compression_context_destroy(s->stream_decompression_ctx); - s->stream_decompression_ctx = NULL; + s->stream_decompression_ctx = nullptr; } if (s->unprocessed_incoming_frames_buffer.length == 0) { *slice = grpc_empty_slice(); @@ -2947,7 +2947,7 @@ static grpc_error* incoming_byte_stream_pull(grpc_exec_ctx* exec_ctx, } error = grpc_deframe_unprocessed_incoming_frames( exec_ctx, &s->data_parser, s, &s->unprocessed_incoming_frames_buffer, - slice, NULL); + slice, nullptr); if (error != GRPC_ERROR_NONE) { return error; } @@ -2985,7 +2985,7 @@ static void incoming_byte_stream_publish_error( GPR_ASSERT(error != GRPC_ERROR_NONE); GRPC_CLOSURE_SCHED(exec_ctx, s->on_next, GRPC_ERROR_REF(error)); - s->on_next = NULL; + s->on_next = nullptr; GRPC_ERROR_UNREF(s->byte_stream_error); s->byte_stream_error = GRPC_ERROR_REF(error); grpc_chttp2_cancel_stream(exec_ctx, bs->transport, bs->stream, @@ -3006,7 +3006,7 @@ grpc_error* grpc_chttp2_incoming_byte_stream_push( return error; } else { bs->remaining_bytes -= (uint32_t)GRPC_SLICE_LENGTH(slice); - if (slice_out != NULL) { + if (slice_out != nullptr) { *slice_out = slice; } return GRPC_ERROR_NONE; @@ -3248,7 +3248,7 @@ void grpc_chttp2_transport_start_reading(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t = (grpc_chttp2_transport*)transport; GRPC_CHTTP2_REF_TRANSPORT( t, "reading_action"); /* matches unref inside reading_action */ - if (read_buffer != NULL) { + if (read_buffer != nullptr) { grpc_slice_buffer_move_into(read_buffer, &t->read_buffer); gpr_free(read_buffer); } diff --git a/src/core/ext/transport/chttp2/transport/flow_control.h b/src/core/ext/transport/chttp2/transport/flow_control.h index 7dd348ed5f..c6ab2ca9aa 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.h +++ b/src/core/ext/transport/chttp2/transport/flow_control.h @@ -41,7 +41,7 @@ class TrickledCHTTP2; // to make this a friend namespace grpc_core { namespace chttp2 { -static constexpr uint32_t kDefaultWindow = 65535; +static constexpr uint32_t;;;;;;;;;;;;; kDefaultWindow = 65535; class TransportFlowControl; class StreamFlowControl; diff --git a/src/core/ext/transport/chttp2/transport/frame_data.cc b/src/core/ext/transport/chttp2/transport/frame_data.cc index 7d2c7f5ab9..f0c3b55792 100644 --- a/src/core/ext/transport/chttp2/transport/frame_data.cc +++ b/src/core/ext/transport/chttp2/transport/frame_data.cc @@ -32,13 +32,13 @@ grpc_error* grpc_chttp2_data_parser_init(grpc_chttp2_data_parser* parser) { parser->state = GRPC_CHTTP2_DATA_FH_0; - parser->parsing_frame = NULL; + parser->parsing_frame = nullptr; return GRPC_ERROR_NONE; } void grpc_chttp2_data_parser_destroy(grpc_exec_ctx* exec_ctx, grpc_chttp2_data_parser* parser) { - if (parser->parsing_frame != NULL) { + if (parser->parsing_frame != nullptr) { GRPC_ERROR_UNREF(grpc_chttp2_incoming_byte_stream_finished( exec_ctx, parser->parsing_frame, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Parser destroyed"), false)); @@ -105,9 +105,9 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( grpc_chttp2_transport* t = s->t; while (slices->count > 0) { - uint8_t* beg = NULL; - uint8_t* end = NULL; - uint8_t* cur = NULL; + uint8_t* beg = nullptr; + uint8_t* end = nullptr; + uint8_t* cur = nullptr; grpc_slice slice = grpc_slice_buffer_take_first(slices); @@ -188,8 +188,8 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( /* fallthrough */ case GRPC_CHTTP2_DATA_FH_4: s->stats.incoming.framing_bytes++; - GPR_ASSERT(stream_out != NULL); - GPR_ASSERT(p->parsing_frame == NULL); + GPR_ASSERT(stream_out != nullptr); + GPR_ASSERT(p->parsing_frame == nullptr); p->frame_size |= ((uint32_t)*cur); p->state = GRPC_CHTTP2_DATA_FRAME; ++cur; @@ -203,7 +203,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( if (p->parsing_frame->remaining_bytes == 0) { GRPC_ERROR_UNREF(grpc_chttp2_incoming_byte_stream_finished( exec_ctx, p->parsing_frame, GRPC_ERROR_NONE, true)); - p->parsing_frame = NULL; + p->parsing_frame = nullptr; p->state = GRPC_CHTTP2_DATA_FH_0; } s->pending_byte_stream = true; @@ -216,8 +216,8 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( grpc_slice_unref_internal(exec_ctx, slice); return GRPC_ERROR_NONE; case GRPC_CHTTP2_DATA_FRAME: { - GPR_ASSERT(p->parsing_frame != NULL); - GPR_ASSERT(slice_out != NULL); + GPR_ASSERT(p->parsing_frame != nullptr); + GPR_ASSERT(slice_out != nullptr); if (cur == end) { grpc_slice_unref_internal(exec_ctx, slice); continue; @@ -239,7 +239,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( grpc_slice_unref_internal(exec_ctx, slice); return error; } - p->parsing_frame = NULL; + p->parsing_frame = nullptr; p->state = GRPC_CHTTP2_DATA_FH_0; grpc_slice_unref_internal(exec_ctx, slice); return GRPC_ERROR_NONE; @@ -273,7 +273,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames( grpc_slice_unref_internal(exec_ctx, slice); return error; } - p->parsing_frame = NULL; + p->parsing_frame = nullptr; p->state = GRPC_CHTTP2_DATA_FH_0; cur += p->frame_size; grpc_slice_buffer_undo_take_first( @@ -302,7 +302,7 @@ grpc_error* grpc_chttp2_data_parser_parse(grpc_exec_ctx* exec_ctx, void* parser, grpc_slice_ref_internal(slice); grpc_slice_buffer_add(&s->unprocessed_incoming_frames_buffer, slice); GRPC_CLOSURE_SCHED(exec_ctx, s->on_next, GRPC_ERROR_NONE); - s->on_next = NULL; + s->on_next = nullptr; s->unprocessed_incoming_frames_decompressed = false; } else { grpc_slice_ref_internal(slice); diff --git a/src/core/ext/transport/chttp2/transport/frame_goaway.cc b/src/core/ext/transport/chttp2/transport/frame_goaway.cc index 6be1d0e0f0..a2ce709a2e 100644 --- a/src/core/ext/transport/chttp2/transport/frame_goaway.cc +++ b/src/core/ext/transport/chttp2/transport/frame_goaway.cc @@ -26,7 +26,7 @@ #include <grpc/support/string_util.h> void grpc_chttp2_goaway_parser_init(grpc_chttp2_goaway_parser* p) { - p->debug_data = NULL; + p->debug_data = nullptr; } void grpc_chttp2_goaway_parser_destroy(grpc_chttp2_goaway_parser* p) { @@ -137,7 +137,7 @@ grpc_error* grpc_chttp2_goaway_parser_parse(grpc_exec_ctx* exec_ctx, grpc_chttp2_add_incoming_goaway( exec_ctx, t, (uint32_t)p->error_code, grpc_slice_new(p->debug_data, p->debug_length, gpr_free)); - p->debug_data = NULL; + p->debug_data = nullptr; } return GRPC_ERROR_NONE; } diff --git a/src/core/ext/transport/chttp2/transport/frame_window_update.cc b/src/core/ext/transport/chttp2/transport/frame_window_update.cc index 62a4587ac6..08407a8e67 100644 --- a/src/core/ext/transport/chttp2/transport/frame_window_update.cc +++ b/src/core/ext/transport/chttp2/transport/frame_window_update.cc @@ -79,7 +79,7 @@ grpc_error* grpc_chttp2_window_update_parser_parse( p->byte++; } - if (s != NULL) { + if (s != nullptr) { s->stats.incoming.framing_bytes += (uint32_t)(end - cur); } @@ -95,7 +95,7 @@ grpc_error* grpc_chttp2_window_update_parser_parse( GPR_ASSERT(is_last); if (t->incoming_stream_id != 0) { - if (s != NULL) { + if (s != nullptr) { s->flow_control->RecvUpdate(received_update); if (grpc_chttp2_list_remove_stalled_by_stream(t, s)) { grpc_chttp2_mark_stream_writable(exec_ctx, t, s); diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc index 3636440905..33e4fc415a 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.cc @@ -51,10 +51,10 @@ /* don't consider adding anything bigger than this to the hpack table */ #define MAX_DECODER_SPACE_USAGE 512 -static grpc_slice_refcount terminal_slice_refcount = {NULL, NULL}; +static grpc_slice_refcount terminal_slice_refcount = {nullptr, nullptr}; static const grpc_slice terminal_slice = { &terminal_slice_refcount, /* refcount */ - {{0, 0}} /* data.refcounted */ + {{nullptr, 0}} /* data.refcounted */ }; extern "C" grpc_tracer_flag grpc_http_trace; @@ -477,7 +477,7 @@ static void hpack_enc(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_compressor* c, if (GRPC_TRACER_ON(grpc_http_trace)) { char* k = grpc_slice_to_c_string(GRPC_MDKEY(elem)); - char* v = NULL; + char* v = nullptr; if (grpc_is_binary_header(GRPC_MDKEY(elem))) { v = grpc_dump_slice(GRPC_MDVALUE(elem), GPR_DUMP_HEX); } else { diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc index 1181402918..960610eee0 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc @@ -653,7 +653,7 @@ static grpc_error* on_hdr(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, grpc_mdelem md, int add_to_table) { if (GRPC_TRACER_ON(grpc_http_trace)) { char* k = grpc_slice_to_c_string(GRPC_MDKEY(md)); - char* v = NULL; + char* v = nullptr; if (grpc_is_binary_header(GRPC_MDKEY(md))) { v = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX); } else { @@ -674,7 +674,7 @@ static grpc_error* on_hdr(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p, grpc_error* err = grpc_chttp2_hptbl_add(exec_ctx, &p->table, md); if (err != GRPC_ERROR_NONE) return err; } - if (p->on_header == NULL) { + if (p->on_header == nullptr) { GRPC_MDELEM_UNREF(exec_ctx, md); return GRPC_ERROR_CREATE_FROM_STATIC_STRING("on_header callback not set"); } @@ -1523,7 +1523,7 @@ static grpc_error* begin_parse_string(grpc_exec_ctx* exec_ctx, uint8_t binary, grpc_chttp2_hpack_parser_string* str) { if (!p->huff && binary == NOT_BINARY && (end - cur) >= (intptr_t)p->strlen && - p->current_slice_refcount != NULL) { + p->current_slice_refcount != nullptr) { GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED(exec_ctx); str->copied = false; str->data.referenced.refcount = p->current_slice_refcount; @@ -1613,15 +1613,15 @@ static grpc_error* parse_value_string_with_literal_key( void grpc_chttp2_hpack_parser_init(grpc_exec_ctx* exec_ctx, grpc_chttp2_hpack_parser* p) { - p->on_header = NULL; - p->on_header_user_data = NULL; + p->on_header = nullptr; + p->on_header_user_data = nullptr; p->state = parse_begin; p->key.data.referenced = grpc_empty_slice(); - p->key.data.copied.str = NULL; + p->key.data.copied.str = nullptr; p->key.data.copied.capacity = 0; p->key.data.copied.length = 0; p->value.data.referenced = grpc_empty_slice(); - p->value.data.copied.str = NULL; + p->value.data.copied.str = nullptr; p->value.data.copied.capacity = 0; p->value.data.copied.length = 0; p->dynamic_table_update_allowed = 2; @@ -1659,7 +1659,7 @@ grpc_error* grpc_chttp2_hpack_parser_parse(grpc_exec_ctx* exec_ctx, error = p->state(exec_ctx, p, start, target); start = target; } - p->current_slice_refcount = NULL; + p->current_slice_refcount = nullptr; return error; } @@ -1689,7 +1689,7 @@ static void parse_stream_compression_md(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_metadata_batch* initial_metadata) { - if (initial_metadata->idx.named.content_encoding == NULL || + if (initial_metadata->idx.named.content_encoding == nullptr || grpc_stream_compression_method_parse( GRPC_MDVALUE(initial_metadata->idx.named.content_encoding->md), false, &s->stream_decompression_method) == 0) { @@ -1705,7 +1705,7 @@ grpc_error* grpc_chttp2_header_parser_parse(grpc_exec_ctx* exec_ctx, grpc_slice slice, int is_last) { grpc_chttp2_hpack_parser* parser = (grpc_chttp2_hpack_parser*)hpack_parser; GPR_TIMER_BEGIN("grpc_chttp2_hpack_parser_parse", 0); - if (s != NULL) { + if (s != nullptr) { s->stats.incoming.header_bytes += GRPC_SLICE_LENGTH(slice); } grpc_error* error = grpc_chttp2_hpack_parser_parse(exec_ctx, parser, slice); @@ -1721,7 +1721,7 @@ grpc_error* grpc_chttp2_header_parser_parse(grpc_exec_ctx* exec_ctx, } /* need to check for null stream: this can occur if we receive an invalid stream id on a header */ - if (s != NULL) { + if (s != nullptr) { if (parser->is_boundary) { if (s->header_frames_received == GPR_ARRAY_SIZE(s->metadata_buffer)) { GPR_TIMER_END("grpc_chttp2_hpack_parser_parse", 0); @@ -1756,8 +1756,8 @@ grpc_error* grpc_chttp2_header_parser_parse(grpc_exec_ctx* exec_ctx, GRPC_ERROR_NONE); } } - parser->on_header = NULL; - parser->on_header_user_data = NULL; + parser->on_header = nullptr; + parser->on_header_user_data = nullptr; parser->is_boundary = 0xde; parser->is_eof = 0xde; parser->dynamic_table_update_allowed = 2; diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.cc b/src/core/ext/transport/chttp2/transport/hpack_table.cc index 1a2bc9224e..7970d2ae27 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_table.cc @@ -35,7 +35,7 @@ static struct { const char* value; } static_table[] = { /* 0: */ - {NULL, NULL}, + {nullptr, nullptr}, /* 1: */ {":authority", ""}, /* 2: */ diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.cc b/src/core/ext/transport/chttp2/transport/incoming_metadata.cc index 15f80fb8a1..4461f8c12c 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.cc @@ -51,7 +51,7 @@ grpc_error* grpc_chttp2_incoming_metadata_buffer_add( grpc_error* grpc_chttp2_incoming_metadata_buffer_replace_or_add( grpc_exec_ctx* exec_ctx, grpc_chttp2_incoming_metadata_buffer* buffer, grpc_mdelem elem) { - for (grpc_linked_mdelem* l = buffer->batch.list.head; l != NULL; + for (grpc_linked_mdelem* l = buffer->batch.list.head; l != nullptr; l = l->next) { if (grpc_slice_eq(GRPC_MDKEY(l->md), GRPC_MDKEY(elem))) { GRPC_MDELEM_UNREF(exec_ctx, l->md); diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index 6737c26e72..5f07dec8e8 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -191,7 +191,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, if (err != GRPC_ERROR_NONE) { return err; } - t->incoming_stream = NULL; + t->incoming_stream = nullptr; if (++cur == end) { t->deframe_state = GRPC_DTS_FH_0; return GRPC_ERROR_NONE; @@ -225,7 +225,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, return err; } t->deframe_state = GRPC_DTS_FH_0; - t->incoming_stream = NULL; + t->incoming_stream = nullptr; return GRPC_ERROR_NONE; } else if ((uint32_t)(end - cur) > t->incoming_frame_size) { size_t cur_offset = (size_t)(cur - beg); @@ -238,7 +238,7 @@ grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, return err; } cur += t->incoming_frame_size; - t->incoming_stream = NULL; + t->incoming_stream = nullptr; goto dts_fh_0; /* loop */ } else { err = @@ -252,10 +252,10 @@ grpc_error* grpc_chttp2_perform_read(grpc_exec_ctx* exec_ctx, t->incoming_frame_size -= (uint32_t)(end - cur); return GRPC_ERROR_NONE; } - GPR_UNREACHABLE_CODE(return 0); + GPR_UNREACHABLE_CODE(return nullptr); } - GPR_UNREACHABLE_CODE(return 0); + GPR_UNREACHABLE_CODE(return nullptr); } static grpc_error* init_frame_parser(grpc_exec_ctx* exec_ctx, @@ -337,7 +337,7 @@ static grpc_error* init_skip_frame_parser(grpc_exec_ctx* exec_ctx, t->parser = grpc_chttp2_header_parser_parse; t->parser_data = &t->hpack_parser; t->hpack_parser.on_header = skip_header; - t->hpack_parser.on_header_user_data = NULL; + t->hpack_parser.on_header_user_data = nullptr; t->hpack_parser.is_boundary = is_eoh; t->hpack_parser.is_eof = (uint8_t)(is_eoh ? t->header_eof : 0); } else { @@ -369,7 +369,7 @@ static grpc_error* init_data_frame_parser(grpc_exec_ctx* exec_ctx, if (err != GRPC_ERROR_NONE) { goto error_handler; } - if (s == NULL) { + if (s == nullptr) { return init_skip_frame_parser(exec_ctx, t, 0); } s->received_bytes += t->incoming_frame_size; @@ -391,9 +391,9 @@ error_handler: t->ping_policy.max_pings_without_data; t->ping_state.last_ping_sent_time = GRPC_MILLIS_INF_PAST; return GRPC_ERROR_NONE; - } else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, NULL)) { + } else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, nullptr)) { /* handle stream errors by closing the stream */ - if (s != NULL) { + if (s != nullptr) { grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, false, err); } grpc_slice_buffer_add( @@ -415,7 +415,7 @@ static void on_initial_header(grpc_exec_ctx* exec_ctx, void* tp, GPR_TIMER_BEGIN("on_initial_header", 0); - GPR_ASSERT(s != NULL); + GPR_ASSERT(s != nullptr); if (GRPC_TRACER_ON(grpc_http_trace)) { char* key = grpc_slice_to_c_string(GRPC_MDKEY(md)); @@ -437,7 +437,7 @@ static void on_initial_header(grpc_exec_ctx* exec_ctx, void* tp, grpc_millis* cached_timeout = static_cast<grpc_millis*>(grpc_mdelem_get_user_data(md, free_timeout)); grpc_millis timeout; - if (cached_timeout != NULL) { + if (cached_timeout != nullptr) { timeout = *cached_timeout; } else { if (!grpc_http2_decode_timeout(GRPC_MDVALUE(md), &timeout)) { @@ -499,7 +499,7 @@ static void on_trailing_header(grpc_exec_ctx* exec_ctx, void* tp, GPR_TIMER_BEGIN("on_trailing_header", 0); - GPR_ASSERT(s != NULL); + GPR_ASSERT(s != nullptr); if (GRPC_TRACER_ON(grpc_http_trace)) { char* key = grpc_slice_to_c_string(GRPC_MDKEY(md)); @@ -575,7 +575,7 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, /* could be a new grpc_chttp2_stream or an existing grpc_chttp2_stream */ s = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id); - if (s == NULL) { + if (s == nullptr) { if (is_continuation) { GRPC_CHTTP2_IF_TRACING( gpr_log(GPR_ERROR, @@ -617,7 +617,7 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, t->last_new_stream_id = t->incoming_stream_id; s = t->incoming_stream = grpc_chttp2_parsing_accept_stream(exec_ctx, t, t->incoming_stream_id); - if (s == NULL) { + if (s == nullptr) { GRPC_CHTTP2_IF_TRACING( gpr_log(GPR_ERROR, "grpc_chttp2_stream not accepted")); return init_skip_frame_parser(exec_ctx, t, 1); @@ -625,12 +625,12 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, } else { t->incoming_stream = s; } - GPR_ASSERT(s != NULL); + GPR_ASSERT(s != nullptr); s->stats.incoming.framing_bytes += 9; if (s->read_closed) { GRPC_CHTTP2_IF_TRACING(gpr_log( GPR_ERROR, "skipping already closed grpc_chttp2_stream header")); - t->incoming_stream = NULL; + t->incoming_stream = nullptr; return init_skip_frame_parser(exec_ctx, t, 1); } t->parser = grpc_chttp2_header_parser_parse; @@ -639,7 +639,7 @@ static grpc_error* init_header_frame_parser(grpc_exec_ctx* exec_ctx, case 0: if (t->is_client && t->header_eof) { GRPC_CHTTP2_IF_TRACING(gpr_log(GPR_INFO, "parsing Trailers-Only")); - if (s->trailing_metadata_available != NULL) { + if (s->trailing_metadata_available != nullptr) { *s->trailing_metadata_available = true; } t->hpack_parser.on_header = on_trailing_header; @@ -677,7 +677,7 @@ static grpc_error* init_window_update_frame_parser(grpc_exec_ctx* exec_ctx, if (t->incoming_stream_id != 0) { grpc_chttp2_stream* s = t->incoming_stream = grpc_chttp2_parsing_lookup_stream(t, t->incoming_stream_id); - if (s == NULL) { + if (s == nullptr) { return init_skip_frame_parser(exec_ctx, t, 0); } s->stats.incoming.framing_bytes += 9; @@ -757,7 +757,7 @@ static grpc_error* parse_frame_slice(grpc_exec_ctx* exec_ctx, grpc_error* err = t->parser(exec_ctx, t->parser_data, t, s, slice, is_last); if (err == GRPC_ERROR_NONE) { return err; - } else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, NULL)) { + } else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, nullptr)) { if (GRPC_TRACER_ON(grpc_http_trace)) { const char* msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); diff --git a/src/core/ext/transport/chttp2/transport/stream_lists.cc b/src/core/ext/transport/chttp2/transport/stream_lists.cc index 8d25ab277d..d92527f05c 100644 --- a/src/core/ext/transport/chttp2/transport/stream_lists.cc +++ b/src/core/ext/transport/chttp2/transport/stream_lists.cc @@ -46,7 +46,7 @@ grpc_tracer_flag grpc_trace_http2_stream_state = static bool stream_list_empty(grpc_chttp2_transport* t, grpc_chttp2_stream_list_id id) { - return t->lists[id].head == NULL; + return t->lists[id].head == nullptr; } static bool stream_list_pop(grpc_chttp2_transport* t, @@ -58,10 +58,10 @@ static bool stream_list_pop(grpc_chttp2_transport* t, GPR_ASSERT(s->included[id]); if (new_head) { t->lists[id].head = new_head; - new_head->links[id].prev = NULL; + new_head->links[id].prev = nullptr; } else { - t->lists[id].head = NULL; - t->lists[id].tail = NULL; + t->lists[id].head = nullptr; + t->lists[id].tail = nullptr; } s->included[id] = 0; } @@ -70,7 +70,7 @@ static bool stream_list_pop(grpc_chttp2_transport* t, gpr_log(GPR_DEBUG, "%p[%d][%s]: pop from %s", t, s->id, t->is_client ? "cli" : "svr", stream_list_id_string(id)); } - return s != 0; + return s != nullptr; } static void stream_list_remove(grpc_chttp2_transport* t, grpc_chttp2_stream* s, @@ -111,7 +111,7 @@ static void stream_list_add_tail(grpc_chttp2_transport* t, grpc_chttp2_stream* old_tail; GPR_ASSERT(!s->included[id]); old_tail = t->lists[id].tail; - s->links[id].next = NULL; + s->links[id].next = nullptr; s->links[id].prev = old_tail; if (old_tail) { old_tail->links[id].next = s; diff --git a/src/core/ext/transport/chttp2/transport/stream_map.cc b/src/core/ext/transport/chttp2/transport/stream_map.cc index c863191795..3e7bc23bc1 100644 --- a/src/core/ext/transport/chttp2/transport/stream_map.cc +++ b/src/core/ext/transport/chttp2/transport/stream_map.cc @@ -62,7 +62,7 @@ void grpc_chttp2_stream_map_add(grpc_chttp2_stream_map* map, uint32_t key, GPR_ASSERT(count == 0 || keys[count - 1] < key); GPR_ASSERT(value); - GPR_ASSERT(grpc_chttp2_stream_map_find(map, key) == NULL); + GPR_ASSERT(grpc_chttp2_stream_map_find(map, key) == nullptr); if (count == capacity) { if (map->free > capacity / 4) { @@ -92,7 +92,7 @@ static void** find(grpc_chttp2_stream_map* map, uint32_t key) { void** values = map->values; uint32_t mid_key; - if (max_idx == 0) return NULL; + if (max_idx == 0) return nullptr; while (min_idx < max_idx) { /* find the midpoint, avoiding overflow */ @@ -109,29 +109,29 @@ static void** find(grpc_chttp2_stream_map* map, uint32_t key) { } } - return NULL; + return nullptr; } void* grpc_chttp2_stream_map_delete(grpc_chttp2_stream_map* map, uint32_t key) { void** pvalue = find(map, key); - void* out = NULL; - if (pvalue != NULL) { + void* out = nullptr; + if (pvalue != nullptr) { out = *pvalue; - *pvalue = NULL; - map->free += (out != NULL); + *pvalue = nullptr; + map->free += (out != nullptr); /* recognize complete emptyness and ensure we can skip * defragmentation later */ if (map->free == map->count) { map->free = map->count = 0; } - GPR_ASSERT(grpc_chttp2_stream_map_find(map, key) == NULL); + GPR_ASSERT(grpc_chttp2_stream_map_find(map, key) == nullptr); } return out; } void* grpc_chttp2_stream_map_find(grpc_chttp2_stream_map* map, uint32_t key) { void** pvalue = find(map, key); - return pvalue != NULL ? *pvalue : NULL; + return pvalue != nullptr ? *pvalue : nullptr; } size_t grpc_chttp2_stream_map_size(grpc_chttp2_stream_map* map) { @@ -140,7 +140,7 @@ size_t grpc_chttp2_stream_map_size(grpc_chttp2_stream_map* map) { void* grpc_chttp2_stream_map_rand(grpc_chttp2_stream_map* map) { if (map->count == map->free) { - return NULL; + return nullptr; } if (map->free != 0) { map->count = compact(map->keys, map->values, map->count); diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index 6154bdb682..3ade27982d 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -120,7 +120,7 @@ static bool update_list(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t, grpc_error* error) { bool sched_any = false; grpc_chttp2_write_cb* cb = *list; - *list = NULL; + *list = nullptr; *ctr += send_bytes; while (cb) { grpc_chttp2_write_cb* next = cb->next; @@ -330,24 +330,24 @@ class DataSendContext { bool is_last_data_frame = (send_bytes == s_->compressed_data_buffer.length && s_->flow_controlled_buffer.length == 0 && - s_->fetching_send_message == NULL); - if (is_last_data_frame && s_->send_trailing_metadata != NULL && - s_->stream_compression_ctx != NULL) { + s_->fetching_send_message == nullptr); + if (is_last_data_frame && s_->send_trailing_metadata != nullptr && + s_->stream_compression_ctx != nullptr) { if (!grpc_stream_compress(s_->stream_compression_ctx, &s_->flow_controlled_buffer, - &s_->compressed_data_buffer, NULL, MAX_SIZE_T, + &s_->compressed_data_buffer, nullptr, MAX_SIZE_T, GRPC_STREAM_COMPRESSION_FLUSH_FINISH)) { gpr_log(GPR_ERROR, "Stream compression failed."); } grpc_stream_compression_context_destroy(s_->stream_compression_ctx); - s_->stream_compression_ctx = NULL; + s_->stream_compression_ctx = nullptr; /* After finish, bytes in s->compressed_data_buffer may be * more than max_outgoing. Start another round of the current * while loop so that send_bytes and is_last_data_frame are * recalculated. */ return; } - is_last_frame_ = is_last_data_frame && s_->send_trailing_metadata != NULL && + is_last_frame_ = is_last_data_frame && s_->send_trailing_metadata != nullptr && grpc_metadata_batch_is_empty(s_->send_trailing_metadata); grpc_chttp2_encode_data(s_->id, &s_->compressed_data_buffer, send_bytes, is_last_frame_, &s_->stats.outgoing, &t_->outbuf); @@ -358,14 +358,14 @@ class DataSendContext { } void CompressMoreBytes() { - if (s_->stream_compression_ctx == NULL) { + if (s_->stream_compression_ctx == nullptr) { s_->stream_compression_ctx = grpc_stream_compression_context_create(s_->stream_compression_method); } s_->uncompressed_data_size = s_->flow_controlled_buffer.length; if (!grpc_stream_compress(s_->stream_compression_ctx, &s_->flow_controlled_buffer, - &s_->compressed_data_buffer, NULL, MAX_SIZE_T, + &s_->compressed_data_buffer, nullptr, MAX_SIZE_T, GRPC_STREAM_COMPRESSION_FLUSH_SYNC)) { gpr_log(GPR_ERROR, "Stream compression failed."); } @@ -429,13 +429,13 @@ class StreamWriteContext { [GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE], // max_frame_size &s_->stats.outgoing // stats }; - grpc_chttp2_encode_header(exec_ctx, &t_->hpack_compressor, NULL, 0, + grpc_chttp2_encode_header(exec_ctx, &t_->hpack_compressor, nullptr, 0, s_->send_initial_metadata, &hopt, &t_->outbuf); write_context_->ResetPingRecvClock(); write_context_->IncInitialMetadataWrites(); } - s_->send_initial_metadata = NULL; + s_->send_initial_metadata = nullptr; s_->sent_initial_metadata = true; write_context_->NoteScheduledResults(); grpc_chttp2_complete_closure_step( @@ -502,8 +502,8 @@ class StreamWriteContext { void FlushTrailingMetadata(grpc_exec_ctx* exec_ctx) { if (!s_->sent_initial_metadata) return; - if (s_->send_trailing_metadata == NULL) return; - if (s_->fetching_send_message != NULL) return; + if (s_->send_trailing_metadata == nullptr) return; + if (s_->fetching_send_message != nullptr) return; if (s_->flow_controlled_buffer.length != 0) return; if (s_->compressed_data_buffer.length != 0) return; @@ -543,12 +543,12 @@ class StreamWriteContext { gpr_log(GPR_INFO, "not sending initial_metadata (Trailers-Only)")); // When sending Trailers-Only, we need to move the :status and // content-type headers to the trailers. - if (s_->send_initial_metadata->idx.named.status != NULL) { + if (s_->send_initial_metadata->idx.named.status != nullptr) { extra_headers_for_trailing_metadata_ [num_extra_headers_for_trailing_metadata_++] = &s_->send_initial_metadata->idx.named.status->md; } - if (s_->send_initial_metadata->idx.named.content_type != NULL) { + if (s_->send_initial_metadata->idx.named.content_type != nullptr) { extra_headers_for_trailing_metadata_ [num_extra_headers_for_trailing_metadata_++] = &s_->send_initial_metadata->idx.named.content_type->md; @@ -556,7 +556,7 @@ class StreamWriteContext { } void SentLastFrame(grpc_exec_ctx* exec_ctx) { - s_->send_trailing_metadata = NULL; + s_->send_trailing_metadata = nullptr; s_->sent_trailing_metadata = true; if (!t_->is_client && !s_->read_closed) { diff --git a/src/core/ext/transport/cronet/transport/cronet_api_dummy.cc b/src/core/ext/transport/cronet/transport/cronet_api_dummy.cc index 4f248ad919..578cbb8ac6 100644 --- a/src/core/ext/transport/cronet/transport/cronet_api_dummy.cc +++ b/src/core/ext/transport/cronet/transport/cronet_api_dummy.cc @@ -33,7 +33,7 @@ bidirectional_stream* bidirectional_stream_create( stream_engine* engine, void* annotation, bidirectional_stream_callback* callback) { GPR_ASSERT(0); - return NULL; + return nullptr; } int bidirectional_stream_destroy(bidirectional_stream* stream) { diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.cc b/src/core/ext/transport/cronet/transport/cronet_transport.cc index 0b1ddf8839..4d24efe47b 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.cc +++ b/src/core/ext/transport/cronet/transport/cronet_transport.cc @@ -273,7 +273,7 @@ static void null_and_maybe_free_read_buffer(stream_obj* s) { s->state.rs.read_buffer != s->state.rs.grpc_header_bytes) { gpr_free(s->state.rs.read_buffer); } - s->state.rs.read_buffer = NULL; + s->state.rs.read_buffer = nullptr; } static void maybe_flush_read(stream_obj* s) { @@ -342,7 +342,7 @@ static void add_to_storage(struct stream_obj* s, static void remove_from_storage(struct stream_obj* s, struct op_and_state* oas) { struct op_and_state* curr; - if (s->storage.head == NULL || oas == NULL) { + if (s->storage.head == nullptr || oas == nullptr) { return; } if (s->storage.head == oas) { @@ -352,7 +352,7 @@ static void remove_from_storage(struct stream_obj* s, CRONET_LOG(GPR_DEBUG, "Freed %p. Now %d in the queue", oas, s->storage.num_pending_ops); } else { - for (curr = s->storage.head; curr != NULL; curr = curr->next) { + for (curr = s->storage.head; curr != nullptr; curr = curr->next) { if (curr->next == oas) { curr->next = oas->next; s->storage.num_pending_ops--; @@ -360,7 +360,7 @@ static void remove_from_storage(struct stream_obj* s, s->storage.num_pending_ops); gpr_free(oas); break; - } else if (curr->next == NULL) { + } else if (curr->next == nullptr) { CRONET_LOG(GPR_ERROR, "Reached end of LL and did not find op to free"); } } @@ -375,7 +375,7 @@ static void remove_from_storage(struct stream_obj* s, */ static void execute_from_storage(grpc_exec_ctx* exec_ctx, stream_obj* s) { gpr_mu_lock(&s->mu); - for (struct op_and_state* curr = s->storage.head; curr != NULL;) { + for (struct op_and_state* curr = s->storage.head; curr != nullptr;) { CRONET_LOG(GPR_DEBUG, "calling op at %p. done = %d", curr, curr->done); GPR_ASSERT(curr->done == 0); enum e_op_result result = execute_stream_op(exec_ctx, curr); @@ -408,14 +408,14 @@ static void on_failed(bidirectional_stream* stream, int net_error) { gpr_mu_lock(&s->mu); bidirectional_stream_destroy(s->cbs); s->state.state_callback_received[OP_FAILED] = true; - s->cbs = NULL; + s->cbs = nullptr; if (s->header_array.headers) { gpr_free(s->header_array.headers); - s->header_array.headers = NULL; + s->header_array.headers = nullptr; } if (s->state.ws.write_buffer) { gpr_free(s->state.ws.write_buffer); - s->state.ws.write_buffer = NULL; + s->state.ws.write_buffer = nullptr; } null_and_maybe_free_read_buffer(s); gpr_mu_unlock(&s->mu); @@ -435,14 +435,14 @@ static void on_canceled(bidirectional_stream* stream) { gpr_mu_lock(&s->mu); bidirectional_stream_destroy(s->cbs); s->state.state_callback_received[OP_CANCELED] = true; - s->cbs = NULL; + s->cbs = nullptr; if (s->header_array.headers) { gpr_free(s->header_array.headers); - s->header_array.headers = NULL; + s->header_array.headers = nullptr; } if (s->state.ws.write_buffer) { gpr_free(s->state.ws.write_buffer); - s->state.ws.write_buffer = NULL; + s->state.ws.write_buffer = nullptr; } null_and_maybe_free_read_buffer(s); gpr_mu_unlock(&s->mu); @@ -462,7 +462,7 @@ static void on_succeeded(bidirectional_stream* stream) { gpr_mu_lock(&s->mu); bidirectional_stream_destroy(s->cbs); s->state.state_callback_received[OP_SUCCEEDED] = true; - s->cbs = NULL; + s->cbs = nullptr; null_and_maybe_free_read_buffer(s); gpr_mu_unlock(&s->mu); execute_from_storage(&exec_ctx, s); @@ -484,7 +484,7 @@ static void on_stream_ready(bidirectional_stream* stream) { /* Free the memory allocated for headers */ if (s->header_array.headers) { gpr_free(s->header_array.headers); - s->header_array.headers = NULL; + s->header_array.headers = nullptr; } /* Send the initial metadata on wire if there is no SEND_MESSAGE or * SEND_TRAILING_METADATA ops pending */ @@ -566,7 +566,7 @@ static void on_write_completed(bidirectional_stream* stream, const char* data) { gpr_mu_lock(&s->mu); if (s->state.ws.write_buffer) { gpr_free(s->state.ws.write_buffer); - s->state.ws.write_buffer = NULL; + s->state.ws.write_buffer = nullptr; } s->state.state_callback_received[OP_SEND_MESSAGE] = true; gpr_mu_unlock(&s->mu); @@ -713,7 +713,7 @@ static void convert_metadata_to_cronet_headers( grpc_linked_mdelem* curr = head; /* Walk the linked list and get number of header fields */ size_t num_headers_available = 0; - while (curr != NULL) { + while (curr != nullptr) { curr = curr->next; num_headers_available++; } @@ -765,7 +765,7 @@ static void convert_metadata_to_cronet_headers( headers[num_headers].key = key; headers[num_headers].value = value; num_headers++; - if (curr == NULL) { + if (curr == nullptr) { break; } } @@ -785,7 +785,7 @@ static void parse_grpc_header(const uint8_t* data, int* length, } static bool header_has_authority(grpc_linked_mdelem* head) { - while (head != NULL) { + while (head != nullptr) { if (grpc_slice_eq(GRPC_MDKEY(head->md), GRPC_MDSTR_AUTHORITY)) { return true; } @@ -993,7 +993,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, CRONET_LOG(GPR_DEBUG, "running: %p OP_SEND_INITIAL_METADATA", oas); /* Start new cronet stream. It is destroyed in on_succeeded, on_canceled, * on_failed */ - GPR_ASSERT(s->cbs == NULL); + GPR_ASSERT(s->cbs == nullptr); GPR_ASSERT(!stream_state->state_op_done[OP_SEND_INITIAL_METADATA]); s->cbs = bidirectional_stream_create(t->engine, s->curr_gs, &cronet_callbacks); @@ -1002,9 +1002,9 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, bidirectional_stream_disable_auto_flush(s->cbs, true); bidirectional_stream_delay_request_headers_until_flush(s->cbs, true); } - char* url = NULL; + char* url = nullptr; const char* method = "POST"; - s->header_array.headers = NULL; + s->header_array.headers = nullptr; convert_metadata_to_cronet_headers(stream_op->payload->send_initial_metadata .send_initial_metadata->list.head, t->host, &url, &s->header_array.headers, @@ -1042,7 +1042,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx* exec_ctx, if (1 != grpc_byte_stream_next( exec_ctx, stream_op->payload->send_message.send_message, stream_op->payload->send_message.send_message->length, - NULL)) { + nullptr)) { /* Should never reach here */ GPR_ASSERT(false); } @@ -1358,10 +1358,10 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, s->refcount = refcount; GRPC_CRONET_STREAM_REF(s, "cronet transport"); memset(&s->storage, 0, sizeof(s->storage)); - s->storage.head = NULL; + s->storage.head = nullptr; memset(&s->state, 0, sizeof(s->state)); - s->curr_op = NULL; - s->cbs = NULL; + s->curr_op = nullptr; + s->cbs = nullptr; memset(&s->header_array, 0, sizeof(s->header_array)); memset(&s->state.rs, 0, sizeof(s->state.rs)); memset(&s->state.ws, 0, sizeof(s->state.ws)); @@ -1369,7 +1369,7 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, memset(s->state.state_callback_received, 0, sizeof(s->state.state_callback_received)); s->state.fail_state = s->state.flush_read = false; - s->state.cancel_error = NULL; + s->state.cancel_error = nullptr; s->state.flush_cronet_when_ready = s->state.pending_write_for_trailer = false; s->state.pending_send_message = false; s->state.pending_recv_trailing_metadata = false; @@ -1432,7 +1432,7 @@ static void destroy_transport(grpc_exec_ctx* exec_ctx, grpc_transport* gt) {} static grpc_endpoint* get_endpoint(grpc_exec_ctx* exec_ctx, grpc_transport* gt) { - return NULL; + return nullptr; } static void perform_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, @@ -1491,5 +1491,5 @@ error: gpr_free(ct); } - return NULL; + return nullptr; } diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index a7a6db8bc2..a629942c2d 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -184,7 +184,7 @@ static void really_destroy_stream(grpc_exec_ctx* exec_ctx, inproc_stream* s) { static void log_metadata(const grpc_metadata_batch* md_batch, bool is_client, bool is_initial) { - for (grpc_linked_mdelem* md = md_batch->list.head; md != NULL; + for (grpc_linked_mdelem* md = md_batch->list.head; md != nullptr; md = md->next) { char* key = grpc_slice_to_c_string(GRPC_MDKEY(md->md)); char* value = grpc_slice_to_c_string(GRPC_MDVALUE(md->md)); @@ -200,18 +200,18 @@ static grpc_error* fill_in_metadata(grpc_exec_ctx* exec_ctx, inproc_stream* s, uint32_t flags, grpc_metadata_batch* out_md, uint32_t* outflags, bool* markfilled) { if (GRPC_TRACER_ON(grpc_inproc_trace)) { - log_metadata(metadata, s->t->is_client, outflags != NULL); + log_metadata(metadata, s->t->is_client, outflags != nullptr); } - if (outflags != NULL) { + if (outflags != nullptr) { *outflags = flags; } - if (markfilled != NULL) { + if (markfilled != nullptr) { *markfilled = true; } grpc_error* error = GRPC_ERROR_NONE; for (grpc_linked_mdelem* elem = metadata->list.head; - (elem != NULL) && (error == GRPC_ERROR_NONE); elem = elem->next) { + (elem != nullptr) && (error == GRPC_ERROR_NONE); elem = elem->next) { grpc_linked_mdelem* nelem = (grpc_linked_mdelem*)gpr_arena_alloc(s->arena, sizeof(*nelem)); nelem->md = grpc_mdelem_from_slices( @@ -250,7 +250,7 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, GRPC_CLOSURE_INIT(&s->op_closure, op_state_machine, s, grpc_schedule_on_exec_ctx); s->t = t; - s->closure_at_destroy = NULL; + s->closure_at_destroy = nullptr; s->other_side_closed = false; s->initial_md_sent = s->trailing_md_sent = s->initial_md_recvd = @@ -264,7 +264,7 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, s->deadline = GRPC_MILLIS_INF_FUTURE; s->write_buffer_deadline = GRPC_MILLIS_INF_FUTURE; - s->stream_list_prev = NULL; + s->stream_list_prev = nullptr; gpr_mu_lock(&t->mu->mu); s->listed = true; ref_stream(s, "inproc_init_stream:list"); @@ -279,7 +279,7 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, ref_transport(t); inproc_transport* st = t->other_side; ref_transport(st); - s->other_side = NULL; // will get filled in soon + s->other_side = nullptr; // will get filled in soon // Pass the client-side stream address to the server-side for a ref ref_stream(s, "inproc_init_stream:clt"); // ref it now on behalf of server // side to avoid destruction @@ -311,7 +311,7 @@ static int init_stream(grpc_exec_ctx* exec_ctx, grpc_transport* gt, } if (cs->write_buffer_trailing_md_filled) { fill_in_metadata(exec_ctx, s, &cs->write_buffer_trailing_md, 0, - &s->to_read_trailing_md, NULL, + &s->to_read_trailing_md, nullptr, &s->to_read_trailing_md_filled); grpc_metadata_batch_clear(exec_ctx, &cs->write_buffer_trailing_md); cs->write_buffer_trailing_md_filled = false; @@ -335,12 +335,12 @@ static void close_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s) { if (s->listed) { inproc_stream* p = s->stream_list_prev; inproc_stream* n = s->stream_list_next; - if (p != NULL) { + if (p != nullptr) { p->stream_list_next = n; } else { s->t->stream_list = n; } - if (n != NULL) { + if (n != nullptr) { n->stream_list_prev = p; } s->listed = false; @@ -354,14 +354,14 @@ static void close_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s) { // This function means that we are done talking/listening to the other side static void close_other_side_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, const char* reason) { - if (s->other_side != NULL) { + if (s->other_side != nullptr) { // First release the metadata that came from the other side's arena grpc_metadata_batch_destroy(exec_ctx, &s->to_read_initial_md); grpc_metadata_batch_destroy(exec_ctx, &s->to_read_trailing_md); unref_stream(exec_ctx, s->other_side, reason); s->other_side_closed = true; - s->other_side = NULL; + s->other_side = nullptr; } else if (!s->other_side_closed) { s->write_buffer_other_side_closed = true; } @@ -410,14 +410,14 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, grpc_metadata_batch_init(&fake_md); inproc_stream* other = s->other_side; - grpc_metadata_batch* dest = (other == NULL) ? &s->write_buffer_trailing_md + grpc_metadata_batch* dest = (other == nullptr) ? &s->write_buffer_trailing_md : &other->to_read_trailing_md; - bool* destfilled = (other == NULL) ? &s->write_buffer_trailing_md_filled + bool* destfilled = (other == nullptr) ? &s->write_buffer_trailing_md_filled : &other->to_read_trailing_md_filled; - fill_in_metadata(exec_ctx, s, &fake_md, 0, dest, NULL, destfilled); + fill_in_metadata(exec_ctx, s, &fake_md, 0, dest, nullptr, destfilled); grpc_metadata_batch_destroy(exec_ctx, &fake_md); - if (other != NULL) { + if (other != nullptr) { if (other->cancel_other_error == GRPC_ERROR_NONE) { other->cancel_other_error = GRPC_ERROR_REF(error); } @@ -451,7 +451,7 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, s->recv_initial_md_op->payload->recv_initial_metadata .recv_initial_metadata, s->recv_initial_md_op->payload->recv_initial_metadata.recv_flags, - NULL); + nullptr); grpc_metadata_batch_destroy(exec_ctx, &fake_md); err = GRPC_ERROR_NONE; } else { @@ -469,7 +469,7 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, complete_if_batch_end_locked( exec_ctx, s, error, s->recv_initial_md_op, "fail_helper scheduling recv-initial-metadata-on-complete"); - s->recv_initial_md_op = NULL; + s->recv_initial_md_op = nullptr; } if (s->recv_message_op) { INPROC_LOG(GPR_DEBUG, "fail_helper %p scheduling message-ready %p", s, @@ -480,19 +480,19 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, complete_if_batch_end_locked( exec_ctx, s, error, s->recv_message_op, "fail_helper scheduling recv-message-on-complete"); - s->recv_message_op = NULL; + s->recv_message_op = nullptr; } if (s->send_message_op) { complete_if_batch_end_locked( exec_ctx, s, error, s->send_message_op, "fail_helper scheduling send-message-on-complete"); - s->send_message_op = NULL; + s->send_message_op = nullptr; } if (s->send_trailing_md_op) { complete_if_batch_end_locked( exec_ctx, s, error, s->send_trailing_md_op, "fail_helper scheduling send-trailng-md-on-complete"); - s->send_trailing_md_op = NULL; + s->send_trailing_md_op = nullptr; } if (s->recv_trailing_md_op) { INPROC_LOG(GPR_DEBUG, @@ -501,7 +501,7 @@ static void fail_helper_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, complete_if_batch_end_locked( exec_ctx, s, error, s->recv_trailing_md_op, "fail_helper scheduling recv-trailing-metadata-on-complete"); - s->recv_trailing_md_op = NULL; + s->recv_trailing_md_op = nullptr; } close_other_side_locked(exec_ctx, s, "fail_helper:other_side"); close_stream_locked(exec_ctx, s); @@ -554,8 +554,8 @@ static void message_transfer_locked(grpc_exec_ctx* exec_ctx, exec_ctx, receiver, GRPC_ERROR_NONE, receiver->recv_message_op, "message_transfer scheduling receiver on_complete"); - receiver->recv_message_op = NULL; - sender->send_message_op = NULL; + receiver->recv_message_op = nullptr; + sender->send_message_op = nullptr; } static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, @@ -601,7 +601,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, complete_if_batch_end_locked( exec_ctx, s, GRPC_ERROR_NONE, s->send_message_op, "op_state_machine scheduling send-message-on-complete"); - s->send_message_op = NULL; + s->send_message_op = nullptr; } } // Pause a send trailing metadata if there is still an outstanding @@ -612,9 +612,9 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, (!s->send_message_op || (s->t->is_client && (s->trailing_md_recvd || s->to_read_trailing_md_filled)))) { - grpc_metadata_batch* dest = (other == NULL) ? &s->write_buffer_trailing_md + grpc_metadata_batch* dest = (other == nullptr) ? &s->write_buffer_trailing_md : &other->to_read_trailing_md; - bool* destfilled = (other == NULL) ? &s->write_buffer_trailing_md_filled + bool* destfilled = (other == nullptr) ? &s->write_buffer_trailing_md_filled : &other->to_read_trailing_md_filled; if (*destfilled || s->trailing_md_sent) { // The buffer is already in use; that's an error! @@ -627,7 +627,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, fill_in_metadata(exec_ctx, s, s->send_trailing_md_op->payload->send_trailing_metadata .send_trailing_metadata, - 0, dest, NULL, destfilled); + 0, dest, nullptr, destfilled); } s->trailing_md_sent = true; if (!s->t->is_client && s->trailing_md_recvd && s->recv_trailing_md_op) { @@ -635,7 +635,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, "op_state_machine %p scheduling trailing-md-on-complete", s); GRPC_CLOSURE_SCHED(exec_ctx, s->recv_trailing_md_op->on_complete, GRPC_ERROR_NONE); - s->recv_trailing_md_op = NULL; + s->recv_trailing_md_op = nullptr; needs_close = true; } } @@ -643,7 +643,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, complete_if_batch_end_locked( exec_ctx, s, GRPC_ERROR_NONE, s->send_trailing_md_op, "op_state_machine scheduling send-trailing-metadata-on-complete"); - s->send_trailing_md_op = NULL; + s->send_trailing_md_op = nullptr; } if (s->recv_initial_md_op) { if (s->initial_md_recvd) { @@ -665,7 +665,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, s->recv_initial_md_op->payload->recv_initial_metadata .recv_initial_metadata, s->recv_initial_md_op->payload->recv_initial_metadata.recv_flags, - NULL); + nullptr); s->recv_initial_md_op->payload->recv_initial_metadata .recv_initial_metadata->deadline = s->deadline; grpc_metadata_batch_clear(exec_ctx, &s->to_read_initial_md); @@ -680,7 +680,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, complete_if_batch_end_locked( exec_ctx, s, new_err, s->recv_initial_md_op, "op_state_machine scheduling recv-initial-metadata-on-complete"); - s->recv_initial_md_op = NULL; + s->recv_initial_md_op = nullptr; if (new_err != GRPC_ERROR_NONE) { INPROC_LOG(GPR_DEBUG, @@ -713,7 +713,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, fail_helper_locked(exec_ctx, s, GRPC_ERROR_REF(new_err)); goto done; } - if (s->recv_message_op != NULL) { + if (s->recv_message_op != nullptr) { // This message needs to be wrapped up because it will never be // satisfied INPROC_LOG(GPR_DEBUG, "op_state_machine %p scheduling message-ready", s); @@ -724,7 +724,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, complete_if_batch_end_locked( exec_ctx, s, new_err, s->recv_message_op, "op_state_machine scheduling recv-message-on-complete"); - s->recv_message_op = NULL; + s->recv_message_op = nullptr; } if ((s->trailing_md_sent || s->t->is_client) && s->send_message_op) { // Nothing further will try to receive from this stream, so finish off @@ -732,16 +732,16 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, complete_if_batch_end_locked( exec_ctx, s, new_err, s->send_message_op, "op_state_machine scheduling send-message-on-complete"); - s->send_message_op = NULL; + s->send_message_op = nullptr; } - if (s->recv_trailing_md_op != NULL) { + if (s->recv_trailing_md_op != nullptr) { // We wanted trailing metadata and we got it s->trailing_md_recvd = true; new_err = fill_in_metadata(exec_ctx, s, &s->to_read_trailing_md, 0, s->recv_trailing_md_op->payload ->recv_trailing_metadata.recv_trailing_metadata, - NULL, NULL); + nullptr, nullptr); grpc_metadata_batch_clear(exec_ctx, &s->to_read_trailing_md); s->to_read_trailing_md_filled = false; @@ -756,7 +756,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, s, new_err); GRPC_CLOSURE_SCHED(exec_ctx, s->recv_trailing_md_op->on_complete, GRPC_ERROR_REF(new_err)); - s->recv_trailing_md_op = NULL; + s->recv_trailing_md_op = nullptr; needs_close = true; } else { INPROC_LOG(GPR_DEBUG, @@ -780,7 +780,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, complete_if_batch_end_locked( exec_ctx, s, new_err, s->recv_message_op, "op_state_machine scheduling recv-message-on-complete"); - s->recv_message_op = NULL; + s->recv_message_op = nullptr; } if (s->trailing_md_recvd && (s->trailing_md_sent || s->t->is_client) && s->send_message_op) { @@ -789,7 +789,7 @@ static void op_state_machine(grpc_exec_ctx* exec_ctx, void* arg, complete_if_batch_end_locked( exec_ctx, s, new_err, s->send_message_op, "op_state_machine scheduling send-message-on-complete"); - s->send_message_op = NULL; + s->send_message_op = nullptr; } if (s->send_message_op || s->send_trailing_md_op || s->recv_initial_md_op || s->recv_message_op || s->recv_trailing_md_op) { @@ -827,14 +827,14 @@ static bool cancel_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, grpc_metadata_batch_init(&cancel_md); inproc_stream* other = s->other_side; - grpc_metadata_batch* dest = (other == NULL) ? &s->write_buffer_trailing_md + grpc_metadata_batch* dest = (other == nullptr) ? &s->write_buffer_trailing_md : &other->to_read_trailing_md; - bool* destfilled = (other == NULL) ? &s->write_buffer_trailing_md_filled + bool* destfilled = (other == nullptr) ? &s->write_buffer_trailing_md_filled : &other->to_read_trailing_md_filled; - fill_in_metadata(exec_ctx, s, &cancel_md, 0, dest, NULL, destfilled); + fill_in_metadata(exec_ctx, s, &cancel_md, 0, dest, nullptr, destfilled); grpc_metadata_batch_destroy(exec_ctx, &cancel_md); - if (other != NULL) { + if (other != nullptr) { if (other->cancel_other_error == GRPC_ERROR_NONE) { other->cancel_other_error = GRPC_ERROR_REF(s->cancel_self_error); } @@ -851,7 +851,7 @@ static bool cancel_stream_locked(grpc_exec_ctx* exec_ctx, inproc_stream* s, complete_if_batch_end_locked( exec_ctx, s, s->cancel_self_error, s->recv_trailing_md_op, "cancel_stream scheduling trailing-md-on-complete"); - s->recv_trailing_md_op = NULL; + s->recv_trailing_md_op = nullptr; } } @@ -882,7 +882,7 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, } grpc_error* error = GRPC_ERROR_NONE; grpc_closure* on_complete = op->on_complete; - if (on_complete == NULL) { + if (on_complete == nullptr) { on_complete = &do_nothing_closure; } @@ -914,11 +914,11 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Endpoint already shutdown"); } if (error == GRPC_ERROR_NONE && op->send_initial_metadata) { - grpc_metadata_batch* dest = (other == NULL) ? &s->write_buffer_initial_md + grpc_metadata_batch* dest = (other == nullptr) ? &s->write_buffer_initial_md : &other->to_read_initial_md; - uint32_t* destflags = (other == NULL) ? &s->write_buffer_initial_md_flags + uint32_t* destflags = (other == nullptr) ? &s->write_buffer_initial_md_flags : &other->to_read_initial_md_flags; - bool* destfilled = (other == NULL) ? &s->write_buffer_initial_md_filled + bool* destfilled = (other == nullptr) ? &s->write_buffer_initial_md_filled : &other->to_read_initial_md_filled; if (*destfilled || s->initial_md_sent) { // The buffer is already in use; that's an error! @@ -934,7 +934,7 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, } if (s->t->is_client) { grpc_millis* dl = - (other == NULL) ? &s->write_buffer_deadline : &other->deadline; + (other == nullptr) ? &s->write_buffer_deadline : &other->deadline; *dl = GPR_MIN(*dl, op->payload->send_initial_metadata .send_initial_metadata->deadline); s->initial_md_sent = true; @@ -973,11 +973,11 @@ static void perform_stream_op(grpc_exec_ctx* exec_ctx, grpc_transport* gt, // 5. There is trailing metadata, even if nothing specifically wants // that because that can shut down the receive message as well if ((op->send_message && other && - ((other->recv_message_op != NULL) || - (other->recv_trailing_md_op != NULL))) || + ((other->recv_message_op != nullptr) || + (other->recv_trailing_md_op != nullptr))) || (op->send_trailing_metadata && !op->send_message) || (op->recv_initial_metadata && s->to_read_initial_md_filled) || - (op->recv_message && other && (other->send_message_op != NULL)) || + (op->recv_message && other && (other->send_message_op != nullptr)) || (s->to_read_trailing_md_filled || s->trailing_md_recvd)) { if (!s->op_closure_scheduled) { GRPC_CLOSURE_SCHED(exec_ctx, &s->op_closure, GRPC_ERROR_NONE); @@ -1031,7 +1031,7 @@ static void close_transport_locked(grpc_exec_ctx* exec_ctx, if (!t->is_closed) { t->is_closed = true; /* Also end all streams on this transport */ - while (t->stream_list != NULL) { + while (t->stream_list != nullptr) { // cancel_stream_locked also adjusts stream list cancel_stream_locked( exec_ctx, t->stream_list, @@ -1110,7 +1110,7 @@ static void set_pollset_set(grpc_exec_ctx* exec_ctx, grpc_transport* gt, } static grpc_endpoint* get_endpoint(grpc_exec_ctx* exec_ctx, grpc_transport* t) { - return NULL; + return nullptr; } /******************************************************************************* @@ -1120,9 +1120,9 @@ static void do_nothing(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) {} void grpc_inproc_transport_init(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_CLOSURE_INIT(&do_nothing_closure, do_nothing, NULL, + GRPC_CLOSURE_INIT(&do_nothing_closure, do_nothing, nullptr, grpc_schedule_on_exec_ctx); - g_empty_slice = grpc_slice_from_static_buffer(NULL, 0); + g_empty_slice = grpc_slice_from_static_buffer(nullptr, 0); grpc_slice key_tmp = grpc_slice_from_static_string(":path"); g_fake_path_key = grpc_slice_intern(key_tmp); @@ -1173,8 +1173,8 @@ static void inproc_transports_create(grpc_exec_ctx* exec_ctx, "inproc_client"); st->other_side = ct; ct->other_side = st; - st->stream_list = NULL; - ct->stream_list = NULL; + st->stream_list = nullptr; + ct->stream_list = nullptr; *server_transport = (grpc_transport*)st; *client_transport = (grpc_transport*)ct; } @@ -1203,7 +1203,7 @@ grpc_channel* grpc_inproc_channel_create(grpc_server* server, inproc_transports_create(&exec_ctx, &server_transport, server_args, &client_transport, client_args); - grpc_server_setup_transport(&exec_ctx, server, server_transport, NULL, + grpc_server_setup_transport(&exec_ctx, server, server_transport, nullptr, server_args); grpc_channel* channel = grpc_channel_create(&exec_ctx, "inproc", client_args, diff --git a/src/core/lib/channel/channel_args.cc b/src/core/lib/channel/channel_args.cc index 23a604301e..735fcbe405 100644 --- a/src/core/lib/channel/channel_args.cc +++ b/src/core/lib/channel/channel_args.cc @@ -54,7 +54,7 @@ static grpc_arg copy_arg(const grpc_arg* src) { grpc_channel_args* grpc_channel_args_copy_and_add(const grpc_channel_args* src, const grpc_arg* to_add, size_t num_to_add) { - return grpc_channel_args_copy_and_add_and_remove(src, NULL, 0, to_add, + return grpc_channel_args_copy_and_add_and_remove(src, nullptr, 0, to_add, num_to_add); } @@ -62,7 +62,7 @@ grpc_channel_args* grpc_channel_args_copy_and_remove( const grpc_channel_args* src, const char** to_remove, size_t num_to_remove) { return grpc_channel_args_copy_and_add_and_remove(src, to_remove, - num_to_remove, NULL, 0); + num_to_remove, nullptr, 0); } static bool should_remove_arg(const grpc_arg* arg, const char** to_remove, @@ -78,7 +78,7 @@ grpc_channel_args* grpc_channel_args_copy_and_add_and_remove( const grpc_arg* to_add, size_t num_to_add) { // Figure out how many args we'll be copying. size_t num_args_to_copy = 0; - if (src != NULL) { + if (src != nullptr) { for (size_t i = 0; i < src->num_args; ++i) { if (!should_remove_arg(&src->args[i], to_remove, num_to_remove)) { ++num_args_to_copy; @@ -90,13 +90,13 @@ grpc_channel_args* grpc_channel_args_copy_and_add_and_remove( (grpc_channel_args*)gpr_malloc(sizeof(grpc_channel_args)); dst->num_args = num_args_to_copy + num_to_add; if (dst->num_args == 0) { - dst->args = NULL; + dst->args = nullptr; return dst; } dst->args = (grpc_arg*)gpr_malloc(sizeof(grpc_arg) * dst->num_args); // Copy args from src that are not being removed. size_t dst_idx = 0; - if (src != NULL) { + if (src != nullptr) { for (size_t i = 0; i < src->num_args; ++i) { if (!should_remove_arg(&src->args[i], to_remove, num_to_remove)) { dst->args[dst_idx++] = copy_arg(&src->args[i]); @@ -112,7 +112,7 @@ grpc_channel_args* grpc_channel_args_copy_and_add_and_remove( } grpc_channel_args* grpc_channel_args_copy(const grpc_channel_args* src) { - return grpc_channel_args_copy_and_add(src, NULL, 0); + return grpc_channel_args_copy_and_add(src, nullptr, 0); } grpc_channel_args* grpc_channel_args_union(const grpc_channel_args* a, @@ -124,12 +124,12 @@ grpc_channel_args* grpc_channel_args_union(const grpc_channel_args* a, size_t uniques_idx = a->num_args; for (size_t i = 0; i < b->num_args; ++i) { const char* b_key = b->args[i].key; - if (grpc_channel_args_find(a, b_key) == NULL) { // not found + if (grpc_channel_args_find(a, b_key) == nullptr) { // not found uniques[uniques_idx++] = b->args[i]; } } grpc_channel_args* result = - grpc_channel_args_copy_and_add(NULL, uniques, uniques_idx); + grpc_channel_args_copy_and_add(nullptr, uniques, uniques_idx); gpr_free(uniques); return result; } @@ -212,7 +212,7 @@ void grpc_channel_args_destroy(grpc_exec_ctx* exec_ctx, grpc_channel_args* a) { grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( const grpc_channel_args* a) { size_t i; - if (a == NULL) return GRPC_COMPRESS_NONE; + if (a == nullptr) return GRPC_COMPRESS_NONE; for (i = 0; i < a->num_args; ++i) { if (a->args[i].type == GRPC_ARG_INTEGER && !strcmp(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM, a->args[i].key)) { @@ -226,7 +226,7 @@ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( grpc_stream_compression_algorithm grpc_channel_args_get_stream_compression_algorithm(const grpc_channel_args* a) { size_t i; - if (a == NULL) return GRPC_STREAM_COMPRESS_NONE; + if (a == nullptr) return GRPC_STREAM_COMPRESS_NONE; for (i = 0; i < a->num_args; ++i) { if (a->args[i].type == GRPC_ARG_INTEGER && !strcmp(GRPC_STREAM_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM, @@ -263,7 +263,7 @@ grpc_channel_args* grpc_channel_args_set_stream_compression_algorithm( * 0. */ static int find_compression_algorithm_states_bitset(const grpc_channel_args* a, int** states_arg) { - if (a != NULL) { + if (a != nullptr) { size_t i; for (i = 0; i < a->num_args; ++i) { if (a->args[i].type == GRPC_ARG_INTEGER && @@ -283,7 +283,7 @@ static int find_compression_algorithm_states_bitset(const grpc_channel_args* a, * 0. */ static int find_stream_compression_algorithm_states_bitset( const grpc_channel_args* a, int** states_arg) { - if (a != NULL) { + if (a != nullptr) { size_t i; for (i = 0; i < a->num_args; ++i) { if (a->args[i].type == GRPC_ARG_INTEGER && @@ -301,14 +301,14 @@ static int find_stream_compression_algorithm_states_bitset( grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( grpc_exec_ctx* exec_ctx, grpc_channel_args** a, grpc_compression_algorithm algorithm, int state) { - int* states_arg = NULL; + int* states_arg = nullptr; grpc_channel_args* result = *a; const int states_arg_found = find_compression_algorithm_states_bitset(*a, &states_arg); if (grpc_channel_args_get_compression_algorithm(*a) == algorithm && state == 0) { - const char* algo_name = NULL; + const char* algo_name = nullptr; GPR_ASSERT(grpc_compression_algorithm_name(algorithm, &algo_name) != 0); gpr_log(GPR_ERROR, "Tried to disable default compression algorithm '%s'. The " @@ -342,14 +342,14 @@ grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( grpc_channel_args* grpc_channel_args_stream_compression_algorithm_set_state( grpc_exec_ctx* exec_ctx, grpc_channel_args** a, grpc_stream_compression_algorithm algorithm, int state) { - int* states_arg = NULL; + int* states_arg = nullptr; grpc_channel_args* result = *a; const int states_arg_found = find_stream_compression_algorithm_states_bitset(*a, &states_arg); if (grpc_channel_args_get_stream_compression_algorithm(*a) == algorithm && state == 0) { - const char* algo_name = NULL; + const char* algo_name = nullptr; GPR_ASSERT(grpc_stream_compression_algorithm_name(algorithm, &algo_name) != 0); gpr_log(GPR_ERROR, @@ -421,19 +421,19 @@ int grpc_channel_args_compare(const grpc_channel_args* a, const grpc_arg* grpc_channel_args_find(const grpc_channel_args* args, const char* name) { - if (args != NULL) { + if (args != nullptr) { for (size_t i = 0; i < args->num_args; ++i) { if (strcmp(args->args[i].key, name) == 0) { return &args->args[i]; } } } - return NULL; + return nullptr; } int grpc_channel_arg_get_integer(const grpc_arg* arg, const grpc_integer_options options) { - if (arg == NULL) return options.default_value; + if (arg == nullptr) return options.default_value; if (arg->type != GRPC_ARG_INTEGER) { gpr_log(GPR_ERROR, "%s ignored: it must be an integer", arg->key); return options.default_value; @@ -452,7 +452,7 @@ int grpc_channel_arg_get_integer(const grpc_arg* arg, } bool grpc_channel_arg_get_bool(const grpc_arg* arg, bool default_value) { - if (arg == NULL) return default_value; + if (arg == nullptr) return default_value; if (arg->type != GRPC_ARG_INTEGER) { gpr_log(GPR_ERROR, "%s ignored: it must be an integer", arg->key); return default_value; diff --git a/src/core/lib/channel/channel_stack.cc b/src/core/lib/channel/channel_stack.cc index 3ab2e33d6d..6e5080995e 100644 --- a/src/core/lib/channel/channel_stack.cc +++ b/src/core/lib/channel/channel_stack.cc @@ -225,7 +225,7 @@ void grpc_call_stack_destroy(grpc_exec_ctx* exec_ctx, grpc_call_stack* stack, for (i = 0; i < count; i++) { elems[i].filter->destroy_call_elem( exec_ctx, &elems[i], final_info, - i == count - 1 ? then_schedule_closure : NULL); + i == count - 1 ? then_schedule_closure : nullptr); } } diff --git a/src/core/lib/channel/channel_stack_builder.cc b/src/core/lib/channel/channel_stack_builder.cc index 83748db3c2..1e553bfb03 100644 --- a/src/core/lib/channel/channel_stack_builder.cc +++ b/src/core/lib/channel/channel_stack_builder.cc @@ -54,8 +54,8 @@ grpc_channel_stack_builder* grpc_channel_stack_builder_create(void) { grpc_channel_stack_builder* b = (grpc_channel_stack_builder*)gpr_zalloc(sizeof(*b)); - b->begin.filter = NULL; - b->end.filter = NULL; + b->begin.filter = nullptr; + b->end.filter = nullptr; b->begin.next = &b->end; b->begin.prev = &b->end; b->end.next = &b->begin; @@ -108,7 +108,7 @@ bool grpc_channel_stack_builder_iterator_is_end( const char* grpc_channel_stack_builder_iterator_filter_name( grpc_channel_stack_builder_iterator* iterator) { - if (iterator->node->filter == NULL) return NULL; + if (iterator->node->filter == nullptr) return nullptr; return iterator->node->filter->name; } @@ -128,7 +128,7 @@ bool grpc_channel_stack_builder_move_prev( grpc_channel_stack_builder_iterator* grpc_channel_stack_builder_iterator_find( grpc_channel_stack_builder* builder, const char* filter_name) { - GPR_ASSERT(filter_name != NULL); + GPR_ASSERT(filter_name != nullptr); grpc_channel_stack_builder_iterator* it = grpc_channel_stack_builder_create_iterator_at_first(builder); while (grpc_channel_stack_builder_move_next(it)) { @@ -145,14 +145,14 @@ bool grpc_channel_stack_builder_move_prev( void grpc_channel_stack_builder_set_name(grpc_channel_stack_builder* builder, const char* name) { - GPR_ASSERT(builder->name == NULL); + GPR_ASSERT(builder->name == nullptr); builder->name = name; } void grpc_channel_stack_builder_set_channel_arguments( grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, const grpc_channel_args* args) { - if (builder->args != NULL) { + if (builder->args != nullptr) { grpc_channel_args_destroy(exec_ctx, builder->args); } builder->args = grpc_channel_args_copy(args); @@ -160,7 +160,7 @@ void grpc_channel_stack_builder_set_channel_arguments( void grpc_channel_stack_builder_set_transport( grpc_channel_stack_builder* builder, grpc_transport* transport) { - GPR_ASSERT(builder->transport == NULL); + GPR_ASSERT(builder->transport == nullptr); builder->transport = transport; } @@ -249,7 +249,7 @@ void grpc_channel_stack_builder_destroy(grpc_exec_ctx* exec_ctx, gpr_free(p); p = next; } - if (builder->args != NULL) { + if (builder->args != nullptr) { grpc_channel_args_destroy(exec_ctx, builder->args); } gpr_free(builder->target); @@ -285,19 +285,19 @@ grpc_error* grpc_channel_stack_builder_finish( // and initialize it grpc_error* error = grpc_channel_stack_init( exec_ctx, initial_refs, destroy, - destroy_arg == NULL ? *result : destroy_arg, filters, num_filters, + destroy_arg == nullptr ? *result : destroy_arg, filters, num_filters, builder->args, builder->transport, builder->name, channel_stack); if (error != GRPC_ERROR_NONE) { grpc_channel_stack_destroy(exec_ctx, channel_stack); gpr_free(*result); - *result = NULL; + *result = nullptr; } else { // run post-initialization functions i = 0; for (filter_node* p = builder->begin.next; p != &builder->end; p = p->next) { - if (p->init != NULL) { + if (p->init != nullptr) { p->init(channel_stack, grpc_channel_stack_element(channel_stack, i), p->init_arg); } diff --git a/src/core/lib/channel/connected_channel.cc b/src/core/lib/channel/connected_channel.cc index 49b9f140c0..af2f88ab2e 100644 --- a/src/core/lib/channel/connected_channel.cc +++ b/src/core/lib/channel/connected_channel.cc @@ -85,7 +85,7 @@ static callback_state* get_state_for_batch( if (batch->recv_initial_metadata) return &calld->on_complete[3]; if (batch->recv_message) return &calld->on_complete[4]; if (batch->recv_trailing_metadata) return &calld->on_complete[5]; - GPR_UNREACHABLE_CODE(return NULL); + GPR_UNREACHABLE_CODE(return nullptr); } /* We perform a small hack to locate transport data alongside the connected @@ -181,7 +181,7 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, grpc_channel_element_args* args) { channel_data* cd = (channel_data*)elem->channel_data; GPR_ASSERT(args->is_last); - cd->transport = NULL; + cd->transport = nullptr; return GRPC_ERROR_NONE; } @@ -217,7 +217,7 @@ static void bind_transport(grpc_channel_stack* channel_stack, grpc_channel_element* elem, void* t) { channel_data* cd = (channel_data*)elem->channel_data; GPR_ASSERT(elem->filter == &grpc_connected_filter); - GPR_ASSERT(cd->transport == NULL); + GPR_ASSERT(cd->transport == nullptr); cd->transport = (grpc_transport*)t; /* HACK(ctiller): increase call stack size for the channel to make space @@ -233,9 +233,9 @@ static void bind_transport(grpc_channel_stack* channel_stack, bool grpc_add_connected_filter(grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg_must_be_null) { - GPR_ASSERT(arg_must_be_null == NULL); + GPR_ASSERT(arg_must_be_null == nullptr); grpc_transport* t = grpc_channel_stack_builder_get_transport(builder); - GPR_ASSERT(t != NULL); + GPR_ASSERT(t != nullptr); return grpc_channel_stack_builder_append_filter( builder, &grpc_connected_filter, bind_transport, t); } diff --git a/src/core/lib/channel/handshaker.cc b/src/core/lib/channel/handshaker.cc index b27ee37e5b..aae1b35845 100644 --- a/src/core/lib/channel/handshaker.cc +++ b/src/core/lib/channel/handshaker.cc @@ -93,8 +93,8 @@ grpc_handshake_manager* grpc_handshake_manager_create() { void grpc_handshake_manager_pending_list_add(grpc_handshake_manager** head, grpc_handshake_manager* mgr) { - GPR_ASSERT(mgr->prev == NULL); - GPR_ASSERT(mgr->next == NULL); + GPR_ASSERT(mgr->prev == nullptr); + GPR_ASSERT(mgr->next == nullptr); mgr->next = *head; if (*head) { (*head)->prev = mgr; @@ -104,10 +104,10 @@ void grpc_handshake_manager_pending_list_add(grpc_handshake_manager** head, void grpc_handshake_manager_pending_list_remove(grpc_handshake_manager** head, grpc_handshake_manager* mgr) { - if (mgr->next != NULL) { + if (mgr->next != nullptr) { mgr->next->prev = mgr->prev; } - if (mgr->prev != NULL) { + if (mgr->prev != nullptr) { mgr->prev->next = mgr->next; } else { GPR_ASSERT(*head == mgr); @@ -117,7 +117,7 @@ void grpc_handshake_manager_pending_list_remove(grpc_handshake_manager** head, void grpc_handshake_manager_pending_list_shutdown_all( grpc_exec_ctx* exec_ctx, grpc_handshake_manager* head, grpc_error* why) { - while (head != NULL) { + while (head != nullptr) { grpc_handshake_manager_shutdown(exec_ctx, head, GRPC_ERROR_REF(why)); head = head->next; } diff --git a/src/core/lib/channel/handshaker_factory.cc b/src/core/lib/channel/handshaker_factory.cc index bf1188dbb9..015006ade0 100644 --- a/src/core/lib/channel/handshaker_factory.cc +++ b/src/core/lib/channel/handshaker_factory.cc @@ -23,8 +23,8 @@ void grpc_handshaker_factory_add_handshakers( grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory, const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) { - if (handshaker_factory != NULL) { - GPR_ASSERT(handshaker_factory->vtable != NULL); + if (handshaker_factory != nullptr) { + GPR_ASSERT(handshaker_factory->vtable != nullptr); handshaker_factory->vtable->add_handshakers(exec_ctx, handshaker_factory, args, handshake_mgr); } @@ -32,8 +32,8 @@ void grpc_handshaker_factory_add_handshakers( void grpc_handshaker_factory_destroy( grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* handshaker_factory) { - if (handshaker_factory != NULL) { - GPR_ASSERT(handshaker_factory->vtable != NULL); + if (handshaker_factory != nullptr) { + GPR_ASSERT(handshaker_factory->vtable != nullptr); handshaker_factory->vtable->destroy(exec_ctx, handshaker_factory); } } diff --git a/src/core/lib/compression/stream_compression.cc b/src/core/lib/compression/stream_compression.cc index 8a57b33230..1ccbe162b6 100644 --- a/src/core/lib/compression/stream_compression.cc +++ b/src/core/lib/compression/stream_compression.cc @@ -51,7 +51,7 @@ grpc_stream_compression_context* grpc_stream_compression_context_create( return grpc_stream_compression_gzip_vtable.context_create(method); default: gpr_log(GPR_ERROR, "Unknown stream compression method: %d", method); - return NULL; + return nullptr; } } diff --git a/src/core/lib/compression/stream_compression_gzip.cc b/src/core/lib/compression/stream_compression_gzip.cc index 53ec7ca223..0c3fdd1269 100644 --- a/src/core/lib/compression/stream_compression_gzip.cc +++ b/src/core/lib/compression/stream_compression_gzip.cc @@ -137,7 +137,7 @@ static bool grpc_stream_compress_gzip(grpc_stream_compression_context* ctx, size_t* output_size, size_t max_output_size, grpc_stream_compression_flush flush) { - if (ctx == NULL) { + if (ctx == nullptr) { return false; } grpc_stream_compression_context_gzip* gzip_ctx = @@ -158,7 +158,7 @@ static bool grpc_stream_compress_gzip(grpc_stream_compression_context* ctx, gzip_flush = 0; } return gzip_flate(gzip_ctx, in, out, output_size, max_output_size, gzip_flush, - NULL); + nullptr); } static bool grpc_stream_decompress_gzip(grpc_stream_compression_context* ctx, @@ -167,7 +167,7 @@ static bool grpc_stream_decompress_gzip(grpc_stream_compression_context* ctx, size_t* output_size, size_t max_output_size, bool* end_of_context) { - if (ctx == NULL) { + if (ctx == nullptr) { return false; } grpc_stream_compression_context_gzip* gzip_ctx = @@ -186,8 +186,8 @@ grpc_stream_compression_context_create_gzip( (grpc_stream_compression_context_gzip*)gpr_zalloc( sizeof(grpc_stream_compression_context_gzip)); int r; - if (gzip_ctx == NULL) { - return NULL; + if (gzip_ctx == nullptr) { + return nullptr; } if (method == GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS) { r = inflateInit2(&gzip_ctx->zs, 0x1F); @@ -199,7 +199,7 @@ grpc_stream_compression_context_create_gzip( } if (r != Z_OK) { gpr_free(gzip_ctx); - return NULL; + return nullptr; } gzip_ctx->base.vtable = &grpc_stream_compression_gzip_vtable; @@ -208,7 +208,7 @@ grpc_stream_compression_context_create_gzip( static void grpc_stream_compression_context_destroy_gzip( grpc_stream_compression_context* ctx) { - if (ctx == NULL) { + if (ctx == nullptr) { return; } grpc_stream_compression_context_gzip* gzip_ctx = diff --git a/src/core/lib/compression/stream_compression_identity.cc b/src/core/lib/compression/stream_compression_identity.cc index 5e8bfc09a6..af4051144c 100644 --- a/src/core/lib/compression/stream_compression_identity.cc +++ b/src/core/lib/compression/stream_compression_identity.cc @@ -52,7 +52,7 @@ static bool grpc_stream_compress_identity(grpc_stream_compression_context* ctx, size_t* output_size, size_t max_output_size, grpc_stream_compression_flush flush) { - if (ctx == NULL) { + if (ctx == nullptr) { return false; } grpc_stream_compression_pass_through(in, out, output_size, max_output_size); @@ -63,7 +63,7 @@ static bool grpc_stream_decompress_identity( grpc_stream_compression_context* ctx, grpc_slice_buffer* in, grpc_slice_buffer* out, size_t* output_size, size_t max_output_size, bool* end_of_context) { - if (ctx == NULL) { + if (ctx == nullptr) { return false; } grpc_stream_compression_pass_through(in, out, output_size, max_output_size); diff --git a/src/core/lib/debug/stats.cc b/src/core/lib/debug/stats.cc index b32cf19028..7d2af71c47 100644 --- a/src/core/lib/debug/stats.cc +++ b/src/core/lib/debug/stats.cc @@ -27,7 +27,7 @@ #include "src/core/lib/support/string.h" -grpc_stats_data* grpc_stats_per_cpu_storage = NULL; +grpc_stats_data* grpc_stats_per_cpu_storage = nullptr; static size_t g_num_cores; void grpc_stats_init(void) { @@ -168,7 +168,7 @@ char* grpc_stats_data_as_json(const grpc_stats_data* data) { is_first = false; } gpr_strvec_add(&v, gpr_strdup("}")); - tmp = gpr_strvec_flatten(&v, NULL); + tmp = gpr_strvec_flatten(&v, nullptr); gpr_strvec_destroy(&v); return tmp; } diff --git a/src/core/lib/debug/trace.cc b/src/core/lib/debug/trace.cc index b1ae1fa185..9c75ef124a 100644 --- a/src/core/lib/debug/trace.cc +++ b/src/core/lib/debug/trace.cc @@ -64,7 +64,7 @@ static void add(const char* beg, const char* end, char*** ss, size_t* ns) { static void split(const char* s, char*** ss, size_t* ns) { const char* c = strchr(s, ','); - if (c == NULL) { + if (c == nullptr) { add(s, s + strlen(s), ss, ns); } else { add(s, c, ss, ns); @@ -73,7 +73,7 @@ static void split(const char* s, char*** ss, size_t* ns) { } static void parse(const char* s) { - char** strings = NULL; + char** strings = nullptr; size_t nstrings = 0; size_t i; split(s, &strings, &nstrings); @@ -102,7 +102,7 @@ static void list_tracers() { void grpc_tracer_init(const char* env_var) { char* e = gpr_getenv(env_var); - if (e != NULL) { + if (e != nullptr) { parse(e); gpr_free(e); } @@ -126,7 +126,7 @@ int grpc_tracer_set_enabled(const char* name, int enabled) { list_tracers(); } else if (0 == strcmp(name, "refcount")) { for (t = tracers; t; t = t->next) { - if (strstr(t->flag->name, "refcount") != NULL) { + if (strstr(t->flag->name, "refcount") != nullptr) { TRACER_SET(*t->flag, enabled); } } diff --git a/src/core/lib/http/httpcli.cc b/src/core/lib/http/httpcli.cc index 493e6af95c..4b10a624da 100644 --- a/src/core/lib/http/httpcli.cc +++ b/src/core/lib/http/httpcli.cc @@ -60,8 +60,8 @@ typedef struct { grpc_resource_quota* resource_quota; } internal_request; -static grpc_httpcli_get_override g_get_override = NULL; -static grpc_httpcli_post_override g_post_override = NULL; +static grpc_httpcli_get_override g_get_override = nullptr; +static grpc_httpcli_post_override g_post_override = nullptr; static void plaintext_handshake(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* endpoint, const char* host, @@ -93,10 +93,10 @@ static void finish(grpc_exec_ctx* exec_ctx, internal_request* req, req->context->pollset_set); GRPC_CLOSURE_SCHED(exec_ctx, req->on_done, error); grpc_http_parser_destroy(&req->parser); - if (req->addresses != NULL) { + if (req->addresses != nullptr) { grpc_resolved_addresses_destroy(req->addresses); } - if (req->ep != NULL) { + if (req->ep != nullptr) { grpc_endpoint_destroy(exec_ctx, req->ep); } grpc_slice_unref_internal(exec_ctx, req->request_text); @@ -137,7 +137,7 @@ static void on_read(grpc_exec_ctx* exec_ctx, void* user_data, if (GRPC_SLICE_LENGTH(req->incoming.slices[i])) { req->have_read_byte = 1; grpc_error* err = - grpc_http_parser_parse(&req->parser, req->incoming.slices[i], NULL); + grpc_http_parser_parse(&req->parser, req->incoming.slices[i], nullptr); if (err != GRPC_ERROR_NONE) { finish(exec_ctx, req, err); return; diff --git a/src/core/lib/http/httpcli_security_connector.cc b/src/core/lib/http/httpcli_security_connector.cc index d029323eac..d25fba538f 100644 --- a/src/core/lib/http/httpcli_security_connector.cc +++ b/src/core/lib/http/httpcli_security_connector.cc @@ -42,11 +42,11 @@ static void httpcli_ssl_destroy(grpc_exec_ctx* exec_ctx, grpc_security_connector* sc) { grpc_httpcli_ssl_channel_security_connector* c = (grpc_httpcli_ssl_channel_security_connector*)sc; - if (c->handshaker_factory != NULL) { + if (c->handshaker_factory != nullptr) { tsi_ssl_client_handshaker_factory_unref(c->handshaker_factory); - c->handshaker_factory = NULL; + c->handshaker_factory = nullptr; } - if (c->secure_peer_name != NULL) gpr_free(c->secure_peer_name); + if (c->secure_peer_name != nullptr) gpr_free(c->secure_peer_name); gpr_free(sc); } @@ -55,8 +55,8 @@ static void httpcli_ssl_add_handshakers(grpc_exec_ctx* exec_ctx, grpc_handshake_manager* handshake_mgr) { grpc_httpcli_ssl_channel_security_connector* c = (grpc_httpcli_ssl_channel_security_connector*)sc; - tsi_handshaker* handshaker = NULL; - if (c->handshaker_factory != NULL) { + tsi_handshaker* handshaker = nullptr; + if (c->handshaker_factory != nullptr) { tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker( c->handshaker_factory, c->secure_peer_name, &handshaker); if (result != TSI_OK) { @@ -79,7 +79,7 @@ static void httpcli_ssl_check_peer(grpc_exec_ctx* exec_ctx, grpc_error* error = GRPC_ERROR_NONE; /* Check the peer name. */ - if (c->secure_peer_name != NULL && + if (c->secure_peer_name != nullptr && !tsi_ssl_peer_matches_name(&peer, c->secure_peer_name)) { char* msg; gpr_asprintf(&msg, "Peer name %s is not in peer certificate", @@ -109,7 +109,7 @@ static grpc_security_status httpcli_ssl_channel_security_connector_create( tsi_result result = TSI_OK; grpc_httpcli_ssl_channel_security_connector* c; - if (secure_peer_name != NULL && pem_root_certs == NULL) { + if (secure_peer_name != nullptr && pem_root_certs == nullptr) { gpr_log(GPR_ERROR, "Cannot assert a secure peer name without a trust root."); return GRPC_SECURITY_ERROR; @@ -120,16 +120,16 @@ static grpc_security_status httpcli_ssl_channel_security_connector_create( gpr_ref_init(&c->base.base.refcount, 1); c->base.base.vtable = &httpcli_ssl_vtable; - if (secure_peer_name != NULL) { + if (secure_peer_name != nullptr) { c->secure_peer_name = gpr_strdup(secure_peer_name); } result = tsi_create_ssl_client_handshaker_factory( - NULL, pem_root_certs, NULL, NULL, 0, &c->handshaker_factory); + nullptr, pem_root_certs, nullptr, nullptr, 0, &c->handshaker_factory); if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", tsi_result_to_string(result)); httpcli_ssl_destroy(exec_ctx, &c->base.base); - *sc = NULL; + *sc = nullptr; return GRPC_SECURITY_ERROR; } // We don't actually need a channel credentials object in this case, @@ -157,7 +157,7 @@ static void on_handshake_done(grpc_exec_ctx* exec_ctx, void* arg, const char* msg = grpc_error_string(error); gpr_log(GPR_ERROR, "Secure transport setup failed: %s", msg); - c->func(exec_ctx, c->arg, NULL); + c->func(exec_ctx, c->arg, nullptr); } else { grpc_channel_args_destroy(exec_ctx, args->args); grpc_slice_buffer_destroy_internal(exec_ctx, args->read_buffer); @@ -175,15 +175,15 @@ static void ssl_handshake(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* endpoint)) { on_done_closure* c = (on_done_closure*)gpr_malloc(sizeof(*c)); const char* pem_root_certs = grpc_get_default_ssl_roots(); - if (pem_root_certs == NULL) { + if (pem_root_certs == nullptr) { gpr_log(GPR_ERROR, "Could not get default pem root certs."); - on_done(exec_ctx, arg, NULL); + on_done(exec_ctx, arg, nullptr); gpr_free(c); return; } c->func = on_done; c->arg = arg; - grpc_channel_security_connector* sc = NULL; + grpc_channel_security_connector* sc = nullptr; GPR_ASSERT(httpcli_ssl_channel_security_connector_create( exec_ctx, pem_root_certs, host, &sc) == GRPC_SECURITY_OK); grpc_arg channel_arg = grpc_security_connector_to_arg(&sc->base); @@ -191,8 +191,8 @@ static void ssl_handshake(grpc_exec_ctx* exec_ctx, void* arg, c->handshake_mgr = grpc_handshake_manager_create(); grpc_handshakers_add(exec_ctx, HANDSHAKER_CLIENT, &args, c->handshake_mgr); grpc_handshake_manager_do_handshake( - exec_ctx, c->handshake_mgr, tcp, NULL /* channel_args */, deadline, - NULL /* acceptor */, on_handshake_done, c /* user_data */); + exec_ctx, c->handshake_mgr, tcp, nullptr /* channel_args */, deadline, + nullptr /* acceptor */, on_handshake_done, c /* user_data */); GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, &sc->base, "httpcli"); } diff --git a/src/core/lib/http/parser.cc b/src/core/lib/http/parser.cc index 99a4919401..9134b0ced2 100644 --- a/src/core/lib/http/parser.cc +++ b/src/core/lib/http/parser.cc @@ -152,9 +152,9 @@ static grpc_error* add_header(grpc_http_parser* parser) { uint8_t* beg = parser->cur_line; uint8_t* cur = beg; uint8_t* end = beg + parser->cur_line_length; - size_t* hdr_count = NULL; - grpc_http_header** hdrs = NULL; - grpc_http_header hdr = {NULL, NULL}; + size_t* hdr_count = nullptr; + grpc_http_header** hdrs = nullptr; + grpc_http_header hdr = {nullptr, nullptr}; grpc_error* error = GRPC_ERROR_NONE; GPR_ASSERT(cur != end); @@ -240,8 +240,8 @@ static grpc_error* finish_line(grpc_http_parser* parser, } static grpc_error* addbyte_body(grpc_http_parser* parser, uint8_t byte) { - size_t* body_length = NULL; - char** body = NULL; + size_t* body_length = nullptr; + char** body = nullptr; if (parser->type == GRPC_HTTP_RESPONSE) { body_length = &parser->http.response->body_length; @@ -352,7 +352,7 @@ grpc_error* grpc_http_parser_parse(grpc_http_parser* parser, grpc_slice slice, grpc_error* err = addbyte(parser, GRPC_SLICE_START_PTR(slice)[i], &found_body_start); if (err != GRPC_ERROR_NONE) return err; - if (found_body_start && start_of_body != NULL) *start_of_body = i + 1; + if (found_body_start && start_of_body != nullptr) *start_of_body = i + 1; } return GRPC_ERROR_NONE; } diff --git a/src/core/lib/iomgr/call_combiner.cc b/src/core/lib/iomgr/call_combiner.cc index d45719608b..74b077de06 100644 --- a/src/core/lib/iomgr/call_combiner.cc +++ b/src/core/lib/iomgr/call_combiner.cc @@ -120,7 +120,7 @@ void grpc_call_combiner_stop(grpc_exec_ctx* exec_ctx, bool empty; grpc_closure* closure = (grpc_closure*)gpr_mpscq_pop_and_check_end( &call_combiner->queue, &empty); - if (closure == NULL) { + if (closure == nullptr) { // This can happen either due to a race condition within the mpscq // code or because of a race with grpc_call_combiner_start(). if (GRPC_TRACER_ON(grpc_call_combiner_trace)) { diff --git a/src/core/lib/iomgr/closure.cc b/src/core/lib/iomgr/closure.cc index 60e99d0e4e..09257d258c 100644 --- a/src/core/lib/iomgr/closure.cc +++ b/src/core/lib/iomgr/closure.cc @@ -43,7 +43,7 @@ grpc_closure* grpc_closure_init(grpc_closure* closure, grpc_iomgr_cb_func cb, closure->scheduler = scheduler; #ifndef NDEBUG closure->scheduled = false; - closure->file_initiated = NULL; + closure->file_initiated = nullptr; closure->line_initiated = 0; closure->run = false; closure->file_created = file; @@ -53,18 +53,18 @@ grpc_closure* grpc_closure_init(grpc_closure* closure, grpc_iomgr_cb_func cb, } void grpc_closure_list_init(grpc_closure_list* closure_list) { - closure_list->head = closure_list->tail = NULL; + closure_list->head = closure_list->tail = nullptr; } bool grpc_closure_list_append(grpc_closure_list* closure_list, grpc_closure* closure, grpc_error* error) { - if (closure == NULL) { + if (closure == nullptr) { GRPC_ERROR_UNREF(error); return false; } closure->error_data.error = error; - closure->next_data.next = NULL; - bool was_empty = (closure_list->head == NULL); + closure->next_data.next = nullptr; + bool was_empty = (closure_list->head == nullptr); if (was_empty) { closure_list->head = closure; } else { @@ -76,7 +76,7 @@ bool grpc_closure_list_append(grpc_closure_list* closure_list, void grpc_closure_list_fail_all(grpc_closure_list* list, grpc_error* forced_failure) { - for (grpc_closure* c = list->head; c != NULL; c = c->next_data.next) { + for (grpc_closure* c = list->head; c != nullptr; c = c->next_data.next) { if (c->error_data.error == GRPC_ERROR_NONE) { c->error_data.error = GRPC_ERROR_REF(forced_failure); } @@ -85,20 +85,20 @@ void grpc_closure_list_fail_all(grpc_closure_list* list, } bool grpc_closure_list_empty(grpc_closure_list closure_list) { - return closure_list.head == NULL; + return closure_list.head == nullptr; } void grpc_closure_list_move(grpc_closure_list* src, grpc_closure_list* dst) { - if (src->head == NULL) { + if (src->head == nullptr) { return; } - if (dst->head == NULL) { + if (dst->head == nullptr) { *dst = *src; } else { dst->tail->next_data.next = src->head; dst->tail = src->tail; } - src->head = src->tail = NULL; + src->head = src->tail = nullptr; } typedef struct { @@ -143,7 +143,7 @@ void grpc_closure_run(grpc_exec_ctx* exec_ctx, grpc_closure* c, grpc_error* error) { #endif GPR_TIMER_BEGIN("grpc_closure_run", 0); - if (c != NULL) { + if (c != nullptr) { #ifndef NDEBUG c->file_initiated = file; c->line_initiated = line; @@ -165,7 +165,7 @@ void grpc_closure_sched(grpc_exec_ctx* exec_ctx, grpc_closure* c, grpc_error* error) { #endif GPR_TIMER_BEGIN("grpc_closure_sched", 0); - if (c != NULL) { + if (c != nullptr) { #ifndef NDEBUG if (c->scheduled) { gpr_log(GPR_ERROR, @@ -195,7 +195,7 @@ void grpc_closure_list_sched(const char* file, int line, void grpc_closure_list_sched(grpc_exec_ctx* exec_ctx, grpc_closure_list* list) { #endif grpc_closure* c = list->head; - while (c != NULL) { + while (c != nullptr) { grpc_closure* next = c->next_data.next; #ifndef NDEBUG if (c->scheduled) { @@ -215,5 +215,5 @@ void grpc_closure_list_sched(grpc_exec_ctx* exec_ctx, grpc_closure_list* list) { c->scheduler->vtable->sched(exec_ctx, c, c->error_data.error); c = next; } - list->head = list->tail = NULL; + list->head = list->tail = nullptr; } diff --git a/src/core/lib/iomgr/combiner.cc b/src/core/lib/iomgr/combiner.cc index ca9c00b935..b28ca3464c 100644 --- a/src/core/lib/iomgr/combiner.cc +++ b/src/core/lib/iomgr/combiner.cc @@ -132,8 +132,8 @@ grpc_combiner* grpc_combiner_ref(grpc_combiner* lock GRPC_COMBINER_DEBUG_ARGS) { static void push_last_on_exec_ctx(grpc_exec_ctx* exec_ctx, grpc_combiner* lock) { - lock->next_combiner_on_this_exec_ctx = NULL; - if (exec_ctx->active_combiner == NULL) { + lock->next_combiner_on_this_exec_ctx = nullptr; + if (exec_ctx->active_combiner == nullptr) { exec_ctx->active_combiner = exec_ctx->last_combiner = lock; } else { exec_ctx->last_combiner->next_combiner_on_this_exec_ctx = lock; @@ -145,7 +145,7 @@ static void push_first_on_exec_ctx(grpc_exec_ctx* exec_ctx, grpc_combiner* lock) { lock->next_combiner_on_this_exec_ctx = exec_ctx->active_combiner; exec_ctx->active_combiner = lock; - if (lock->next_combiner_on_this_exec_ctx == NULL) { + if (lock->next_combiner_on_this_exec_ctx == nullptr) { exec_ctx->last_combiner = lock; } } @@ -190,8 +190,8 @@ static void combiner_exec(grpc_exec_ctx* exec_ctx, grpc_closure* cl, static void move_next(grpc_exec_ctx* exec_ctx) { exec_ctx->active_combiner = exec_ctx->active_combiner->next_combiner_on_this_exec_ctx; - if (exec_ctx->active_combiner == NULL) { - exec_ctx->last_combiner = NULL; + if (exec_ctx->active_combiner == nullptr) { + exec_ctx->last_combiner = nullptr; } } @@ -210,7 +210,7 @@ static void queue_offload(grpc_exec_ctx* exec_ctx, grpc_combiner* lock) { bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* exec_ctx) { GPR_TIMER_BEGIN("combiner.continue_exec_ctx", 0); grpc_combiner* lock = exec_ctx->active_combiner; - if (lock == NULL) { + if (lock == nullptr) { GPR_TIMER_END("combiner.continue_exec_ctx", 0); return false; } @@ -244,7 +244,7 @@ bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* exec_ctx) { gpr_mpscq_node* n = gpr_mpscq_pop(&lock->queue); GRPC_COMBINER_TRACE( gpr_log(GPR_DEBUG, "C:%p maybe_finish_one n=%p", lock, n)); - if (n == NULL) { + if (n == nullptr) { // queue is in an inconsistent state: use this as a cue that we should // go off and do something else for a while (and come back later) GPR_TIMER_MARK("delay_busy", 0); @@ -263,10 +263,10 @@ bool grpc_combiner_continue_exec_ctx(grpc_exec_ctx* exec_ctx) { GPR_TIMER_END("combiner.exec1", 0); } else { grpc_closure* c = lock->final_list.head; - GPR_ASSERT(c != NULL); + GPR_ASSERT(c != nullptr); grpc_closure_list_init(&lock->final_list); int loops = 0; - while (c != NULL) { + while (c != nullptr) { GPR_TIMER_BEGIN("combiner.exec_1final", 0); GRPC_COMBINER_TRACE( gpr_log(GPR_DEBUG, "C:%p execute_final[%d] c=%p", lock, loops, c)); diff --git a/src/core/lib/iomgr/error.cc b/src/core/lib/iomgr/error.cc index 123ff72851..d4cc1ac52b 100644 --- a/src/core/lib/iomgr/error.cc +++ b/src/core/lib/iomgr/error.cc @@ -325,7 +325,7 @@ grpc_error* grpc_error_create(const char* file, int line, grpc_slice desc, (uint8_t)(num_referencing * SLOTS_PER_LINKED_ERROR) + SURPLUS_CAPACITY); grpc_error* err = (grpc_error*)gpr_malloc( sizeof(*err) + initial_arena_capacity * sizeof(intptr_t)); - if (err == NULL) { // TODO(ctiller): make gpr_malloc return NULL + if (err == nullptr) { // TODO(ctiller): make gpr_malloc return NULL return GRPC_ERROR_OOM; } #ifndef NDEBUG @@ -457,7 +457,7 @@ bool grpc_error_get_int(grpc_error* err, grpc_error_ints which, intptr_t* p) { if (which == GRPC_ERROR_INT_GRPC_STATUS) { for (size_t i = 0; i < GPR_ARRAY_SIZE(error_status_map); i++) { if (error_status_map[i].error == err) { - if (p != NULL) *p = error_status_map[i].code; + if (p != nullptr) *p = error_status_map[i].code; GPR_TIMER_END("grpc_error_get_int", 0); return true; } @@ -468,7 +468,7 @@ bool grpc_error_get_int(grpc_error* err, grpc_error_ints which, intptr_t* p) { } uint8_t slot = err->ints[which]; if (slot != UINT8_MAX) { - if (p != NULL) *p = err->arena[slot]; + if (p != nullptr) *p = err->arena[slot]; GPR_TIMER_END("grpc_error_get_int", 0); return true; } @@ -618,7 +618,7 @@ static char* key_str(grpc_error_strs which) { } static char* fmt_str(grpc_slice slice) { - char* s = NULL; + char* s = nullptr; size_t sz = 0; size_t cap = 0; append_esc_str((const uint8_t*)GRPC_SLICE_START_PTR(slice), @@ -688,7 +688,7 @@ static void add_errs(grpc_error* err, char** s, size_t* sz, size_t* cap) { } static char* errs_string(grpc_error* err) { - char* s = NULL; + char* s = nullptr; size_t sz = 0; size_t cap = 0; append_chr('[', &s, &sz, &cap); @@ -705,7 +705,7 @@ static int cmp_kvs(const void* a, const void* b) { } static char* finish_kvs(kv_pairs* kvs) { - char* s = NULL; + char* s = nullptr; size_t sz = 0; size_t cap = 0; @@ -733,7 +733,7 @@ const char* grpc_error_string(grpc_error* err) { if (err == GRPC_ERROR_CANCELLED) return cancelled_error_string; void* p = (void*)gpr_atm_acq_load(&err->atomics.error_string); - if (p != NULL) { + if (p != nullptr) { GPR_TIMER_END("grpc_error_string", 0); return (const char*)p; } @@ -767,7 +767,7 @@ grpc_error* grpc_os_error(const char* file, int line, int err, grpc_error_set_str( grpc_error_set_int( grpc_error_create(file, line, - grpc_slice_from_static_string("OS Error"), NULL, + grpc_slice_from_static_string("OS Error"), nullptr, 0), GRPC_ERROR_INT_ERRNO, err), GRPC_ERROR_STR_OS_ERROR, diff --git a/src/core/lib/iomgr/error_internal.h b/src/core/lib/iomgr/error_internal.h index acf6e04e9c..14c15d44b2 100644 --- a/src/core/lib/iomgr/error_internal.h +++ b/src/core/lib/iomgr/error_internal.h @@ -59,7 +59,7 @@ struct grpc_error { intptr_t arena[0]; }; -bool grpc_error_is_special(grpc_error* err); +bool grpc_error_is_special(struct grpc_error* err); #ifdef __cplusplus } diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index 61da996781..918bc6f933 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -235,7 +235,7 @@ static bool append_error(grpc_error** composite, grpc_error* error, * alarm 'epoch'). This wakeup_fd gives us something to alert on when such a * case occurs. */ -static grpc_fd* fd_freelist = NULL; +static grpc_fd* fd_freelist = nullptr; static gpr_mu fd_freelist_mu; static void fd_global_init(void) { gpr_mu_init(&fd_freelist_mu); } @@ -243,7 +243,7 @@ static void fd_global_init(void) { gpr_mu_init(&fd_freelist_mu); } static void fd_global_shutdown(void) { gpr_mu_lock(&fd_freelist_mu); gpr_mu_unlock(&fd_freelist_mu); - while (fd_freelist != NULL) { + while (fd_freelist != nullptr) { grpc_fd* fd = fd_freelist; fd_freelist = fd_freelist->freelist_next; gpr_free(fd); @@ -252,16 +252,16 @@ static void fd_global_shutdown(void) { } static grpc_fd* fd_create(int fd, const char* name) { - grpc_fd* new_fd = NULL; + grpc_fd* new_fd = nullptr; gpr_mu_lock(&fd_freelist_mu); - if (fd_freelist != NULL) { + if (fd_freelist != nullptr) { new_fd = fd_freelist; fd_freelist = fd_freelist->freelist_next; } gpr_mu_unlock(&fd_freelist_mu); - if (new_fd == NULL) { + if (new_fd == nullptr) { new_fd = (grpc_fd*)gpr_malloc(sizeof(grpc_fd)); } @@ -270,7 +270,7 @@ static grpc_fd* fd_create(int fd, const char* name) { new_fd->write_closure.Init(); gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL); - new_fd->freelist_next = NULL; + new_fd->freelist_next = nullptr; char* fd_name; gpr_asprintf(&fd_name, "%s fd=%d", name, fd); @@ -317,7 +317,7 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_closure* on_done, int* release_fd, bool already_closed, const char* reason) { grpc_error* error = GRPC_ERROR_NONE; - bool is_release_fd = (release_fd != NULL); + bool is_release_fd = (release_fd != nullptr); if (!fd->read_closure->IsShutdown()) { fd_shutdown_internal(exec_ctx, fd, @@ -391,7 +391,7 @@ static size_t g_num_neighborhoods; /* Return true if first in list */ static bool worker_insert(grpc_pollset* pollset, grpc_pollset_worker* worker) { - if (pollset->root_worker == NULL) { + if (pollset->root_worker == nullptr) { pollset->root_worker = worker; worker->next = worker->prev = worker; return true; @@ -411,7 +411,7 @@ static worker_remove_result worker_remove(grpc_pollset* pollset, grpc_pollset_worker* worker) { if (worker == pollset->root_worker) { if (worker == worker->next) { - pollset->root_worker = NULL; + pollset->root_worker = nullptr; return EMPTIED; } else { pollset->root_worker = worker->next; @@ -468,13 +468,13 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { *mu = &pollset->mu; pollset->neighborhood = &g_neighborhoods[choose_neighborhood()]; pollset->reassigning_neighborhood = false; - pollset->root_worker = NULL; + pollset->root_worker = nullptr; pollset->kicked_without_poller = false; pollset->seen_inactive = true; pollset->shutting_down = false; - pollset->shutdown_closure = NULL; + pollset->shutdown_closure = nullptr; pollset->begin_refs = 0; - pollset->next = pollset->prev = NULL; + pollset->next = pollset->prev = nullptr; } static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { @@ -496,7 +496,7 @@ static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { pollset->next->prev = pollset->prev; if (pollset == pollset->neighborhood->active_root) { pollset->neighborhood->active_root = - pollset->next == pollset ? NULL : pollset->next; + pollset->next == pollset ? nullptr : pollset->next; } } gpr_mu_unlock(&pollset->neighborhood->mu); @@ -509,7 +509,7 @@ static grpc_error* pollset_kick_all(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { GPR_TIMER_BEGIN("pollset_kick_all", 0); grpc_error* error = GRPC_ERROR_NONE; - if (pollset->root_worker != NULL) { + if (pollset->root_worker != nullptr) { grpc_pollset_worker* worker = pollset->root_worker; do { GRPC_STATS_INC_POLLSET_KICK(exec_ctx); @@ -543,18 +543,18 @@ static grpc_error* pollset_kick_all(grpc_exec_ctx* exec_ctx, static void pollset_maybe_finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { - if (pollset->shutdown_closure != NULL && pollset->root_worker == NULL && + if (pollset->shutdown_closure != nullptr && pollset->root_worker == nullptr && pollset->begin_refs == 0) { GPR_TIMER_MARK("pollset_finish_shutdown", 0); GRPC_CLOSURE_SCHED(exec_ctx, pollset->shutdown_closure, GRPC_ERROR_NONE); - pollset->shutdown_closure = NULL; + pollset->shutdown_closure = nullptr; } } static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_closure* closure) { GPR_TIMER_BEGIN("pollset_shutdown", 0); - GPR_ASSERT(pollset->shutdown_closure == NULL); + GPR_ASSERT(pollset->shutdown_closure == nullptr); GPR_ASSERT(!pollset->shutting_down); pollset->shutdown_closure = closure; pollset->shutting_down = true; @@ -667,7 +667,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { GPR_TIMER_BEGIN("begin_worker", 0); - if (worker_hdl != NULL) *worker_hdl = worker; + if (worker_hdl != nullptr) *worker_hdl = worker; worker->initialized_cv = false; SET_KICK_STATE(worker, UNKICKED); worker->schedule_on_end_work = (grpc_closure_list)GRPC_CLOSURE_LIST_INIT; @@ -716,7 +716,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, not visible in the "kick any" path yet */ if (worker->state == UNKICKED) { pollset->seen_inactive = false; - if (neighborhood->active_root == NULL) { + if (neighborhood->active_root == nullptr) { neighborhood->active_root = pollset->next = pollset->prev = pollset; /* Make this the designated poller if there isn't one already */ if (worker->state == UNKICKED && @@ -794,13 +794,13 @@ static bool check_neighborhood_for_available_poller( bool found_worker = false; do { grpc_pollset* inspect = neighborhood->active_root; - if (inspect == NULL) { + if (inspect == nullptr) { break; } gpr_mu_lock(&inspect->mu); GPR_ASSERT(!inspect->seen_inactive); grpc_pollset_worker* inspect_worker = inspect->root_worker; - if (inspect_worker != NULL) { + if (inspect_worker != nullptr) { do { switch (inspect_worker->state) { case UNKICKED: @@ -841,11 +841,11 @@ static bool check_neighborhood_for_available_poller( inspect->seen_inactive = true; if (inspect == neighborhood->active_root) { neighborhood->active_root = - inspect->next == inspect ? NULL : inspect->next; + inspect->next == inspect ? nullptr : inspect->next; } inspect->next->prev = inspect->prev; inspect->prev->next = inspect->next; - inspect->next = inspect->prev = NULL; + inspect->next = inspect->prev = nullptr; } gpr_mu_unlock(&inspect->mu); } while (!found_worker); @@ -860,7 +860,7 @@ static void end_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, if (GRPC_TRACER_ON(grpc_polling_trace)) { gpr_log(GPR_DEBUG, "PS:%p END_WORKER:%p", pollset, worker); } - if (worker_hdl != NULL) *worker_hdl = NULL; + if (worker_hdl != nullptr) *worker_hdl = nullptr; /* Make sure we appear kicked */ SET_KICK_STATE(worker, KICKED); grpc_closure_list_move(&worker->schedule_on_end_work, @@ -1002,28 +1002,28 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, (void*)gpr_tls_get(&g_current_thread_worker), pollset->root_worker); gpr_strvec_add(&log, tmp); - if (pollset->root_worker != NULL) { + if (pollset->root_worker != nullptr) { gpr_asprintf(&tmp, " {kick_state=%s next=%p {kick_state=%s}}", kick_state_string(pollset->root_worker->state), pollset->root_worker->next, kick_state_string(pollset->root_worker->next->state)); gpr_strvec_add(&log, tmp); } - if (specific_worker != NULL) { + if (specific_worker != nullptr) { gpr_asprintf(&tmp, " worker_kick_state=%s", kick_state_string(specific_worker->state)); gpr_strvec_add(&log, tmp); } - tmp = gpr_strvec_flatten(&log, NULL); + tmp = gpr_strvec_flatten(&log, nullptr); gpr_strvec_destroy(&log); gpr_log(GPR_ERROR, "%s", tmp); gpr_free(tmp); } - if (specific_worker == NULL) { + if (specific_worker == nullptr) { if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) { grpc_pollset_worker* root_worker = pollset->root_worker; - if (root_worker == NULL) { + if (root_worker == nullptr) { GRPC_STATS_INC_POLLSET_KICKED_WITHOUT_POLLER(exec_ctx); pollset->kicked_without_poller = true; if (GRPC_TRACER_ON(grpc_polling_trace)) { @@ -1232,11 +1232,11 @@ static const grpc_event_engine_vtable vtable = { const grpc_event_engine_vtable* grpc_init_epoll1_linux(bool explicit_request) { if (!grpc_has_wakeup_fd()) { gpr_log(GPR_ERROR, "Skipping epoll1 because of no wakeup fd."); - return NULL; + return nullptr; } if (!epoll_set_init()) { - return NULL; + return nullptr; } fd_global_init(); @@ -1244,7 +1244,7 @@ const grpc_event_engine_vtable* grpc_init_epoll1_linux(bool explicit_request) { if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) { fd_global_shutdown(); epoll_set_shutdown(); - return NULL; + return nullptr; } return &vtable; diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index caaee76b8c..bfd2ac4326 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -254,7 +254,7 @@ static bool append_error(grpc_error** composite, grpc_error* error, * becomes a spurious read notification on a reused fd. */ -static grpc_fd* fd_freelist = NULL; +static grpc_fd* fd_freelist = nullptr; static gpr_mu fd_freelist_mu; #ifndef NDEBUG @@ -322,7 +322,7 @@ static void fd_global_init(void) { gpr_mu_init(&fd_freelist_mu); } static void fd_global_shutdown(void) { gpr_mu_lock(&fd_freelist_mu); gpr_mu_unlock(&fd_freelist_mu); - while (fd_freelist != NULL) { + while (fd_freelist != nullptr) { grpc_fd* fd = fd_freelist; fd_freelist = fd_freelist->freelist_next; gpr_free(fd); @@ -331,30 +331,30 @@ static void fd_global_shutdown(void) { } static grpc_fd* fd_create(int fd, const char* name) { - grpc_fd* new_fd = NULL; + grpc_fd* new_fd = nullptr; gpr_mu_lock(&fd_freelist_mu); - if (fd_freelist != NULL) { + if (fd_freelist != nullptr) { new_fd = fd_freelist; fd_freelist = fd_freelist->freelist_next; } gpr_mu_unlock(&fd_freelist_mu); - if (new_fd == NULL) { + if (new_fd == nullptr) { new_fd = (grpc_fd*)gpr_malloc(sizeof(grpc_fd)); } gpr_mu_init(&new_fd->pollable_mu); gpr_mu_init(&new_fd->orphan_mu); - new_fd->pollable_obj = NULL; + new_fd->pollable_obj = nullptr; gpr_atm_rel_store(&new_fd->refst, (gpr_atm)1); new_fd->fd = fd; new_fd->read_closure.Init(); new_fd->write_closure.Init(); gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL); - new_fd->freelist_next = NULL; - new_fd->on_done_closure = NULL; + new_fd->freelist_next = nullptr; + new_fd->on_done_closure = nullptr; char* fd_name; gpr_asprintf(&fd_name, "%s fd=%d", name, fd); @@ -384,7 +384,7 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, /* If release_fd is not NULL, we should be relinquishing control of the file descriptor fd->fd (but we still own the grpc_fd structure). */ - if (release_fd != NULL) { + if (release_fd != nullptr) { *release_fd = fd->fd; } else if (!is_fd_closed) { close(fd->fd); @@ -440,7 +440,7 @@ static void fd_notify_on_write(grpc_exec_ctx* exec_ctx, grpc_fd* fd, */ static grpc_error* pollable_create(pollable_type type, pollable** p) { - *p = NULL; + *p = nullptr; int epfd = epoll_create1(EPOLL_CLOEXEC); if (epfd == -1) { @@ -451,7 +451,7 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) { if (err != GRPC_ERROR_NONE) { close(epfd); gpr_free(*p); - *p = NULL; + *p = nullptr; return err; } struct epoll_event ev; @@ -462,7 +462,7 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) { close(epfd); grpc_wakeup_fd_destroy(&(*p)->wakeup); gpr_free(*p); - *p = NULL; + *p = nullptr; return err; } @@ -470,10 +470,10 @@ static grpc_error* pollable_create(pollable_type type, pollable** p) { gpr_ref_init(&(*p)->refs, 1); gpr_mu_init(&(*p)->mu); (*p)->epfd = epfd; - (*p)->owner_fd = NULL; - (*p)->pollset_set = NULL; + (*p)->owner_fd = nullptr; + (*p)->pollset_set = nullptr; (*p)->next = (*p)->prev = *p; - (*p)->root_worker = NULL; + (*p)->root_worker = nullptr; (*p)->event_cursor = 0; (*p)->event_count = 0; return GRPC_ERROR_NONE; @@ -497,14 +497,14 @@ static pollable* pollable_ref(pollable* p, int line, const char* reason) { static void pollable_unref(pollable* p) { #else static void pollable_unref(pollable* p, int line, const char* reason) { - if (p == NULL) return; + if (p == nullptr) return; if (GRPC_TRACER_ON(grpc_trace_pollable_refcount)) { int r = (int)gpr_atm_no_barrier_load(&p->refs.count); gpr_log(__FILE__, line, GPR_LOG_SEVERITY_DEBUG, "POLLABLE:%p unref %d->%d %s", p, r, r - 1, reason); } #endif - if (p != NULL && gpr_unref(&p->refs)) { + if (p != nullptr && gpr_unref(&p->refs)) { close(p->epfd); grpc_wakeup_fd_destroy(&p->wakeup); gpr_free(p); @@ -565,10 +565,10 @@ static void pollset_maybe_finish_shutdown(grpc_exec_ctx* exec_ctx, pollset, pollset->active_pollable, pollset->shutdown_closure, pollset->root_worker, pollset->containing_pollset_set_count); } - if (pollset->shutdown_closure != NULL && pollset->root_worker == NULL && + if (pollset->shutdown_closure != nullptr && pollset->root_worker == nullptr && pollset->containing_pollset_set_count == 0) { GRPC_CLOSURE_SCHED(exec_ctx, pollset->shutdown_closure, GRPC_ERROR_NONE); - pollset->shutdown_closure = NULL; + pollset->shutdown_closure = nullptr; } } @@ -579,7 +579,7 @@ static grpc_error* kick_one_worker(grpc_exec_ctx* exec_ctx, grpc_pollset_worker* specific_worker) { pollable* p = specific_worker->pollable_obj; grpc_core::mu_guard lock(&p->mu); - GPR_ASSERT(specific_worker != NULL); + GPR_ASSERT(specific_worker != nullptr); if (specific_worker->kicked) { if (GRPC_TRACER_ON(grpc_polling_trace)) { gpr_log(GPR_DEBUG, "PS:%p kicked_specific_but_already_kicked", p); @@ -628,9 +628,9 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, (void*)gpr_tls_get(&g_current_thread_pollset), (void*)gpr_tls_get(&g_current_thread_worker), pollset->root_worker); } - if (specific_worker == NULL) { + if (specific_worker == nullptr) { if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)pollset) { - if (pollset->root_worker == NULL) { + if (pollset->root_worker == nullptr) { if (GRPC_TRACER_ON(grpc_polling_trace)) { gpr_log(GPR_DEBUG, "PS:%p kicked_any_without_poller", pollset); } @@ -673,7 +673,7 @@ static grpc_error* pollset_kick_all(grpc_exec_ctx* exec_ctx, grpc_error* error = GRPC_ERROR_NONE; const char* err_desc = "pollset_kick_all"; grpc_pollset_worker* w = pollset->root_worker; - if (w != NULL) { + if (w != nullptr) { do { GRPC_STATS_INC_POLLSET_KICK(exec_ctx); append_error(&error, kick_one_worker(exec_ctx, w), err_desc); @@ -722,23 +722,23 @@ static grpc_error* fd_get_or_become_pollable(grpc_fd* fd, pollable** p) { gpr_mu_lock(&fd->pollable_mu); grpc_error* error = GRPC_ERROR_NONE; static const char* err_desc = "fd_get_or_become_pollable"; - if (fd->pollable_obj == NULL) { + if (fd->pollable_obj == nullptr) { if (append_error(&error, pollable_create(PO_FD, &fd->pollable_obj), err_desc)) { fd->pollable_obj->owner_fd = fd; if (!append_error(&error, pollable_add_fd(fd->pollable_obj, fd), err_desc)) { POLLABLE_UNREF(fd->pollable_obj, "fd_pollable"); - fd->pollable_obj = NULL; + fd->pollable_obj = nullptr; } } } if (error == GRPC_ERROR_NONE) { - GPR_ASSERT(fd->pollable_obj != NULL); + GPR_ASSERT(fd->pollable_obj != nullptr); *p = POLLABLE_REF(fd->pollable_obj, "pollset"); } else { - GPR_ASSERT(fd->pollable_obj == NULL); - *p = NULL; + GPR_ASSERT(fd->pollable_obj == nullptr); + *p = nullptr; } gpr_mu_unlock(&fd->pollable_mu); return error; @@ -747,7 +747,7 @@ static grpc_error* fd_get_or_become_pollable(grpc_fd* fd, pollable** p) { /* pollset->po.mu lock must be held by the caller before calling this */ static void pollset_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_closure* closure) { - GPR_ASSERT(pollset->shutdown_closure == NULL); + GPR_ASSERT(pollset->shutdown_closure == nullptr); pollset->shutdown_closure = closure; GRPC_LOG_IF_ERROR("pollset_shutdown", pollset_kick_all(exec_ctx, pollset)); pollset_maybe_finish_shutdown(exec_ctx, pollset); @@ -798,7 +798,7 @@ static grpc_error* pollable_process_events(grpc_exec_ctx* exec_ctx, /* pollset_shutdown is guaranteed to be called before pollset_destroy. */ static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset) { POLLABLE_UNREF(pollset->active_pollable, "pollset"); - pollset->active_pollable = NULL; + pollset->active_pollable = nullptr; } static grpc_error* pollable_epoll(grpc_exec_ctx* exec_ctx, pollable* p, @@ -838,7 +838,7 @@ static grpc_error* pollable_epoll(grpc_exec_ctx* exec_ctx, pollable* p, /* Return true if first in list */ static bool worker_insert(grpc_pollset_worker** root_worker, grpc_pollset_worker* worker, pwlinks link) { - if (*root_worker == NULL) { + if (*root_worker == nullptr) { *root_worker = worker; worker->links[link].next = worker->links[link].prev = worker; return true; @@ -859,7 +859,7 @@ static worker_remove_result worker_remove(grpc_pollset_worker** root_worker, pwlinks link) { if (worker == *root_worker) { if (worker == worker->links[link].next) { - *root_worker = NULL; + *root_worker = nullptr; return WRR_EMPTIED; } else { *root_worker = worker->links[link].next; @@ -880,7 +880,7 @@ static bool begin_worker(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker** worker_hdl, grpc_millis deadline) { bool do_poll = (pollset->shutdown_closure == nullptr); - if (worker_hdl != NULL) *worker_hdl = worker; + if (worker_hdl != nullptr) *worker_hdl = worker; worker->initialized_cv = false; worker->kicked = false; worker->pollset = pollset; @@ -1053,12 +1053,12 @@ static grpc_error* pollset_transition_pollable_from_fd_to_multi_locked( append_error(&error, pollset_kick_all(exec_ctx, pollset), err_desc); grpc_fd* initial_fd = pollset->active_pollable->owner_fd; POLLABLE_UNREF(pollset->active_pollable, "pollset"); - pollset->active_pollable = NULL; + pollset->active_pollable = nullptr; if (append_error(&error, pollable_create(PO_MULTI, &pollset->active_pollable), err_desc)) { append_error(&error, pollable_add_fd(pollset->active_pollable, initial_fd), err_desc); - if (and_add_fd != NULL) { + if (and_add_fd != nullptr) { append_error(&error, pollable_add_fd(pollset->active_pollable, and_add_fd), err_desc); @@ -1124,7 +1124,7 @@ static grpc_error* pollset_as_multipollable_locked(grpc_exec_ctx* exec_ctx, error = pollable_create(PO_MULTI, &pollset->active_pollable); } else { error = pollset_transition_pollable_from_fd_to_multi_locked( - exec_ctx, pollset, NULL); + exec_ctx, pollset, nullptr); } gpr_mu_unlock(&po_at_start->owner_fd->orphan_mu); break; @@ -1134,7 +1134,7 @@ static grpc_error* pollset_as_multipollable_locked(grpc_exec_ctx* exec_ctx, if (error != GRPC_ERROR_NONE) { POLLABLE_UNREF(pollset->active_pollable, "pollset"); pollset->active_pollable = po_at_start; - *pollable_obj = NULL; + *pollable_obj = nullptr; } else { *pollable_obj = POLLABLE_REF(pollset->active_pollable, "pollset_set"); POLLABLE_UNREF(po_at_start, "pollset_as_multipollable"); @@ -1156,7 +1156,7 @@ static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, static grpc_pollset_set* pss_lock_adam(grpc_pollset_set* pss) { gpr_mu_lock(&pss->mu); - while (pss->parent != NULL) { + while (pss->parent != nullptr) { gpr_mu_unlock(&pss->mu); pss = pss->parent; gpr_mu_lock(&pss->mu); @@ -1172,7 +1172,7 @@ static grpc_pollset_set* pollset_set_create(void) { } static void pollset_set_unref(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss) { - if (pss == NULL) return; + if (pss == nullptr) return; if (!gpr_unref(&pss->refs)) return; pollset_set_unref(exec_ctx, pss->parent); gpr_mu_destroy(&pss->mu); @@ -1294,11 +1294,11 @@ static void pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, } grpc_error* error = GRPC_ERROR_NONE; static const char* err_desc = "pollset_set_add_pollset"; - pollable* pollable_obj = NULL; + pollable* pollable_obj = nullptr; gpr_mu_lock(&ps->mu); if (!GRPC_LOG_IF_ERROR(err_desc, pollset_as_multipollable_locked( exec_ctx, ps, &pollable_obj))) { - GPR_ASSERT(pollable_obj == NULL); + GPR_ASSERT(pollable_obj == nullptr); gpr_mu_unlock(&ps->mu); return; } @@ -1343,9 +1343,9 @@ static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, gpr_mu* b_mu = &b->mu; gpr_mu_lock(a_mu); gpr_mu_lock(b_mu); - if (a->parent != NULL) { + if (a->parent != nullptr) { a = a->parent; - } else if (b->parent != NULL) { + } else if (b->parent != nullptr) { b = b->parent; } else { break; // exit loop, both pollsets locked @@ -1394,8 +1394,8 @@ static void pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, a->pollset_count += b->pollset_count; gpr_free(b->fds); gpr_free(b->pollsets); - b->fds = NULL; - b->pollsets = NULL; + b->fds = nullptr; + b->pollsets = nullptr; b->fd_count = b->fd_capacity = b->pollset_count = b->pollset_capacity = 0; gpr_mu_unlock(&a->mu); gpr_mu_unlock(&b->mu); @@ -1448,17 +1448,17 @@ static const grpc_event_engine_vtable vtable = { const grpc_event_engine_vtable* grpc_init_epollex_linux( bool explicitly_requested) { if (!explicitly_requested) { - return NULL; + return nullptr; } if (!grpc_has_wakeup_fd()) { gpr_log(GPR_ERROR, "Skipping epollex because of no wakeup fd."); - return NULL; + return nullptr; } if (!grpc_is_epollexclusive_available()) { gpr_log(GPR_INFO, "Skipping epollex because it is not supported."); - return NULL; + return nullptr; } #ifndef NDEBUG @@ -1470,7 +1470,7 @@ const grpc_event_engine_vtable* grpc_init_epollex_linux( if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) { pollset_global_shutdown(); fd_global_shutdown(); - return NULL; + return nullptr; } return &vtable; diff --git a/src/core/lib/iomgr/ev_epollsig_linux.cc b/src/core/lib/iomgr/ev_epollsig_linux.cc index 42806e9d14..5b4a7ba19c 100644 --- a/src/core/lib/iomgr/ev_epollsig_linux.cc +++ b/src/core/lib/iomgr/ev_epollsig_linux.cc @@ -328,7 +328,7 @@ static void pi_unref(grpc_exec_ctx* exec_ctx, polling_island* pi) { if (1 == gpr_atm_full_fetch_add(&pi->ref_count, -1)) { polling_island* next = (polling_island*)gpr_atm_acq_load(&pi->merged_to); polling_island_delete(exec_ctx, pi); - if (next != NULL) { + if (next != nullptr) { PI_UNREF(exec_ctx, next, "pi_delete"); /* Recursive call */ } } @@ -414,7 +414,7 @@ static void polling_island_remove_all_fds_locked(polling_island* pi, const char* err_desc = "polling_island_remove_fds"; for (i = 0; i < pi->fd_cnt; i++) { - err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_DEL, pi->fds[i]->fd, NULL); + err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_DEL, pi->fds[i]->fd, nullptr); if (err < 0 && errno != ENOENT) { gpr_asprintf(&err_msg, "epoll_ctl (epoll_fd: %d) delete fds[%zu]: %d failed with " @@ -444,7 +444,7 @@ static void polling_island_remove_fd_locked(polling_island* pi, grpc_fd* fd, /* If fd is already closed, then it would have been automatically been removed from the epoll set */ if (!is_fd_closed) { - err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_DEL, fd->fd, NULL); + err = epoll_ctl(pi->epoll_fd, EPOLL_CTL_DEL, fd->fd, nullptr); if (err < 0 && errno != ENOENT) { gpr_asprintf( &err_msg, @@ -468,7 +468,7 @@ static void polling_island_remove_fd_locked(polling_island* pi, grpc_fd* fd, static polling_island* polling_island_create(grpc_exec_ctx* exec_ctx, grpc_fd* initial_fd, grpc_error** error) { - polling_island* pi = NULL; + polling_island* pi = nullptr; const char* err_desc = "polling_island_create"; *error = GRPC_ERROR_NONE; @@ -477,7 +477,7 @@ static polling_island* polling_island_create(grpc_exec_ctx* exec_ctx, gpr_mu_init(&pi->mu); pi->fd_cnt = 0; pi->fd_capacity = 0; - pi->fds = NULL; + pi->fds = nullptr; pi->epoll_fd = -1; gpr_atm_rel_store(&pi->ref_count, 0); @@ -491,14 +491,14 @@ static polling_island* polling_island_create(grpc_exec_ctx* exec_ctx, goto done; } - if (initial_fd != NULL) { + if (initial_fd != nullptr) { polling_island_add_fds_locked(pi, &initial_fd, 1, true, error); } done: if (*error != GRPC_ERROR_NONE) { polling_island_delete(exec_ctx, pi); - pi = NULL; + pi = nullptr; } return pi; } @@ -519,7 +519,7 @@ static void polling_island_delete(grpc_exec_ctx* exec_ctx, polling_island* pi) { * guarantees that the island returned is the last island */ static polling_island* polling_island_maybe_get_latest(polling_island* pi) { polling_island* next = (polling_island*)gpr_atm_acq_load(&pi->merged_to); - while (next != NULL) { + while (next != nullptr) { pi = next; next = (polling_island*)gpr_atm_acq_load(&pi->merged_to); } @@ -537,18 +537,18 @@ static polling_island* polling_island_maybe_get_latest(polling_island* pi) { ... gpr_mu_unlock(&pi_latest->mu); // NOTE: use pi_latest->mu. NOT pi->mu */ static polling_island* polling_island_lock(polling_island* pi) { - polling_island* next = NULL; + polling_island* next = nullptr; while (true) { next = (polling_island*)gpr_atm_acq_load(&pi->merged_to); - if (next == NULL) { + if (next == nullptr) { /* Looks like 'pi' is the last node in the linked list but unless we check this by holding the pi->mu lock, we cannot be sure (i.e without the pi->mu lock, we don't prevent island merges). To be absolutely sure, check once more by holding the pi->mu lock */ gpr_mu_lock(&pi->mu); next = (polling_island*)gpr_atm_acq_load(&pi->merged_to); - if (next == NULL) { + if (next == nullptr) { /* pi is infact the last node and we have the pi->mu lock. we're done */ break; } @@ -588,8 +588,8 @@ static polling_island* polling_island_lock(polling_island* pi) { static void polling_island_lock_pair(polling_island** p, polling_island** q) { polling_island* pi_1 = *p; polling_island* pi_2 = *q; - polling_island* next_1 = NULL; - polling_island* next_2 = NULL; + polling_island* next_1 = nullptr; + polling_island* next_2 = nullptr; /* The algorithm is simple: - Go to the last polling islands in the linked lists *pi_1 and *pi_2 (and @@ -607,13 +607,13 @@ static void polling_island_lock_pair(polling_island** p, polling_island** q) { release the locks and continue the process from the first step */ while (true) { next_1 = (polling_island*)gpr_atm_acq_load(&pi_1->merged_to); - while (next_1 != NULL) { + while (next_1 != nullptr) { pi_1 = next_1; next_1 = (polling_island*)gpr_atm_acq_load(&pi_1->merged_to); } next_2 = (polling_island*)gpr_atm_acq_load(&pi_2->merged_to); - while (next_2 != NULL) { + while (next_2 != nullptr) { pi_2 = next_2; next_2 = (polling_island*)gpr_atm_acq_load(&pi_2->merged_to); } @@ -633,7 +633,7 @@ static void polling_island_lock_pair(polling_island** p, polling_island** q) { next_1 = (polling_island*)gpr_atm_acq_load(&pi_1->merged_to); next_2 = (polling_island*)gpr_atm_acq_load(&pi_2->merged_to); - if (next_1 == NULL && next_2 == NULL) { + if (next_1 == nullptr && next_2 == nullptr) { break; } @@ -725,7 +725,7 @@ static void polling_island_global_shutdown() { * alarm 'epoch'). This wakeup_fd gives us something to alert on when such a * case occurs. */ -static grpc_fd* fd_freelist = NULL; +static grpc_fd* fd_freelist = nullptr; static gpr_mu fd_freelist_mu; #ifndef NDEBUG @@ -797,7 +797,7 @@ static void fd_global_init(void) { gpr_mu_init(&fd_freelist_mu); } static void fd_global_shutdown(void) { gpr_mu_lock(&fd_freelist_mu); gpr_mu_unlock(&fd_freelist_mu); - while (fd_freelist != NULL) { + while (fd_freelist != nullptr) { grpc_fd* fd = fd_freelist; fd_freelist = fd_freelist->freelist_next; gpr_mu_destroy(&fd->po.mu); @@ -807,16 +807,16 @@ static void fd_global_shutdown(void) { } static grpc_fd* fd_create(int fd, const char* name) { - grpc_fd* new_fd = NULL; + grpc_fd* new_fd = nullptr; gpr_mu_lock(&fd_freelist_mu); - if (fd_freelist != NULL) { + if (fd_freelist != nullptr) { new_fd = fd_freelist; fd_freelist = fd_freelist->freelist_next; } gpr_mu_unlock(&fd_freelist_mu); - if (new_fd == NULL) { + if (new_fd == nullptr) { new_fd = (grpc_fd*)gpr_malloc(sizeof(grpc_fd)); gpr_mu_init(&new_fd->po.mu); } @@ -825,7 +825,7 @@ static grpc_fd* fd_create(int fd, const char* name) { * is a newly created fd (or an fd we got from the freelist), no one else * would be holding a lock to it anyway. */ gpr_mu_lock(&new_fd->po.mu); - new_fd->po.pi = NULL; + new_fd->po.pi = nullptr; #ifndef NDEBUG new_fd->po.obj_type = POLL_OBJ_FD; #endif @@ -837,8 +837,8 @@ static grpc_fd* fd_create(int fd, const char* name) { new_fd->write_closure.Init(); gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL); - new_fd->freelist_next = NULL; - new_fd->on_done_closure = NULL; + new_fd->freelist_next = nullptr; + new_fd->on_done_closure = nullptr; gpr_mu_unlock(&new_fd->po.mu); @@ -864,7 +864,7 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_closure* on_done, int* release_fd, bool already_closed, const char* reason) { grpc_error* error = GRPC_ERROR_NONE; - polling_island* unref_pi = NULL; + polling_island* unref_pi = nullptr; gpr_mu_lock(&fd->po.mu); fd->on_done_closure = on_done; @@ -881,18 +881,18 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, - Unlock the latest polling island - Set fd->po.pi to NULL (but remove the ref on the polling island before doing this.) */ - if (fd->po.pi != NULL) { + if (fd->po.pi != nullptr) { polling_island* pi_latest = polling_island_lock(fd->po.pi); polling_island_remove_fd_locked(pi_latest, fd, already_closed, &error); gpr_mu_unlock(&pi_latest->mu); unref_pi = fd->po.pi; - fd->po.pi = NULL; + fd->po.pi = nullptr; } /* If release_fd is not NULL, we should be relinquishing control of the file descriptor fd->fd (but we still own the grpc_fd structure). */ - if (release_fd != NULL) { + if (release_fd != nullptr) { *release_fd = fd->fd; } else { close(fd->fd); @@ -904,7 +904,7 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, gpr_mu_unlock(&fd->po.mu); UNREF_BY(fd, 2, reason); /* Drop the reference */ - if (unref_pi != NULL) { + if (unref_pi != nullptr) { /* Unref stale polling island here, outside the fd lock above. The polling island owns a workqueue which owns an fd, and unreffing inside the lock can cause an eventual lock loop that makes TSAN very @@ -1009,7 +1009,7 @@ static grpc_pollset_worker* pop_front_worker(grpc_pollset* p) { remove_worker(p, w); return w; } else { - return NULL; + return nullptr; } } @@ -1033,7 +1033,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* p, GRPC_STATS_INC_POLLSET_KICK(exec_ctx); const char* err_desc = "Kick Failure"; grpc_pollset_worker* worker = specific_worker; - if (worker != NULL) { + if (worker != nullptr) { if (worker == GRPC_POLLSET_KICK_BROADCAST) { if (pollset_has_workers(p)) { GPR_TIMER_BEGIN("pollset_kick.broadcast", 0); @@ -1063,7 +1063,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* p, GPR_TIMER_MARK("kick_anonymous", 0); worker = pop_front_worker(p); - if (worker != NULL) { + if (worker != nullptr) { GPR_TIMER_MARK("finally_kick", 0); push_back_worker(p, worker); append_error(&error, pollset_worker_kick(worker), err_desc); @@ -1081,7 +1081,7 @@ static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* p, static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { gpr_mu_init(&pollset->po.mu); *mu = &pollset->po.mu; - pollset->po.pi = NULL; + pollset->po.pi = nullptr; #ifndef NDEBUG pollset->po.obj_type = POLL_OBJ_POLLSET; #endif @@ -1091,7 +1091,7 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { pollset->shutting_down = false; pollset->finish_shutdown_called = false; - pollset->shutdown_done = NULL; + pollset->shutdown_done = nullptr; } static int poll_deadline_to_millis_timeout(grpc_exec_ctx* exec_ctx, @@ -1126,10 +1126,10 @@ static void fd_become_writable(grpc_exec_ctx* exec_ctx, grpc_fd* fd) { static void pollset_release_polling_island(grpc_exec_ctx* exec_ctx, grpc_pollset* ps, const char* reason) { - if (ps->po.pi != NULL) { + if (ps->po.pi != nullptr) { PI_UNREF(exec_ctx, ps->po.pi, reason); } - ps->po.pi = NULL; + ps->po.pi = nullptr; } static void finish_shutdown_locked(grpc_exec_ctx* exec_ctx, @@ -1181,7 +1181,7 @@ static void pollset_work_and_unlock(grpc_exec_ctx* exec_ctx, struct epoll_event ep_ev[GRPC_EPOLL_MAX_EVENTS]; int epoll_fd = -1; int ep_rv; - polling_island* pi = NULL; + polling_island* pi = nullptr; char* err_msg; const char* err_desc = "pollset_work_and_unlock"; GPR_TIMER_BEGIN("pollset_work_and_unlock", 0); @@ -1196,9 +1196,9 @@ static void pollset_work_and_unlock(grpc_exec_ctx* exec_ctx, right-away from epoll_wait() and pick up the latest polling_island the next this function (i.e pollset_work_and_unlock()) is called */ - if (pollset->po.pi == NULL) { - pollset->po.pi = polling_island_create(exec_ctx, NULL, error); - if (pollset->po.pi == NULL) { + if (pollset->po.pi == nullptr) { + pollset->po.pi = polling_island_create(exec_ctx, nullptr, error); + if (pollset->po.pi == nullptr) { GPR_TIMER_END("pollset_work_and_unlock", 0); return; /* Fatal error. We cannot continue */ } @@ -1280,10 +1280,10 @@ static void pollset_work_and_unlock(grpc_exec_ctx* exec_ctx, } } - g_current_thread_polling_island = NULL; + g_current_thread_polling_island = nullptr; gpr_atm_no_barrier_fetch_add(&pi->poller_count, -1); - GPR_ASSERT(pi != NULL); + GPR_ASSERT(pi != nullptr); /* Before leaving, release the extra ref we added to the polling island. It is important to use "pi" here (i.e our old copy of pollset->po.pi @@ -1309,7 +1309,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, sigset_t new_mask; grpc_pollset_worker worker; - worker.next = worker.prev = NULL; + worker.next = worker.prev = nullptr; worker.pt_id = pthread_self(); gpr_atm_no_barrier_store(&worker.is_kicked, (gpr_atm)0); @@ -1391,7 +1391,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, gpr_mu_lock(&pollset->po.mu); } - if (worker_hdl) *worker_hdl = NULL; + if (worker_hdl) *worker_hdl = nullptr; gpr_tls_set(&g_current_thread_pollset, (intptr_t)0); gpr_tls_set(&g_current_thread_worker, (intptr_t)0); @@ -1413,7 +1413,7 @@ static void add_poll_object(grpc_exec_ctx* exec_ctx, poll_obj* bag, #endif grpc_error* error = GRPC_ERROR_NONE; - polling_island* pi_new = NULL; + polling_island* pi_new = nullptr; gpr_mu_lock(&bag->mu); gpr_mu_lock(&item->mu); @@ -1440,7 +1440,7 @@ retry: if (item->pi == bag->pi) { pi_new = item->pi; - if (pi_new == NULL) { + if (pi_new == nullptr) { /* GPR_ASSERT(item->pi == bag->pi == NULL) */ /* If we are adding an fd to a bag (i.e pollset or pollset_set), then @@ -1460,7 +1460,7 @@ retry: /* Need to reverify any assumptions made between the initial lock and getting to this branch: if they've changed, we need to throw away our work and figure things out again. */ - if (item->pi != NULL) { + if (item->pi != nullptr) { GRPC_POLLING_TRACE( "add_poll_object: Raced creating new polling island. pi_new: %p " "(fd: %d, %s: %p)", @@ -1477,7 +1477,7 @@ retry: goto retry; } } else { - pi_new = polling_island_create(exec_ctx, NULL, &error); + pi_new = polling_island_create(exec_ctx, nullptr, &error); } GRPC_POLLING_TRACE( @@ -1490,7 +1490,7 @@ retry: "add_poll_object: Same polling island. pi: %p (%s, %s)", (void*)pi_new, poll_obj_string(item_type), poll_obj_string(bag_type)); } - } else if (item->pi == NULL) { + } else if (item->pi == nullptr) { /* GPR_ASSERT(bag->pi != NULL) */ /* Make pi_new point to latest pi*/ pi_new = polling_island_lock(bag->pi); @@ -1506,7 +1506,7 @@ retry: "bag(%s): %p)", (void*)pi_new, poll_obj_string(item_type), (void*)item, poll_obj_string(bag_type), (void*)bag); - } else if (bag->pi == NULL) { + } else if (bag->pi == nullptr) { /* GPR_ASSERT(item->pi != NULL) */ /* Make pi_new to point to latest pi */ pi_new = polling_island_lock(item->pi); @@ -1530,7 +1530,7 @@ retry: if (item->pi != pi_new) { PI_ADD_REF(pi_new, poll_obj_string(item_type)); - if (item->pi != NULL) { + if (item->pi != nullptr) { PI_UNREF(exec_ctx, item->pi, poll_obj_string(item_type)); } item->pi = pi_new; @@ -1538,7 +1538,7 @@ retry: if (bag->pi != pi_new) { PI_ADD_REF(pi_new, poll_obj_string(bag_type)); - if (bag->pi != NULL) { + if (bag->pi != nullptr) { PI_UNREF(exec_ctx, bag->pi, poll_obj_string(bag_type)); } bag->pi = pi_new; @@ -1564,7 +1564,7 @@ static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, static grpc_pollset_set* pollset_set_create(void) { grpc_pollset_set* pss = (grpc_pollset_set*)gpr_malloc(sizeof(*pss)); gpr_mu_init(&pss->po.mu); - pss->po.pi = NULL; + pss->po.pi = nullptr; #ifndef NDEBUG pss->po.obj_type = POLL_OBJ_POLLSET_SET; #endif @@ -1575,7 +1575,7 @@ static void pollset_set_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset_set* pss) { gpr_mu_destroy(&pss->po.mu); - if (pss->po.pi != NULL) { + if (pss->po.pi != nullptr) { PI_UNREF(exec_ctx, pss->po.pi, "pss_destroy"); } @@ -1712,17 +1712,17 @@ const grpc_event_engine_vtable* grpc_init_epollsig_linux( /* If use of signals is disabled, we cannot use epoll engine*/ if (is_grpc_wakeup_signal_initialized && grpc_wakeup_signal < 0) { gpr_log(GPR_ERROR, "Skipping epollsig because use of signals is disabled."); - return NULL; + return nullptr; } if (!grpc_has_wakeup_fd()) { gpr_log(GPR_ERROR, "Skipping epollsig because of no wakeup fd."); - return NULL; + return nullptr; } if (!is_epoll_available()) { gpr_log(GPR_ERROR, "Skipping epollsig because epoll is unavailable."); - return NULL; + return nullptr; } if (!is_grpc_wakeup_signal_initialized) { @@ -1731,19 +1731,19 @@ const grpc_event_engine_vtable* grpc_init_epollsig_linux( } else { gpr_log(GPR_ERROR, "Skipping epollsig because uninitialized wakeup signal."); - return NULL; + return nullptr; } } fd_global_init(); if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) { - return NULL; + return nullptr; } if (!GRPC_LOG_IF_ERROR("polling_island_global_init", polling_island_global_init())) { - return NULL; + return nullptr; } return &vtable; diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index 5745a2ae5b..f8b9629462 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -335,11 +335,11 @@ static grpc_fd* fd_create(int fd, const char* name) { r->fd = fd; r->inactive_watcher_root.next = r->inactive_watcher_root.prev = &r->inactive_watcher_root; - r->read_watcher = r->write_watcher = NULL; - r->on_done_closure = NULL; + r->read_watcher = r->write_watcher = nullptr; + r->on_done_closure = nullptr; r->closed = 0; r->released = 0; - r->read_notifier_pollset = NULL; + r->read_notifier_pollset = nullptr; char* name2; gpr_asprintf(&name2, "%s fd=%d", name, fd); @@ -355,7 +355,7 @@ static bool fd_is_orphaned(grpc_fd* fd) { /* Return the read-notifier pollset */ static grpc_pollset* fd_get_read_notifier_pollset(grpc_exec_ctx* exec_ctx, grpc_fd* fd) { - grpc_pollset* notifier = NULL; + grpc_pollset* notifier = nullptr; gpr_mu_lock(&fd->mu); notifier = fd->read_notifier_pollset; @@ -401,7 +401,7 @@ static void wake_all_watchers_locked(grpc_exec_ctx* exec_ctx, grpc_fd* fd) { } static int has_watchers(grpc_fd* fd) { - return fd->read_watcher != NULL || fd->write_watcher != NULL || + return fd->read_watcher != nullptr || fd->write_watcher != nullptr || fd->inactive_watcher_root.next != &fd->inactive_watcher_root; } @@ -425,8 +425,8 @@ static void fd_orphan(grpc_exec_ctx* exec_ctx, grpc_fd* fd, grpc_closure* on_done, int* release_fd, bool already_closed, const char* reason) { fd->on_done_closure = on_done; - fd->released = release_fd != NULL; - if (release_fd != NULL) { + fd->released = release_fd != nullptr; + if (release_fd != nullptr) { *release_fd = fd->fd; fd->released = true; } else if (already_closed) { @@ -565,9 +565,9 @@ static uint32_t fd_begin_poll(grpc_fd* fd, grpc_pollset* pollset, /* if we are shutdown, then don't add to the watcher set */ if (fd->shutdown) { - watcher->fd = NULL; - watcher->pollset = NULL; - watcher->worker = NULL; + watcher->fd = nullptr; + watcher->pollset = nullptr; + watcher->worker = nullptr; gpr_mu_unlock(&fd->mu); GRPC_FD_UNREF(fd, "poll"); return 0; @@ -576,7 +576,7 @@ static uint32_t fd_begin_poll(grpc_fd* fd, grpc_pollset* pollset, /* if there is nobody polling for read, but we need to, then start doing so */ cur = fd->read_closure; requested = cur != CLOSURE_READY; - if (read_mask && fd->read_watcher == NULL && requested) { + if (read_mask && fd->read_watcher == nullptr && requested) { fd->read_watcher = watcher; mask |= read_mask; } @@ -584,12 +584,12 @@ static uint32_t fd_begin_poll(grpc_fd* fd, grpc_pollset* pollset, */ cur = fd->write_closure; requested = cur != CLOSURE_READY; - if (write_mask && fd->write_watcher == NULL && requested) { + if (write_mask && fd->write_watcher == nullptr && requested) { fd->write_watcher = watcher; mask |= write_mask; } /* if not polling, remember this watcher in case we need someone to later */ - if (mask == 0 && worker != NULL) { + if (mask == 0 && worker != nullptr) { watcher->next = &fd->inactive_watcher_root; watcher->prev = watcher->next->prev; watcher->next->prev = watcher->prev->next = watcher; @@ -609,7 +609,7 @@ static void fd_end_poll(grpc_exec_ctx* exec_ctx, grpc_fd_watcher* watcher, int kick = 0; grpc_fd* fd = watcher->fd; - if (fd == NULL) { + if (fd == nullptr) { return; } @@ -621,7 +621,7 @@ static void fd_end_poll(grpc_exec_ctx* exec_ctx, grpc_fd_watcher* watcher, if (!got_read) { kick = 1; } - fd->read_watcher = NULL; + fd->read_watcher = nullptr; } if (watcher == fd->write_watcher) { /* remove write watcher, kick if we still need a write */ @@ -629,9 +629,9 @@ static void fd_end_poll(grpc_exec_ctx* exec_ctx, grpc_fd_watcher* watcher, if (!got_write) { kick = 1; } - fd->write_watcher = NULL; + fd->write_watcher = nullptr; } - if (!was_polling && watcher->worker != NULL) { + if (!was_polling && watcher->worker != nullptr) { /* remove from inactive list */ watcher->next->prev = watcher->prev; watcher->prev->next = watcher->next; @@ -640,7 +640,7 @@ static void fd_end_poll(grpc_exec_ctx* exec_ctx, grpc_fd_watcher* watcher, if (set_ready_locked(exec_ctx, fd, &fd->read_closure)) { kick = 1; } - if (read_notifier_pollset != NULL) { + if (read_notifier_pollset != nullptr) { set_read_notifier_pollset_locked(exec_ctx, fd, read_notifier_pollset); } } @@ -690,7 +690,7 @@ static grpc_pollset_worker* pop_front_worker(grpc_pollset* p) { remove_worker(p, w); return w; } else { - return NULL; + return nullptr; } } @@ -722,7 +722,7 @@ static grpc_error* pollset_kick_ext(grpc_exec_ctx* exec_ctx, grpc_pollset* p, GRPC_STATS_INC_POLLSET_KICK(exec_ctx); /* pollset->mu already held */ - if (specific_worker != NULL) { + if (specific_worker != nullptr) { if (specific_worker == GRPC_POLLSET_KICK_BROADCAST) { GPR_TIMER_BEGIN("pollset_kick_ext.broadcast", 0); GPR_ASSERT((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP) == 0); @@ -756,7 +756,7 @@ static grpc_error* pollset_kick_ext(grpc_exec_ctx* exec_ctx, grpc_pollset* p, GPR_ASSERT((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP) == 0); GPR_TIMER_MARK("kick_anonymous", 0); specific_worker = pop_front_worker(p); - if (specific_worker != NULL) { + if (specific_worker != nullptr) { if (gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) { GPR_TIMER_MARK("kick_anonymous_not_self", 0); push_back_worker(p, specific_worker); @@ -765,10 +765,10 @@ static grpc_error* pollset_kick_ext(grpc_exec_ctx* exec_ctx, grpc_pollset* p, gpr_tls_get(&g_current_thread_worker) == (intptr_t)specific_worker) { push_back_worker(p, specific_worker); - specific_worker = NULL; + specific_worker = nullptr; } } - if (specific_worker != NULL) { + if (specific_worker != nullptr) { GPR_TIMER_MARK("finally_kick", 0); push_back_worker(p, specific_worker); kick_append_error( @@ -812,12 +812,12 @@ static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { pollset->shutting_down = 0; pollset->called_shutdown = 0; pollset->kicked_without_pollers = 0; - pollset->idle_jobs.head = pollset->idle_jobs.tail = NULL; - pollset->local_wakeup_cache = NULL; + pollset->idle_jobs.head = pollset->idle_jobs.tail = nullptr; + pollset->local_wakeup_cache = nullptr; pollset->kicked_without_pollers = 0; pollset->fd_count = 0; pollset->fd_capacity = 0; - pollset->fds = NULL; + pollset->fds = nullptr; pollset->pollset_set_count = 0; } @@ -850,7 +850,7 @@ static void pollset_add_fd(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, } pollset->fds[pollset->fd_count++] = fd; GRPC_FD_REF(fd, "multipoller"); - pollset_kick(exec_ctx, pollset, NULL); + pollset_kick(exec_ctx, pollset, nullptr); exit: gpr_mu_unlock(&pollset->mu); } @@ -892,9 +892,9 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, int keep_polling = 0; GPR_TIMER_BEGIN("pollset_work", 0); /* this must happen before we (potentially) drop pollset->mu */ - worker.next = worker.prev = NULL; + worker.next = worker.prev = nullptr; worker.reevaluate_polling_on_wakeup = 0; - if (pollset->local_wakeup_cache != NULL) { + if (pollset->local_wakeup_cache != nullptr) { worker.wakeup_fd = pollset->local_wakeup_cache; pollset->local_wakeup_cache = worker.wakeup_fd->next; } else { @@ -1002,8 +1002,8 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, } for (i = 1; i < pfd_count; i++) { - if (watchers[i].fd == NULL) { - fd_end_poll(exec_ctx, &watchers[i], 0, 0, NULL); + if (watchers[i].fd == nullptr) { + fd_end_poll(exec_ctx, &watchers[i], 0, 0, nullptr); } else { // Wake up all the file descriptors, if we have an invalid one // we can identify it on the next pollset_work() @@ -1012,7 +1012,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, } } else if (r == 0) { for (i = 1; i < pfd_count; i++) { - fd_end_poll(exec_ctx, &watchers[i], 0, 0, NULL); + fd_end_poll(exec_ctx, &watchers[i], 0, 0, nullptr); } } else { if (pfds[0].revents & POLLIN_CHECK) { @@ -1023,8 +1023,8 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, &error, grpc_wakeup_fd_consume_wakeup(&worker.wakeup_fd->fd)); } for (i = 1; i < pfd_count; i++) { - if (watchers[i].fd == NULL) { - fd_end_poll(exec_ctx, &watchers[i], 0, 0, NULL); + if (watchers[i].fd == nullptr) { + fd_end_poll(exec_ctx, &watchers[i], 0, 0, nullptr); } else { if (GRPC_TRACER_ON(grpc_polling_trace)) { gpr_log(GPR_DEBUG, "%p got_event: %d r:%d w:%d [%d]", pollset, @@ -1083,7 +1083,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, /* check shutdown conditions */ if (pollset->shutting_down) { if (pollset_has_workers(pollset)) { - pollset_kick(exec_ctx, pollset, NULL); + pollset_kick(exec_ctx, pollset, nullptr); } else if (!pollset->called_shutdown && !pollset_has_observers(pollset)) { pollset->called_shutdown = 1; gpr_mu_unlock(&pollset->mu); @@ -1101,7 +1101,7 @@ static grpc_error* pollset_work(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, gpr_mu_lock(&pollset->mu); } } - if (worker_hdl) *worker_hdl = NULL; + if (worker_hdl) *worker_hdl = nullptr; GPR_TIMER_END("pollset_work", 0); GRPC_LOG_IF_ERROR("pollset_work", GRPC_ERROR_REF(error)); return error; @@ -1319,7 +1319,7 @@ static void cache_insert_locked(poll_args* args) { poll_cache.active_pollers[key]->prev = args; } args->next = poll_cache.active_pollers[key]; - args->prev = NULL; + args->prev = nullptr; poll_cache.active_pollers[key] = args; poll_cache.count++; } @@ -1327,7 +1327,7 @@ static void cache_insert_locked(poll_args* args) { static void init_result(poll_args* pargs) { pargs->result = (poll_result*)gpr_malloc(sizeof(poll_result)); gpr_ref_init(&pargs->result->refcount, 1); - pargs->result->watchers = NULL; + pargs->result->watchers = nullptr; pargs->result->watchcount = 0; pargs->result->fds = (struct pollfd*)gpr_malloc(sizeof(struct pollfd) * pargs->nfds); @@ -1358,12 +1358,12 @@ static poll_args* get_poller_locked(struct pollfd* fds, nfds_t count) { poll_args* pargs = poll_cache.free_pollers; poll_cache.free_pollers = pargs->next; if (poll_cache.free_pollers) { - poll_cache.free_pollers->prev = NULL; + poll_cache.free_pollers->prev = nullptr; } pargs->fds = fds; pargs->nfds = count; - pargs->next = NULL; - pargs->prev = NULL; + pargs->next = nullptr; + pargs->prev = nullptr; init_result(pargs); cache_poller_locked(pargs); return pargs; @@ -1373,8 +1373,8 @@ static poll_args* get_poller_locked(struct pollfd* fds, nfds_t count) { gpr_cv_init(&pargs->trigger); pargs->fds = fds; pargs->nfds = count; - pargs->next = NULL; - pargs->prev = NULL; + pargs->next = nullptr; + pargs->prev = nullptr; pargs->trigger_set = 0; init_result(pargs); cache_poller_locked(pargs); @@ -1405,7 +1405,7 @@ static void cache_delete_locked(poll_args* args) { if (poll_cache.free_pollers) { poll_cache.free_pollers->prev = args; } - args->prev = NULL; + args->prev = nullptr; args->next = poll_cache.free_pollers; gpr_free(args->fds); poll_cache.free_pollers = args; @@ -1419,11 +1419,11 @@ static void cache_poller_locked(poll_args* args) { poll_cache.active_pollers = (poll_args**)gpr_malloc(sizeof(void*) * poll_cache.size); for (unsigned int i = 0; i < poll_cache.size; i++) { - poll_cache.active_pollers[i] = NULL; + poll_cache.active_pollers[i] = nullptr; } for (unsigned int i = 0; i < poll_cache.size / 2; i++) { poll_args* curr = old_active_pollers[i]; - poll_args* next = NULL; + poll_args* next = nullptr; while (curr) { next = curr->next; cache_insert_locked(curr); @@ -1520,10 +1520,10 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) { cv_node* pollcv; int skip_poll = 0; nfds_t nsockfds = 0; - poll_result* result = NULL; + poll_result* result = nullptr; gpr_mu_lock(&g_cvfds.mu); pollcv = (cv_node*)gpr_malloc(sizeof(cv_node)); - pollcv->next = NULL; + pollcv->next = nullptr; gpr_cv pollcv_cv; gpr_cv_init(&pollcv_cv); pollcv->cv = &pollcv_cv; @@ -1534,7 +1534,7 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) { if (fds[i].fd < 0 && (fds[i].events & POLLIN)) { idx = GRPC_FD_TO_IDX(fds[i].fd); fd_cvs[i].cv = &pollcv_cv; - fd_cvs[i].prev = NULL; + fd_cvs[i].prev = nullptr; fd_cvs[i].next = g_cvfds.cvfds[idx].cvs; if (g_cvfds.cvfds[idx].cvs) { g_cvfds.cvfds[idx].cvs->prev = &(fd_cvs[i]); @@ -1573,7 +1573,7 @@ static int cvfd_poll(struct pollfd* fds, nfds_t nfds, int timeout) { poll_args* pargs = get_poller_locked(pollfds, nsockfds); result = pargs->result; pollcv->next = result->watchers; - pollcv->prev = NULL; + pollcv->prev = nullptr; if (result->watchers) { result->watchers->prev = pollcv; } @@ -1624,11 +1624,11 @@ static void global_cv_fd_table_init() { gpr_ref_init(&g_cvfds.pollcount, 1); g_cvfds.size = CV_DEFAULT_TABLE_SIZE; g_cvfds.cvfds = (fd_node*)gpr_malloc(sizeof(fd_node) * CV_DEFAULT_TABLE_SIZE); - g_cvfds.free_fds = NULL; + g_cvfds.free_fds = nullptr; thread_grace = gpr_time_from_millis(POLLCV_THREAD_GRACE_MS, GPR_TIMESPAN); for (int i = 0; i < CV_DEFAULT_TABLE_SIZE; i++) { g_cvfds.cvfds[i].is_set = 0; - g_cvfds.cvfds[i].cvs = NULL; + g_cvfds.cvfds[i].cvs = nullptr; g_cvfds.cvfds[i].next_free = g_cvfds.free_fds; g_cvfds.free_fds = &g_cvfds.cvfds[i]; } @@ -1639,10 +1639,10 @@ static void global_cv_fd_table_init() { // Initialize the cache poll_cache.size = 32; poll_cache.count = 0; - poll_cache.free_pollers = NULL; + poll_cache.free_pollers = nullptr; poll_cache.active_pollers = (poll_args**)gpr_malloc(sizeof(void*) * 32); for (unsigned int i = 0; i < poll_cache.size; i++) { - poll_cache.active_pollers[i] = NULL; + poll_cache.active_pollers[i] = nullptr; } gpr_mu_unlock(&g_cvfds.mu); @@ -1713,10 +1713,10 @@ static const grpc_event_engine_vtable vtable = { const grpc_event_engine_vtable* grpc_init_poll_posix(bool explicit_request) { if (!grpc_has_wakeup_fd()) { gpr_log(GPR_ERROR, "Skipping poll because of no wakeup fd."); - return NULL; + return nullptr; } if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) { - return NULL; + return nullptr; } return &vtable; } @@ -1727,7 +1727,7 @@ const grpc_event_engine_vtable* grpc_init_poll_cv_posix(bool explicit_request) { if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) { global_cv_fd_table_shutdown(); grpc_enable_cv_wakeup_fds(0); - return NULL; + return nullptr; } return &vtable; } diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index a05279a4aa..076d2e6bab 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -51,7 +51,7 @@ grpc_poll_function_type grpc_poll_function = poll; grpc_wakeup_fd grpc_global_wakeup_fd; static const grpc_event_engine_vtable* g_event_engine; -static const char* g_poll_strategy_name = NULL; +static const char* g_poll_strategy_name = nullptr; typedef const grpc_event_engine_vtable* (*event_engine_factory_fn)( bool explicit_request); @@ -114,7 +114,7 @@ static void add(const char* beg, const char* end, char*** ss, size_t* ns) { static void split(const char* s, char*** ss, size_t* ns) { const char* c = strchr(s, ','); - if (c == NULL) { + if (c == nullptr) { add(s, s + strlen(s), ss, ns); } else { add(s, c, ss, ns); @@ -156,15 +156,15 @@ void grpc_event_engine_init(void) { grpc_register_tracer(&grpc_polling_trace); char* s = gpr_getenv("GRPC_POLL_STRATEGY"); - if (s == NULL) { + if (s == nullptr) { s = gpr_strdup("all"); } - char** strings = NULL; + char** strings = nullptr; size_t nstrings = 0; split(s, &strings, &nstrings); - for (size_t i = 0; g_event_engine == NULL && i < nstrings; i++) { + for (size_t i = 0; g_event_engine == nullptr && i < nstrings; i++) { try_engine(strings[i]); } @@ -173,7 +173,7 @@ void grpc_event_engine_init(void) { } gpr_free(strings); - if (g_event_engine == NULL) { + if (g_event_engine == nullptr) { gpr_log(GPR_ERROR, "No event engine could be initialized from %s", s); abort(); } @@ -182,7 +182,7 @@ void grpc_event_engine_init(void) { void grpc_event_engine_shutdown(void) { g_event_engine->shutdown_engine(); - g_event_engine = NULL; + g_event_engine = nullptr; } grpc_fd* grpc_fd_create(int fd, const char* name) { diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index 0a0ed8a055..427941c618 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -47,7 +47,7 @@ bool grpc_always_ready_to_finish(grpc_exec_ctx* exec_ctx, void* arg_ignored) { } bool grpc_exec_ctx_has_work(grpc_exec_ctx* exec_ctx) { - return exec_ctx->active_combiner != NULL || + return exec_ctx->active_combiner != nullptr || !grpc_closure_list_empty(exec_ctx->closure_list); } @@ -82,8 +82,8 @@ bool grpc_exec_ctx_flush(grpc_exec_ctx* exec_ctx) { for (;;) { if (!grpc_closure_list_empty(exec_ctx->closure_list)) { grpc_closure* c = exec_ctx->closure_list.head; - exec_ctx->closure_list.head = exec_ctx->closure_list.tail = NULL; - while (c != NULL) { + exec_ctx->closure_list.head = exec_ctx->closure_list.tail = nullptr; + while (c != nullptr) { grpc_closure* next = c->next_data.next; grpc_error* error = c->error_data.error; did_something = true; @@ -94,7 +94,7 @@ bool grpc_exec_ctx_flush(grpc_exec_ctx* exec_ctx) { break; } } - GPR_ASSERT(exec_ctx->active_combiner == NULL); + GPR_ASSERT(exec_ctx->active_combiner == nullptr); GPR_TIMER_END("grpc_exec_ctx_flush", 0); return did_something; } diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index 2786492494..6097d66024 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -60,7 +60,7 @@ static size_t run_closures(grpc_exec_ctx* exec_ctx, grpc_closure_list list) { size_t n = 0; grpc_closure* c = list.head; - while (c != NULL) { + while (c != nullptr) { grpc_closure* next = c->next_data.next; grpc_error* error = c->error_data.error; if (GRPC_TRACER_ON(executor_trace)) { @@ -148,7 +148,7 @@ static void executor_thread(void* arg) { gpr_tls_set(&g_this_thread_state, (intptr_t)ts); grpc_exec_ctx exec_ctx = - GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, NULL); + GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, nullptr); size_t subtract_depth = 0; for (;;) { @@ -208,7 +208,7 @@ static void executor_push(grpc_exec_ctx* exec_ctx, grpc_closure* closure, return; } thread_state* ts = (thread_state*)gpr_tls_get(&g_this_thread_state); - if (ts == NULL) { + if (ts == nullptr) { ts = &g_thread_state[GPR_HASH_POINTER(exec_ctx, cur_thread_count)]; } else { GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF(exec_ctx); diff --git a/src/core/lib/iomgr/gethostname_host_name_max.cc b/src/core/lib/iomgr/gethostname_host_name_max.cc index 987ff1eac1..2487160916 100644 --- a/src/core/lib/iomgr/gethostname_host_name_max.cc +++ b/src/core/lib/iomgr/gethostname_host_name_max.cc @@ -30,7 +30,7 @@ char* grpc_gethostname() { char* hostname = (char*)gpr_malloc(HOST_NAME_MAX); if (gethostname(hostname, HOST_NAME_MAX) != 0) { gpr_free(hostname); - return NULL; + return nullptr; } return hostname; } diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index 86ea08e901..e077b35014 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -100,7 +100,7 @@ void grpc_iomgr_shutdown(grpc_exec_ctx* exec_ctx) { } exec_ctx->now_is_valid = true; exec_ctx->now = GRPC_MILLIS_INF_FUTURE; - if (grpc_timer_check(exec_ctx, NULL) == GRPC_TIMERS_FIRED) { + if (grpc_timer_check(exec_ctx, nullptr) == GRPC_TIMERS_FIRED) { gpr_mu_unlock(&g_mu); grpc_exec_ctx_flush(exec_ctx); grpc_iomgr_platform_flush(); diff --git a/src/core/lib/iomgr/is_epollexclusive_available.cc b/src/core/lib/iomgr/is_epollexclusive_available.cc index d08844c0df..e5803532e7 100644 --- a/src/core/lib/iomgr/is_epollexclusive_available.cc +++ b/src/core/lib/iomgr/is_epollexclusive_available.cc @@ -62,7 +62,7 @@ bool grpc_is_epollexclusive_available(void) { EPOLLEXCLUSIVE enabled kernels - specifically the combination of EPOLLONESHOT and EPOLLEXCLUSIVE */ ev.events = (uint32_t)(EPOLLET | EPOLLIN | EPOLLEXCLUSIVE | EPOLLONESHOT); - ev.data.ptr = NULL; + ev.data.ptr = nullptr; if (epoll_ctl(fd, EPOLL_CTL_ADD, evfd, &ev) != 0) { if (errno != EINVAL) { if (!logged_why_not) { diff --git a/src/core/lib/iomgr/load_file.cc b/src/core/lib/iomgr/load_file.cc index 97e448fb32..4a05de1410 100644 --- a/src/core/lib/iomgr/load_file.cc +++ b/src/core/lib/iomgr/load_file.cc @@ -30,7 +30,7 @@ grpc_error* grpc_load_file(const char* filename, int add_null_terminator, grpc_slice* output) { - unsigned char* contents = NULL; + unsigned char* contents = nullptr; size_t contents_size = 0; grpc_slice result = grpc_empty_slice(); FILE* file; @@ -39,7 +39,7 @@ grpc_error* grpc_load_file(const char* filename, int add_null_terminator, GRPC_SCHEDULING_START_BLOCKING_REGION; file = fopen(filename, "rb"); - if (file == NULL) { + if (file == nullptr) { error = GRPC_OS_ERROR(errno, "fopen"); goto end; } @@ -62,7 +62,7 @@ grpc_error* grpc_load_file(const char* filename, int add_null_terminator, end: *output = result; - if (file != NULL) fclose(file); + if (file != nullptr) fclose(file); if (error != GRPC_ERROR_NONE) { grpc_error* error_out = grpc_error_set_str(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( diff --git a/src/core/lib/iomgr/lockfree_event.h b/src/core/lib/iomgr/lockfree_event.h index c667dcd3bc..a9f4de14df 100644 --- a/src/core/lib/iomgr/lockfree_event.h +++ b/src/core/lib/iomgr/lockfree_event.h @@ -25,7 +25,7 @@ #include "src/core/lib/iomgr/exec_ctx.h" -namespace grpc_core { +namespace grpc_core; { class LockfreeEvent { public: diff --git a/src/core/lib/iomgr/polling_entity.cc b/src/core/lib/iomgr/polling_entity.cc index f0ef2cfe3d..0ee4ea1255 100644 --- a/src/core/lib/iomgr/polling_entity.cc +++ b/src/core/lib/iomgr/polling_entity.cc @@ -41,7 +41,7 @@ grpc_pollset* grpc_polling_entity_pollset(grpc_polling_entity* pollent) { if (pollent->tag == GRPC_POLLS_POLLSET) { return pollent->pollent.pollset; } - return NULL; + return nullptr; } grpc_pollset_set* grpc_polling_entity_pollset_set( @@ -49,7 +49,7 @@ grpc_pollset_set* grpc_polling_entity_pollset_set( if (pollent->tag == GRPC_POLLS_POLLSET_SET) { return pollent->pollent.pollset_set; } - return NULL; + return nullptr; } bool grpc_polling_entity_is_empty(const grpc_polling_entity* pollent) { @@ -60,10 +60,10 @@ void grpc_polling_entity_add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_polling_entity* pollent, grpc_pollset_set* pss_dst) { if (pollent->tag == GRPC_POLLS_POLLSET) { - GPR_ASSERT(pollent->pollent.pollset != NULL); + GPR_ASSERT(pollent->pollent.pollset != nullptr); grpc_pollset_set_add_pollset(exec_ctx, pss_dst, pollent->pollent.pollset); } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) { - GPR_ASSERT(pollent->pollent.pollset_set != NULL); + GPR_ASSERT(pollent->pollent.pollset_set != nullptr); grpc_pollset_set_add_pollset_set(exec_ctx, pss_dst, pollent->pollent.pollset_set); } else { @@ -76,10 +76,10 @@ void grpc_polling_entity_del_from_pollset_set(grpc_exec_ctx* exec_ctx, grpc_polling_entity* pollent, grpc_pollset_set* pss_dst) { if (pollent->tag == GRPC_POLLS_POLLSET) { - GPR_ASSERT(pollent->pollent.pollset != NULL); + GPR_ASSERT(pollent->pollent.pollset != nullptr); grpc_pollset_set_del_pollset(exec_ctx, pss_dst, pollent->pollent.pollset); } else if (pollent->tag == GRPC_POLLS_POLLSET_SET) { - GPR_ASSERT(pollent->pollent.pollset_set != NULL); + GPR_ASSERT(pollent->pollent.pollset_set != nullptr); grpc_pollset_set_del_pollset_set(exec_ctx, pss_dst, pollent->pollent.pollset_set); } else { diff --git a/src/core/lib/iomgr/resolve_address_posix.cc b/src/core/lib/iomgr/resolve_address_posix.cc index e27c730204..fb5fa9d422 100644 --- a/src/core/lib/iomgr/resolve_address_posix.cc +++ b/src/core/lib/iomgr/resolve_address_posix.cc @@ -43,7 +43,7 @@ static grpc_error* blocking_resolve_address_impl( const char* name, const char* default_port, grpc_resolved_addresses** addresses) { struct addrinfo hints; - struct addrinfo *result = NULL, *resp; + struct addrinfo *result = nullptr, *resp; char* host; char* port; int s; @@ -57,14 +57,14 @@ static grpc_error* blocking_resolve_address_impl( /* parse name, splitting it into host and port parts */ gpr_split_host_port(name, &host, &port); - if (host == NULL) { + if (host == nullptr) { err = grpc_error_set_str( GRPC_ERROR_CREATE_FROM_STATIC_STRING("unparseable host:port"), GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name)); goto done; } - if (port == NULL) { - if (default_port == NULL) { + if (port == nullptr) { + if (default_port == nullptr) { err = grpc_error_set_str( GRPC_ERROR_CREATE_FROM_STATIC_STRING("no port in name"), GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name)); @@ -115,13 +115,13 @@ static grpc_error* blocking_resolve_address_impl( *addresses = (grpc_resolved_addresses*)gpr_malloc(sizeof(grpc_resolved_addresses)); (*addresses)->naddrs = 0; - for (resp = result; resp != NULL; resp = resp->ai_next) { + for (resp = result; resp != nullptr; resp = resp->ai_next) { (*addresses)->naddrs++; } (*addresses)->addrs = (grpc_resolved_address*)gpr_malloc( sizeof(grpc_resolved_address) * (*addresses)->naddrs); i = 0; - for (resp = result; resp != NULL; resp = resp->ai_next) { + for (resp = result; resp != nullptr; resp = resp->ai_next) { memcpy(&(*addresses)->addrs[i].addr, resp->ai_addr, resp->ai_addrlen); (*addresses)->addrs[i].len = resp->ai_addrlen; i++; @@ -164,7 +164,7 @@ static void do_request_thread(grpc_exec_ctx* exec_ctx, void* rp, } void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) { - if (addrs != NULL) { + if (addrs != nullptr) { gpr_free(addrs->addrs); } gpr_free(addrs); diff --git a/src/core/lib/iomgr/resource_quota.cc b/src/core/lib/iomgr/resource_quota.cc index 5077554a56..9a44fa203c 100644 --- a/src/core/lib/iomgr/resource_quota.cc +++ b/src/core/lib/iomgr/resource_quota.cc @@ -166,7 +166,7 @@ static void rulist_add_head(grpc_resource_user* resource_user, grpc_rulist list) { grpc_resource_quota* resource_quota = resource_user->resource_quota; grpc_resource_user** root = &resource_quota->roots[list]; - if (*root == NULL) { + if (*root == nullptr) { *root = resource_user; resource_user->links[list].next = resource_user->links[list].prev = resource_user; @@ -183,7 +183,7 @@ static void rulist_add_tail(grpc_resource_user* resource_user, grpc_rulist list) { grpc_resource_quota* resource_quota = resource_user->resource_quota; grpc_resource_user** root = &resource_quota->roots[list]; - if (*root == NULL) { + if (*root == nullptr) { *root = resource_user; resource_user->links[list].next = resource_user->links[list].prev = resource_user; @@ -197,18 +197,18 @@ static void rulist_add_tail(grpc_resource_user* resource_user, static bool rulist_empty(grpc_resource_quota* resource_quota, grpc_rulist list) { - return resource_quota->roots[list] == NULL; + return resource_quota->roots[list] == nullptr; } static grpc_resource_user* rulist_pop_head(grpc_resource_quota* resource_quota, grpc_rulist list) { grpc_resource_user** root = &resource_quota->roots[list]; grpc_resource_user* resource_user = *root; - if (resource_user == NULL) { - return NULL; + if (resource_user == nullptr) { + return nullptr; } if (resource_user->links[list].next == resource_user) { - *root = NULL; + *root = nullptr; } else { resource_user->links[list].next->links[list].prev = resource_user->links[list].prev; @@ -216,24 +216,24 @@ static grpc_resource_user* rulist_pop_head(grpc_resource_quota* resource_quota, resource_user->links[list].next; *root = resource_user->links[list].next; } - resource_user->links[list].next = resource_user->links[list].prev = NULL; + resource_user->links[list].next = resource_user->links[list].prev = nullptr; return resource_user; } static void rulist_remove(grpc_resource_user* resource_user, grpc_rulist list) { - if (resource_user->links[list].next == NULL) return; + if (resource_user->links[list].next == nullptr) return; grpc_resource_quota* resource_quota = resource_user->resource_quota; if (resource_quota->roots[list] == resource_user) { resource_quota->roots[list] = resource_user->links[list].next; if (resource_quota->roots[list] == resource_user) { - resource_quota->roots[list] = NULL; + resource_quota->roots[list] = nullptr; } } resource_user->links[list].next->links[list].prev = resource_user->links[list].prev; resource_user->links[list].prev->links[list].next = resource_user->links[list].next; - resource_user->links[list].next = resource_user->links[list].prev = NULL; + resource_user->links[list].next = resource_user->links[list].prev = nullptr; } /******************************************************************************* @@ -380,7 +380,7 @@ static bool rq_reclaim(grpc_exec_ctx* exec_ctx, grpc_rulist list = destructive ? GRPC_RULIST_RECLAIMER_DESTRUCTIVE : GRPC_RULIST_RECLAIMER_BENIGN; grpc_resource_user* resource_user = rulist_pop_head(resource_quota, list); - if (resource_user == NULL) return false; + if (resource_user == nullptr) return false; if (GRPC_TRACER_ON(grpc_resource_quota_trace)) { gpr_log(GPR_DEBUG, "RQ %s %s: initiate %s reclamation", resource_quota->name, resource_user->name, @@ -392,7 +392,7 @@ static bool rq_reclaim(grpc_exec_ctx* exec_ctx, GPR_ASSERT(c); resource_quota->debug_only_last_reclaimer_resource_user = resource_user; resource_quota->debug_only_last_initiated_reclaimer = c; - resource_user->reclaimers[destructive] = NULL; + resource_user->reclaimers[destructive] = nullptr; GRPC_CLOSURE_RUN(exec_ctx, c, GRPC_ERROR_NONE); return true; } @@ -471,9 +471,9 @@ static bool ru_post_reclaimer(grpc_exec_ctx* exec_ctx, grpc_resource_user* resource_user, bool destructive) { grpc_closure* closure = resource_user->new_reclaimers[destructive]; - GPR_ASSERT(closure != NULL); - resource_user->new_reclaimers[destructive] = NULL; - GPR_ASSERT(resource_user->reclaimers[destructive] == NULL); + GPR_ASSERT(closure != nullptr); + resource_user->new_reclaimers[destructive] = nullptr; + GPR_ASSERT(resource_user->reclaimers[destructive] == nullptr); if (gpr_atm_acq_load(&resource_user->shutdown) > 0) { GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_CANCELLED); return false; @@ -523,8 +523,8 @@ static void ru_shutdown(grpc_exec_ctx* exec_ctx, void* ru, grpc_error* error) { GRPC_ERROR_CANCELLED); GRPC_CLOSURE_SCHED(exec_ctx, resource_user->reclaimers[1], GRPC_ERROR_CANCELLED); - resource_user->reclaimers[0] = NULL; - resource_user->reclaimers[1] = NULL; + resource_user->reclaimers[0] = nullptr; + resource_user->reclaimers[1] = nullptr; rulist_remove(resource_user, GRPC_RULIST_RECLAIMER_BENIGN); rulist_remove(resource_user, GRPC_RULIST_RECLAIMER_DESTRUCTIVE); if (resource_user->allocating) { @@ -612,7 +612,7 @@ grpc_resource_quota* grpc_resource_quota_create(const char* name) { resource_quota->step_scheduled = false; resource_quota->reclaiming = false; gpr_atm_no_barrier_store(&resource_quota->memory_usage_estimation, 0); - if (name != NULL) { + if (name != nullptr) { resource_quota->name = gpr_strdup(name); } else { gpr_asprintf(&resource_quota->name, "anonymous_pool_%" PRIxPTR, @@ -624,7 +624,7 @@ grpc_resource_quota* grpc_resource_quota_create(const char* name) { rq_reclamation_done, resource_quota, grpc_combiner_scheduler(resource_quota->combiner)); for (int i = 0; i < GRPC_RULIST_COUNT; i++) { - resource_quota->roots[i] = NULL; + resource_quota->roots[i] = nullptr; } return resource_quota; } @@ -697,7 +697,7 @@ grpc_resource_quota* grpc_resource_quota_from_channel_args( } } } - return grpc_resource_quota_create(NULL); + return grpc_resource_quota_create(nullptr); } static void* rq_copy(void* rq) { @@ -747,15 +747,15 @@ grpc_resource_user* grpc_resource_user_create( grpc_closure_list_init(&resource_user->on_allocated); resource_user->allocating = false; resource_user->added_to_free_pool = false; - resource_user->reclaimers[0] = NULL; - resource_user->reclaimers[1] = NULL; - resource_user->new_reclaimers[0] = NULL; - resource_user->new_reclaimers[1] = NULL; + resource_user->reclaimers[0] = nullptr; + resource_user->reclaimers[1] = nullptr; + resource_user->new_reclaimers[0] = nullptr; + resource_user->new_reclaimers[1] = nullptr; resource_user->outstanding_allocations = 0; for (int i = 0; i < GRPC_RULIST_COUNT; i++) { - resource_user->links[i].next = resource_user->links[i].prev = NULL; + resource_user->links[i].next = resource_user->links[i].prev = nullptr; } - if (name != NULL) { + if (name != nullptr) { resource_user->name = gpr_strdup(name); } else { gpr_asprintf(&resource_user->name, "anonymous_resource_user_%" PRIxPTR, @@ -858,7 +858,7 @@ void grpc_resource_user_post_reclaimer(grpc_exec_ctx* exec_ctx, grpc_resource_user* resource_user, bool destructive, grpc_closure* closure) { - GPR_ASSERT(resource_user->new_reclaimers[destructive] == NULL); + GPR_ASSERT(resource_user->new_reclaimers[destructive] == nullptr); resource_user->new_reclaimers[destructive] = closure; GRPC_CLOSURE_SCHED(exec_ctx, &resource_user->post_reclaimer_closure[destructive], @@ -900,6 +900,6 @@ void grpc_resource_user_alloc_slices( grpc_slice grpc_resource_user_slice_malloc(grpc_exec_ctx* exec_ctx, grpc_resource_user* resource_user, size_t size) { - grpc_resource_user_alloc(exec_ctx, resource_user, size, NULL); + grpc_resource_user_alloc(exec_ctx, resource_user, size, nullptr); return ru_slice_create(resource_user, size); } diff --git a/src/core/lib/iomgr/sockaddr_utils.cc b/src/core/lib/iomgr/sockaddr_utils.cc index 2dbc5aa6e7..e01dc4e65c 100644 --- a/src/core/lib/iomgr/sockaddr_utils.cc +++ b/src/core/lib/iomgr/sockaddr_utils.cc @@ -41,14 +41,14 @@ int grpc_sockaddr_is_v4mapped(const grpc_resolved_address* resolved_addr, GPR_ASSERT(resolved_addr != resolved_addr4_out); const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr; struct sockaddr_in* addr4_out = - resolved_addr4_out == NULL - ? NULL + resolved_addr4_out == nullptr + ? nullptr : (struct sockaddr_in*)resolved_addr4_out->addr; if (addr->sa_family == AF_INET6) { const struct sockaddr_in6* addr6 = (const struct sockaddr_in6*)addr; if (memcmp(addr6->sin6_addr.s6_addr, kV4MappedPrefix, sizeof(kV4MappedPrefix)) == 0) { - if (resolved_addr4_out != NULL) { + if (resolved_addr4_out != nullptr) { /* Normalize ::ffff:0.0.0.0/96 to IPv4. */ memset(resolved_addr4_out, 0, sizeof(*resolved_addr4_out)); addr4_out->sin_family = AF_INET; @@ -147,12 +147,12 @@ int grpc_sockaddr_to_string(char** out, const int save_errno = errno; grpc_resolved_address addr_normalized; char ntop_buf[INET6_ADDRSTRLEN]; - const void* ip = NULL; + const void* ip = nullptr; int port; uint32_t sin6_scope_id = 0; int ret; - *out = NULL; + *out = nullptr; if (normalize && grpc_sockaddr_is_v4mapped(resolved_addr, &addr_normalized)) { resolved_addr = &addr_normalized; } @@ -167,8 +167,8 @@ int grpc_sockaddr_to_string(char** out, port = ntohs(addr6->sin6_port); sin6_scope_id = addr6->sin6_scope_id; } - if (ip != NULL && - grpc_inet_ntop(addr->sa_family, ip, ntop_buf, sizeof(ntop_buf)) != NULL) { + if (ip != nullptr && + grpc_inet_ntop(addr->sa_family, ip, ntop_buf, sizeof(ntop_buf)) != nullptr) { if (sin6_scope_id != 0) { char* host_with_scope; /* Enclose sin6_scope_id with the format defined in RFC 6784 section 2. */ @@ -192,18 +192,18 @@ char* grpc_sockaddr_to_uri(const grpc_resolved_address* resolved_addr) { resolved_addr = &addr_normalized; } const char* scheme = grpc_sockaddr_get_uri_scheme(resolved_addr); - if (scheme == NULL || strcmp("unix", scheme) == 0) { + if (scheme == nullptr || strcmp("unix", scheme) == 0) { return grpc_sockaddr_to_uri_unix_if_possible(resolved_addr); } - char* path = NULL; - char* uri_str = NULL; + char* path = nullptr; + char* uri_str = nullptr; if (grpc_sockaddr_to_string(&path, resolved_addr, false /* suppress errors */) && - scheme != NULL) { + scheme != nullptr) { gpr_asprintf(&uri_str, "%s:%s", scheme, path); } gpr_free(path); - return uri_str != NULL ? uri_str : NULL; + return uri_str != nullptr ? uri_str : nullptr; } const char* grpc_sockaddr_get_uri_scheme( @@ -217,7 +217,7 @@ const char* grpc_sockaddr_get_uri_scheme( case AF_UNIX: return "unix"; } - return NULL; + return nullptr; } int grpc_sockaddr_get_family(const grpc_resolved_address* resolved_addr) { diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc index 88b757a4ae..d87aba3af2 100644 --- a/src/core/lib/iomgr/socket_utils_common_posix.cc +++ b/src/core/lib/iomgr/socket_utils_common_posix.cc @@ -263,13 +263,13 @@ static grpc_error* error_for_fd(int fd, const grpc_resolved_address* addr) { grpc_error* grpc_create_dualstack_socket( const grpc_resolved_address* resolved_addr, int type, int protocol, grpc_dualstack_mode* dsmode, int* newfd) { - return grpc_create_dualstack_socket_using_factory(NULL, resolved_addr, type, + return grpc_create_dualstack_socket_using_factory(nullptr, resolved_addr, type, protocol, dsmode, newfd); } static int create_socket(grpc_socket_factory* factory, int domain, int type, int protocol) { - return (factory != NULL) + return (factory != nullptr) ? grpc_socket_factory_socket(factory, domain, type, protocol) : socket(domain, type, protocol); } @@ -292,7 +292,7 @@ grpc_error* grpc_create_dualstack_socket_using_factory( return GRPC_ERROR_NONE; } /* If this isn't an IPv4 address, then return whatever we've got. */ - if (!grpc_sockaddr_is_v4mapped(resolved_addr, NULL)) { + if (!grpc_sockaddr_is_v4mapped(resolved_addr, nullptr)) { *dsmode = GRPC_DSMODE_IPV6; return error_for_fd(*newfd, resolved_addr); } diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index e72d70c027..85a4c29497 100644 --- a/src/core/lib/iomgr/tcp_client_posix.cc +++ b/src/core/lib/iomgr/tcp_client_posix.cc @@ -105,7 +105,7 @@ static void tc_on_alarm(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { str); } gpr_mu_lock(&ac->mu); - if (ac->fd != NULL) { + if (ac->fd != nullptr) { grpc_fd_shutdown( exec_ctx, ac->fd, GRPC_ERROR_CREATE_FROM_STATIC_STRING("connect() timed out")); @@ -147,7 +147,7 @@ static void on_writable(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { gpr_mu_lock(&ac->mu); GPR_ASSERT(ac->fd); fd = ac->fd; - ac->fd = NULL; + ac->fd = nullptr; gpr_mu_unlock(&ac->mu); grpc_timer_cancel(exec_ctx, &ac->alarm); @@ -175,7 +175,7 @@ static void on_writable(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { grpc_pollset_set_del_fd(exec_ctx, ac->interested_parties, fd); *ep = grpc_tcp_client_create_from_fd(exec_ctx, fd, ac->channel_args, ac->addr_str); - fd = NULL; + fd = nullptr; break; case ENOBUFS: /* We will get one of these errors if we have run out of @@ -208,11 +208,11 @@ static void on_writable(grpc_exec_ctx* exec_ctx, void* acp, grpc_error* error) { } finish: - if (fd != NULL) { + if (fd != nullptr) { grpc_pollset_set_del_fd(exec_ctx, ac->interested_parties, fd); - grpc_fd_orphan(exec_ctx, fd, NULL, NULL, false /* already_closed */, + grpc_fd_orphan(exec_ctx, fd, nullptr, nullptr, false /* already_closed */, "tcp_client_orphan"); - fd = NULL; + fd = nullptr; } done = (--ac->refs == 0); gpr_mu_unlock(&ac->mu); @@ -256,7 +256,7 @@ static void tcp_client_connect_impl(grpc_exec_ctx* exec_ctx, char* addr_str; grpc_error* error; - *ep = NULL; + *ep = nullptr; /* Use dualstack sockets where available. */ if (grpc_sockaddr_to_v4mapped(addr, &addr6_v4mapped)) { @@ -296,7 +296,7 @@ static void tcp_client_connect_impl(grpc_exec_ctx* exec_ctx, } if (errno != EWOULDBLOCK && errno != EINPROGRESS) { - grpc_fd_orphan(exec_ctx, fdobj, NULL, NULL, false /* already_closed */, + grpc_fd_orphan(exec_ctx, fdobj, nullptr, nullptr, false /* already_closed */, "tcp_client_connect_error"); GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_OS_ERROR(errno, "connect")); goto done; @@ -310,7 +310,7 @@ static void tcp_client_connect_impl(grpc_exec_ctx* exec_ctx, ac->fd = fdobj; ac->interested_parties = interested_parties; ac->addr_str = addr_str; - addr_str = NULL; + addr_str = nullptr; gpr_mu_init(&ac->mu); ac->refs = 2; GRPC_CLOSURE_INIT(&ac->write_closure, on_writable, ac, diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index fbbb1762b7..104d233c15 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -139,7 +139,7 @@ static void run_poller(grpc_exec_ctx* exec_ctx, void* bp, GRPC_STATS_INC_TCP_BACKUP_POLLER_POLLS(exec_ctx); GRPC_LOG_IF_ERROR( "backup_poller:pollset_work", - grpc_pollset_work(exec_ctx, BACKUP_POLLER_POLLSET(p), NULL, deadline)); + grpc_pollset_work(exec_ctx, BACKUP_POLLER_POLLSET(p), nullptr, deadline)); gpr_mu_unlock(p->pollset_mu); /* last "uncovered" notification is the ref that keeps us polling, if we get * there try a cas to release it */ @@ -198,7 +198,7 @@ static void cover_self(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { grpc_executor_scheduler(GRPC_EXECUTOR_LONG)), GRPC_ERROR_NONE); } else { - while ((p = (backup_poller*)gpr_atm_acq_load(&g_backup_poller)) == NULL) { + while ((p = (backup_poller*)gpr_atm_acq_load(&g_backup_poller)) == nullptr) { // spin waiting for backup poller } } @@ -368,8 +368,8 @@ static void call_read_cb(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, } } - tcp->read_cb = NULL; - tcp->incoming_buffer = NULL; + tcp->read_cb = nullptr; + tcp->incoming_buffer = nullptr; GRPC_CLOSURE_RUN(exec_ctx, cb, error); } @@ -389,11 +389,11 @@ static void tcp_do_read(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { iov[i].iov_len = GRPC_SLICE_LENGTH(tcp->incoming_buffer->slices[i]); } - msg.msg_name = NULL; + msg.msg_name = nullptr; msg.msg_namelen = 0; msg.msg_iov = iov; msg.msg_iovlen = (msg_iovlen_type)tcp->incoming_buffer->count; - msg.msg_control = NULL; + msg.msg_control = nullptr; msg.msg_controllen = 0; msg.msg_flags = 0; @@ -504,7 +504,7 @@ static void tcp_handle_read(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, static void tcp_read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, grpc_slice_buffer* incoming_buffer, grpc_closure* cb) { grpc_tcp* tcp = (grpc_tcp*)ep; - GPR_ASSERT(tcp->read_cb == NULL); + GPR_ASSERT(tcp->read_cb == nullptr); tcp->read_cb = cb; tcp->incoming_buffer = incoming_buffer; grpc_slice_buffer_reset_and_unref_internal(exec_ctx, incoming_buffer); @@ -552,11 +552,11 @@ static bool tcp_flush(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp, } GPR_ASSERT(iov_size > 0); - msg.msg_name = NULL; + msg.msg_name = nullptr; msg.msg_namelen = 0; msg.msg_iov = iov; msg.msg_iovlen = iov_size; - msg.msg_control = NULL; + msg.msg_control = nullptr; msg.msg_controllen = 0; msg.msg_flags = 0; @@ -617,7 +617,7 @@ static void tcp_handle_write(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, if (error != GRPC_ERROR_NONE) { cb = tcp->write_cb; - tcp->write_cb = NULL; + tcp->write_cb = nullptr; cb->cb(exec_ctx, cb->cb_arg, error); TCP_UNREF(exec_ctx, tcp, "write"); return; @@ -630,7 +630,7 @@ static void tcp_handle_write(grpc_exec_ctx* exec_ctx, void* arg /* grpc_tcp */, notify_on_write(exec_ctx, tcp); } else { cb = tcp->write_cb; - tcp->write_cb = NULL; + tcp->write_cb = nullptr; if (GRPC_TRACER_ON(grpc_tcp_trace)) { const char* str = grpc_error_string(error); gpr_log(GPR_DEBUG, "write: %s", str); @@ -658,7 +658,7 @@ static void tcp_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, } GPR_TIMER_BEGIN("tcp_write", 0); - GPR_ASSERT(tcp->write_cb == NULL); + GPR_ASSERT(tcp->write_cb == nullptr); if (buf->length == 0) { GPR_TIMER_END("tcp_write", 0); @@ -745,8 +745,8 @@ grpc_endpoint* grpc_tcp_create(grpc_exec_ctx* exec_ctx, grpc_fd* em_fd, int tcp_read_chunk_size = GRPC_TCP_DEFAULT_READ_SLICE_SIZE; int tcp_max_read_chunk_size = 4 * 1024 * 1024; int tcp_min_read_chunk_size = 256; - grpc_resource_quota* resource_quota = grpc_resource_quota_create(NULL); - if (channel_args != NULL) { + grpc_resource_quota* resource_quota = grpc_resource_quota_create(nullptr); + if (channel_args != nullptr) { for (size_t i = 0; i < channel_args->num_args; i++) { if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_TCP_READ_CHUNK_SIZE)) { @@ -785,11 +785,11 @@ grpc_endpoint* grpc_tcp_create(grpc_exec_ctx* exec_ctx, grpc_fd* em_fd, tcp->base.vtable = &vtable; tcp->peer_string = gpr_strdup(peer_string); tcp->fd = grpc_fd_wrapped_fd(em_fd); - tcp->read_cb = NULL; - tcp->write_cb = NULL; - tcp->release_fd_cb = NULL; - tcp->release_fd = NULL; - tcp->incoming_buffer = NULL; + tcp->read_cb = nullptr; + tcp->write_cb = nullptr; + tcp->release_fd_cb = nullptr; + tcp->release_fd = nullptr; + tcp->incoming_buffer = nullptr; tcp->target_length = (double)tcp_read_chunk_size; tcp->min_read_chunk_size = tcp_min_read_chunk_size; tcp->max_read_chunk_size = tcp_max_read_chunk_size; diff --git a/src/core/lib/iomgr/tcp_server_posix.cc b/src/core/lib/iomgr/tcp_server_posix.cc index 6fcbac03a2..f84fa9751d 100644 --- a/src/core/lib/iomgr/tcp_server_posix.cc +++ b/src/core/lib/iomgr/tcp_server_posix.cc @@ -77,7 +77,7 @@ grpc_error* grpc_tcp_server_create(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s = (grpc_tcp_server*)gpr_zalloc(sizeof(grpc_tcp_server)); s->so_reuseport = has_so_reuseport; s->expand_wildcard_addrs = false; - for (size_t i = 0; i < (args == NULL ? 0 : args->num_args); i++) { + for (size_t i = 0; i < (args == nullptr ? 0 : args->num_args); i++) { if (0 == strcmp(GRPC_ARG_ALLOW_REUSEPORT, args->args[i].key)) { if (args->args[i].type == GRPC_ARG_INTEGER) { s->so_reuseport = @@ -102,13 +102,13 @@ grpc_error* grpc_tcp_server_create(grpc_exec_ctx* exec_ctx, s->active_ports = 0; s->destroyed_ports = 0; s->shutdown = false; - s->shutdown_starting.head = NULL; - s->shutdown_starting.tail = NULL; + s->shutdown_starting.head = nullptr; + s->shutdown_starting.tail = nullptr; s->shutdown_complete = shutdown_complete; - s->on_accept_cb = NULL; - s->on_accept_cb_arg = NULL; - s->head = NULL; - s->tail = NULL; + s->on_accept_cb = nullptr; + s->on_accept_cb_arg = nullptr; + s->head = nullptr; + s->tail = nullptr; s->nports = 0; s->channel_args = grpc_channel_args_copy(args); gpr_atm_no_barrier_store(&s->next_pollset_to_assign, 0); @@ -120,7 +120,7 @@ static void finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { gpr_mu_lock(&s->mu); GPR_ASSERT(s->shutdown); gpr_mu_unlock(&s->mu); - if (s->shutdown_complete != NULL) { + if (s->shutdown_complete != nullptr) { GRPC_CLOSURE_SCHED(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE); } @@ -165,7 +165,7 @@ static void deactivated_all_ports(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s) { grpc_unlink_if_unix_domain_socket(&sp->addr); GRPC_CLOSURE_INIT(&sp->destroyed_closure, destroyed_port, s, grpc_schedule_on_exec_ctx); - grpc_fd_orphan(exec_ctx, sp->emfd, &sp->destroyed_closure, NULL, + grpc_fd_orphan(exec_ctx, sp->emfd, &sp->destroyed_closure, nullptr, false /* already_closed */, "tcp_listener_shutdown"); } gpr_mu_unlock(&s->mu); @@ -288,8 +288,8 @@ static grpc_error* add_wildcard_addrs_to_server(grpc_tcp_server* s, grpc_resolved_address wild6; unsigned fd_index = 0; grpc_dualstack_mode dsmode; - grpc_tcp_listener* sp = NULL; - grpc_tcp_listener* sp2 = NULL; + grpc_tcp_listener* sp = nullptr; + grpc_tcp_listener* sp2 = nullptr; grpc_error* v6_err = GRPC_ERROR_NONE; grpc_error* v4_err = GRPC_ERROR_NONE; *out_port = -1; @@ -314,7 +314,7 @@ static grpc_error* add_wildcard_addrs_to_server(grpc_tcp_server* s, if ((v4_err = grpc_tcp_server_add_addr(s, &wild4, port_index, fd_index, &dsmode, &sp2)) == GRPC_ERROR_NONE) { *out_port = sp2->port; - if (sp != NULL) { + if (sp != nullptr) { sp2->is_sibling = 1; sp->sibling = sp2; } @@ -346,7 +346,7 @@ static grpc_error* add_wildcard_addrs_to_server(grpc_tcp_server* s, } static grpc_error* clone_port(grpc_tcp_listener* listener, unsigned count) { - grpc_tcp_listener* sp = NULL; + grpc_tcp_listener* sp = nullptr; char* addr_str; char* name; grpc_error* err; @@ -383,7 +383,7 @@ static grpc_error* clone_port(grpc_tcp_listener* listener, unsigned count) { sp->port_index = listener->port_index; sp->fd_index = listener->fd_index + count - i; GPR_ASSERT(sp->emfd); - while (listener->server->tail->next != NULL) { + while (listener->server->tail->next != nullptr) { listener->server->tail = listener->server->tail->next; } gpr_free(addr_str); @@ -404,7 +404,7 @@ grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, grpc_dualstack_mode dsmode; grpc_error* err; *out_port = -1; - if (s->tail != NULL) { + if (s->tail != nullptr) { port_index = s->tail->port_index + 1; } grpc_unlink_if_unix_domain_socket(addr); @@ -454,7 +454,7 @@ static grpc_tcp_listener* get_port_index(grpc_tcp_server* s, } } } - return NULL; + return nullptr; } unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server* s, @@ -498,7 +498,7 @@ void grpc_tcp_server_start(grpc_exec_ctx* exec_ctx, grpc_tcp_server* s, s->pollsets = pollsets; s->pollset_count = pollset_count; sp = s->head; - while (sp != NULL) { + while (sp != nullptr) { if (s->so_reuseport && !grpc_is_unix_socket(&sp->addr) && pollset_count > 1) { GPR_ASSERT(GRPC_LOG_IF_ERROR( diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc index 51e6731729..72443cc29e 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc @@ -47,7 +47,7 @@ static void init_max_accept_queue_size(void) { int n = SOMAXCONN; char buf[64]; FILE* fp = fopen("/proc/sys/net/core/somaxconn", "r"); - if (fp == NULL) { + if (fp == nullptr) { /* 2.4 kernel. */ s_max_accept_queue_size = SOMAXCONN; return; @@ -79,7 +79,7 @@ static grpc_error* add_socket_to_server(grpc_tcp_server* s, int fd, const grpc_resolved_address* addr, unsigned port_index, unsigned fd_index, grpc_tcp_listener** listener) { - grpc_tcp_listener* sp = NULL; + grpc_tcp_listener* sp = nullptr; int port = -1; char* addr_str; char* name; @@ -94,8 +94,8 @@ static grpc_error* add_socket_to_server(grpc_tcp_server* s, int fd, s->nports++; GPR_ASSERT(!s->on_accept_cb && "must add ports before starting server"); sp = (grpc_tcp_listener*)gpr_malloc(sizeof(grpc_tcp_listener)); - sp->next = NULL; - if (s->head == NULL) { + sp->next = nullptr; + if (s->head == nullptr) { s->head = sp; } else { s->tail->next = sp; @@ -109,7 +109,7 @@ static grpc_error* add_socket_to_server(grpc_tcp_server* s, int fd, sp->port_index = port_index; sp->fd_index = fd_index; sp->is_sibling = 0; - sp->sibling = NULL; + sp->sibling = nullptr; GPR_ASSERT(sp->emfd); gpr_mu_unlock(&s->mu); gpr_free(addr_str); diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc index b7437dbf4d..227bf94aa7 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc @@ -40,7 +40,7 @@ static grpc_tcp_listener* find_listener_with_addr(grpc_tcp_server* s, grpc_resolved_address* addr) { grpc_tcp_listener* l; gpr_mu_lock(&s->mu); - for (l = s->head; l != NULL; l = l->next) { + for (l = s->head; l != nullptr; l = l->next) { if (l->addr.len != addr->len) { continue; } @@ -87,10 +87,10 @@ grpc_error* grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, unsigned port_index, int requested_port, int* out_port) { - struct ifaddrs* ifa = NULL; + struct ifaddrs* ifa = nullptr; struct ifaddrs* ifa_it; unsigned fd_index = 0; - grpc_tcp_listener* sp = NULL; + grpc_tcp_listener* sp = nullptr; grpc_error* err = GRPC_ERROR_NONE; if (requested_port == 0) { /* Note: There could be a race where some local addrs can listen on the @@ -104,16 +104,16 @@ grpc_error* grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, } gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port); } - if (getifaddrs(&ifa) != 0 || ifa == NULL) { + if (getifaddrs(&ifa) != 0 || ifa == nullptr) { return GRPC_OS_ERROR(errno, "getifaddrs"); } - for (ifa_it = ifa; ifa_it != NULL; ifa_it = ifa_it->ifa_next) { + for (ifa_it = ifa; ifa_it != nullptr; ifa_it = ifa_it->ifa_next) { grpc_resolved_address addr; - char* addr_str = NULL; + char* addr_str = nullptr; grpc_dualstack_mode dsmode; - grpc_tcp_listener* new_sp = NULL; + grpc_tcp_listener* new_sp = nullptr; const char* ifa_name = (ifa_it->ifa_name ? ifa_it->ifa_name : "<unknown>"); - if (ifa_it->ifa_addr == NULL) { + if (ifa_it->ifa_addr == nullptr) { continue; } else if (ifa_it->ifa_addr->sa_family == AF_INET) { addr.len = sizeof(struct sockaddr_in); @@ -136,7 +136,7 @@ grpc_error* grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, ifa_name, ifa_it->ifa_flags, addr_str); /* We could have multiple interfaces with the same address (e.g., bonding), so look for duplicates. */ - if (find_listener_with_addr(s, &addr) != NULL) { + if (find_listener_with_addr(s, &addr) != nullptr) { gpr_log(GPR_DEBUG, "Skipping duplicate addr %s on interface %s", addr_str, ifa_name); gpr_free(addr_str); @@ -144,7 +144,7 @@ grpc_error* grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, } if ((err = grpc_tcp_server_add_addr(s, &addr, port_index, fd_index, &dsmode, &new_sp)) != GRPC_ERROR_NONE) { - char* err_str = NULL; + char* err_str = nullptr; grpc_error* root_err; if (gpr_asprintf(&err_str, "Failed to add listener: %s", addr_str) < 0) { err_str = gpr_strdup("Failed to add listener"); @@ -157,7 +157,7 @@ grpc_error* grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, } else { GPR_ASSERT(requested_port == new_sp->port); ++fd_index; - if (sp != NULL) { + if (sp != nullptr) { new_sp->is_sibling = 1; sp->sibling = new_sp; } @@ -168,7 +168,7 @@ grpc_error* grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, freeifaddrs(ifa); if (err != GRPC_ERROR_NONE) { return err; - } else if (sp == NULL) { + } else if (sp == nullptr) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No local addresses"); } else { *out_port = sp->port; diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index 2333f180d4..7996777c3c 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -90,7 +90,7 @@ static timer_shard* g_shard_queue[NUM_SHARDS]; #define NUM_HASH_BUCKETS 1009 /* Prime number close to 1000 */ static gpr_mu g_hash_mu[NUM_HASH_BUCKETS]; /* One mutex per bucket */ -static grpc_timer* g_timer_ht[NUM_HASH_BUCKETS] = {NULL}; +static grpc_timer* g_timer_ht[NUM_HASH_BUCKETS] = {nullptr}; static void init_timer_ht() { for (int i = 0; i < NUM_HASH_BUCKETS; i++) { @@ -103,7 +103,7 @@ static bool is_in_ht(grpc_timer* t) { gpr_mu_lock(&g_hash_mu[i]); grpc_timer* p = g_timer_ht[i]; - while (p != NULL && p != t) { + while (p != nullptr && p != t) { p = p->hash_table_next; } gpr_mu_unlock(&g_hash_mu[i]); @@ -117,7 +117,7 @@ static void add_to_ht(grpc_timer* t) { gpr_mu_lock(&g_hash_mu[i]); grpc_timer* p = g_timer_ht[i]; - while (p != NULL && p != t) { + while (p != nullptr && p != t) { p = p->hash_table_next; } @@ -145,9 +145,9 @@ static void remove_from_ht(grpc_timer* t) { if (g_timer_ht[i] == t) { g_timer_ht[i] = g_timer_ht[i]->hash_table_next; removed = true; - } else if (g_timer_ht[i] != NULL) { + } else if (g_timer_ht[i] != nullptr) { grpc_timer* p = g_timer_ht[i]; - while (p->hash_table_next != NULL && p->hash_table_next != t) { + while (p->hash_table_next != nullptr && p->hash_table_next != t) { p = p->hash_table_next; } @@ -168,7 +168,7 @@ static void remove_from_ht(grpc_timer* t) { abort(); } - t->hash_table_next = NULL; + t->hash_table_next = nullptr; } /* If a timer is added to a timer shard (either heap or a list), it cannot @@ -269,7 +269,7 @@ void grpc_timer_list_init(grpc_exec_ctx* exec_ctx) { void grpc_timer_list_shutdown(grpc_exec_ctx* exec_ctx) { int i; run_some_expired_timers( - exec_ctx, GPR_ATM_MAX, NULL, + exec_ctx, GPR_ATM_MAX, nullptr, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Timer list shutdown")); for (i = 0; i < NUM_SHARDS; i++) { timer_shard* shard = &g_shards[i]; @@ -328,7 +328,7 @@ void grpc_timer_init(grpc_exec_ctx* exec_ctx, grpc_timer* timer, timer->deadline = deadline; #ifndef NDEBUG - timer->hash_table_next = NULL; + timer->hash_table_next = nullptr; #endif if (GRPC_TRACER_ON(grpc_timer_trace)) { @@ -491,8 +491,8 @@ static grpc_timer* pop_one(timer_shard* shard, gpr_atm now) { grpc_timer_heap_is_empty(&shard->heap) ? "true" : "false"); } if (grpc_timer_heap_is_empty(&shard->heap)) { - if (now < shard->queue_deadline_cap) return NULL; - if (!refill_heap(shard, now)) return NULL; + if (now < shard->queue_deadline_cap) return nullptr; + if (!refill_heap(shard, now)) return nullptr; } timer = grpc_timer_heap_top(&shard->heap); if (GRPC_TRACER_ON(grpc_timer_check_trace)) { @@ -500,7 +500,7 @@ static grpc_timer* pop_one(timer_shard* shard, gpr_atm now) { " .. check top timer deadline=%" PRIdPTR " now=%" PRIdPTR, timer->deadline, now); } - if (timer->deadline > now) return NULL; + if (timer->deadline > now) return nullptr; if (GRPC_TRACER_ON(grpc_timer_trace)) { gpr_log(GPR_DEBUG, "TIMER %p: FIRE %" PRIdPTR "ms late via %s scheduler", timer, now - timer->deadline, @@ -542,7 +542,7 @@ static grpc_timer_check_result run_some_expired_timers(grpc_exec_ctx* exec_ctx, gpr_atm min_timer = gpr_atm_no_barrier_load(&g_shared_mutables.min_timer); gpr_tls_set(&g_last_seen_min_timer, min_timer); if (now < min_timer) { - if (next != NULL) *next = GPR_MIN(*next, min_timer); + if (next != nullptr) *next = GPR_MIN(*next, min_timer); return GRPC_TIMERS_CHECKED_AND_EMPTY; } @@ -610,7 +610,7 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, mutable cacheline in the common case */ grpc_millis min_timer = gpr_tls_get(&g_last_seen_min_timer); if (now < min_timer) { - if (next != NULL) { + if (next != nullptr) { *next = GPR_MIN(*next, min_timer); } if (GRPC_TRACER_ON(grpc_timer_check_trace)) { @@ -629,7 +629,7 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, // tracing if (GRPC_TRACER_ON(grpc_timer_check_trace)) { char* next_str; - if (next == NULL) { + if (next == nullptr) { next_str = gpr_strdup("NULL"); } else { gpr_asprintf(&next_str, "%" PRIdPTR, *next); @@ -647,7 +647,7 @@ grpc_timer_check_result grpc_timer_check(grpc_exec_ctx* exec_ctx, // tracing if (GRPC_TRACER_ON(grpc_timer_check_trace)) { char* next_str; - if (next == NULL) { + if (next == nullptr) { next_str = gpr_strdup("NULL"); } else { gpr_asprintf(&next_str, "%" PRIdPTR, *next); diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 16e9e7e707..a0ed6e029e 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -62,11 +62,11 @@ static uint64_t g_timed_waiter_generation; static void timer_thread(void* completed_thread_ptr); static void gc_completed_threads(void) { - if (g_completed_threads != NULL) { + if (g_completed_threads != nullptr) { completed_thread* to_gc = g_completed_threads; - g_completed_threads = NULL; + g_completed_threads = nullptr; gpr_mu_unlock(&g_mu); - while (to_gc != NULL) { + while (to_gc != nullptr) { gpr_thd_join(to_gc->t); completed_thread* next = to_gc->next; gpr_free(to_gc); @@ -275,7 +275,7 @@ static void timer_thread(void* completed_thread_ptr) { // this threads exec_ctx: we try to run things through to completion here // since it's easy to spin up new threads grpc_exec_ctx exec_ctx = - GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, NULL); + GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, nullptr); timer_main_loop(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx); timer_thread_cleanup((completed_thread*)completed_thread_ptr); @@ -299,7 +299,7 @@ void grpc_timer_manager_init(void) { g_threaded = false; g_thread_count = 0; g_waiter_count = 0; - g_completed_threads = NULL; + g_completed_threads = nullptr; g_has_timed_waiter = false; g_timed_waiter_deadline = GRPC_MILLIS_INF_FUTURE; diff --git a/src/core/lib/iomgr/udp_server.cc b/src/core/lib/iomgr/udp_server.cc index 8ce8b961ff..28f53f4fbf 100644 --- a/src/core/lib/iomgr/udp_server.cc +++ b/src/core/lib/iomgr/udp_server.cc @@ -121,7 +121,7 @@ static grpc_socket_factory* get_socket_factory(const grpc_channel_args* args) { return (grpc_socket_factory*)arg->value.pointer.p; } } - return NULL; + return nullptr; } grpc_udp_server* grpc_udp_server_create(const grpc_channel_args* args) { @@ -134,8 +134,8 @@ grpc_udp_server* grpc_udp_server_create(const grpc_channel_args* args) { s->active_ports = 0; s->destroyed_ports = 0; s->shutdown = 0; - s->head = NULL; - s->tail = NULL; + s->head = nullptr; + s->tail = nullptr; s->nports = 0; return s; @@ -155,7 +155,7 @@ static void dummy_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { } static void finish_shutdown(grpc_exec_ctx* exec_ctx, grpc_udp_server* s) { - if (s->shutdown_complete != NULL) { + if (s->shutdown_complete != nullptr) { GRPC_CLOSURE_SCHED(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE); } @@ -213,7 +213,7 @@ static void deactivated_all_ports(grpc_exec_ctx* exec_ctx, grpc_udp_server* s) { sp->orphan_cb(exec_ctx, sp->emfd, &sp->orphan_fd_closure, sp->server->user_data); } - grpc_fd_orphan(exec_ctx, sp->emfd, &sp->destroyed_closure, NULL, + grpc_fd_orphan(exec_ctx, sp->emfd, &sp->destroyed_closure, nullptr, false /* already_closed */, "udp_listener_shutdown"); } gpr_mu_unlock(&s->mu); @@ -256,7 +256,7 @@ void grpc_udp_server_destroy(grpc_exec_ctx* exec_ctx, grpc_udp_server* s, static int bind_socket(grpc_socket_factory* socket_factory, int sockfd, const grpc_resolved_address* addr) { - return (socket_factory != NULL) + return (socket_factory != nullptr) ? grpc_socket_factory_bind(socket_factory, sockfd, addr) : bind(sockfd, (struct sockaddr*)addr->addr, (socklen_t)addr->len); } @@ -394,8 +394,8 @@ static int add_socket_to_server(grpc_udp_server* s, int fd, gpr_mu_lock(&s->mu); s->nports++; sp = (grpc_udp_listener*)gpr_malloc(sizeof(grpc_udp_listener)); - sp->next = NULL; - if (s->head == NULL) { + sp->next = nullptr; + if (s->head == nullptr) { s->head = sp; } else { s->tail->next = sp; @@ -431,7 +431,7 @@ int grpc_udp_server_add_port(grpc_udp_server* s, grpc_resolved_address wild4; grpc_resolved_address wild6; grpc_resolved_address addr4_copy; - grpc_resolved_address* allocated_addr = NULL; + grpc_resolved_address* allocated_addr = nullptr; grpc_resolved_address sockname_temp; int port; @@ -522,7 +522,7 @@ void grpc_udp_server_start(grpc_exec_ctx* exec_ctx, grpc_udp_server* s, s->user_data = user_data; sp = s->head; - while (sp != NULL) { + while (sp != nullptr) { for (i = 0; i < pollset_count; i++) { grpc_pollset_add_fd(exec_ctx, pollsets[i], sp->emfd); } diff --git a/src/core/lib/iomgr/unix_sockets_posix.cc b/src/core/lib/iomgr/unix_sockets_posix.cc index 5d3689c38f..154c58e98b 100644 --- a/src/core/lib/iomgr/unix_sockets_posix.cc +++ b/src/core/lib/iomgr/unix_sockets_posix.cc @@ -39,7 +39,7 @@ void grpc_create_socketpair_if_unix(int sv[2]) { grpc_error* grpc_resolve_unix_domain_address(const char* name, grpc_resolved_addresses** addrs) { struct sockaddr_un* un; - if (strlen(name) > GPR_ARRAY_SIZE(((struct sockaddr_un*)0)->sun_path) - 1) { + if (strlen(name) > GPR_ARRAY_SIZE(((struct sockaddr_un*)nullptr)->sun_path) - 1) { char* err_msg; grpc_error* err; gpr_asprintf(&err_msg, @@ -84,7 +84,7 @@ char* grpc_sockaddr_to_uri_unix_if_possible( const grpc_resolved_address* resolved_addr) { const struct sockaddr* addr = (const struct sockaddr*)resolved_addr->addr; if (addr->sa_family != AF_UNIX) { - return NULL; + return nullptr; } char* result; diff --git a/src/core/lib/iomgr/wakeup_fd_cv.cc b/src/core/lib/iomgr/wakeup_fd_cv.cc index 268e0175dd..5c1f16d3fc 100644 --- a/src/core/lib/iomgr/wakeup_fd_cv.cc +++ b/src/core/lib/iomgr/wakeup_fd_cv.cc @@ -46,7 +46,7 @@ static grpc_error* cv_fd_init(grpc_wakeup_fd* fd_info) { (fd_node*)gpr_realloc(g_cvfds.cvfds, sizeof(fd_node) * newsize); for (i = g_cvfds.size; i < newsize; i++) { g_cvfds.cvfds[i].is_set = 0; - g_cvfds.cvfds[i].cvs = NULL; + g_cvfds.cvfds[i].cvs = nullptr; g_cvfds.cvfds[i].next_free = g_cvfds.free_fds; g_cvfds.free_fds = &g_cvfds.cvfds[i]; } @@ -55,7 +55,7 @@ static grpc_error* cv_fd_init(grpc_wakeup_fd* fd_info) { idx = (int)(g_cvfds.free_fds - g_cvfds.cvfds); g_cvfds.free_fds = g_cvfds.free_fds->next_free; - g_cvfds.cvfds[idx].cvs = NULL; + g_cvfds.cvfds[idx].cvs = nullptr; g_cvfds.cvfds[idx].is_set = 0; fd_info->read_fd = GRPC_IDX_TO_FD(idx); fd_info->write_fd = -1; diff --git a/src/core/lib/iomgr/wakeup_fd_posix.cc b/src/core/lib/iomgr/wakeup_fd_posix.cc index dcad61b097..e8de208a25 100644 --- a/src/core/lib/iomgr/wakeup_fd_posix.cc +++ b/src/core/lib/iomgr/wakeup_fd_posix.cc @@ -25,7 +25,7 @@ #include "src/core/lib/iomgr/wakeup_fd_pipe.h" #include "src/core/lib/iomgr/wakeup_fd_posix.h" -static const grpc_wakeup_fd_vtable* wakeup_fd_vtable = NULL; +static const grpc_wakeup_fd_vtable* wakeup_fd_vtable = nullptr; int grpc_allow_specialized_wakeup_fd = 1; int grpc_allow_pipe_wakeup_fd = 1; @@ -45,7 +45,7 @@ void grpc_wakeup_fd_global_init(void) { } } -void grpc_wakeup_fd_global_destroy(void) { wakeup_fd_vtable = NULL; } +void grpc_wakeup_fd_global_destroy(void) { wakeup_fd_vtable = nullptr; } int grpc_has_wakeup_fd(void) { return has_real_wakeup_fd; } diff --git a/src/core/lib/json/json_string.cc b/src/core/lib/json/json_string.cc index 8674d72b7e..a339eec81b 100644 --- a/src/core/lib/json/json_string.cc +++ b/src/core/lib/json/json_string.cc @@ -201,7 +201,7 @@ static void json_reader_container_begins(void* userdata, grpc_json_type type) { container = json_create_and_link(userdata, type); state->current_container = container; - state->current_value = NULL; + state->current_value = nullptr; } /* It's important to remember that the reader is mostly stateless, so it @@ -280,13 +280,13 @@ static grpc_json_reader_vtable reader_vtable = { grpc_json* grpc_json_parse_string_with_len(char* input, size_t size) { grpc_json_reader reader; json_reader_userdata state; - grpc_json* json = NULL; + grpc_json* json = nullptr; grpc_json_reader_status status; - if (!input) return NULL; + if (!input) return nullptr; - state.top = state.current_container = state.current_value = NULL; - state.string = state.key = NULL; + state.top = state.current_container = state.current_value = nullptr; + state.string = state.key = nullptr; state.string_ptr = state.input = (uint8_t*)input; state.remaining_input = size; grpc_json_reader_init(&reader, &reader_vtable, &state); @@ -296,7 +296,7 @@ grpc_json* grpc_json_parse_string_with_len(char* input, size_t size) { if ((status != GRPC_JSON_DONE) && json) { grpc_json_destroy(json); - json = NULL; + json = nullptr; } return json; @@ -352,7 +352,7 @@ char* grpc_json_dump_to_string(grpc_json* json, int indent) { grpc_json_writer writer; json_writer_userdata state; - state.output = NULL; + state.output = nullptr; state.free_space = state.string_len = state.allocated = 0; grpc_json_writer_init(&writer, indent, &writer_vtable, &state); diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index b2b90e86e0..36362d95bb 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -39,7 +39,7 @@ grpc_tracer_flag grpc_trace_auth_context_refcount = grpc_call_error grpc_call_set_credentials(grpc_call* call, grpc_call_credentials* creds) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_client_security_context* ctx = NULL; + grpc_client_security_context* ctx = nullptr; GRPC_API_TRACE("grpc_call_set_credentials(call=%p, creds=%p)", 2, (call, creds)); if (!grpc_call_is_client(call)) { @@ -48,7 +48,7 @@ grpc_call_error grpc_call_set_credentials(grpc_call* call, } ctx = (grpc_client_security_context*)grpc_call_context_get( call, GRPC_CONTEXT_SECURITY); - if (ctx == NULL) { + if (ctx == nullptr) { ctx = grpc_client_security_context_create(); ctx->creds = grpc_call_credentials_ref(creds); grpc_call_context_set(call, GRPC_CONTEXT_SECURITY, ctx, @@ -64,7 +64,7 @@ grpc_call_error grpc_call_set_credentials(grpc_call* call, grpc_auth_context* grpc_call_auth_context(grpc_call* call) { void* sec_ctx = grpc_call_context_get(call, GRPC_CONTEXT_SECURITY); GRPC_API_TRACE("grpc_call_auth_context(call=%p)", 1, (call)); - if (sec_ctx == NULL) return NULL; + if (sec_ctx == nullptr) return nullptr; return grpc_call_is_client(call) ? GRPC_AUTH_CONTEXT_REF( ((grpc_client_security_context*)sec_ctx)->auth_context, @@ -91,7 +91,7 @@ void grpc_client_security_context_destroy(void* ctx) { grpc_client_security_context* c = (grpc_client_security_context*)ctx; grpc_call_credentials_unref(&exec_ctx, c->creds); GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "client_security_context"); - if (c->extension.instance != NULL && c->extension.destroy != NULL) { + if (c->extension.instance != nullptr && c->extension.destroy != nullptr) { c->extension.destroy(c->extension.instance); } gpr_free(ctx); @@ -108,7 +108,7 @@ grpc_server_security_context* grpc_server_security_context_create(void) { void grpc_server_security_context_destroy(void* ctx) { grpc_server_security_context* c = (grpc_server_security_context*)ctx; GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "server_security_context"); - if (c->extension.instance != NULL && c->extension.destroy != NULL) { + if (c->extension.instance != nullptr && c->extension.destroy != nullptr) { c->extension.destroy(c->extension.instance); } gpr_free(ctx); @@ -116,13 +116,13 @@ void grpc_server_security_context_destroy(void* ctx) { /* --- grpc_auth_context --- */ -static grpc_auth_property_iterator empty_iterator = {NULL, 0, NULL}; +static grpc_auth_property_iterator empty_iterator = {nullptr, 0, nullptr}; grpc_auth_context* grpc_auth_context_create(grpc_auth_context* chained) { grpc_auth_context* ctx = (grpc_auth_context*)gpr_zalloc(sizeof(grpc_auth_context)); gpr_ref_init(&ctx->refcount, 1); - if (chained != NULL) { + if (chained != nullptr) { ctx->chained = GRPC_AUTH_CONTEXT_REF(chained, "chained"); ctx->peer_identity_property_name = ctx->chained->peer_identity_property_name; @@ -134,7 +134,7 @@ grpc_auth_context* grpc_auth_context_create(grpc_auth_context* chained) { grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* ctx, const char* file, int line, const char* reason) { - if (ctx == NULL) return NULL; + if (ctx == nullptr) return nullptr; if (GRPC_TRACER_ON(grpc_trace_auth_context_refcount)) { gpr_atm val = gpr_atm_no_barrier_load(&ctx->refcount.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -152,7 +152,7 @@ grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* ctx) { #ifndef NDEBUG void grpc_auth_context_unref(grpc_auth_context* ctx, const char* file, int line, const char* reason) { - if (ctx == NULL) return; + if (ctx == nullptr) return; if (GRPC_TRACER_ON(grpc_trace_auth_context_refcount)) { gpr_atm val = gpr_atm_no_barrier_load(&ctx->refcount.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -166,7 +166,7 @@ void grpc_auth_context_unref(grpc_auth_context* ctx) { if (gpr_unref(&ctx->refcount)) { size_t i; GRPC_AUTH_CONTEXT_UNREF(ctx->chained, "chained"); - if (ctx->properties.array != NULL) { + if (ctx->properties.array != nullptr) { for (i = 0; i < ctx->properties.count; i++) { grpc_auth_property_reset(&ctx->properties.array[i]); } @@ -191,9 +191,9 @@ int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context* ctx, GRPC_API_TRACE( "grpc_auth_context_set_peer_identity_property_name(ctx=%p, name=%s)", 2, (ctx, name)); - if (prop == NULL) { + if (prop == nullptr) { gpr_log(GPR_ERROR, "Property name %s not found in auth context.", - name != NULL ? name : "NULL"); + name != nullptr ? name : "NULL"); return 0; } ctx->peer_identity_property_name = prop->name; @@ -202,14 +202,14 @@ int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context* ctx, int grpc_auth_context_peer_is_authenticated(const grpc_auth_context* ctx) { GRPC_API_TRACE("grpc_auth_context_peer_is_authenticated(ctx=%p)", 1, (ctx)); - return ctx->peer_identity_property_name == NULL ? 0 : 1; + return ctx->peer_identity_property_name == nullptr ? 0 : 1; } grpc_auth_property_iterator grpc_auth_context_property_iterator( const grpc_auth_context* ctx) { grpc_auth_property_iterator it = empty_iterator; GRPC_API_TRACE("grpc_auth_context_property_iterator(ctx=%p)", 1, (ctx)); - if (ctx == NULL) return it; + if (ctx == nullptr) return it; it.ctx = ctx; return it; } @@ -217,18 +217,18 @@ grpc_auth_property_iterator grpc_auth_context_property_iterator( const grpc_auth_property* grpc_auth_property_iterator_next( grpc_auth_property_iterator* it) { GRPC_API_TRACE("grpc_auth_property_iterator_next(it=%p)", 1, (it)); - if (it == NULL || it->ctx == NULL) return NULL; + if (it == nullptr || it->ctx == nullptr) return nullptr; while (it->index == it->ctx->properties.count) { - if (it->ctx->chained == NULL) return NULL; + if (it->ctx->chained == nullptr) return nullptr; it->ctx = it->ctx->chained; it->index = 0; } - if (it->name == NULL) { + if (it->name == nullptr) { return &it->ctx->properties.array[it->index++]; } else { while (it->index < it->ctx->properties.count) { const grpc_auth_property* prop = &it->ctx->properties.array[it->index++]; - GPR_ASSERT(prop->name != NULL); + GPR_ASSERT(prop->name != nullptr); if (strcmp(it->name, prop->name) == 0) { return prop; } @@ -243,7 +243,7 @@ grpc_auth_property_iterator grpc_auth_context_find_properties_by_name( grpc_auth_property_iterator it = empty_iterator; GRPC_API_TRACE("grpc_auth_context_find_properties_by_name(ctx=%p, name=%s)", 2, (ctx, name)); - if (ctx == NULL || name == NULL) return empty_iterator; + if (ctx == nullptr || name == nullptr) return empty_iterator; it.ctx = ctx; it.name = name; return it; @@ -252,7 +252,7 @@ grpc_auth_property_iterator grpc_auth_context_find_properties_by_name( grpc_auth_property_iterator grpc_auth_context_peer_identity( const grpc_auth_context* ctx) { GRPC_API_TRACE("grpc_auth_context_peer_identity(ctx=%p)", 1, (ctx)); - if (ctx == NULL) return empty_iterator; + if (ctx == nullptr) return empty_iterator; return grpc_auth_context_find_properties_by_name( ctx, ctx->peer_identity_property_name); } @@ -326,11 +326,11 @@ grpc_arg grpc_auth_context_to_arg(grpc_auth_context* p) { } grpc_auth_context* grpc_auth_context_from_arg(const grpc_arg* arg) { - if (strcmp(arg->key, GRPC_AUTH_CONTEXT_ARG) != 0) return NULL; + if (strcmp(arg->key, GRPC_AUTH_CONTEXT_ARG) != 0) return nullptr; if (arg->type != GRPC_ARG_POINTER) { gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type, GRPC_AUTH_CONTEXT_ARG); - return NULL; + return nullptr; } return (grpc_auth_context*)arg->value.pointer.p; } @@ -338,10 +338,10 @@ grpc_auth_context* grpc_auth_context_from_arg(const grpc_arg* arg) { grpc_auth_context* grpc_find_auth_context_in_args( const grpc_channel_args* args) { size_t i; - if (args == NULL) return NULL; + if (args == nullptr) return nullptr; for (i = 0; i < args->num_args; i++) { grpc_auth_context* p = grpc_auth_context_from_arg(&args->args[i]); - if (p != NULL) return p; + if (p != nullptr) return p; } - return NULL; + return nullptr; } diff --git a/src/core/lib/security/credentials/composite/composite_credentials.cc b/src/core/lib/security/credentials/composite/composite_credentials.cc index 5eb7f9d09e..867b851dc1 100644 --- a/src/core/lib/security/credentials/composite/composite_credentials.cc +++ b/src/core/lib/security/credentials/composite/composite_credentials.cc @@ -144,9 +144,9 @@ grpc_call_credentials* grpc_composite_call_credentials_create( "grpc_composite_call_credentials_create(creds1=%p, creds2=%p, " "reserved=%p)", 3, (creds1, creds2, reserved)); - GPR_ASSERT(reserved == NULL); - GPR_ASSERT(creds1 != NULL); - GPR_ASSERT(creds2 != NULL); + GPR_ASSERT(reserved == nullptr); + GPR_ASSERT(creds1 != nullptr); + GPR_ASSERT(creds2 != nullptr); c = (grpc_composite_call_credentials*)gpr_zalloc( sizeof(grpc_composite_call_credentials)); c->base.type = GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE; @@ -183,19 +183,19 @@ grpc_call_credentials* grpc_credentials_contains_type( grpc_call_credentials** composite_creds) { size_t i; if (strcmp(creds->type, type) == 0) { - if (composite_creds != NULL) *composite_creds = NULL; + if (composite_creds != nullptr) *composite_creds = nullptr; return creds; } else if (strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0) { const grpc_call_credentials_array* inner_creds_array = grpc_composite_call_credentials_get_credentials(creds); for (i = 0; i < inner_creds_array->num_creds; i++) { if (strcmp(type, inner_creds_array->creds_array[i]->type) == 0) { - if (composite_creds != NULL) *composite_creds = creds; + if (composite_creds != nullptr) *composite_creds = creds; return inner_creds_array->creds_array[i]; } } } - return NULL; + return nullptr; } /* -- Composite channel credentials. -- */ @@ -217,14 +217,14 @@ static grpc_security_status composite_channel_create_security_connector( (grpc_composite_channel_credentials*)creds; grpc_security_status status = GRPC_SECURITY_ERROR; - GPR_ASSERT(c->inner_creds != NULL && c->call_creds != NULL && - c->inner_creds->vtable != NULL && - c->inner_creds->vtable->create_security_connector != NULL); + GPR_ASSERT(c->inner_creds != nullptr && c->call_creds != nullptr && + c->inner_creds->vtable != nullptr && + c->inner_creds->vtable->create_security_connector != nullptr); /* If we are passed a call_creds, create a call composite to pass it downstream. */ - if (call_creds != NULL) { + if (call_creds != nullptr) { grpc_call_credentials* composite_call_creds = - grpc_composite_call_credentials_create(c->call_creds, call_creds, NULL); + grpc_composite_call_credentials_create(c->call_creds, call_creds, nullptr); status = c->inner_creds->vtable->create_security_connector( exec_ctx, c->inner_creds, composite_call_creds, target, args, sc, new_args); @@ -253,7 +253,7 @@ grpc_channel_credentials* grpc_composite_channel_credentials_create( void* reserved) { grpc_composite_channel_credentials* c = (grpc_composite_channel_credentials*)gpr_zalloc(sizeof(*c)); - GPR_ASSERT(channel_creds != NULL && call_creds != NULL && reserved == NULL); + GPR_ASSERT(channel_creds != nullptr && call_creds != nullptr && reserved == nullptr); GRPC_API_TRACE( "grpc_composite_channel_credentials_create(channel_creds=%p, " "call_creds=%p, reserved=%p)", diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc index e60d022f1b..b29abdc6aa 100644 --- a/src/core/lib/security/credentials/credentials.cc +++ b/src/core/lib/security/credentials/credentials.cc @@ -55,16 +55,16 @@ void grpc_credentials_metadata_request_destroy( grpc_channel_credentials* grpc_channel_credentials_ref( grpc_channel_credentials* creds) { - if (creds == NULL) return NULL; + if (creds == nullptr) return nullptr; gpr_ref(&creds->refcount); return creds; } void grpc_channel_credentials_unref(grpc_exec_ctx* exec_ctx, grpc_channel_credentials* creds) { - if (creds == NULL) return; + if (creds == nullptr) return; if (gpr_unref(&creds->refcount)) { - if (creds->vtable->destruct != NULL) { + if (creds->vtable->destruct != nullptr) { creds->vtable->destruct(exec_ctx, creds); } gpr_free(creds); @@ -79,16 +79,16 @@ void grpc_channel_credentials_release(grpc_channel_credentials* creds) { } grpc_call_credentials* grpc_call_credentials_ref(grpc_call_credentials* creds) { - if (creds == NULL) return NULL; + if (creds == nullptr) return nullptr; gpr_ref(&creds->refcount); return creds; } void grpc_call_credentials_unref(grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds) { - if (creds == NULL) return; + if (creds == nullptr) return; if (gpr_unref(&creds->refcount)) { - if (creds->vtable->destruct != NULL) { + if (creds->vtable->destruct != nullptr) { creds->vtable->destruct(exec_ctx, creds); } gpr_free(creds); @@ -107,7 +107,7 @@ bool grpc_call_credentials_get_request_metadata( grpc_polling_entity* pollent, grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, grpc_error** error) { - if (creds == NULL || creds->vtable->get_request_metadata == NULL) { + if (creds == nullptr || creds->vtable->get_request_metadata == nullptr) { return true; } return creds->vtable->get_request_metadata( @@ -117,7 +117,7 @@ bool grpc_call_credentials_get_request_metadata( void grpc_call_credentials_cancel_get_request_metadata( grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array, grpc_error* error) { - if (creds == NULL || creds->vtable->cancel_get_request_metadata == NULL) { + if (creds == nullptr || creds->vtable->cancel_get_request_metadata == nullptr) { return; } creds->vtable->cancel_get_request_metadata(exec_ctx, creds, md_array, error); @@ -127,20 +127,20 @@ grpc_security_status grpc_channel_credentials_create_security_connector( grpc_exec_ctx* exec_ctx, grpc_channel_credentials* channel_creds, const char* target, const grpc_channel_args* args, grpc_channel_security_connector** sc, grpc_channel_args** new_args) { - *new_args = NULL; - if (channel_creds == NULL) { + *new_args = nullptr; + if (channel_creds == nullptr) { return GRPC_SECURITY_ERROR; } - GPR_ASSERT(channel_creds->vtable->create_security_connector != NULL); + GPR_ASSERT(channel_creds->vtable->create_security_connector != nullptr); return channel_creds->vtable->create_security_connector( - exec_ctx, channel_creds, NULL, target, args, sc, new_args); + exec_ctx, channel_creds, nullptr, target, args, sc, new_args); } grpc_channel_credentials* grpc_channel_credentials_duplicate_without_call_credentials( grpc_channel_credentials* channel_creds) { - if (channel_creds != NULL && channel_creds->vtable != NULL && - channel_creds->vtable->duplicate_without_call_credentials != NULL) { + if (channel_creds != nullptr && channel_creds->vtable != nullptr && + channel_creds->vtable->duplicate_without_call_credentials != nullptr) { return channel_creds->vtable->duplicate_without_call_credentials( channel_creds); } else { @@ -171,11 +171,11 @@ grpc_arg grpc_channel_credentials_to_arg( grpc_channel_credentials* grpc_channel_credentials_from_arg( const grpc_arg* arg) { - if (strcmp(arg->key, GRPC_ARG_CHANNEL_CREDENTIALS)) return NULL; + if (strcmp(arg->key, GRPC_ARG_CHANNEL_CREDENTIALS)) return nullptr; if (arg->type != GRPC_ARG_POINTER) { gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type, GRPC_ARG_CHANNEL_CREDENTIALS); - return NULL; + return nullptr; } return (grpc_channel_credentials*)arg->value.pointer.p; } @@ -183,30 +183,30 @@ grpc_channel_credentials* grpc_channel_credentials_from_arg( grpc_channel_credentials* grpc_channel_credentials_find_in_args( const grpc_channel_args* args) { size_t i; - if (args == NULL) return NULL; + if (args == nullptr) return nullptr; for (i = 0; i < args->num_args; i++) { grpc_channel_credentials* credentials = grpc_channel_credentials_from_arg(&args->args[i]); - if (credentials != NULL) return credentials; + if (credentials != nullptr) return credentials; } - return NULL; + return nullptr; } grpc_server_credentials* grpc_server_credentials_ref( grpc_server_credentials* creds) { - if (creds == NULL) return NULL; + if (creds == nullptr) return nullptr; gpr_ref(&creds->refcount); return creds; } void grpc_server_credentials_unref(grpc_exec_ctx* exec_ctx, grpc_server_credentials* creds) { - if (creds == NULL) return; + if (creds == nullptr) return; if (gpr_unref(&creds->refcount)) { - if (creds->vtable->destruct != NULL) { + if (creds->vtable->destruct != nullptr) { creds->vtable->destruct(exec_ctx, creds); } - if (creds->processor.destroy != NULL && creds->processor.state != NULL) { + if (creds->processor.destroy != nullptr && creds->processor.state != nullptr) { creds->processor.destroy(creds->processor.state); } gpr_free(creds); @@ -223,7 +223,7 @@ void grpc_server_credentials_release(grpc_server_credentials* creds) { grpc_security_status grpc_server_credentials_create_security_connector( grpc_exec_ctx* exec_ctx, grpc_server_credentials* creds, grpc_server_security_connector** sc) { - if (creds == NULL || creds->vtable->create_security_connector == NULL) { + if (creds == nullptr || creds->vtable->create_security_connector == nullptr) { gpr_log(GPR_ERROR, "Server credentials cannot create security context."); return GRPC_SECURITY_ERROR; } @@ -237,8 +237,8 @@ void grpc_server_credentials_set_auth_metadata_processor( "creds=%p, " "processor=grpc_auth_metadata_processor { process: %p, state: %p })", 3, (creds, (void*)(intptr_t)processor.process, processor.state)); - if (creds == NULL) return; - if (creds->processor.destroy != NULL && creds->processor.state != NULL) { + if (creds == nullptr) return; + if (creds->processor.destroy != nullptr && creds->processor.state != nullptr) { creds->processor.destroy(creds->processor.state); } creds->processor = processor; @@ -267,11 +267,11 @@ grpc_arg grpc_server_credentials_to_arg(grpc_server_credentials* p) { } grpc_server_credentials* grpc_server_credentials_from_arg(const grpc_arg* arg) { - if (strcmp(arg->key, GRPC_SERVER_CREDENTIALS_ARG) != 0) return NULL; + if (strcmp(arg->key, GRPC_SERVER_CREDENTIALS_ARG) != 0) return nullptr; if (arg->type != GRPC_ARG_POINTER) { gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type, GRPC_SERVER_CREDENTIALS_ARG); - return NULL; + return nullptr; } return (grpc_server_credentials*)arg->value.pointer.p; } @@ -279,11 +279,11 @@ grpc_server_credentials* grpc_server_credentials_from_arg(const grpc_arg* arg) { grpc_server_credentials* grpc_find_server_credentials_in_args( const grpc_channel_args* args) { size_t i; - if (args == NULL) return NULL; + if (args == nullptr) return nullptr; for (i = 0; i < args->num_args; i++) { grpc_server_credentials* p = grpc_server_credentials_from_arg(&args->args[i]); - if (p != NULL) return p; + if (p != nullptr) return p; } - return NULL; + return nullptr; } diff --git a/src/core/lib/security/credentials/fake/fake_credentials.cc b/src/core/lib/security/credentials/fake/fake_credentials.cc index 17700f5651..a535a317ee 100644 --- a/src/core/lib/security/credentials/fake/fake_credentials.cc +++ b/src/core/lib/security/credentials/fake/fake_credentials.cc @@ -53,11 +53,11 @@ fake_transport_security_server_create_security_connector( static grpc_channel_credentials_vtable fake_transport_security_credentials_vtable = { - NULL, fake_transport_security_create_security_connector, NULL}; + nullptr, fake_transport_security_create_security_connector, nullptr}; static grpc_server_credentials_vtable fake_transport_security_server_credentials_vtable = { - NULL, fake_transport_security_server_create_security_connector}; + nullptr, fake_transport_security_server_create_security_connector}; grpc_channel_credentials* grpc_fake_transport_security_credentials_create( void) { @@ -89,11 +89,11 @@ const char* grpc_fake_transport_get_expected_targets( const grpc_channel_args* args) { const grpc_arg* expected_target_arg = grpc_channel_args_find(args, GRPC_ARG_FAKE_SECURITY_EXPECTED_TARGETS); - if (expected_target_arg != NULL && + if (expected_target_arg != nullptr && expected_target_arg->type == GRPC_ARG_STRING) { return expected_target_arg->value.string; } - return NULL; + return nullptr; } /* -- Metadata-only test credentials. -- */ diff --git a/src/core/lib/security/credentials/google_default/credentials_generic.cc b/src/core/lib/security/credentials/google_default/credentials_generic.cc index c2a336ff07..58ee080cf3 100644 --- a/src/core/lib/security/credentials/google_default/credentials_generic.cc +++ b/src/core/lib/security/credentials/google_default/credentials_generic.cc @@ -26,12 +26,12 @@ #include "src/core/lib/support/string.h" char* grpc_get_well_known_google_credentials_file_path_impl(void) { - char* result = NULL; + char* result = nullptr; char* base = gpr_getenv(GRPC_GOOGLE_CREDENTIALS_PATH_ENV_VAR); - if (base == NULL) { + if (base == nullptr) { gpr_log(GPR_ERROR, "Could not get " GRPC_GOOGLE_CREDENTIALS_ENV_VAR " environment variable."); - return NULL; + return nullptr; } gpr_asprintf(&result, "%s/%s", base, GRPC_GOOGLE_CREDENTIALS_PATH_SUFFIX); gpr_free(base); diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.cc b/src/core/lib/security/credentials/google_default/google_default_credentials.cc index 3ce19e9a05..b4df1dc116 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.cc +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.cc @@ -43,7 +43,7 @@ /* -- Default credentials. -- */ -static grpc_channel_credentials* default_credentials = NULL; +static grpc_channel_credentials* default_credentials = nullptr; static int compute_engine_detection_done = 0; static gpr_mu g_state_mu; static gpr_mu* g_polling_mu; @@ -81,7 +81,7 @@ static void on_compute_engine_detection_http_response(grpc_exec_ctx* exec_ctx, GRPC_LOG_IF_ERROR( "Pollset kick", grpc_pollset_kick(exec_ctx, - grpc_polling_entity_pollset(&detector->pollent), NULL)); + grpc_polling_entity_pollset(&detector->pollent), nullptr)); gpr_mu_unlock(g_polling_mu); } @@ -128,7 +128,7 @@ static int is_stack_running_on_compute_engine(grpc_exec_ctx* exec_ctx) { called once for the lifetime of the process by the default credentials. */ gpr_mu_lock(g_polling_mu); while (!detector.is_done) { - grpc_pollset_worker* worker = NULL; + grpc_pollset_worker* worker = nullptr; if (!GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(exec_ctx, @@ -147,7 +147,7 @@ static int is_stack_running_on_compute_engine(grpc_exec_ctx* exec_ctx) { grpc_pollset_shutdown(exec_ctx, grpc_polling_entity_pollset(&detector.pollent), &destroy_closure); - g_polling_mu = NULL; + g_polling_mu = nullptr; grpc_exec_ctx_flush(exec_ctx); gpr_free(grpc_polling_entity_pollset(&detector.pollent)); @@ -159,13 +159,13 @@ static int is_stack_running_on_compute_engine(grpc_exec_ctx* exec_ctx) { /* Takes ownership of creds_path if not NULL. */ static grpc_error* create_default_creds_from_path( grpc_exec_ctx* exec_ctx, char* creds_path, grpc_call_credentials** creds) { - grpc_json* json = NULL; + grpc_json* json = nullptr; grpc_auth_json_key key; grpc_auth_refresh_token token; - grpc_call_credentials* result = NULL; + grpc_call_credentials* result = nullptr; grpc_slice creds_data = grpc_empty_slice(); grpc_error* error = GRPC_ERROR_NONE; - if (creds_path == NULL) { + if (creds_path == nullptr) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("creds_path unset"); goto end; } @@ -175,7 +175,7 @@ static grpc_error* create_default_creds_from_path( } json = grpc_json_parse_string_with_len( (char*)GRPC_SLICE_START_PTR(creds_data), GRPC_SLICE_LENGTH(creds_data)); - if (json == NULL) { + if (json == nullptr) { error = grpc_error_set_str( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to parse JSON"), GRPC_ERROR_STR_RAW_BYTES, grpc_slice_ref_internal(creds_data)); @@ -188,7 +188,7 @@ static grpc_error* create_default_creds_from_path( result = grpc_service_account_jwt_access_credentials_create_from_auth_json_key( exec_ctx, key, grpc_max_auth_token_lifetime()); - if (result == NULL) { + if (result == nullptr) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "grpc_service_account_jwt_access_credentials_create_from_auth_json_" "key failed"); @@ -201,7 +201,7 @@ static grpc_error* create_default_creds_from_path( if (grpc_auth_refresh_token_is_valid(&token)) { result = grpc_refresh_token_credentials_create_from_auth_refresh_token(token); - if (result == NULL) { + if (result == nullptr) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "grpc_refresh_token_credentials_create_from_auth_refresh_token " "failed"); @@ -210,17 +210,17 @@ static grpc_error* create_default_creds_from_path( } end: - GPR_ASSERT((result == NULL) + (error == GRPC_ERROR_NONE) == 1); - if (creds_path != NULL) gpr_free(creds_path); + GPR_ASSERT((result == nullptr) + (error == GRPC_ERROR_NONE) == 1); + if (creds_path != nullptr) gpr_free(creds_path); grpc_slice_unref_internal(exec_ctx, creds_data); - if (json != NULL) grpc_json_destroy(json); + if (json != nullptr) grpc_json_destroy(json); *creds = result; return error; } grpc_channel_credentials* grpc_google_default_credentials_create(void) { - grpc_channel_credentials* result = NULL; - grpc_call_credentials* call_creds = NULL; + grpc_channel_credentials* result = nullptr; + grpc_call_credentials* call_creds = nullptr; grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Failed to create Google credentials"); grpc_error* err; @@ -232,7 +232,7 @@ grpc_channel_credentials* grpc_google_default_credentials_create(void) { gpr_mu_lock(&g_state_mu); - if (default_credentials != NULL) { + if (default_credentials != nullptr) { result = grpc_channel_credentials_ref(default_credentials); goto end; } @@ -257,8 +257,8 @@ grpc_channel_credentials* grpc_google_default_credentials_create(void) { is_stack_running_on_compute_engine(&exec_ctx); compute_engine_detection_done = 1; if (need_compute_engine_creds) { - call_creds = grpc_google_compute_engine_credentials_create(NULL); - if (call_creds == NULL) { + call_creds = grpc_google_compute_engine_credentials_create(nullptr); + if (call_creds == nullptr) { error = grpc_error_add_child( error, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Failed to get credentials from network")); @@ -267,17 +267,17 @@ grpc_channel_credentials* grpc_google_default_credentials_create(void) { } end: - if (result == NULL) { - if (call_creds != NULL) { + if (result == nullptr) { + if (call_creds != nullptr) { /* Blend with default ssl credentials and add a global reference so that it can be cached and re-served. */ grpc_channel_credentials* ssl_creds = - grpc_ssl_credentials_create(NULL, NULL, NULL); + grpc_ssl_credentials_create(nullptr, nullptr, nullptr); default_credentials = grpc_channel_credentials_ref( grpc_composite_channel_credentials_create(ssl_creds, call_creds, - NULL)); - GPR_ASSERT(default_credentials != NULL); + nullptr)); + GPR_ASSERT(default_credentials != nullptr); grpc_channel_credentials_unref(&exec_ctx, ssl_creds); grpc_call_credentials_unref(&exec_ctx, call_creds); result = default_credentials; @@ -286,7 +286,7 @@ end: } } gpr_mu_unlock(&g_state_mu); - if (result == NULL) { + if (result == nullptr) { GRPC_LOG_IF_ERROR("grpc_google_default_credentials_create", error); } else { GRPC_ERROR_UNREF(error); @@ -299,9 +299,9 @@ void grpc_flush_cached_google_default_credentials(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; gpr_once_init(&g_once, init_default_credentials); gpr_mu_lock(&g_state_mu); - if (default_credentials != NULL) { + if (default_credentials != nullptr) { grpc_channel_credentials_unref(&exec_ctx, default_credentials); - default_credentials = NULL; + default_credentials = nullptr; } compute_engine_detection_done = 0; gpr_mu_unlock(&g_state_mu); @@ -310,10 +310,10 @@ void grpc_flush_cached_google_default_credentials(void) { /* -- Well known credentials path. -- */ -static grpc_well_known_credentials_path_getter creds_path_getter = NULL; +static grpc_well_known_credentials_path_getter creds_path_getter = nullptr; char* grpc_get_well_known_google_credentials_file_path(void) { - if (creds_path_getter != NULL) return creds_path_getter(); + if (creds_path_getter != nullptr) return creds_path_getter(); return grpc_get_well_known_google_credentials_file_path_impl(); } diff --git a/src/core/lib/security/credentials/iam/iam_credentials.cc b/src/core/lib/security/credentials/iam/iam_credentials.cc index 7410294a20..1741bf3068 100644 --- a/src/core/lib/security/credentials/iam/iam_credentials.cc +++ b/src/core/lib/security/credentials/iam/iam_credentials.cc @@ -61,9 +61,9 @@ grpc_call_credentials* grpc_google_iam_credentials_create( "grpc_iam_credentials_create(token=%s, authority_selector=%s, " "reserved=%p)", 3, (token, authority_selector, reserved)); - GPR_ASSERT(reserved == NULL); - GPR_ASSERT(token != NULL); - GPR_ASSERT(authority_selector != NULL); + GPR_ASSERT(reserved == nullptr); + GPR_ASSERT(token != nullptr); + GPR_ASSERT(authority_selector != nullptr); grpc_google_iam_credentials* c = (grpc_google_iam_credentials*)gpr_zalloc(sizeof(*c)); c->base.type = GRPC_CALL_CREDENTIALS_TYPE_IAM; diff --git a/src/core/lib/security/credentials/jwt/json_token.cc b/src/core/lib/security/credentials/jwt/json_token.cc index e195ec7509..07807201ce 100644 --- a/src/core/lib/security/credentials/jwt/json_token.cc +++ b/src/core/lib/security/credentials/jwt/json_token.cc @@ -52,30 +52,30 @@ gpr_timespec grpc_max_auth_token_lifetime() { /* --- Override for testing. --- */ -static grpc_jwt_encode_and_sign_override g_jwt_encode_and_sign_override = NULL; +static grpc_jwt_encode_and_sign_override g_jwt_encode_and_sign_override = nullptr; /* --- grpc_auth_json_key. --- */ int grpc_auth_json_key_is_valid(const grpc_auth_json_key* json_key) { - return (json_key != NULL) && + return (json_key != nullptr) && strcmp(json_key->type, GRPC_AUTH_JSON_TYPE_INVALID); } grpc_auth_json_key grpc_auth_json_key_create_from_json(const grpc_json* json) { grpc_auth_json_key result; - BIO* bio = NULL; + BIO* bio = nullptr; const char* prop_value; int success = 0; memset(&result, 0, sizeof(grpc_auth_json_key)); result.type = GRPC_AUTH_JSON_TYPE_INVALID; - if (json == NULL) { + if (json == nullptr) { gpr_log(GPR_ERROR, "Invalid json."); goto end; } prop_value = grpc_json_get_string_property(json, "type"); - if (prop_value == NULL || + if (prop_value == nullptr || strcmp(prop_value, GRPC_AUTH_JSON_TYPE_SERVICE_ACCOUNT)) { goto end; } @@ -90,7 +90,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const grpc_json* json) { } prop_value = grpc_json_get_string_property(json, "private_key"); - if (prop_value == NULL) { + if (prop_value == nullptr) { goto end; } bio = BIO_new(BIO_s_mem()); @@ -99,15 +99,15 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const grpc_json* json) { gpr_log(GPR_ERROR, "Could not write into openssl BIO."); goto end; } - result.private_key = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, (void*)""); - if (result.private_key == NULL) { + result.private_key = PEM_read_bio_RSAPrivateKey(bio, nullptr, nullptr, (void*)""); + if (result.private_key == nullptr) { gpr_log(GPR_ERROR, "Could not deserialize private key."); goto end; } success = 1; end: - if (bio != NULL) BIO_free(bio); + if (bio != nullptr) BIO_free(bio); if (!success) grpc_auth_json_key_destruct(&result); return result; } @@ -117,29 +117,29 @@ grpc_auth_json_key grpc_auth_json_key_create_from_string( char* scratchpad = gpr_strdup(json_string); grpc_json* json = grpc_json_parse_string(scratchpad); grpc_auth_json_key result = grpc_auth_json_key_create_from_json(json); - if (json != NULL) grpc_json_destroy(json); + if (json != nullptr) grpc_json_destroy(json); gpr_free(scratchpad); return result; } void grpc_auth_json_key_destruct(grpc_auth_json_key* json_key) { - if (json_key == NULL) return; + if (json_key == nullptr) return; json_key->type = GRPC_AUTH_JSON_TYPE_INVALID; - if (json_key->client_id != NULL) { + if (json_key->client_id != nullptr) { gpr_free(json_key->client_id); - json_key->client_id = NULL; + json_key->client_id = nullptr; } - if (json_key->private_key_id != NULL) { + if (json_key->private_key_id != nullptr) { gpr_free(json_key->private_key_id); - json_key->private_key_id = NULL; + json_key->private_key_id = nullptr; } - if (json_key->client_email != NULL) { + if (json_key->client_email != nullptr) { gpr_free(json_key->client_email); - json_key->client_email = NULL; + json_key->client_email = nullptr; } - if (json_key->private_key != NULL) { + if (json_key->private_key != nullptr) { RSA_free(json_key->private_key); - json_key->private_key = NULL; + json_key->private_key = nullptr; } } @@ -159,11 +159,11 @@ static grpc_json* create_child(grpc_json* brother, grpc_json* parent, static char* encoded_jwt_header(const char* key_id, const char* algorithm) { grpc_json* json = grpc_json_create(GRPC_JSON_OBJECT); - grpc_json* child = NULL; - char* json_str = NULL; - char* result = NULL; + grpc_json* child = nullptr; + char* json_str = nullptr; + char* result = nullptr; - child = create_child(NULL, json, "alg", algorithm, GRPC_JSON_STRING); + child = create_child(nullptr, json, "alg", algorithm, GRPC_JSON_STRING); child = create_child(child, json, "typ", GRPC_JWT_TYPE, GRPC_JSON_STRING); create_child(child, json, "kid", key_id, GRPC_JSON_STRING); @@ -178,9 +178,9 @@ static char* encoded_jwt_claim(const grpc_auth_json_key* json_key, const char* audience, gpr_timespec token_lifetime, const char* scope) { grpc_json* json = grpc_json_create(GRPC_JSON_OBJECT); - grpc_json* child = NULL; - char* json_str = NULL; - char* result = NULL; + grpc_json* child = nullptr; + char* json_str = nullptr; + char* result = nullptr; gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec expiration = gpr_time_add(now, token_lifetime); char now_str[GPR_LTOA_MIN_BUFSIZE]; @@ -193,8 +193,8 @@ static char* encoded_jwt_claim(const grpc_auth_json_key* json_key, int64_ttoa(expiration.tv_sec, expiration_str); child = - create_child(NULL, json, "iss", json_key->client_email, GRPC_JSON_STRING); - if (scope != NULL) { + create_child(nullptr, json, "iss", json_key->client_email, GRPC_JSON_STRING); + if (scope != nullptr) { child = create_child(child, json, "scope", scope, GRPC_JSON_STRING); } else { /* Unscoped JWTs need a sub field. */ @@ -237,7 +237,7 @@ const EVP_MD* openssl_digest_from_algorithm(const char* algorithm) { return EVP_sha256(); } else { gpr_log(GPR_ERROR, "Unknown algorithm %s.", algorithm); - return NULL; + return nullptr; } } @@ -245,19 +245,19 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key, const char* signature_algorithm, const char* to_sign) { const EVP_MD* md = openssl_digest_from_algorithm(signature_algorithm); - EVP_MD_CTX* md_ctx = NULL; + EVP_MD_CTX* md_ctx = nullptr; EVP_PKEY* key = EVP_PKEY_new(); size_t sig_len = 0; - unsigned char* sig = NULL; - char* result = NULL; - if (md == NULL) return NULL; + unsigned char* sig = nullptr; + char* result = nullptr; + if (md == nullptr) return nullptr; md_ctx = EVP_MD_CTX_create(); - if (md_ctx == NULL) { + if (md_ctx == nullptr) { gpr_log(GPR_ERROR, "Could not create MD_CTX"); goto end; } EVP_PKEY_set1_RSA(key, json_key->private_key); - if (EVP_DigestSignInit(md_ctx, NULL, md, NULL, key) != 1) { + if (EVP_DigestSignInit(md_ctx, nullptr, md, nullptr, key) != 1) { gpr_log(GPR_ERROR, "DigestInit failed."); goto end; } @@ -265,7 +265,7 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key, gpr_log(GPR_ERROR, "DigestUpdate failed."); goto end; } - if (EVP_DigestSignFinal(md_ctx, NULL, &sig_len) != 1) { + if (EVP_DigestSignFinal(md_ctx, nullptr, &sig_len) != 1) { gpr_log(GPR_ERROR, "DigestFinal (get signature length) failed."); goto end; } @@ -277,16 +277,16 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key, result = grpc_base64_encode(sig, sig_len, 1, 0); end: - if (key != NULL) EVP_PKEY_free(key); - if (md_ctx != NULL) EVP_MD_CTX_destroy(md_ctx); - if (sig != NULL) gpr_free(sig); + if (key != nullptr) EVP_PKEY_free(key); + if (md_ctx != nullptr) EVP_MD_CTX_destroy(md_ctx); + if (sig != nullptr) gpr_free(sig); return result; } char* grpc_jwt_encode_and_sign(const grpc_auth_json_key* json_key, const char* audience, gpr_timespec token_lifetime, const char* scope) { - if (g_jwt_encode_and_sign_override != NULL) { + if (g_jwt_encode_and_sign_override != nullptr) { return g_jwt_encode_and_sign_override(json_key, audience, token_lifetime, scope); } else { @@ -295,9 +295,9 @@ char* grpc_jwt_encode_and_sign(const grpc_auth_json_key* json_key, encoded_jwt_header(json_key->private_key_id, sig_algo), encoded_jwt_claim(json_key, audience, token_lifetime, scope)); char* sig = compute_and_encode_signature(json_key, sig_algo, to_sign); - if (sig == NULL) { + if (sig == nullptr) { gpr_free(to_sign); - return NULL; + return nullptr; } return dot_concat_and_free_strings(to_sign, sig); } diff --git a/src/core/lib/security/credentials/jwt/jwt_credentials.cc b/src/core/lib/security/credentials/jwt/jwt_credentials.cc index e8baa7e053..d666e6b658 100644 --- a/src/core/lib/security/credentials/jwt/jwt_credentials.cc +++ b/src/core/lib/security/credentials/jwt/jwt_credentials.cc @@ -34,9 +34,9 @@ static void jwt_reset_cache(grpc_exec_ctx* exec_ctx, grpc_service_account_jwt_access_credentials* c) { GRPC_MDELEM_UNREF(exec_ctx, c->cached.jwt_md); c->cached.jwt_md = GRPC_MDNULL; - if (c->cached.service_url != NULL) { + if (c->cached.service_url != nullptr) { gpr_free(c->cached.service_url); - c->cached.service_url = NULL; + c->cached.service_url = nullptr; } c->cached.jwt_expiration = gpr_inf_past(GPR_CLOCK_REALTIME); } @@ -66,7 +66,7 @@ static bool jwt_get_request_metadata(grpc_exec_ctx* exec_ctx, grpc_mdelem jwt_md = GRPC_MDNULL; { gpr_mu_lock(&c->cache_mu); - if (c->cached.service_url != NULL && + if (c->cached.service_url != nullptr && strcmp(c->cached.service_url, context.service_url) == 0 && !GRPC_MDISNULL(c->cached.jwt_md) && (gpr_time_cmp(gpr_time_sub(c->cached.jwt_expiration, @@ -78,13 +78,13 @@ static bool jwt_get_request_metadata(grpc_exec_ctx* exec_ctx, } if (GRPC_MDISNULL(jwt_md)) { - char* jwt = NULL; + char* jwt = nullptr; /* Generate a new jwt. */ gpr_mu_lock(&c->cache_mu); jwt_reset_cache(exec_ctx, c); jwt = grpc_jwt_encode_and_sign(&c->key, context.service_url, - c->jwt_lifetime, NULL); - if (jwt != NULL) { + c->jwt_lifetime, nullptr); + if (jwt != nullptr) { char* md_value; gpr_asprintf(&md_value, "Bearer %s", jwt); gpr_free(jwt); @@ -126,7 +126,7 @@ grpc_service_account_jwt_access_credentials_create_from_auth_json_key( grpc_service_account_jwt_access_credentials* c; if (!grpc_auth_json_key_is_valid(&key)) { gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation"); - return NULL; + return nullptr; } c = (grpc_service_account_jwt_access_credentials*)gpr_zalloc( sizeof(grpc_service_account_jwt_access_credentials)); @@ -185,7 +185,7 @@ grpc_call_credentials* grpc_service_account_jwt_access_credentials_create( (int)token_lifetime.clock_type, reserved); gpr_free(clean_json); } - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_call_credentials* creds = grpc_service_account_jwt_access_credentials_create_from_auth_json_key( diff --git a/src/core/lib/security/credentials/jwt/jwt_verifier.cc b/src/core/lib/security/credentials/jwt/jwt_verifier.cc index 0fce5f5555..105178ff4c 100644 --- a/src/core/lib/security/credentials/jwt/jwt_verifier.cc +++ b/src/core/lib/security/credentials/jwt/jwt_verifier.cc @@ -70,7 +70,7 @@ static const EVP_MD* evp_md_from_alg(const char* alg) { } else if (strcmp(alg, "RS512") == 0) { return EVP_sha512(); } else { - return NULL; + return nullptr; } } @@ -82,11 +82,11 @@ static grpc_json* parse_json_part_from_jwt(grpc_exec_ctx* exec_ctx, *buffer = grpc_base64_decode_with_len(exec_ctx, str, len, 1); if (GRPC_SLICE_IS_EMPTY(*buffer)) { gpr_log(GPR_ERROR, "Invalid base64."); - return NULL; + return nullptr; } json = grpc_json_parse_string_with_len((char*)GRPC_SLICE_START_PTR(*buffer), GRPC_SLICE_LENGTH(*buffer)); - if (json == NULL) { + if (json == nullptr) { grpc_slice_unref_internal(exec_ctx, *buffer); gpr_log(GPR_ERROR, "JSON parsing error."); } @@ -97,7 +97,7 @@ static const char* validate_string_field(const grpc_json* json, const char* key) { if (json->type != GRPC_JSON_STRING) { gpr_log(GPR_ERROR, "Invalid %s field [%s]", key, json->value); - return NULL; + return nullptr; } return json->value; } @@ -109,7 +109,7 @@ static gpr_timespec validate_time_field(const grpc_json* json, gpr_log(GPR_ERROR, "Invalid %s field [%s]", key, json->value); return result; } - result.tv_sec = strtol(json->value, NULL, 10); + result.tv_sec = strtol(json->value, nullptr, 10); return result; } @@ -134,27 +134,27 @@ static jose_header* jose_header_from_json(grpc_exec_ctx* exec_ctx, grpc_json* cur; jose_header* h = (jose_header*)gpr_zalloc(sizeof(jose_header)); h->buffer = buffer; - for (cur = json->child; cur != NULL; cur = cur->next) { + for (cur = json->child; cur != nullptr; cur = cur->next) { if (strcmp(cur->key, "alg") == 0) { /* We only support RSA-1.5 signatures for now. Beware of this if we add HMAC support: https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/ */ if (cur->type != GRPC_JSON_STRING || strncmp(cur->value, "RS", 2) || - evp_md_from_alg(cur->value) == NULL) { + evp_md_from_alg(cur->value) == nullptr) { gpr_log(GPR_ERROR, "Invalid alg field [%s]", cur->value); goto error; } h->alg = cur->value; } else if (strcmp(cur->key, "typ") == 0) { h->typ = validate_string_field(cur, "typ"); - if (h->typ == NULL) goto error; + if (h->typ == nullptr) goto error; } else if (strcmp(cur->key, "kid") == 0) { h->kid = validate_string_field(cur, "kid"); - if (h->kid == NULL) goto error; + if (h->kid == nullptr) goto error; } } - if (h->alg == NULL) { + if (h->alg == nullptr) { gpr_log(GPR_ERROR, "Missing alg field."); goto error; } @@ -165,7 +165,7 @@ static jose_header* jose_header_from_json(grpc_exec_ctx* exec_ctx, error: grpc_json_destroy(json); jose_header_destroy(exec_ctx, h); - return NULL; + return nullptr; } /* --- JWT claims. see http://tools.ietf.org/html/rfc7519#section-4.1 */ @@ -191,42 +191,42 @@ void grpc_jwt_claims_destroy(grpc_exec_ctx* exec_ctx, grpc_jwt_claims* claims) { } const grpc_json* grpc_jwt_claims_json(const grpc_jwt_claims* claims) { - if (claims == NULL) return NULL; + if (claims == nullptr) return nullptr; return claims->json; } const char* grpc_jwt_claims_subject(const grpc_jwt_claims* claims) { - if (claims == NULL) return NULL; + if (claims == nullptr) return nullptr; return claims->sub; } const char* grpc_jwt_claims_issuer(const grpc_jwt_claims* claims) { - if (claims == NULL) return NULL; + if (claims == nullptr) return nullptr; return claims->iss; } const char* grpc_jwt_claims_id(const grpc_jwt_claims* claims) { - if (claims == NULL) return NULL; + if (claims == nullptr) return nullptr; return claims->jti; } const char* grpc_jwt_claims_audience(const grpc_jwt_claims* claims) { - if (claims == NULL) return NULL; + if (claims == nullptr) return nullptr; return claims->aud; } gpr_timespec grpc_jwt_claims_issued_at(const grpc_jwt_claims* claims) { - if (claims == NULL) return gpr_inf_past(GPR_CLOCK_REALTIME); + if (claims == nullptr) return gpr_inf_past(GPR_CLOCK_REALTIME); return claims->iat; } gpr_timespec grpc_jwt_claims_expires_at(const grpc_jwt_claims* claims) { - if (claims == NULL) return gpr_inf_future(GPR_CLOCK_REALTIME); + if (claims == nullptr) return gpr_inf_future(GPR_CLOCK_REALTIME); return claims->exp; } gpr_timespec grpc_jwt_claims_not_before(const grpc_jwt_claims* claims) { - if (claims == NULL) return gpr_inf_past(GPR_CLOCK_REALTIME); + if (claims == nullptr) return gpr_inf_past(GPR_CLOCK_REALTIME); return claims->nbf; } @@ -244,19 +244,19 @@ grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_exec_ctx* exec_ctx, claims->exp = gpr_inf_future(GPR_CLOCK_REALTIME); /* Per the spec, all fields are optional. */ - for (cur = json->child; cur != NULL; cur = cur->next) { + for (cur = json->child; cur != nullptr; cur = cur->next) { if (strcmp(cur->key, "sub") == 0) { claims->sub = validate_string_field(cur, "sub"); - if (claims->sub == NULL) goto error; + if (claims->sub == nullptr) goto error; } else if (strcmp(cur->key, "iss") == 0) { claims->iss = validate_string_field(cur, "iss"); - if (claims->iss == NULL) goto error; + if (claims->iss == nullptr) goto error; } else if (strcmp(cur->key, "aud") == 0) { claims->aud = validate_string_field(cur, "aud"); - if (claims->aud == NULL) goto error; + if (claims->aud == nullptr) goto error; } else if (strcmp(cur->key, "jti") == 0) { claims->jti = validate_string_field(cur, "jti"); - if (claims->jti == NULL) goto error; + if (claims->jti == nullptr) goto error; } else if (strcmp(cur->key, "iat") == 0) { claims->iat = validate_time_field(cur, "iat"); if (gpr_time_cmp(claims->iat, gpr_time_0(GPR_CLOCK_REALTIME)) == 0) @@ -275,7 +275,7 @@ grpc_jwt_claims* grpc_jwt_claims_from_json(grpc_exec_ctx* exec_ctx, error: grpc_jwt_claims_destroy(exec_ctx, claims); - return NULL; + return nullptr; } grpc_jwt_verifier_status grpc_jwt_claims_check(const grpc_jwt_claims* claims, @@ -283,7 +283,7 @@ grpc_jwt_verifier_status grpc_jwt_claims_check(const grpc_jwt_claims* claims, gpr_timespec skewed_now; int audience_ok; - GPR_ASSERT(claims != NULL); + GPR_ASSERT(claims != nullptr); skewed_now = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), grpc_jwt_verifier_clock_skew); @@ -301,23 +301,23 @@ grpc_jwt_verifier_status grpc_jwt_claims_check(const grpc_jwt_claims* claims, /* This should be probably up to the upper layer to decide but let's harcode the 99% use case here for email issuers, where the JWT must be self issued. */ - if (grpc_jwt_issuer_email_domain(claims->iss) != NULL && - claims->sub != NULL && strcmp(claims->iss, claims->sub) != 0) { + if (grpc_jwt_issuer_email_domain(claims->iss) != nullptr && + claims->sub != nullptr && strcmp(claims->iss, claims->sub) != 0) { gpr_log(GPR_ERROR, "Email issuer (%s) cannot assert another subject (%s) than itself.", claims->iss, claims->sub); return GRPC_JWT_VERIFIER_BAD_SUBJECT; } - if (audience == NULL) { - audience_ok = claims->aud == NULL; + if (audience == nullptr) { + audience_ok = claims->aud == nullptr; } else { - audience_ok = claims->aud != NULL && strcmp(audience, claims->aud) == 0; + audience_ok = claims->aud != nullptr && strcmp(audience, claims->aud) == 0; } if (!audience_ok) { gpr_log(GPR_ERROR, "Audience mismatch: expected %s and found %s.", - audience == NULL ? "NULL" : audience, - claims->aud == NULL ? "NULL" : claims->aud); + audience == nullptr ? "NULL" : audience, + claims->aud == nullptr ? "NULL" : claims->aud); return GRPC_JWT_VERIFIER_BAD_AUDIENCE; } return GRPC_JWT_VERIFIER_OK; @@ -366,8 +366,8 @@ static verifier_cb_ctx* verifier_cb_ctx_create( } void verifier_cb_ctx_destroy(grpc_exec_ctx* exec_ctx, verifier_cb_ctx* ctx) { - if (ctx->audience != NULL) gpr_free(ctx->audience); - if (ctx->claims != NULL) grpc_jwt_claims_destroy(exec_ctx, ctx->claims); + if (ctx->audience != nullptr) gpr_free(ctx->audience); + if (ctx->claims != nullptr) grpc_jwt_claims_destroy(exec_ctx, ctx->claims); grpc_slice_unref_internal(exec_ctx, ctx->signature); grpc_slice_unref_internal(exec_ctx, ctx->signed_data); jose_header_destroy(exec_ctx, ctx->header); @@ -399,20 +399,20 @@ struct grpc_jwt_verifier { }; static grpc_json* json_from_http(const grpc_httpcli_response* response) { - grpc_json* json = NULL; + grpc_json* json = nullptr; - if (response == NULL) { + if (response == nullptr) { gpr_log(GPR_ERROR, "HTTP response is NULL."); - return NULL; + return nullptr; } if (response->status != 200) { gpr_log(GPR_ERROR, "Call to http server failed with error %d.", response->status); - return NULL; + return nullptr; } json = grpc_json_parse_string_with_len(response->body, response->body_length); - if (json == NULL) { + if (json == nullptr) { gpr_log(GPR_ERROR, "Invalid JSON found in response."); } return json; @@ -421,26 +421,26 @@ static grpc_json* json_from_http(const grpc_httpcli_response* response) { static const grpc_json* find_property_by_name(const grpc_json* json, const char* name) { const grpc_json* cur; - for (cur = json->child; cur != NULL; cur = cur->next) { + for (cur = json->child; cur != nullptr; cur = cur->next) { if (strcmp(cur->key, name) == 0) return cur; } - return NULL; + return nullptr; } static EVP_PKEY* extract_pkey_from_x509(const char* x509_str) { - X509* x509 = NULL; - EVP_PKEY* result = NULL; + X509* x509 = nullptr; + EVP_PKEY* result = nullptr; BIO* bio = BIO_new(BIO_s_mem()); 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) { + x509 = PEM_read_bio_X509(bio, nullptr, nullptr, nullptr); + if (x509 == nullptr) { gpr_log(GPR_ERROR, "Unable to parse x509 cert."); goto end; } result = X509_get_pubkey(x509); - if (result == NULL) { + if (result == nullptr) { gpr_log(GPR_ERROR, "Cannot find public key in X509 cert."); } @@ -451,17 +451,17 @@ end: } static BIGNUM* bignum_from_base64(grpc_exec_ctx* exec_ctx, const char* b64) { - BIGNUM* result = NULL; + BIGNUM* result = nullptr; grpc_slice bin; - if (b64 == NULL) return NULL; + if (b64 == nullptr) return nullptr; bin = grpc_base64_decode(exec_ctx, b64, 1); if (GRPC_SLICE_IS_EMPTY(bin)) { gpr_log(GPR_ERROR, "Invalid base64 for big num."); - return NULL; + return nullptr; } result = BN_bin2bn(GRPC_SLICE_START_PTR(bin), - TSI_SIZE_AS_SIZE(GRPC_SLICE_LENGTH(bin)), NULL); + TSI_SIZE_AS_SIZE(GRPC_SLICE_LENGTH(bin)), nullptr); grpc_slice_unref_internal(exec_ctx, bin); return result; } @@ -474,19 +474,19 @@ static int RSA_set0_key(RSA* r, BIGNUM* n, BIGNUM* e, BIGNUM* d) { * parameters MUST be non-NULL for n and e. d may be * left NULL (in case only the public key is used). */ - if ((r->n == NULL && n == NULL) || (r->e == NULL && e == NULL)) { + if ((r->n == nullptr && n == nullptr) || (r->e == nullptr && e == nullptr)) { return 0; } - if (n != NULL) { + if (n != nullptr) { BN_free(r->n); r->n = n; } - if (e != NULL) { + if (e != nullptr) { BN_free(r->e); r->e = e; } - if (d != NULL) { + if (d != nullptr) { BN_free(r->d); r->d = d; } @@ -498,43 +498,43 @@ static int RSA_set0_key(RSA* r, BIGNUM* n, BIGNUM* e, BIGNUM* d) { static EVP_PKEY* pkey_from_jwk(grpc_exec_ctx* exec_ctx, const grpc_json* json, const char* kty) { const grpc_json* key_prop; - RSA* rsa = NULL; - EVP_PKEY* result = NULL; - BIGNUM* tmp_n = NULL; - BIGNUM* tmp_e = NULL; + RSA* rsa = nullptr; + EVP_PKEY* result = nullptr; + BIGNUM* tmp_n = nullptr; + BIGNUM* tmp_e = nullptr; - GPR_ASSERT(kty != NULL && json != NULL); + GPR_ASSERT(kty != nullptr && json != nullptr); if (strcmp(kty, "RSA") != 0) { gpr_log(GPR_ERROR, "Unsupported key type %s.", kty); goto end; } rsa = RSA_new(); - if (rsa == NULL) { + if (rsa == nullptr) { gpr_log(GPR_ERROR, "Could not create rsa key."); goto end; } - for (key_prop = json->child; key_prop != NULL; key_prop = key_prop->next) { + for (key_prop = json->child; key_prop != nullptr; key_prop = key_prop->next) { if (strcmp(key_prop->key, "n") == 0) { tmp_n = bignum_from_base64(exec_ctx, validate_string_field(key_prop, "n")); - if (tmp_n == NULL) goto end; + if (tmp_n == nullptr) goto end; } else if (strcmp(key_prop->key, "e") == 0) { tmp_e = bignum_from_base64(exec_ctx, validate_string_field(key_prop, "e")); - if (tmp_e == NULL) goto end; + if (tmp_e == nullptr) goto end; } } - if (tmp_e == NULL || tmp_n == NULL) { + if (tmp_e == nullptr || tmp_n == nullptr) { gpr_log(GPR_ERROR, "Missing RSA public key field."); goto end; } - if (!RSA_set0_key(rsa, tmp_n, tmp_e, NULL)) { + if (!RSA_set0_key(rsa, tmp_n, tmp_e, nullptr)) { gpr_log(GPR_ERROR, "Cannot set RSA key from inputs."); goto end; } /* RSA_set0_key takes ownership on success. */ - tmp_n = NULL; - tmp_e = NULL; + tmp_n = nullptr; + tmp_e = nullptr; result = EVP_PKEY_new(); EVP_PKEY_set1_RSA(result, rsa); /* uprefs rsa. */ @@ -554,29 +554,29 @@ static EVP_PKEY* find_verification_key(grpc_exec_ctx* exec_ctx, /* Try to parse the json as a JWK set: https://tools.ietf.org/html/rfc7517#section-5. */ jwk_keys = find_property_by_name(json, "keys"); - if (jwk_keys == NULL) { + if (jwk_keys == nullptr) { /* Use the google proprietary format which is: { <kid1>: <x5091>, <kid2>: <x5092>, ... } */ const grpc_json* cur = find_property_by_name(json, header_kid); - if (cur == NULL) return NULL; + if (cur == nullptr) return nullptr; return extract_pkey_from_x509(cur->value); } if (jwk_keys->type != GRPC_JSON_ARRAY) { gpr_log(GPR_ERROR, "Unexpected value type of keys property in jwks key set."); - return NULL; + return nullptr; } /* Key format is specified in: https://tools.ietf.org/html/rfc7518#section-6. */ - for (jkey = jwk_keys->child; jkey != NULL; jkey = jkey->next) { + for (jkey = jwk_keys->child; jkey != nullptr; jkey = jkey->next) { grpc_json* key_prop; - const char* alg = NULL; - const char* kid = NULL; - const char* kty = NULL; + const char* alg = nullptr; + const char* kid = nullptr; + const char* kty = nullptr; if (jkey->type != GRPC_JSON_OBJECT) continue; - for (key_prop = jkey->child; key_prop != NULL; key_prop = key_prop->next) { + for (key_prop = jkey->child; key_prop != nullptr; key_prop = key_prop->next) { if (strcmp(key_prop->key, "alg") == 0 && key_prop->type == GRPC_JSON_STRING) { alg = key_prop->value; @@ -588,7 +588,7 @@ static EVP_PKEY* find_verification_key(grpc_exec_ctx* exec_ctx, kty = key_prop->value; } } - if (alg != NULL && kid != NULL && kty != NULL && + if (alg != nullptr && kid != nullptr && kty != nullptr && strcmp(kid, header_kid) == 0 && strcmp(alg, header_alg) == 0) { return pkey_from_jwk(exec_ctx, jkey, kty); } @@ -596,7 +596,7 @@ static EVP_PKEY* find_verification_key(grpc_exec_ctx* exec_ctx, gpr_log(GPR_ERROR, "Could not find matching key in key set for kid=%s and alg=%s", header_kid, header_alg); - return NULL; + return nullptr; } static int verify_jwt_signature(EVP_PKEY* key, const char* alg, @@ -605,12 +605,12 @@ static int verify_jwt_signature(EVP_PKEY* key, const char* alg, const EVP_MD* md = evp_md_from_alg(alg); int result = 0; - GPR_ASSERT(md != NULL); /* Checked before. */ - if (md_ctx == NULL) { + GPR_ASSERT(md != nullptr); /* Checked before. */ + if (md_ctx == nullptr) { gpr_log(GPR_ERROR, "Could not create EVP_MD_CTX."); goto end; } - if (EVP_DigestVerifyInit(md_ctx, NULL, md, NULL, key) != 1) { + if (EVP_DigestVerifyInit(md_ctx, nullptr, md, nullptr, key) != 1) { gpr_log(GPR_ERROR, "EVP_DigestVerifyInit failed."); goto end; } @@ -635,17 +635,17 @@ static void on_keys_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, grpc_error* error) { verifier_cb_ctx* ctx = (verifier_cb_ctx*)user_data; grpc_json* json = json_from_http(&ctx->responses[HTTP_RESPONSE_KEYS]); - EVP_PKEY* verification_key = NULL; + EVP_PKEY* verification_key = nullptr; grpc_jwt_verifier_status status = GRPC_JWT_VERIFIER_GENERIC_ERROR; - grpc_jwt_claims* claims = NULL; + grpc_jwt_claims* claims = nullptr; - if (json == NULL) { + if (json == nullptr) { status = GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR; goto end; } verification_key = find_verification_key(exec_ctx, json, ctx->header->alg, ctx->header->kid); - if (verification_key == NULL) { + if (verification_key == nullptr) { gpr_log(GPR_ERROR, "Could not find verification key with kid %s.", ctx->header->kid); status = GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR; @@ -662,11 +662,11 @@ static void on_keys_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, if (status == GRPC_JWT_VERIFIER_OK) { /* Pass ownership. */ claims = ctx->claims; - ctx->claims = NULL; + ctx->claims = nullptr; } end: - if (json != NULL) grpc_json_destroy(json); + if (json != nullptr) grpc_json_destroy(json); EVP_PKEY_free(verification_key); ctx->user_cb(exec_ctx, ctx->user_data, status, claims); verifier_cb_ctx_destroy(exec_ctx, ctx); @@ -680,17 +680,17 @@ static void on_openid_config_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, grpc_json* json = json_from_http(response); grpc_httpcli_request req; const char* jwks_uri; - grpc_resource_quota* resource_quota = NULL; + grpc_resource_quota* resource_quota = nullptr; /* TODO(jboeuf): Cache the jwks_uri in order to avoid this hop next time. */ - if (json == NULL) goto error; + if (json == nullptr) goto error; cur = find_property_by_name(json, "jwks_uri"); - if (cur == NULL) { + if (cur == nullptr) { gpr_log(GPR_ERROR, "Could not find jwks_uri in openid config."); goto error; } jwks_uri = validate_string_field(cur, "jwks_uri"); - if (jwks_uri == NULL) goto error; + if (jwks_uri == nullptr) goto error; if (strstr(jwks_uri, "https://") != jwks_uri) { gpr_log(GPR_ERROR, "Invalid non https jwks_uri: %s.", jwks_uri); goto error; @@ -699,7 +699,7 @@ static void on_openid_config_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, req.handshaker = &grpc_httpcli_ssl; req.host = gpr_strdup(jwks_uri); req.http.path = (char*)strchr(jwks_uri, '/'); - if (req.http.path == NULL) { + if (req.http.path == nullptr) { req.http.path = (char*)""; } else { *(req.host + (req.http.path - jwks_uri)) = '\0'; @@ -720,29 +720,29 @@ static void on_openid_config_retrieved(grpc_exec_ctx* exec_ctx, void* user_data, return; error: - if (json != NULL) grpc_json_destroy(json); + if (json != nullptr) grpc_json_destroy(json); ctx->user_cb(exec_ctx, ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, - NULL); + nullptr); verifier_cb_ctx_destroy(exec_ctx, ctx); } static email_key_mapping* verifier_get_mapping(grpc_jwt_verifier* v, const char* email_domain) { size_t i; - if (v->mappings == NULL) return NULL; + if (v->mappings == nullptr) return nullptr; for (i = 0; i < v->num_mappings; i++) { if (strcmp(email_domain, v->mappings[i].email_domain) == 0) { return &v->mappings[i]; } } - return NULL; + return nullptr; } static void verifier_put_mapping(grpc_jwt_verifier* v, const char* email_domain, const char* key_url_prefix) { email_key_mapping* mapping = verifier_get_mapping(v, email_domain); GPR_ASSERT(v->num_mappings < v->allocated_mappings); - if (mapping != NULL) { + if (mapping != nullptr) { gpr_free(mapping->key_url_prefix); mapping->key_url_prefix = gpr_strdup(key_url_prefix); return; @@ -757,16 +757,16 @@ static void verifier_put_mapping(grpc_jwt_verifier* v, const char* email_domain, enough for now... */ const char* grpc_jwt_issuer_email_domain(const char* issuer) { const char* at_sign = strchr(issuer, '@'); - if (at_sign == NULL) return NULL; + if (at_sign == nullptr) return nullptr; const char* email_domain = at_sign + 1; - if (*email_domain == '\0') return NULL; + if (*email_domain == '\0') return nullptr; const char* dot = strrchr(email_domain, '.'); - if (dot == NULL || dot == email_domain) return email_domain; + if (dot == nullptr || dot == email_domain) return email_domain; GPR_ASSERT(dot > email_domain); /* There may be a subdomain, we just want the domain. */ dot = (const char*)gpr_memrchr((void*)email_domain, '.', (size_t)(dot - email_domain)); - if (dot == NULL) return email_domain; + if (dot == nullptr) return email_domain; return dot + 1; } @@ -775,21 +775,21 @@ static void retrieve_key_and_verify(grpc_exec_ctx* exec_ctx, verifier_cb_ctx* ctx) { const char* email_domain; grpc_closure* http_cb; - char* path_prefix = NULL; + char* path_prefix = nullptr; const char* iss; grpc_httpcli_request req; - grpc_resource_quota* resource_quota = NULL; + grpc_resource_quota* resource_quota = nullptr; memset(&req, 0, sizeof(grpc_httpcli_request)); req.handshaker = &grpc_httpcli_ssl; http_response_index rsp_idx; - GPR_ASSERT(ctx != NULL && ctx->header != NULL && ctx->claims != NULL); + GPR_ASSERT(ctx != nullptr && ctx->header != nullptr && ctx->claims != nullptr); iss = ctx->claims->iss; - if (ctx->header->kid == NULL) { + if (ctx->header->kid == nullptr) { gpr_log(GPR_ERROR, "Missing kid in jose header."); goto error; } - if (iss == NULL) { + if (iss == nullptr) { gpr_log(GPR_ERROR, "Missing iss in claims."); goto error; } @@ -800,17 +800,17 @@ static void retrieve_key_and_verify(grpc_exec_ctx* exec_ctx, so we will rely instead on email/url mappings if we detect such an issuer. Part 4, on the other hand is implemented by both google and salesforce. */ email_domain = grpc_jwt_issuer_email_domain(iss); - if (email_domain != NULL) { + if (email_domain != nullptr) { email_key_mapping* mapping; - GPR_ASSERT(ctx->verifier != NULL); + GPR_ASSERT(ctx->verifier != nullptr); mapping = verifier_get_mapping(ctx->verifier, email_domain); - if (mapping == NULL) { + if (mapping == nullptr) { gpr_log(GPR_ERROR, "Missing mapping for issuer email."); goto error; } req.host = gpr_strdup(mapping->key_url_prefix); path_prefix = strchr(req.host, '/'); - if (path_prefix == NULL) { + if (path_prefix == nullptr) { gpr_asprintf(&req.http.path, "/%s", iss); } else { *(path_prefix++) = '\0'; @@ -822,7 +822,7 @@ static void retrieve_key_and_verify(grpc_exec_ctx* exec_ctx, } else { req.host = gpr_strdup(strstr(iss, "https://") == iss ? iss + 8 : iss); path_prefix = strchr(req.host, '/'); - if (path_prefix == NULL) { + if (path_prefix == nullptr) { req.http.path = gpr_strdup(GRPC_OPENID_CONFIG_URL_SUFFIX); } else { *(path_prefix++) = 0; @@ -849,7 +849,7 @@ static void retrieve_key_and_verify(grpc_exec_ctx* exec_ctx, error: ctx->user_cb(exec_ctx, ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, - NULL); + nullptr); verifier_cb_ctx_destroy(exec_ctx, ctx); } @@ -859,33 +859,33 @@ void grpc_jwt_verifier_verify(grpc_exec_ctx* exec_ctx, const char* audience, grpc_jwt_verification_done_cb cb, void* user_data) { - const char* dot = NULL; + const char* dot = nullptr; grpc_json* json; - jose_header* header = NULL; - grpc_jwt_claims* claims = NULL; + jose_header* header = nullptr; + grpc_jwt_claims* claims = nullptr; grpc_slice header_buffer; grpc_slice claims_buffer; grpc_slice signature; size_t signed_jwt_len; const char* cur = jwt; - GPR_ASSERT(verifier != NULL && jwt != NULL && audience != NULL && cb != NULL); + GPR_ASSERT(verifier != nullptr && jwt != nullptr && audience != nullptr && cb != nullptr); dot = strchr(cur, '.'); - if (dot == NULL) goto error; + if (dot == nullptr) goto error; json = parse_json_part_from_jwt(exec_ctx, cur, (size_t)(dot - cur), &header_buffer); - if (json == NULL) goto error; + if (json == nullptr) goto error; header = jose_header_from_json(exec_ctx, json, header_buffer); - if (header == NULL) goto error; + if (header == nullptr) goto error; cur = dot + 1; dot = strchr(cur, '.'); - if (dot == NULL) goto error; + if (dot == nullptr) goto error; json = parse_json_part_from_jwt(exec_ctx, cur, (size_t)(dot - cur), &claims_buffer); - if (json == NULL) goto error; + if (json == nullptr) goto error; claims = grpc_jwt_claims_from_json(exec_ctx, json, claims_buffer); - if (claims == NULL) goto error; + if (claims == nullptr) goto error; signed_jwt_len = (size_t)(dot - jwt); cur = dot + 1; @@ -898,9 +898,9 @@ void grpc_jwt_verifier_verify(grpc_exec_ctx* exec_ctx, return; error: - if (header != NULL) jose_header_destroy(exec_ctx, header); - if (claims != NULL) grpc_jwt_claims_destroy(exec_ctx, claims); - cb(exec_ctx, user_data, GRPC_JWT_VERIFIER_BAD_FORMAT, NULL); + if (header != nullptr) jose_header_destroy(exec_ctx, header); + if (claims != nullptr) grpc_jwt_claims_destroy(exec_ctx, claims); + cb(exec_ctx, user_data, GRPC_JWT_VERIFIER_BAD_FORMAT, nullptr); } grpc_jwt_verifier* grpc_jwt_verifier_create( @@ -917,7 +917,7 @@ grpc_jwt_verifier* grpc_jwt_verifier_create( verifier_put_mapping(v, GRPC_GOOGLE_SERVICE_ACCOUNTS_EMAIL_DOMAIN, GRPC_GOOGLE_SERVICE_ACCOUNTS_KEY_URL_PREFIX); /* User-Provided mappings. */ - if (mappings != NULL) { + if (mappings != nullptr) { size_t i; for (i = 0; i < num_mappings; i++) { verifier_put_mapping(v, mappings[i].email_domain, @@ -929,9 +929,9 @@ grpc_jwt_verifier* grpc_jwt_verifier_create( void grpc_jwt_verifier_destroy(grpc_exec_ctx* exec_ctx, grpc_jwt_verifier* v) { size_t i; - if (v == NULL) return; + if (v == nullptr) return; grpc_httpcli_context_destroy(exec_ctx, &v->http_ctx); - if (v->mappings != NULL) { + if (v->mappings != nullptr) { for (i = 0; i < v->num_mappings; i++) { gpr_free(v->mappings[i].email_domain); gpr_free(v->mappings[i].key_url_prefix); diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc index 2a44211228..943d23f21e 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc @@ -33,7 +33,7 @@ int grpc_auth_refresh_token_is_valid( const grpc_auth_refresh_token* refresh_token) { - return (refresh_token != NULL) && + return (refresh_token != nullptr) && strcmp(refresh_token->type, GRPC_AUTH_JSON_TYPE_INVALID); } @@ -45,13 +45,13 @@ grpc_auth_refresh_token grpc_auth_refresh_token_create_from_json( memset(&result, 0, sizeof(grpc_auth_refresh_token)); result.type = GRPC_AUTH_JSON_TYPE_INVALID; - if (json == NULL) { + if (json == nullptr) { gpr_log(GPR_ERROR, "Invalid json."); goto end; } prop_value = grpc_json_get_string_property(json, "type"); - if (prop_value == NULL || + if (prop_value == nullptr || strcmp(prop_value, GRPC_AUTH_JSON_TYPE_AUTHORIZED_USER)) { goto end; } @@ -77,25 +77,25 @@ grpc_auth_refresh_token grpc_auth_refresh_token_create_from_string( grpc_json* json = grpc_json_parse_string(scratchpad); grpc_auth_refresh_token result = grpc_auth_refresh_token_create_from_json(json); - if (json != NULL) grpc_json_destroy(json); + if (json != nullptr) grpc_json_destroy(json); gpr_free(scratchpad); return result; } void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token) { - if (refresh_token == NULL) return; + if (refresh_token == nullptr) return; refresh_token->type = GRPC_AUTH_JSON_TYPE_INVALID; - if (refresh_token->client_id != NULL) { + if (refresh_token->client_id != nullptr) { gpr_free(refresh_token->client_id); - refresh_token->client_id = NULL; + refresh_token->client_id = nullptr; } - if (refresh_token->client_secret != NULL) { + if (refresh_token->client_secret != nullptr) { gpr_free(refresh_token->client_secret); - refresh_token->client_secret = NULL; + refresh_token->client_secret = nullptr; } - if (refresh_token->refresh_token != NULL) { + if (refresh_token->refresh_token != nullptr) { gpr_free(refresh_token->refresh_token); - refresh_token->refresh_token = NULL; + refresh_token->refresh_token = nullptr; } } @@ -118,12 +118,12 @@ grpc_credentials_status grpc_oauth2_token_fetcher_credentials_parse_server_response( grpc_exec_ctx* exec_ctx, const grpc_http_response* response, grpc_mdelem* token_md, grpc_millis* token_lifetime) { - char* null_terminated_body = NULL; - char* new_access_token = NULL; + char* null_terminated_body = nullptr; + char* new_access_token = nullptr; grpc_credentials_status status = GRPC_CREDENTIALS_OK; - grpc_json* json = NULL; + grpc_json* json = nullptr; - if (response == NULL) { + if (response == nullptr) { gpr_log(GPR_ERROR, "Received NULL response."); status = GRPC_CREDENTIALS_ERROR; goto end; @@ -138,16 +138,16 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( if (response->status != 200) { gpr_log(GPR_ERROR, "Call to http server ended with error %d [%s].", response->status, - null_terminated_body != NULL ? null_terminated_body : ""); + null_terminated_body != nullptr ? null_terminated_body : ""); status = GRPC_CREDENTIALS_ERROR; goto end; } else { - grpc_json* access_token = NULL; - grpc_json* token_type = NULL; - grpc_json* expires_in = NULL; + grpc_json* access_token = nullptr; + grpc_json* token_type = nullptr; + grpc_json* expires_in = nullptr; grpc_json* ptr; json = grpc_json_parse_string(null_terminated_body); - if (json == NULL) { + if (json == nullptr) { gpr_log(GPR_ERROR, "Could not parse JSON from %s", null_terminated_body); status = GRPC_CREDENTIALS_ERROR; goto end; @@ -166,24 +166,24 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response( expires_in = ptr; } } - if (access_token == NULL || access_token->type != GRPC_JSON_STRING) { + if (access_token == nullptr || access_token->type != GRPC_JSON_STRING) { gpr_log(GPR_ERROR, "Missing or invalid access_token in JSON."); status = GRPC_CREDENTIALS_ERROR; goto end; } - if (token_type == NULL || token_type->type != GRPC_JSON_STRING) { + if (token_type == nullptr || token_type->type != GRPC_JSON_STRING) { gpr_log(GPR_ERROR, "Missing or invalid token_type in JSON."); status = GRPC_CREDENTIALS_ERROR; goto end; } - if (expires_in == NULL || expires_in->type != GRPC_JSON_NUMBER) { + if (expires_in == nullptr || expires_in->type != GRPC_JSON_NUMBER) { gpr_log(GPR_ERROR, "Missing or invalid expires_in in JSON."); status = GRPC_CREDENTIALS_ERROR; goto end; } gpr_asprintf(&new_access_token, "%s %s", token_type->value, access_token->value); - *token_lifetime = strtol(expires_in->value, NULL, 10) * GPR_MS_PER_SEC; + *token_lifetime = strtol(expires_in->value, nullptr, 10) * GPR_MS_PER_SEC; if (!GRPC_MDISNULL(*token_md)) GRPC_MDELEM_UNREF(exec_ctx, *token_md); *token_md = grpc_mdelem_from_slices( exec_ctx, @@ -197,9 +197,9 @@ end: GRPC_MDELEM_UNREF(exec_ctx, *token_md); *token_md = GRPC_MDNULL; } - if (null_terminated_body != NULL) gpr_free(null_terminated_body); - if (new_access_token != NULL) gpr_free(new_access_token); - if (json != NULL) grpc_json_destroy(json); + if (null_terminated_body != nullptr) gpr_free(null_terminated_body); + if (new_access_token != nullptr) gpr_free(new_access_token); + if (json != nullptr) grpc_json_destroy(json); return status; } @@ -225,10 +225,10 @@ static void on_oauth2_token_fetcher_http_response(grpc_exec_ctx* exec_ctx, : 0; grpc_oauth2_pending_get_request_metadata* pending_request = c->pending_requests; - c->pending_requests = NULL; + c->pending_requests = nullptr; gpr_mu_unlock(&c->mu); // Invoke callbacks for all pending requests. - while (pending_request != NULL) { + while (pending_request != nullptr) { if (status == GRPC_CREDENTIALS_OK) { grpc_credentials_mdelem_array_add(pending_request->md_array, access_token_md); @@ -305,13 +305,13 @@ static void oauth2_token_fetcher_cancel_get_request_metadata( grpc_oauth2_token_fetcher_credentials* c = (grpc_oauth2_token_fetcher_credentials*)creds; gpr_mu_lock(&c->mu); - grpc_oauth2_pending_get_request_metadata* prev = NULL; + grpc_oauth2_pending_get_request_metadata* prev = nullptr; grpc_oauth2_pending_get_request_metadata* pending_request = c->pending_requests; - while (pending_request != NULL) { + while (pending_request != nullptr) { if (pending_request->md_array == md_array) { // Remove matching pending request from the list. - if (prev != NULL) { + if (prev != nullptr) { prev->next = pending_request->next; } else { c->pending_requests = pending_request->next; @@ -380,7 +380,7 @@ grpc_call_credentials* grpc_google_compute_engine_credentials_create( sizeof(grpc_oauth2_token_fetcher_credentials)); GRPC_API_TRACE("grpc_compute_engine_credentials_create(reserved=%p)", 1, (reserved)); - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); init_oauth2_token_fetcher(c, compute_engine_fetch_oauth2); c->base.vtable = &compute_engine_vtable; return &c->base; @@ -411,7 +411,7 @@ static void refresh_token_fetch_oauth2( grpc_http_header header = {(char*)"Content-Type", (char*)"application/x-www-form-urlencoded"}; grpc_httpcli_request request; - char* body = NULL; + char* body = nullptr; gpr_asprintf(&body, GRPC_REFRESH_TOKEN_POST_BODY_FORMAT_STRING, c->refresh_token.client_id, c->refresh_token.client_secret, c->refresh_token.refresh_token); @@ -441,7 +441,7 @@ grpc_refresh_token_credentials_create_from_auth_refresh_token( grpc_google_refresh_token_credentials* c; if (!grpc_auth_refresh_token_is_valid(&refresh_token)) { gpr_log(GPR_ERROR, "Invalid input for refresh token credentials creation"); - return NULL; + return nullptr; } c = (grpc_google_refresh_token_credentials*)gpr_zalloc( sizeof(grpc_google_refresh_token_credentials)); @@ -455,7 +455,7 @@ static char* create_loggable_refresh_token(grpc_auth_refresh_token* token) { if (strcmp(token->type, GRPC_AUTH_JSON_TYPE_INVALID) == 0) { return gpr_strdup("<Invalid json token>"); } - char* loggable_token = NULL; + char* loggable_token = nullptr; gpr_asprintf(&loggable_token, "{\n type: %s\n client_id: %s\n client_secret: " "<redacted>\n refresh_token: <redacted>\n}", @@ -475,7 +475,7 @@ grpc_call_credentials* grpc_google_refresh_token_credentials_create( loggable_token, reserved); gpr_free(loggable_token); } - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); return grpc_refresh_token_credentials_create_from_auth_refresh_token(token); } @@ -517,7 +517,7 @@ grpc_call_credentials* grpc_access_token_credentials_create( "grpc_access_token_credentials_create(access_token=<redacted>, " "reserved=%p)", 1, (reserved)); - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); c->base.type = GRPC_CALL_CREDENTIALS_TYPE_OAUTH2; c->base.vtable = &access_token_vtable; gpr_ref_init(&c->base.refcount, 1); diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.cc b/src/core/lib/security/credentials/plugin/plugin_credentials.cc index e75b00c01a..b83a1b426a 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.cc +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.cc @@ -38,7 +38,7 @@ static void plugin_destruct(grpc_exec_ctx* exec_ctx, grpc_call_credentials* creds) { grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds; gpr_mu_destroy(&c->mu); - if (c->plugin.state != NULL && c->plugin.destroy != NULL) { + if (c->plugin.state != nullptr && c->plugin.destroy != nullptr) { c->plugin.destroy(c->plugin.state); } } @@ -46,12 +46,12 @@ static void plugin_destruct(grpc_exec_ctx* exec_ctx, static void pending_request_remove_locked( grpc_plugin_credentials* c, grpc_plugin_credentials_pending_request* pending_request) { - if (pending_request->prev == NULL) { + if (pending_request->prev == nullptr) { c->pending_requests = pending_request->next; } else { pending_request->prev->next = pending_request->next; } - if (pending_request->next != NULL) { + if (pending_request->next != nullptr) { pending_request->next->prev = pending_request->prev; } } @@ -120,7 +120,7 @@ static void plugin_md_request_metadata_ready(void* request, /* called from application code */ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INITIALIZER( GRPC_EXEC_CTX_FLAG_IS_FINISHED | GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP, - NULL, NULL); + nullptr, nullptr); grpc_plugin_credentials_pending_request* r = (grpc_plugin_credentials_pending_request*)request; if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { @@ -155,7 +155,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx* exec_ctx, grpc_error** error) { grpc_plugin_credentials* c = (grpc_plugin_credentials*)creds; bool retval = true; // Synchronous return. - if (c->plugin.get_metadata != NULL) { + if (c->plugin.get_metadata != nullptr) { // Create pending_request object. grpc_plugin_credentials_pending_request* pending_request = (grpc_plugin_credentials_pending_request*)gpr_zalloc( @@ -165,7 +165,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx* exec_ctx, pending_request->on_request_metadata = on_request_metadata; // Add it to the pending list. gpr_mu_lock(&c->mu); - if (c->pending_requests != NULL) { + if (c->pending_requests != nullptr) { c->pending_requests->prev = pending_request; } pending_request->next = c->pending_requests; @@ -180,7 +180,7 @@ static bool plugin_get_request_metadata(grpc_exec_ctx* exec_ctx, grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX]; size_t num_creds_md = 0; grpc_status_code status = GRPC_STATUS_OK; - const char* error_details = NULL; + const char* error_details = nullptr; if (!c->plugin.get_metadata(c->plugin.state, context, plugin_md_request_metadata_ready, pending_request, creds_md, &num_creds_md, @@ -235,7 +235,7 @@ static void plugin_cancel_get_request_metadata( gpr_mu_lock(&c->mu); for (grpc_plugin_credentials_pending_request* pending_request = c->pending_requests; - pending_request != NULL; pending_request = pending_request->next) { + pending_request != nullptr; pending_request = pending_request->next) { if (pending_request->md_array == md_array) { if (GRPC_TRACER_ON(grpc_plugin_credentials_trace)) { gpr_log(GPR_INFO, "plugin_credentials[%p]: cancelling request %p", c, @@ -261,7 +261,7 @@ grpc_call_credentials* grpc_metadata_credentials_create_from_plugin( grpc_plugin_credentials* c = (grpc_plugin_credentials*)gpr_zalloc(sizeof(*c)); GRPC_API_TRACE("grpc_metadata_credentials_create_from_plugin(reserved=%p)", 1, (reserved)); - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); c->base.type = plugin.type; c->base.vtable = &plugin_vtable; gpr_ref_init(&c->base.refcount, 1); diff --git a/src/core/lib/security/credentials/ssl/ssl_credentials.cc b/src/core/lib/security/credentials/ssl/ssl_credentials.cc index 79e223ddcb..39dd38cf88 100644 --- a/src/core/lib/security/credentials/ssl/ssl_credentials.cc +++ b/src/core/lib/security/credentials/ssl/ssl_credentials.cc @@ -33,7 +33,7 @@ void grpc_tsi_ssl_pem_key_cert_pairs_destroy(tsi_ssl_pem_key_cert_pair* kp, size_t num_key_cert_pairs) { - if (kp == NULL) return; + if (kp == nullptr) return; for (size_t i = 0; i < num_key_cert_pairs; i++) { gpr_free((void*)kp[i].private_key); gpr_free((void*)kp[i].cert_chain); @@ -55,7 +55,7 @@ static grpc_security_status ssl_create_security_connector( grpc_channel_args** new_args) { grpc_ssl_credentials* c = (grpc_ssl_credentials*)creds; grpc_security_status status = GRPC_SECURITY_OK; - const char* overridden_target_name = NULL; + const char* overridden_target_name = nullptr; for (size_t i = 0; args && i < args->num_args; i++) { grpc_arg* arg = &args->args[i]; if (strcmp(arg->key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG) == 0 && @@ -77,17 +77,17 @@ static grpc_security_status ssl_create_security_connector( } static grpc_channel_credentials_vtable ssl_vtable = { - ssl_destruct, ssl_create_security_connector, NULL}; + ssl_destruct, ssl_create_security_connector, nullptr}; static void ssl_build_config(const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair, grpc_ssl_config* config) { - if (pem_root_certs != NULL) { + if (pem_root_certs != nullptr) { config->pem_root_certs = gpr_strdup(pem_root_certs); } - if (pem_key_cert_pair != NULL) { - GPR_ASSERT(pem_key_cert_pair->private_key != NULL); - GPR_ASSERT(pem_key_cert_pair->cert_chain != NULL); + if (pem_key_cert_pair != nullptr) { + GPR_ASSERT(pem_key_cert_pair->private_key != nullptr); + GPR_ASSERT(pem_key_cert_pair->cert_chain != nullptr); config->pem_key_cert_pair = (tsi_ssl_pem_key_cert_pair*)gpr_zalloc( sizeof(tsi_ssl_pem_key_cert_pair)); config->pem_key_cert_pair->cert_chain = @@ -107,7 +107,7 @@ grpc_channel_credentials* grpc_ssl_credentials_create( "pem_key_cert_pair=%p, " "reserved=%p)", 3, (pem_root_certs, pem_key_cert_pair, reserved)); - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); c->base.type = GRPC_CHANNEL_CREDENTIALS_TYPE_SSL; c->base.vtable = &ssl_vtable; gpr_ref_init(&c->base.refcount, 1); @@ -145,15 +145,15 @@ static grpc_server_credentials_vtable ssl_server_vtable = { tsi_ssl_pem_key_cert_pair* grpc_convert_grpc_to_tsi_cert_pairs( const grpc_ssl_pem_key_cert_pair* pem_key_cert_pairs, size_t num_key_cert_pairs) { - tsi_ssl_pem_key_cert_pair* tsi_pairs = NULL; + tsi_ssl_pem_key_cert_pair* tsi_pairs = nullptr; if (num_key_cert_pairs > 0) { - GPR_ASSERT(pem_key_cert_pairs != NULL); + GPR_ASSERT(pem_key_cert_pairs != nullptr); tsi_pairs = (tsi_ssl_pem_key_cert_pair*)gpr_zalloc( num_key_cert_pairs * sizeof(tsi_ssl_pem_key_cert_pair)); } for (size_t i = 0; i < num_key_cert_pairs; i++) { - GPR_ASSERT(pem_key_cert_pairs[i].private_key != NULL); - GPR_ASSERT(pem_key_cert_pairs[i].cert_chain != NULL); + GPR_ASSERT(pem_key_cert_pairs[i].private_key != nullptr); + GPR_ASSERT(pem_key_cert_pairs[i].cert_chain != nullptr); tsi_pairs[i].cert_chain = gpr_strdup(pem_key_cert_pairs[i].cert_chain); tsi_pairs[i].private_key = gpr_strdup(pem_key_cert_pairs[i].private_key); } @@ -166,7 +166,7 @@ static void ssl_build_server_config( grpc_ssl_client_certificate_request_type client_certificate_request, grpc_ssl_server_config* config) { config->client_certificate_request = client_certificate_request; - if (pem_root_certs != NULL) { + if (pem_root_certs != nullptr) { config->pem_root_certs = gpr_strdup(pem_root_certs); } config->pem_key_cert_pairs = grpc_convert_grpc_to_tsi_cert_pairs( @@ -181,18 +181,18 @@ grpc_ssl_server_certificate_config* grpc_ssl_server_certificate_config_create( grpc_ssl_server_certificate_config* config = (grpc_ssl_server_certificate_config*)gpr_zalloc( sizeof(grpc_ssl_server_certificate_config)); - if (pem_root_certs != NULL) { + if (pem_root_certs != nullptr) { config->pem_root_certs = gpr_strdup(pem_root_certs); } if (num_key_cert_pairs > 0) { - GPR_ASSERT(pem_key_cert_pairs != NULL); + GPR_ASSERT(pem_key_cert_pairs != nullptr); config->pem_key_cert_pairs = (grpc_ssl_pem_key_cert_pair*)gpr_zalloc( num_key_cert_pairs * sizeof(grpc_ssl_pem_key_cert_pair)); } config->num_key_cert_pairs = num_key_cert_pairs; for (size_t i = 0; i < num_key_cert_pairs; i++) { - GPR_ASSERT(pem_key_cert_pairs[i].private_key != NULL); - GPR_ASSERT(pem_key_cert_pairs[i].cert_chain != NULL); + GPR_ASSERT(pem_key_cert_pairs[i].private_key != nullptr); + GPR_ASSERT(pem_key_cert_pairs[i].cert_chain != nullptr); config->pem_key_cert_pairs[i].cert_chain = gpr_strdup(pem_key_cert_pairs[i].cert_chain); config->pem_key_cert_pairs[i].private_key = @@ -203,7 +203,7 @@ grpc_ssl_server_certificate_config* grpc_ssl_server_certificate_config_create( void grpc_ssl_server_certificate_config_destroy( grpc_ssl_server_certificate_config* config) { - if (config == NULL) return; + if (config == nullptr) return; for (size_t i = 0; i < config->num_key_cert_pairs; i++) { gpr_free((void*)config->pem_key_cert_pairs[i].private_key); gpr_free((void*)config->pem_key_cert_pairs[i].cert_chain); @@ -217,8 +217,8 @@ grpc_ssl_server_credentials_options* grpc_ssl_server_credentials_create_options_using_config( grpc_ssl_client_certificate_request_type client_certificate_request, grpc_ssl_server_certificate_config* config) { - grpc_ssl_server_credentials_options* options = NULL; - if (config == NULL) { + grpc_ssl_server_credentials_options* options = nullptr; + if (config == nullptr) { gpr_log(GPR_ERROR, "Certificate config must not be NULL."); goto done; } @@ -234,9 +234,9 @@ grpc_ssl_server_credentials_options* grpc_ssl_server_credentials_create_options_using_config_fetcher( grpc_ssl_client_certificate_request_type client_certificate_request, grpc_ssl_server_certificate_config_callback cb, void* user_data) { - if (cb == NULL) { + if (cb == nullptr) { gpr_log(GPR_ERROR, "Invalid certificate config callback parameter."); - return NULL; + return nullptr; } grpc_ssl_server_certificate_config_fetcher* fetcher = @@ -277,7 +277,7 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_ex( 5, (pem_root_certs, pem_key_cert_pairs, (unsigned long)num_key_cert_pairs, client_certificate_request, reserved)); - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); grpc_ssl_server_certificate_config* cert_config = grpc_ssl_server_certificate_config_create( @@ -291,23 +291,23 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_ex( grpc_server_credentials* grpc_ssl_server_credentials_create_with_options( grpc_ssl_server_credentials_options* options) { - grpc_server_credentials* retval = NULL; - grpc_ssl_server_credentials* c = NULL; + grpc_server_credentials* retval = nullptr; + grpc_ssl_server_credentials* c = nullptr; - if (options == NULL) { + if (options == nullptr) { gpr_log(GPR_ERROR, "Invalid options trying to create SSL server credentials."); goto done; } - if (options->certificate_config == NULL && - options->certificate_config_fetcher == NULL) { + if (options->certificate_config == nullptr && + options->certificate_config_fetcher == nullptr) { gpr_log(GPR_ERROR, "SSL server credentials options must specify either " "certificate config or fetcher."); goto done; - } else if (options->certificate_config_fetcher != NULL && - options->certificate_config_fetcher->cb == NULL) { + } else if (options->certificate_config_fetcher != nullptr && + options->certificate_config_fetcher->cb == nullptr) { gpr_log(GPR_ERROR, "Certificate config fetcher callback must not be NULL."); goto done; } @@ -318,7 +318,7 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_with_options( gpr_ref_init(&c->base.refcount, 1); c->base.vtable = &ssl_server_vtable; - if (options->certificate_config_fetcher != NULL) { + if (options->certificate_config_fetcher != nullptr) { c->config.client_certificate_request = options->client_certificate_request; c->certificate_config_fetcher = *options->certificate_config_fetcher; } else { @@ -337,7 +337,7 @@ done: void grpc_ssl_server_credentials_options_destroy( grpc_ssl_server_credentials_options* o) { - if (o == NULL) return; + if (o == nullptr) return; gpr_free(o->certificate_config_fetcher); grpc_ssl_server_certificate_config_destroy(o->certificate_config); gpr_free(o); diff --git a/src/core/lib/security/transport/client_auth_filter.cc b/src/core/lib/security/transport/client_auth_filter.cc index 11f5a13ccc..0ea33de6ca 100644 --- a/src/core/lib/security/transport/client_auth_filter.cc +++ b/src/core/lib/security/transport/client_auth_filter.cc @@ -67,18 +67,18 @@ typedef struct { void grpc_auth_metadata_context_reset( grpc_auth_metadata_context* auth_md_context) { - if (auth_md_context->service_url != NULL) { + if (auth_md_context->service_url != nullptr) { gpr_free((char*)auth_md_context->service_url); - auth_md_context->service_url = NULL; + auth_md_context->service_url = nullptr; } - if (auth_md_context->method_name != NULL) { + if (auth_md_context->method_name != nullptr) { gpr_free((char*)auth_md_context->method_name); - auth_md_context->method_name = NULL; + auth_md_context->method_name = nullptr; } GRPC_AUTH_CONTEXT_UNREF( (grpc_auth_context*)auth_md_context->channel_auth_context, "grpc_auth_metadata_context"); - auth_md_context->channel_auth_context = NULL; + auth_md_context->channel_auth_context = nullptr; } static void add_error(grpc_error** combined, grpc_error* error) { @@ -125,10 +125,10 @@ void grpc_auth_metadata_context_build( grpc_auth_metadata_context* auth_md_context) { char* service = grpc_slice_to_c_string(call_method); char* last_slash = strrchr(service, '/'); - char* method_name = NULL; - char* service_url = NULL; + char* method_name = nullptr; + char* service_url = nullptr; grpc_auth_metadata_context_reset(auth_md_context); - if (last_slash == NULL) { + if (last_slash == nullptr) { gpr_log(GPR_ERROR, "No '/' found in fully qualified method name"); service[0] = '\0'; method_name = gpr_strdup(""); @@ -139,14 +139,14 @@ void grpc_auth_metadata_context_build( method_name = gpr_strdup(last_slash + 1); } char* host_and_port = grpc_slice_to_c_string(call_host); - if (url_scheme != NULL && strcmp(url_scheme, GRPC_SSL_URL_SCHEME) == 0) { + if (url_scheme != nullptr && strcmp(url_scheme, GRPC_SSL_URL_SCHEME) == 0) { /* Remove the port if it is 443. */ char* port_delimiter = strrchr(host_and_port, ':'); - if (port_delimiter != NULL && strcmp(port_delimiter + 1, "443") == 0) { + if (port_delimiter != nullptr && strcmp(port_delimiter + 1, "443") == 0) { *port_delimiter = '\0'; } } - gpr_asprintf(&service_url, "%s://%s%s", url_scheme == NULL ? "" : url_scheme, + gpr_asprintf(&service_url, "%s://%s%s", url_scheme == nullptr ? "" : url_scheme, host_and_port, service); auth_md_context->service_url = service_url; auth_md_context->method_name = method_name; @@ -179,18 +179,18 @@ static void send_security_metadata(grpc_exec_ctx* exec_ctx, .value; grpc_call_credentials* channel_call_creds = chand->security_connector->request_metadata_creds; - int call_creds_has_md = (ctx != NULL) && (ctx->creds != NULL); + int call_creds_has_md = (ctx != nullptr) && (ctx->creds != nullptr); - if (channel_call_creds == NULL && !call_creds_has_md) { + if (channel_call_creds == nullptr && !call_creds_has_md) { /* Skip sending metadata altogether. */ grpc_call_next_op(exec_ctx, elem, batch); return; } - if (channel_call_creds != NULL && call_creds_has_md) { + if (channel_call_creds != nullptr && call_creds_has_md) { calld->creds = grpc_composite_call_credentials_create(channel_call_creds, - ctx->creds, NULL); - if (calld->creds == NULL) { + ctx->creds, nullptr); + if (calld->creds == nullptr) { grpc_transport_stream_op_batch_finish_with_failure( exec_ctx, batch, grpc_error_set_int( @@ -209,7 +209,7 @@ static void send_security_metadata(grpc_exec_ctx* exec_ctx, chand->security_connector->base.url_scheme, calld->host, calld->method, chand->auth_context, &calld->auth_md_context); - GPR_ASSERT(calld->pollent != NULL); + GPR_ASSERT(calld->pollent != nullptr); GRPC_CLOSURE_INIT(&calld->async_result_closure, on_credentials_metadata, batch, grpc_schedule_on_exec_ctx); @@ -278,8 +278,8 @@ static void auth_start_transport_stream_op_batch( channel_data* chand = (channel_data*)elem->channel_data; if (!batch->cancel_stream) { - GPR_ASSERT(batch->payload->context != NULL); - if (batch->payload->context[GRPC_CONTEXT_SECURITY].value == NULL) { + GPR_ASSERT(batch->payload->context != nullptr); + if (batch->payload->context[GRPC_CONTEXT_SECURITY].value == nullptr) { batch->payload->context[GRPC_CONTEXT_SECURITY].value = grpc_client_security_context_create(); batch->payload->context[GRPC_CONTEXT_SECURITY].destroy = @@ -297,7 +297,7 @@ static void auth_start_transport_stream_op_batch( if (batch->send_initial_metadata) { for (grpc_linked_mdelem* l = batch->payload->send_initial_metadata .send_initial_metadata->list.head; - l != NULL; l = l->next) { + l != nullptr; l = l->next) { grpc_mdelem md = l->md; /* Pointer comparison is OK for md_elems created from the same context. */ @@ -386,13 +386,13 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, grpc_channel_element_args* args) { grpc_security_connector* sc = grpc_security_connector_find_in_args(args->channel_args); - if (sc == NULL) { + if (sc == nullptr) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Security connector missing from client auth filter args"); } grpc_auth_context* auth_context = grpc_find_auth_context_in_args(args->channel_args); - if (auth_context == NULL) { + if (auth_context == nullptr) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Auth context missing from client auth filter args"); } @@ -420,7 +420,7 @@ static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, /* grab pointers to our data from the channel element */ channel_data* chand = (channel_data*)elem->channel_data; grpc_channel_security_connector* sc = chand->security_connector; - if (sc != NULL) { + if (sc != nullptr) { GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, &sc->base, "client_auth_filter"); } GRPC_AUTH_CONTEXT_UNREF(chand->auth_context, "client_auth_filter"); diff --git a/src/core/lib/security/transport/lb_targets_info.cc b/src/core/lib/security/transport/lb_targets_info.cc index 1655e18f37..c07be35840 100644 --- a/src/core/lib/security/transport/lb_targets_info.cc +++ b/src/core/lib/security/transport/lb_targets_info.cc @@ -49,9 +49,9 @@ grpc_slice_hash_table* grpc_lb_targets_info_find_in_args( const grpc_channel_args* args) { const grpc_arg* targets_info_arg = grpc_channel_args_find(args, GRPC_ARG_LB_SECURE_NAMING_MAP); - if (targets_info_arg != NULL) { + if (targets_info_arg != nullptr) { GPR_ASSERT(targets_info_arg->type == GRPC_ARG_POINTER); return (grpc_slice_hash_table*)targets_info_arg->value.pointer.p; } - return NULL; + return nullptr; } diff --git a/src/core/lib/security/transport/secure_endpoint.cc b/src/core/lib/security/transport/secure_endpoint.cc index 9a29e05715..3ba987a105 100644 --- a/src/core/lib/security/transport/secure_endpoint.cc +++ b/src/core/lib/security/transport/secure_endpoint.cc @@ -140,7 +140,7 @@ static void call_read_cb(grpc_exec_ctx* exec_ctx, secure_endpoint* ep, gpr_free(data); } } - ep->read_buffer = NULL; + ep->read_buffer = nullptr; GRPC_CLOSURE_SCHED(exec_ctx, ep->read_cb, error); SECURE_ENDPOINT_UNREF(exec_ctx, ep, "read"); } @@ -162,7 +162,7 @@ static void on_read(grpc_exec_ctx* exec_ctx, void* user_data, return; } - if (ep->zero_copy_protector != NULL) { + if (ep->zero_copy_protector != nullptr) { // Use zero-copy grpc protector to unprotect. result = tsi_zero_copy_grpc_protector_unprotect( exec_ctx, ep->zero_copy_protector, &ep->source_buffer, ep->read_buffer); @@ -280,7 +280,7 @@ static void endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* secure_ep, } } - if (ep->zero_copy_protector != NULL) { + if (ep->zero_copy_protector != nullptr) { // Use zero-copy grpc protector to protect. result = tsi_zero_copy_grpc_protector_protect( exec_ctx, ep->zero_copy_protector, slices, &ep->output_buffer); @@ -434,7 +434,7 @@ grpc_endpoint* grpc_secure_endpoint_create( ep->read_staging_buffer = GRPC_SLICE_MALLOC(STAGING_BUFFER_SIZE); grpc_slice_buffer_init(&ep->output_buffer); grpc_slice_buffer_init(&ep->source_buffer); - ep->read_buffer = NULL; + ep->read_buffer = nullptr; GRPC_CLOSURE_INIT(&ep->on_read, on_read, ep, grpc_schedule_on_exec_ctx); gpr_mu_init(&ep->protector_mu); gpr_ref_init(&ep->ref, 1); diff --git a/src/core/lib/security/transport/security_connector.cc b/src/core/lib/security/transport/security_connector.cc index b5822d7454..0e89d005a0 100644 --- a/src/core/lib/security/transport/security_connector.cc +++ b/src/core/lib/security/transport/security_connector.cc @@ -60,7 +60,7 @@ static const char* installed_roots_path = /* -- Overridden default roots. -- */ -static grpc_ssl_roots_override_callback ssl_roots_override_cb = NULL; +static grpc_ssl_roots_override_callback ssl_roots_override_cb = nullptr; void grpc_set_ssl_roots_override_callback(grpc_ssl_roots_override_callback cb) { ssl_roots_override_cb = cb; @@ -74,11 +74,11 @@ void grpc_set_ssl_roots_override_callback(grpc_ssl_roots_override_callback cb) { "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384" static gpr_once cipher_suites_once = GPR_ONCE_INIT; -static const char* cipher_suites = NULL; +static const char* cipher_suites = nullptr; static void init_cipher_suites(void) { char* overridden = gpr_getenv("GRPC_SSL_CIPHER_SUITES"); - cipher_suites = overridden != NULL ? overridden : GRPC_SSL_CIPHER_SUITES; + cipher_suites = overridden != nullptr ? overridden : GRPC_SSL_CIPHER_SUITES; } static const char* ssl_cipher_suites(void) { @@ -92,24 +92,24 @@ static const char* ssl_cipher_suites(void) { const tsi_peer_property* tsi_peer_get_property_by_name(const tsi_peer* peer, const char* name) { size_t i; - if (peer == NULL) return NULL; + if (peer == nullptr) return nullptr; for (i = 0; i < peer->property_count; i++) { const tsi_peer_property* property = &peer->properties[i]; - if (name == NULL && property->name == NULL) { + if (name == nullptr && property->name == nullptr) { return property; } - if (name != NULL && property->name != NULL && + if (name != nullptr && property->name != nullptr && strcmp(property->name, name) == 0) { return property; } } - return NULL; + return nullptr; } void grpc_channel_security_connector_add_handshakers( grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* connector, grpc_handshake_manager* handshake_mgr) { - if (connector != NULL) { + if (connector != nullptr) { connector->add_handshakers(exec_ctx, connector, handshake_mgr); } } @@ -117,7 +117,7 @@ void grpc_channel_security_connector_add_handshakers( void grpc_server_security_connector_add_handshakers( grpc_exec_ctx* exec_ctx, grpc_server_security_connector* connector, grpc_handshake_manager* handshake_mgr) { - if (connector != NULL) { + if (connector != nullptr) { connector->add_handshakers(exec_ctx, connector, handshake_mgr); } } @@ -127,7 +127,7 @@ void grpc_security_connector_check_peer(grpc_exec_ctx* exec_ctx, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { - if (sc == NULL) { + if (sc == nullptr) { GRPC_CLOSURE_SCHED(exec_ctx, on_peer_checked, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "cannot check peer -- no security connector")); @@ -139,7 +139,7 @@ void grpc_security_connector_check_peer(grpc_exec_ctx* exec_ctx, int grpc_security_connector_cmp(grpc_security_connector* sc, grpc_security_connector* other) { - if (sc == NULL || other == NULL) return GPR_ICMP(sc, other); + if (sc == nullptr || other == nullptr) return GPR_ICMP(sc, other); int c = GPR_ICMP(sc->vtable, other->vtable); if (c != 0) return c; return sc->vtable->cmp(sc, other); @@ -147,8 +147,8 @@ int grpc_security_connector_cmp(grpc_security_connector* sc, int grpc_channel_security_connector_cmp(grpc_channel_security_connector* sc1, grpc_channel_security_connector* sc2) { - GPR_ASSERT(sc1->channel_creds != NULL); - GPR_ASSERT(sc2->channel_creds != NULL); + GPR_ASSERT(sc1->channel_creds != nullptr); + GPR_ASSERT(sc2->channel_creds != nullptr); int c = GPR_ICMP(sc1->channel_creds, sc2->channel_creds); if (c != 0) return c; c = GPR_ICMP(sc1->request_metadata_creds, sc2->request_metadata_creds); @@ -163,8 +163,8 @@ int grpc_channel_security_connector_cmp(grpc_channel_security_connector* sc1, int grpc_server_security_connector_cmp(grpc_server_security_connector* sc1, grpc_server_security_connector* sc2) { - GPR_ASSERT(sc1->server_creds != NULL); - GPR_ASSERT(sc2->server_creds != NULL); + GPR_ASSERT(sc1->server_creds != nullptr); + GPR_ASSERT(sc2->server_creds != nullptr); int c = GPR_ICMP(sc1->server_creds, sc2->server_creds); if (c != 0) return c; return GPR_ICMP((void*)sc1->add_handshakers, (void*)sc2->add_handshakers); @@ -174,7 +174,7 @@ bool grpc_channel_security_connector_check_call_host( grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, const char* host, grpc_auth_context* auth_context, grpc_closure* on_call_host_checked, grpc_error** error) { - if (sc == NULL || sc->check_call_host == NULL) { + if (sc == nullptr || sc->check_call_host == nullptr) { *error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "cannot check call host -- no security connector"); return true; @@ -186,7 +186,7 @@ bool grpc_channel_security_connector_check_call_host( void grpc_channel_security_connector_cancel_check_call_host( grpc_exec_ctx* exec_ctx, grpc_channel_security_connector* sc, grpc_closure* on_call_host_checked, grpc_error* error) { - if (sc == NULL || sc->cancel_check_call_host == NULL) { + if (sc == nullptr || sc->cancel_check_call_host == nullptr) { GRPC_ERROR_UNREF(error); return; } @@ -197,7 +197,7 @@ void grpc_channel_security_connector_cancel_check_call_host( grpc_security_connector* grpc_security_connector_ref( grpc_security_connector* sc, const char* file, int line, const char* reason) { - if (sc == NULL) return NULL; + if (sc == nullptr) return nullptr; if (GRPC_TRACER_ON(grpc_trace_security_connector_refcount)) { gpr_atm val = gpr_atm_no_barrier_load(&sc->refcount.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -218,7 +218,7 @@ void grpc_security_connector_unref(grpc_exec_ctx* exec_ctx, grpc_security_connector* sc, const char* file, int line, const char* reason) { - if (sc == NULL) return; + if (sc == nullptr) return; if (GRPC_TRACER_ON(grpc_trace_security_connector_refcount)) { gpr_atm val = gpr_atm_no_barrier_load(&sc->refcount.count); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -257,11 +257,11 @@ grpc_arg grpc_security_connector_to_arg(grpc_security_connector* sc) { } grpc_security_connector* grpc_security_connector_from_arg(const grpc_arg* arg) { - if (strcmp(arg->key, GRPC_ARG_SECURITY_CONNECTOR)) return NULL; + if (strcmp(arg->key, GRPC_ARG_SECURITY_CONNECTOR)) return nullptr; if (arg->type != GRPC_ARG_POINTER) { gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type, GRPC_ARG_SECURITY_CONNECTOR); - return NULL; + return nullptr; } return (grpc_security_connector*)arg->value.pointer.p; } @@ -269,13 +269,13 @@ grpc_security_connector* grpc_security_connector_from_arg(const grpc_arg* arg) { grpc_security_connector* grpc_security_connector_find_in_args( const grpc_channel_args* args) { size_t i; - if (args == NULL) return NULL; + if (args == nullptr) return nullptr; for (i = 0; i < args->num_args; i++) { grpc_security_connector* sc = grpc_security_connector_from_arg(&args->args[i]); - if (sc != NULL) return sc; + if (sc != nullptr) return sc; } - return NULL; + return nullptr; } static tsi_client_certificate_request_type @@ -328,14 +328,14 @@ static void fake_server_destroy(grpc_exec_ctx* exec_ctx, static bool fake_check_target(const char* target_type, const char* target, const char* set_str) { - GPR_ASSERT(target_type != NULL); - GPR_ASSERT(target != NULL); - char** set = NULL; + GPR_ASSERT(target_type != nullptr); + GPR_ASSERT(target != nullptr); + char** set = nullptr; size_t set_size = 0; gpr_string_split(set_str, ",", &set, &set_size); bool found = false; for (size_t i = 0; i < set_size; ++i) { - if (set[i] != NULL && strcmp(target, set[i]) == 0) found = true; + if (set[i] != nullptr && strcmp(target, set[i]) == 0) found = true; } for (size_t i = 0; i < set_size; ++i) { gpr_free(set[i]); @@ -347,8 +347,8 @@ static bool fake_check_target(const char* target_type, const char* target, static void fake_secure_name_check(const char* target, const char* expected_targets, bool is_lb_channel) { - if (expected_targets == NULL) return; - char** lbs_and_backends = NULL; + if (expected_targets == nullptr) return; + char** lbs_and_backends = nullptr; size_t lbs_and_backends_size = 0; bool success = false; gpr_string_split(expected_targets, ";", &lbs_and_backends, @@ -394,18 +394,18 @@ static void fake_check_peer(grpc_exec_ctx* exec_ctx, grpc_closure* on_peer_checked) { const char* prop_name; grpc_error* error = GRPC_ERROR_NONE; - *auth_context = NULL; + *auth_context = nullptr; if (peer.property_count != 1) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Fake peers should only have 1 property."); goto end; } prop_name = peer.properties[0].name; - if (prop_name == NULL || + if (prop_name == nullptr || strcmp(prop_name, TSI_CERTIFICATE_TYPE_PEER_PROPERTY)) { char* msg; gpr_asprintf(&msg, "Unexpected property in fake peer: %s.", - prop_name == NULL ? "<EMPTY>" : prop_name); + prop_name == nullptr ? "<EMPTY>" : prop_name); error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); gpr_free(msg); goto end; @@ -416,7 +416,7 @@ static void fake_check_peer(grpc_exec_ctx* exec_ctx, "Invalid value for cert type property."); goto end; } - *auth_context = grpc_auth_context_create(NULL); + *auth_context = grpc_auth_context_create(nullptr); grpc_auth_context_add_cstring_property( *auth_context, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME, GRPC_FAKE_TRANSPORT_SECURITY_TYPE); @@ -452,7 +452,7 @@ static int fake_channel_cmp(grpc_security_connector* sc1, if (c != 0) return c; c = strcmp(c1->target, c2->target); if (c != 0) return c; - if (c1->expected_targets == NULL || c2->expected_targets == NULL) { + if (c1->expected_targets == nullptr || c2->expected_targets == nullptr) { c = GPR_ICMP(c1->expected_targets, c2->expected_targets); } else { c = strcmp(c1->expected_targets, c2->expected_targets); @@ -527,7 +527,7 @@ grpc_channel_security_connector* grpc_fake_channel_security_connector_create( c->target = gpr_strdup(target); const char* expected_targets = grpc_fake_transport_get_expected_targets(args); c->expected_targets = gpr_strdup(expected_targets); - c->is_lb_channel = (grpc_lb_targets_info_find_in_args(args) != NULL); + c->is_lb_channel = (grpc_lb_targets_info_find_in_args(args) != nullptr); return &c->base; } @@ -560,11 +560,11 @@ typedef struct { static bool server_connector_has_cert_config_fetcher( grpc_ssl_server_security_connector* c) { - GPR_ASSERT(c != NULL); + GPR_ASSERT(c != nullptr); grpc_ssl_server_credentials* server_creds = (grpc_ssl_server_credentials*)c->base.server_creds; - GPR_ASSERT(server_creds != NULL); - return server_creds->certificate_config_fetcher.cb != NULL; + GPR_ASSERT(server_creds != nullptr); + return server_creds->certificate_config_fetcher.cb != nullptr; } static void ssl_channel_destroy(grpc_exec_ctx* exec_ctx, @@ -574,9 +574,9 @@ static void ssl_channel_destroy(grpc_exec_ctx* exec_ctx, grpc_channel_credentials_unref(exec_ctx, c->base.channel_creds); grpc_call_credentials_unref(exec_ctx, c->base.request_metadata_creds); tsi_ssl_client_handshaker_factory_unref(c->client_handshaker_factory); - c->client_handshaker_factory = NULL; - if (c->target_name != NULL) gpr_free(c->target_name); - if (c->overridden_target_name != NULL) gpr_free(c->overridden_target_name); + c->client_handshaker_factory = nullptr; + if (c->target_name != nullptr) gpr_free(c->target_name); + if (c->overridden_target_name != nullptr) gpr_free(c->overridden_target_name); gpr_free(sc); } @@ -586,7 +586,7 @@ static void ssl_server_destroy(grpc_exec_ctx* exec_ctx, (grpc_ssl_server_security_connector*)sc; grpc_server_credentials_unref(exec_ctx, c->base.server_creds); tsi_ssl_server_handshaker_factory_unref(c->server_handshaker_factory); - c->server_handshaker_factory = NULL; + c->server_handshaker_factory = nullptr; gpr_free(sc); } @@ -596,10 +596,10 @@ static void ssl_channel_add_handshakers(grpc_exec_ctx* exec_ctx, grpc_ssl_channel_security_connector* c = (grpc_ssl_channel_security_connector*)sc; // Instantiate TSI handshaker. - tsi_handshaker* tsi_hs = NULL; + tsi_handshaker* tsi_hs = nullptr; tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker( c->client_handshaker_factory, - c->overridden_target_name != NULL ? c->overridden_target_name + c->overridden_target_name != nullptr ? c->overridden_target_name : c->target_name, &tsi_hs); if (result != TSI_OK) { @@ -615,7 +615,7 @@ static void ssl_channel_add_handshakers(grpc_exec_ctx* exec_ctx, } static const char** fill_alpn_protocol_strings(size_t* num_alpn_protocols) { - GPR_ASSERT(num_alpn_protocols != NULL); + GPR_ASSERT(num_alpn_protocols != nullptr); *num_alpn_protocols = grpc_chttp2_num_alpn_versions(); const char** alpn_protocol_strings = (const char**)gpr_malloc(sizeof(const char*) * (*num_alpn_protocols)); @@ -632,7 +632,7 @@ static const char** fill_alpn_protocol_strings(size_t* num_alpn_protocols) { static bool try_replace_server_handshaker_factory( grpc_ssl_server_security_connector* sc, const grpc_ssl_server_certificate_config* config) { - if (config == NULL) { + if (config == nullptr) { gpr_log(GPR_ERROR, "Server certificate config callback returned invalid (NULL) " "config."); @@ -645,7 +645,7 @@ static bool try_replace_server_handshaker_factory( fill_alpn_protocol_strings(&num_alpn_protocols); tsi_ssl_pem_key_cert_pair* cert_pairs = grpc_convert_grpc_to_tsi_cert_pairs( config->pem_key_cert_pairs, config->num_key_cert_pairs); - tsi_ssl_server_handshaker_factory* new_handshaker_factory = NULL; + tsi_ssl_server_handshaker_factory* new_handshaker_factory = nullptr; grpc_ssl_server_credentials* server_creds = (grpc_ssl_server_credentials*)sc->base.server_creds; tsi_result result = tsi_create_ssl_server_handshaker_factory_ex( @@ -672,10 +672,10 @@ static bool try_replace_server_handshaker_factory( * an error. Returns true if new credentials were sucessfully loaded. */ static bool try_fetch_ssl_server_credentials( grpc_ssl_server_security_connector* sc) { - grpc_ssl_server_certificate_config* certificate_config = NULL; + grpc_ssl_server_certificate_config* certificate_config = nullptr; bool status; - GPR_ASSERT(sc != NULL); + GPR_ASSERT(sc != nullptr); if (!server_connector_has_cert_config_fetcher(sc)) return false; grpc_ssl_server_credentials* server_creds = @@ -697,7 +697,7 @@ static bool try_fetch_ssl_server_credentials( status = false; } - if (certificate_config != NULL) { + if (certificate_config != nullptr) { grpc_ssl_server_certificate_config_destroy(certificate_config); } return status; @@ -710,7 +710,7 @@ static void ssl_server_add_handshakers(grpc_exec_ctx* exec_ctx, (grpc_ssl_server_security_connector*)sc; // Instantiate TSI handshaker. try_fetch_ssl_server_credentials(c); - tsi_handshaker* tsi_hs = NULL; + tsi_handshaker* tsi_hs = nullptr; tsi_result result = tsi_ssl_server_handshaker_factory_create_handshaker( c->server_handshaker_factory, &tsi_hs); if (result != TSI_OK) { @@ -726,10 +726,10 @@ static void ssl_server_add_handshakers(grpc_exec_ctx* exec_ctx, } static int ssl_host_matches_name(const tsi_peer* peer, const char* peer_name) { - char* allocated_name = NULL; + char* allocated_name = nullptr; int r; - if (strchr(peer_name, ':') != NULL) { + if (strchr(peer_name, ':') != nullptr) { char* ignored_port; gpr_split_host_port(peer_name, &allocated_name, &ignored_port); gpr_free(ignored_port); @@ -743,21 +743,21 @@ static int ssl_host_matches_name(const tsi_peer* peer, const char* peer_name) { grpc_auth_context* tsi_ssl_peer_to_auth_context(const tsi_peer* peer) { size_t i; - grpc_auth_context* ctx = NULL; - const char* peer_identity_property_name = NULL; + grpc_auth_context* ctx = nullptr; + const char* peer_identity_property_name = nullptr; /* The caller has checked the certificate type property. */ GPR_ASSERT(peer->property_count >= 1); - ctx = grpc_auth_context_create(NULL); + ctx = grpc_auth_context_create(nullptr); grpc_auth_context_add_cstring_property( ctx, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME, GRPC_SSL_TRANSPORT_SECURITY_TYPE); for (i = 0; i < peer->property_count; i++) { const tsi_peer_property* prop = &peer->properties[i]; - if (prop->name == NULL) continue; + if (prop->name == nullptr) continue; if (strcmp(prop->name, TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY) == 0) { /* If there is no subject alt name, have the CN as the identity. */ - if (peer_identity_property_name == NULL) { + if (peer_identity_property_name == nullptr) { peer_identity_property_name = GRPC_X509_CN_PROPERTY_NAME; } grpc_auth_context_add_property(ctx, GRPC_X509_CN_PROPERTY_NAME, @@ -772,7 +772,7 @@ grpc_auth_context* tsi_ssl_peer_to_auth_context(const tsi_peer* peer) { prop->value.data, prop->value.length); } } - if (peer_identity_property_name != NULL) { + if (peer_identity_property_name != nullptr) { GPR_ASSERT(grpc_auth_context_set_peer_identity_property_name( ctx, peer_identity_property_name) == 1); } @@ -785,7 +785,7 @@ static grpc_error* ssl_check_peer(grpc_security_connector* sc, /* Check the ALPN. */ const tsi_peer_property* p = tsi_peer_get_property_by_name(peer, TSI_SSL_ALPN_SELECTED_PROTOCOL); - if (p == NULL) { + if (p == nullptr) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Cannot check peer: missing selected ALPN property."); } @@ -795,7 +795,7 @@ static grpc_error* ssl_check_peer(grpc_security_connector* sc, } /* Check the peer name if specified. */ - if (peer_name != NULL && !ssl_host_matches_name(peer, peer_name)) { + if (peer_name != nullptr && !ssl_host_matches_name(peer, peer_name)) { char* msg; gpr_asprintf(&msg, "Peer name %s is not in peer certificate", peer_name); grpc_error* error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); @@ -813,7 +813,7 @@ static void ssl_channel_check_peer(grpc_exec_ctx* exec_ctx, grpc_ssl_channel_security_connector* c = (grpc_ssl_channel_security_connector*)sc; grpc_error* error = ssl_check_peer(sc, - c->overridden_target_name != NULL + c->overridden_target_name != nullptr ? c->overridden_target_name : c->target_name, &peer, auth_context); @@ -825,7 +825,7 @@ static void ssl_server_check_peer(grpc_exec_ctx* exec_ctx, grpc_security_connector* sc, tsi_peer peer, grpc_auth_context** auth_context, grpc_closure* on_peer_checked) { - grpc_error* error = ssl_check_peer(sc, NULL, &peer, auth_context); + grpc_error* error = ssl_check_peer(sc, nullptr, &peer, auth_context); tsi_peer_destruct(&peer); GRPC_CLOSURE_SCHED(exec_ctx, on_peer_checked, error); } @@ -840,8 +840,8 @@ static int ssl_channel_cmp(grpc_security_connector* sc1, if (c != 0) return c; c = strcmp(c1->target_name, c2->target_name); if (c != 0) return c; - return (c1->overridden_target_name == NULL || - c2->overridden_target_name == NULL) + return (c1->overridden_target_name == nullptr || + c2->overridden_target_name == nullptr) ? GPR_ICMP(c1->overridden_target_name, c2->overridden_target_name) : strcmp(c1->overridden_target_name, c2->overridden_target_name); } @@ -871,13 +871,13 @@ tsi_peer tsi_shallow_peer_from_ssl_auth_context( memset(&peer, 0, sizeof(peer)); it = grpc_auth_context_property_iterator(auth_context); - while (grpc_auth_property_iterator_next(&it) != NULL) max_num_props++; + while (grpc_auth_property_iterator_next(&it) != nullptr) max_num_props++; if (max_num_props > 0) { peer.properties = (tsi_peer_property*)gpr_malloc(max_num_props * sizeof(tsi_peer_property)); it = grpc_auth_context_property_iterator(auth_context); - while ((prop = grpc_auth_property_iterator_next(&it)) != NULL) { + while ((prop = grpc_auth_property_iterator_next(&it)) != nullptr) { if (strcmp(prop->name, GRPC_X509_SAN_PROPERTY_NAME) == 0) { add_shallow_auth_property_to_peer( &peer, prop, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY); @@ -894,7 +894,7 @@ tsi_peer tsi_shallow_peer_from_ssl_auth_context( } void tsi_shallow_peer_destruct(tsi_peer* peer) { - if (peer->properties != NULL) gpr_free(peer->properties); + if (peer->properties != nullptr) gpr_free(peer->properties); } static bool ssl_channel_check_call_host(grpc_exec_ctx* exec_ctx, @@ -911,7 +911,7 @@ static bool ssl_channel_check_call_host(grpc_exec_ctx* exec_ctx, /* If the target name was overridden, then the original target_name was 'checked' transitively during the previous peer check at the end of the handshake. */ - if (c->overridden_target_name != NULL && strcmp(host, c->target_name) == 0) { + if (c->overridden_target_name != nullptr && strcmp(host, c->target_name) == 0) { status = GRPC_SECURITY_OK; } if (status != GRPC_SECURITY_OK) { @@ -941,7 +941,7 @@ static grpc_slice compute_default_pem_root_certs_once(void) { /* First try to load the roots from the environment. */ char* default_root_certs_path = gpr_getenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR); - if (default_root_certs_path != NULL) { + if (default_root_certs_path != nullptr) { GRPC_LOG_IF_ERROR("load_file", grpc_load_file(default_root_certs_path, 1, &result)); gpr_free(default_root_certs_path); @@ -949,11 +949,11 @@ static grpc_slice compute_default_pem_root_certs_once(void) { /* Try overridden roots if needed. */ grpc_ssl_roots_override_result ovrd_res = GRPC_SSL_ROOTS_OVERRIDE_FAIL; - if (GRPC_SLICE_IS_EMPTY(result) && ssl_roots_override_cb != NULL) { - char* pem_root_certs = NULL; + if (GRPC_SLICE_IS_EMPTY(result) && ssl_roots_override_cb != nullptr) { + char* pem_root_certs = nullptr; ovrd_res = ssl_roots_override_cb(&pem_root_certs); if (ovrd_res == GRPC_SSL_ROOTS_OVERRIDE_OK) { - GPR_ASSERT(pem_root_certs != NULL); + GPR_ASSERT(pem_root_certs != nullptr); result = grpc_slice_from_copied_buffer( pem_root_certs, strlen(pem_root_certs) + 1); // NULL terminator. @@ -986,7 +986,7 @@ const char* grpc_get_default_ssl_roots(void) { static gpr_once once = GPR_ONCE_INIT; gpr_once_init(&once, init_default_pem_root_certs); return GRPC_SLICE_IS_EMPTY(default_pem_root_certs) - ? NULL + ? nullptr : (const char*)GRPC_SLICE_START_PTR(default_pem_root_certs); } @@ -1004,13 +1004,13 @@ grpc_security_status grpc_ssl_channel_security_connector_create( char* port; bool has_key_cert_pair; - if (config == NULL || target_name == NULL) { + if (config == nullptr || target_name == nullptr) { gpr_log(GPR_ERROR, "An ssl channel needs a config and a target name."); goto error; } - if (config->pem_root_certs == NULL) { + if (config->pem_root_certs == nullptr) { pem_root_certs = grpc_get_default_ssl_roots(); - if (pem_root_certs == NULL) { + if (pem_root_certs == nullptr) { gpr_log(GPR_ERROR, "Could not get default pem root certs."); goto error; } @@ -1032,22 +1032,22 @@ grpc_security_status grpc_ssl_channel_security_connector_create( c->base.add_handshakers = ssl_channel_add_handshakers; gpr_split_host_port(target_name, &c->target_name, &port); gpr_free(port); - if (overridden_target_name != NULL) { + if (overridden_target_name != nullptr) { c->overridden_target_name = gpr_strdup(overridden_target_name); } - has_key_cert_pair = config->pem_key_cert_pair != NULL && - config->pem_key_cert_pair->private_key != NULL && - config->pem_key_cert_pair->cert_chain != NULL; + has_key_cert_pair = config->pem_key_cert_pair != nullptr && + config->pem_key_cert_pair->private_key != nullptr && + config->pem_key_cert_pair->cert_chain != nullptr; result = tsi_create_ssl_client_handshaker_factory( - has_key_cert_pair ? config->pem_key_cert_pair : NULL, pem_root_certs, + has_key_cert_pair ? config->pem_key_cert_pair : nullptr, pem_root_certs, ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols, &c->client_handshaker_factory); if (result != TSI_OK) { gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", tsi_result_to_string(result)); ssl_channel_destroy(exec_ctx, &c->base.base); - *sc = NULL; + *sc = nullptr; goto error; } *sc = &c->base; @@ -1081,8 +1081,8 @@ grpc_security_status grpc_ssl_server_security_connector_create( (grpc_ssl_server_credentials*)gsc; grpc_security_status retval = GRPC_SECURITY_OK; - GPR_ASSERT(server_credentials != NULL); - GPR_ASSERT(sc != NULL); + GPR_ASSERT(server_credentials != nullptr); + GPR_ASSERT(sc != nullptr); grpc_ssl_server_security_connector* c = grpc_ssl_server_security_connector_initialize(gsc); @@ -1115,8 +1115,8 @@ grpc_security_status grpc_ssl_server_security_connector_create( if (retval == GRPC_SECURITY_OK) { *sc = &c->base; } else { - if (c != NULL) ssl_server_destroy(exec_ctx, &c->base.base); - if (sc != NULL) *sc = NULL; + if (c != nullptr) ssl_server_destroy(exec_ctx, &c->base.base); + if (sc != nullptr) *sc = nullptr; } return retval; } diff --git a/src/core/lib/security/transport/security_handshaker.cc b/src/core/lib/security/transport/security_handshaker.cc index 63706f142b..c540445792 100644 --- a/src/core/lib/security/transport/security_handshaker.cc +++ b/src/core/lib/security/transport/security_handshaker.cc @@ -71,10 +71,10 @@ static void security_handshaker_unref(grpc_exec_ctx* exec_ctx, gpr_mu_destroy(&h->mu); tsi_handshaker_destroy(h->handshaker); tsi_handshaker_result_destroy(h->handshaker_result); - if (h->endpoint_to_destroy != NULL) { + if (h->endpoint_to_destroy != nullptr) { grpc_endpoint_destroy(exec_ctx, h->endpoint_to_destroy); } - if (h->read_buffer_to_destroy != NULL) { + if (h->read_buffer_to_destroy != nullptr) { grpc_slice_buffer_destroy_internal(exec_ctx, h->read_buffer_to_destroy); gpr_free(h->read_buffer_to_destroy); } @@ -91,11 +91,11 @@ static void security_handshaker_unref(grpc_exec_ctx* exec_ctx, static void cleanup_args_for_failure_locked(grpc_exec_ctx* exec_ctx, security_handshaker* h) { h->endpoint_to_destroy = h->args->endpoint; - h->args->endpoint = NULL; + h->args->endpoint = nullptr; h->read_buffer_to_destroy = h->args->read_buffer; - h->args->read_buffer = NULL; + h->args->read_buffer = nullptr; grpc_channel_args_destroy(exec_ctx, h->args->args); - h->args->args = NULL; + h->args->args = nullptr; } // If the handshake failed or we're shutting down, clean up and invoke the @@ -135,9 +135,9 @@ static void on_peer_checked_inner(grpc_exec_ctx* exec_ctx, return; } // Create zero-copy frame protector, if implemented. - tsi_zero_copy_grpc_protector* zero_copy_protector = NULL; + tsi_zero_copy_grpc_protector* zero_copy_protector = nullptr; tsi_result result = tsi_handshaker_result_create_zero_copy_grpc_protector( - exec_ctx, h->handshaker_result, NULL, &zero_copy_protector); + exec_ctx, h->handshaker_result, nullptr, &zero_copy_protector); if (result != TSI_OK && result != TSI_UNIMPLEMENTED) { error = grpc_set_tsi_error_result( GRPC_ERROR_CREATE_FROM_STATIC_STRING( @@ -147,10 +147,10 @@ static void on_peer_checked_inner(grpc_exec_ctx* exec_ctx, return; } // Create frame protector if zero-copy frame protector is NULL. - tsi_frame_protector* protector = NULL; - if (zero_copy_protector == NULL) { + tsi_frame_protector* protector = nullptr; + if (zero_copy_protector == nullptr) { result = tsi_handshaker_result_create_frame_protector(h->handshaker_result, - NULL, &protector); + nullptr, &protector); if (result != TSI_OK) { error = grpc_set_tsi_error_result(GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Frame protector creation failed"), @@ -160,7 +160,7 @@ static void on_peer_checked_inner(grpc_exec_ctx* exec_ctx, } } // Get unused bytes. - const unsigned char* unused_bytes = NULL; + const unsigned char* unused_bytes = nullptr; size_t unused_bytes_size = 0; result = tsi_handshaker_result_get_unused_bytes( h->handshaker_result, &unused_bytes, &unused_bytes_size); @@ -173,10 +173,10 @@ static void on_peer_checked_inner(grpc_exec_ctx* exec_ctx, grpc_slice_unref_internal(exec_ctx, slice); } else { h->args->endpoint = grpc_secure_endpoint_create( - protector, zero_copy_protector, h->args->endpoint, NULL, 0); + protector, zero_copy_protector, h->args->endpoint, nullptr, 0); } tsi_handshaker_result_destroy(h->handshaker_result); - h->handshaker_result = NULL; + h->handshaker_result = nullptr; // Clear out the read buffer before it gets passed to the transport. grpc_slice_buffer_reset_and_unref_internal(exec_ctx, h->args->read_buffer); // Add auth context to channel args. @@ -232,8 +232,8 @@ static grpc_error* on_handshake_next_done_locked( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshake failed"), result); } // Update handshaker result. - if (handshaker_result != NULL) { - GPR_ASSERT(h->handshaker_result == NULL); + if (handshaker_result != nullptr) { + GPR_ASSERT(h->handshaker_result == nullptr); h->handshaker_result = handshaker_result; } if (bytes_to_send_size > 0) { @@ -244,7 +244,7 @@ static grpc_error* on_handshake_next_done_locked( grpc_slice_buffer_add(&h->outgoing, to_send); grpc_endpoint_write(exec_ctx, h->args->endpoint, &h->outgoing, &h->on_handshake_data_sent_to_peer); - } else if (handshaker_result == NULL) { + } else if (handshaker_result == nullptr) { // There is nothing to send, but need to read from peer. grpc_endpoint_read(exec_ctx, h->args->endpoint, h->args->read_buffer, &h->on_handshake_data_received_from_peer); @@ -280,9 +280,9 @@ static grpc_error* do_handshaker_next_locked( grpc_exec_ctx* exec_ctx, security_handshaker* h, const unsigned char* bytes_received, size_t bytes_received_size) { // Invoke TSI handshaker. - const unsigned char* bytes_to_send = NULL; + const unsigned char* bytes_to_send = nullptr; size_t bytes_to_send_size = 0; - tsi_handshaker_result* handshaker_result = NULL; + tsi_handshaker_result* handshaker_result = nullptr; tsi_result result = tsi_handshaker_next( h->handshaker, bytes_received, bytes_received_size, &bytes_to_send, &bytes_to_send_size, &handshaker_result, @@ -356,7 +356,7 @@ static void on_handshake_data_sent_to_peer(grpc_exec_ctx* exec_ctx, void* arg, return; } // We may be done. - if (h->handshaker_result == NULL) { + if (h->handshaker_result == nullptr) { grpc_endpoint_read(exec_ctx, h->args->endpoint, h->args->read_buffer, &h->on_handshake_data_received_from_peer); } else { @@ -405,7 +405,7 @@ static void security_handshaker_do_handshake(grpc_exec_ctx* exec_ctx, h->args = args; h->on_handshake_done = on_handshake_done; gpr_ref(&h->refs); - grpc_error* error = do_handshaker_next_locked(exec_ctx, h, NULL, 0); + grpc_error* error = do_handshaker_next_locked(exec_ctx, h, nullptr, 0); if (error != GRPC_ERROR_NONE) { security_handshake_failed_locked(exec_ctx, h, error); gpr_mu_unlock(&h->mu); @@ -526,7 +526,7 @@ grpc_handshaker* grpc_security_handshaker_create( grpc_security_connector* connector) { // If no TSI handshaker was created, return a handshaker that always fails. // Otherwise, return a real security handshaker. - if (handshaker == NULL) { + if (handshaker == nullptr) { return fail_handshaker_create(); } else { return security_handshaker_create(exec_ctx, handshaker, connector); diff --git a/src/core/lib/security/transport/server_auth_filter.cc b/src/core/lib/security/transport/server_auth_filter.cc index e1307410d6..9cf368acd0 100644 --- a/src/core/lib/security/transport/server_auth_filter.cc +++ b/src/core/lib/security/transport/server_auth_filter.cc @@ -56,8 +56,8 @@ static grpc_metadata_array metadata_batch_to_md_array( grpc_linked_mdelem* l; grpc_metadata_array result; grpc_metadata_array_init(&result); - for (l = batch->list.head; l != NULL; l = l->next) { - grpc_metadata* usr_md = NULL; + for (l = batch->list.head; l != nullptr; l = l->next) { + grpc_metadata* usr_md = nullptr; grpc_mdelem md = l->md; grpc_slice key = GRPC_MDKEY(md); grpc_slice value = GRPC_MDVALUE(md); @@ -98,7 +98,7 @@ static void on_md_processing_done_inner(grpc_exec_ctx* exec_ctx, call_data* calld = (call_data*)elem->call_data; grpc_transport_stream_op_batch* batch = calld->recv_initial_metadata_batch; /* TODO(jboeuf): Implement support for response_md. */ - if (response_md != NULL && num_response_md > 0) { + if (response_md != nullptr && num_response_md > 0) { gpr_log(GPR_INFO, "response_md in auth metadata processing not supported for now. " "Ignoring..."); @@ -127,7 +127,7 @@ static void on_md_processing_done( (gpr_atm)STATE_DONE)) { grpc_error* error = GRPC_ERROR_NONE; if (status != GRPC_STATUS_OK) { - if (error_details == NULL) { + if (error_details == nullptr) { error_details = "Authentication metadata processing failed."; } error = grpc_error_set_int( @@ -154,7 +154,7 @@ static void cancel_call(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { if (error != GRPC_ERROR_NONE && gpr_atm_full_cas(&calld->state, (gpr_atm)STATE_INIT, (gpr_atm)STATE_CANCELLED)) { - on_md_processing_done_inner(exec_ctx, elem, NULL, 0, NULL, 0, + on_md_processing_done_inner(exec_ctx, elem, nullptr, 0, nullptr, 0, GRPC_ERROR_REF(error)); } GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "cancel_call"); @@ -167,7 +167,7 @@ static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx, void* arg, call_data* calld = (call_data*)elem->call_data; grpc_transport_stream_op_batch* batch = calld->recv_initial_metadata_batch; if (error == GRPC_ERROR_NONE) { - if (chand->creds != NULL && chand->creds->processor.process != NULL) { + if (chand->creds != nullptr && chand->creds->processor.process != nullptr) { // We're calling out to the application, so we need to make sure // to drop the call combiner early if we get cancelled. GRPC_CALL_STACK_REF(calld->owning_call, "cancel_call"); @@ -220,7 +220,7 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx, grpc_server_security_context_create(); server_ctx->auth_context = grpc_auth_context_create(chand->auth_context); calld->auth_context = server_ctx->auth_context; - if (args->context[GRPC_CONTEXT_SECURITY].value != NULL) { + if (args->context[GRPC_CONTEXT_SECURITY].value != nullptr) { args->context[GRPC_CONTEXT_SECURITY].destroy( args->context[GRPC_CONTEXT_SECURITY].value); } @@ -243,7 +243,7 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, channel_data* chand = (channel_data*)elem->channel_data; grpc_auth_context* auth_context = grpc_find_auth_context_in_args(args->channel_args); - GPR_ASSERT(auth_context != NULL); + GPR_ASSERT(auth_context != nullptr); chand->auth_context = GRPC_AUTH_CONTEXT_REF(auth_context, "server_auth_filter"); grpc_server_credentials* creds = diff --git a/src/core/lib/security/util/json_util.cc b/src/core/lib/security/util/json_util.cc index 365bd1537c..fef1a1f51d 100644 --- a/src/core/lib/security/util/json_util.cc +++ b/src/core/lib/security/util/json_util.cc @@ -26,12 +26,12 @@ const char* grpc_json_get_string_property(const grpc_json* json, const char* prop_name) { grpc_json* child; - for (child = json->child; child != NULL; child = child->next) { + for (child = json->child; child != nullptr; child = child->next) { if (strcmp(child->key, prop_name) == 0) break; } - if (child == NULL || child->type != GRPC_JSON_STRING) { + if (child == nullptr || child->type != GRPC_JSON_STRING) { gpr_log(GPR_ERROR, "Invalid or missing %s property.", prop_name); - return NULL; + return nullptr; } return child->value; } @@ -40,7 +40,7 @@ bool grpc_copy_json_string_property(const grpc_json* json, const char* prop_name, char** copied_value) { const char* prop_value = grpc_json_get_string_property(json, prop_name); - if (prop_value == NULL) return false; + if (prop_value == nullptr) return false; *copied_value = gpr_strdup(prop_value); return true; } diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc index d8e3200136..bbaf87ba23 100644 --- a/src/core/lib/slice/slice.cc +++ b/src/core/lib/slice/slice.cc @@ -35,7 +35,7 @@ char* grpc_slice_to_c_string(grpc_slice slice) { grpc_slice grpc_empty_slice(void) { grpc_slice out; - out.refcount = NULL; + out.refcount = nullptr; out.data.inlined.length = 0; return out; } @@ -260,7 +260,7 @@ grpc_slice grpc_slice_malloc(size_t length) { return grpc_slice_malloc_large(length); } else { /* small slice: just inline the data */ - slice.refcount = NULL; + slice.refcount = nullptr; slice.data.inlined.length = (uint8_t)length; } return slice; @@ -283,7 +283,7 @@ grpc_slice grpc_slice_sub_no_ref(grpc_slice source, size_t begin, size_t end) { } else { /* Enforce preconditions */ GPR_ASSERT(source.data.inlined.length >= end); - subset.refcount = NULL; + subset.refcount = nullptr; subset.data.inlined.length = (uint8_t)(end - begin); memcpy(subset.data.inlined.bytes, source.data.inlined.bytes + begin, end - begin); @@ -295,7 +295,7 @@ grpc_slice grpc_slice_sub(grpc_slice source, size_t begin, size_t end) { grpc_slice subset; if (end - begin <= sizeof(subset.data.inlined.bytes)) { - subset.refcount = NULL; + subset.refcount = nullptr; subset.data.inlined.length = (uint8_t)(end - begin); memcpy(subset.data.inlined.bytes, GRPC_SLICE_START_PTR(source) + begin, end - begin); @@ -311,10 +311,10 @@ grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice* source, size_t split, grpc_slice_ref_whom ref_whom) { grpc_slice tail; - if (source->refcount == NULL) { + if (source->refcount == nullptr) { /* inlined data, copy it out */ GPR_ASSERT(source->data.inlined.length >= split); - tail.refcount = NULL; + tail.refcount = nullptr; tail.data.inlined.length = (uint8_t)(source->data.inlined.length - split); memcpy(tail.data.inlined.bytes, source->data.inlined.bytes + split, tail.data.inlined.length); @@ -325,7 +325,7 @@ grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice* source, size_t split, if (tail_length < sizeof(tail.data.inlined.bytes) && ref_whom != GRPC_SLICE_REF_TAIL) { /* Copy out the bytes - it'll be cheaper than refcounting */ - tail.refcount = NULL; + tail.refcount = nullptr; tail.data.inlined.length = (uint8_t)tail_length; memcpy(tail.data.inlined.bytes, source->data.refcounted.bytes + split, tail_length); @@ -365,10 +365,10 @@ grpc_slice grpc_slice_split_tail(grpc_slice* source, size_t split) { grpc_slice grpc_slice_split_head(grpc_slice* source, size_t split) { grpc_slice head; - if (source->refcount == NULL) { + if (source->refcount == nullptr) { GPR_ASSERT(source->data.inlined.length >= split); - head.refcount = NULL; + head.refcount = nullptr; head.data.inlined.length = (uint8_t)split; memcpy(head.data.inlined.bytes, source->data.inlined.bytes, split); source->data.inlined.length = @@ -378,7 +378,7 @@ grpc_slice grpc_slice_split_head(grpc_slice* source, size_t split) { } else if (split < sizeof(head.data.inlined.bytes)) { GPR_ASSERT(source->data.refcounted.length >= split); - head.refcount = NULL; + head.refcount = nullptr; head.data.inlined.length = (uint8_t)split; memcpy(head.data.inlined.bytes, source->data.refcounted.bytes, split); source->refcount = source->refcount->sub_refcount; @@ -431,7 +431,7 @@ int grpc_slice_str_cmp(grpc_slice a, const char* b) { } int grpc_slice_is_equivalent(grpc_slice a, grpc_slice b) { - if (a.refcount == NULL || b.refcount == NULL) { + if (a.refcount == nullptr || b.refcount == nullptr) { return grpc_slice_eq(a, b); } return a.data.refcounted.length == b.data.refcounted.length && @@ -454,7 +454,7 @@ int grpc_slice_rchr(grpc_slice s, char c) { int grpc_slice_chr(grpc_slice s, char c) { const char* b = (const char*)GRPC_SLICE_START_PTR(s); const char* p = (const char*)memchr(b, c, GRPC_SLICE_LENGTH(s)); - return p == NULL ? -1 : (int)(p - b); + return p == nullptr ? -1 : (int)(p - b); } int grpc_slice_slice(grpc_slice haystack, grpc_slice needle) { diff --git a/src/core/lib/slice/slice_buffer.cc b/src/core/lib/slice/slice_buffer.cc index 3b71fdd4ea..5db54dad91 100644 --- a/src/core/lib/slice/slice_buffer.cc +++ b/src/core/lib/slice/slice_buffer.cc @@ -98,7 +98,7 @@ add_new: maybe_embiggen(sb); back = &sb->slices[sb->count]; sb->count++; - back->refcount = NULL; + back->refcount = nullptr; back->data.inlined.length = (uint8_t)n; return back->data.inlined.bytes; } @@ -137,7 +137,7 @@ void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice s) { maybe_embiggen(sb); back = &sb->slices[n]; sb->count = n + 1; - back->refcount = NULL; + back->refcount = nullptr; back->data.inlined.length = (uint8_t)(s.data.inlined.length - cp1); memcpy(back->data.inlined.bytes, s.data.inlined.bytes + cp1, s.data.inlined.length - cp1); diff --git a/src/core/lib/slice/slice_hash_table.cc b/src/core/lib/slice/slice_hash_table.cc index 6c2c9c201c..8f8e5a6b34 100644 --- a/src/core/lib/slice/slice_hash_table.cc +++ b/src/core/lib/slice/slice_hash_table.cc @@ -35,12 +35,12 @@ struct grpc_slice_hash_table { }; static bool is_empty(grpc_slice_hash_table_entry* entry) { - return entry->value == NULL; + return entry->value == nullptr; } static void grpc_slice_hash_table_add(grpc_slice_hash_table* table, grpc_slice key, void* value) { - GPR_ASSERT(value != NULL); + GPR_ASSERT(value != nullptr); const size_t hash = grpc_slice_hash(key); for (size_t offset = 0; offset < table->size; ++offset) { const size_t idx = (hash + offset) % table->size; @@ -77,13 +77,13 @@ grpc_slice_hash_table* grpc_slice_hash_table_create( } grpc_slice_hash_table* grpc_slice_hash_table_ref(grpc_slice_hash_table* table) { - if (table != NULL) gpr_ref(&table->refs); + if (table != nullptr) gpr_ref(&table->refs); return table; } void grpc_slice_hash_table_unref(grpc_exec_ctx* exec_ctx, grpc_slice_hash_table* table) { - if (table != NULL && gpr_unref(&table->refs)) { + if (table != nullptr && gpr_unref(&table->refs)) { for (size_t i = 0; i < table->size; ++i) { grpc_slice_hash_table_entry* entry = &table->entries[i]; if (!is_empty(entry)) { @@ -108,16 +108,16 @@ void* grpc_slice_hash_table_get(const grpc_slice_hash_table* table, return table->entries[idx].value; } } - return NULL; // Not found. + return nullptr; // Not found. } static int pointer_cmp(void* a, void* b) { return GPR_ICMP(a, b); } int grpc_slice_hash_table_cmp(const grpc_slice_hash_table* a, const grpc_slice_hash_table* b) { int (*const value_cmp_fn_a)(void* a, void* b) = - a->value_cmp != NULL ? a->value_cmp : pointer_cmp; + a->value_cmp != nullptr ? a->value_cmp : pointer_cmp; int (*const value_cmp_fn_b)(void* a, void* b) = - b->value_cmp != NULL ? b->value_cmp : pointer_cmp; + b->value_cmp != nullptr ? b->value_cmp : pointer_cmp; // Compare value_fns const int value_fns_cmp = GPR_ICMP((void*)value_cmp_fn_a, (void*)value_cmp_fn_b); diff --git a/src/core/lib/slice/slice_intern.cc b/src/core/lib/slice/slice_intern.cc index 50a0eba49c..4ceb712904 100644 --- a/src/core/lib/slice/slice_intern.cc +++ b/src/core/lib/slice/slice_intern.cc @@ -171,7 +171,7 @@ int grpc_static_slice_eq(grpc_slice a, grpc_slice b) { } uint32_t grpc_slice_hash(grpc_slice s) { - return s.refcount == NULL ? grpc_slice_default_hash_impl(s) + return s.refcount == nullptr ? grpc_slice_default_hash_impl(s) : s.refcount->vtable->hash(s); } diff --git a/src/core/lib/support/alloc.cc b/src/core/lib/support/alloc.cc index aef4cb8d51..518bdb99f7 100644 --- a/src/core/lib/support/alloc.cc +++ b/src/core/lib/support/alloc.cc @@ -40,10 +40,10 @@ gpr_allocation_functions gpr_get_allocation_functions() { } void gpr_set_allocation_functions(gpr_allocation_functions functions) { - GPR_ASSERT(functions.malloc_fn != NULL); - GPR_ASSERT(functions.realloc_fn != NULL); - GPR_ASSERT(functions.free_fn != NULL); - if (functions.zalloc_fn == NULL) { + GPR_ASSERT(functions.malloc_fn != nullptr); + GPR_ASSERT(functions.realloc_fn != nullptr); + GPR_ASSERT(functions.free_fn != nullptr); + if (functions.zalloc_fn == nullptr) { functions.zalloc_fn = zalloc_with_gpr_malloc; } g_alloc_functions = functions; @@ -51,7 +51,7 @@ void gpr_set_allocation_functions(gpr_allocation_functions functions) { void* gpr_malloc(size_t size) { void* p; - if (size == 0) return NULL; + if (size == 0) return nullptr; GPR_TIMER_BEGIN("gpr_malloc", 0); p = g_alloc_functions.malloc_fn(size); if (!p) { @@ -63,7 +63,7 @@ void* gpr_malloc(size_t size) { void* gpr_zalloc(size_t size) { void* p; - if (size == 0) return NULL; + if (size == 0) return nullptr; GPR_TIMER_BEGIN("gpr_zalloc", 0); p = g_alloc_functions.zalloc_fn(size); if (!p) { @@ -80,7 +80,7 @@ void gpr_free(void* p) { } void* gpr_realloc(void* p, size_t size) { - if ((size == 0) && (p == NULL)) return NULL; + if ((size == 0) && (p == nullptr)) return nullptr; GPR_TIMER_BEGIN("gpr_realloc", 0); p = g_alloc_functions.realloc_fn(p, size); if (!p) { diff --git a/src/core/lib/support/arena.cc b/src/core/lib/support/arena.cc index 0b37a88230..5b9dd370d8 100644 --- a/src/core/lib/support/arena.cc +++ b/src/core/lib/support/arena.cc @@ -62,7 +62,7 @@ void* gpr_arena_alloc(gpr_arena* arena, size_t size) { zone* z = &arena->initial_zone; while (start > z->size_end) { zone* next_z = (zone*)gpr_atm_acq_load(&z->next_atm); - if (next_z == NULL) { + if (next_z == nullptr) { size_t next_z_size = (size_t)gpr_atm_no_barrier_load(&arena->size_so_far); next_z = (zone*)gpr_zalloc(sizeof(zone) + next_z_size); next_z->size_begin = z->size_end; diff --git a/src/core/lib/support/atomic_with_atm.h b/src/core/lib/support/atomic_with_atm.h index fe00e9b5bc..5d675ff876 100644 --- a/src/core/lib/support/atomic_with_atm.h +++ b/src/core/lib/support/atomic_with_atm.h @@ -21,7 +21,7 @@ #include <grpc/support/atm.h> -namespace grpc_core { +namespace grpc_core;; { enum MemoryOrderRelaxed { memory_order_relaxed }; diff --git a/src/core/lib/support/avl.cc b/src/core/lib/support/avl.cc index 4ba101b74a..ca0e4c6372 100644 --- a/src/core/lib/support/avl.cc +++ b/src/core/lib/support/avl.cc @@ -28,7 +28,7 @@ gpr_avl gpr_avl_create(const gpr_avl_vtable* vtable) { gpr_avl out; out.vtable = vtable; - out.root = NULL; + out.root = nullptr; return out; } @@ -41,7 +41,7 @@ static gpr_avl_node* ref_node(gpr_avl_node* node) { static void unref_node(const gpr_avl_vtable* vtable, gpr_avl_node* node, void* user_data) { - if (node == NULL) { + if (node == nullptr) { return; } if (gpr_unref(&node->refs)) { @@ -54,18 +54,18 @@ static void unref_node(const gpr_avl_vtable* vtable, gpr_avl_node* node, } static long node_height(gpr_avl_node* node) { - return node == NULL ? 0 : node->height; + return node == nullptr ? 0 : node->height; } #ifndef NDEBUG static long calculate_height(gpr_avl_node* node) { - return node == NULL ? 0 + return node == nullptr ? 0 : 1 + GPR_MAX(calculate_height(node->left), calculate_height(node->right)); } static gpr_avl_node* assert_invariants(gpr_avl_node* n) { - if (n == NULL) return NULL; + if (n == nullptr) return nullptr; assert_invariants(n->left); assert_invariants(n->right); assert(calculate_height(n) == n->height); @@ -92,8 +92,8 @@ static gpr_avl_node* get(const gpr_avl_vtable* vtable, gpr_avl_node* node, void* key, void* user_data) { long cmp; - if (node == NULL) { - return NULL; + if (node == nullptr) { + return nullptr; } cmp = vtable->compare_keys(node->key, key, user_data); @@ -108,12 +108,12 @@ static gpr_avl_node* get(const gpr_avl_vtable* vtable, gpr_avl_node* node, void* gpr_avl_get(gpr_avl avl, void* key, void* user_data) { gpr_avl_node* node = get(avl.vtable, avl.root, key, user_data); - return node ? node->value : NULL; + return node ? node->value : nullptr; } int gpr_avl_maybe_get(gpr_avl avl, void* key, void** value, void* user_data) { gpr_avl_node* node = get(avl.vtable, avl.root, key, user_data); - if (node != NULL) { + if (node != nullptr) { *value = node->value; return 1; } @@ -200,8 +200,8 @@ static gpr_avl_node* rebalance(const gpr_avl_vtable* vtable, void* key, static gpr_avl_node* add_key(const gpr_avl_vtable* vtable, gpr_avl_node* node, void* key, void* value, void* user_data) { long cmp; - if (node == NULL) { - return new_node(key, value, NULL, NULL); + if (node == nullptr) { + return new_node(key, value, nullptr, nullptr); } cmp = vtable->compare_keys(node->key, key, user_data); if (cmp == 0) { @@ -228,14 +228,14 @@ gpr_avl gpr_avl_add(gpr_avl avl, void* key, void* value, void* user_data) { } static gpr_avl_node* in_order_head(gpr_avl_node* node) { - while (node->left != NULL) { + while (node->left != nullptr) { node = node->left; } return node; } static gpr_avl_node* in_order_tail(gpr_avl_node* node) { - while (node->right != NULL) { + while (node->right != nullptr) { node = node->right; } return node; @@ -245,14 +245,14 @@ static gpr_avl_node* remove_key(const gpr_avl_vtable* vtable, gpr_avl_node* node, void* key, void* user_data) { long cmp; - if (node == NULL) { - return NULL; + if (node == nullptr) { + return nullptr; } cmp = vtable->compare_keys(node->key, key, user_data); if (cmp == 0) { - if (node->left == NULL) { + if (node->left == nullptr) { return ref_node(node->right); - } else if (node->right == NULL) { + } else if (node->right == nullptr) { return ref_node(node->left); } else if (node->left->height < node->right->height) { gpr_avl_node* h = in_order_head(node->right); @@ -297,4 +297,4 @@ void gpr_avl_unref(gpr_avl avl, void* user_data) { unref_node(avl.vtable, avl.root, user_data); } -int gpr_avl_is_empty(gpr_avl avl) { return avl.root == NULL; } +int gpr_avl_is_empty(gpr_avl avl) { return avl.root == nullptr; } diff --git a/src/core/lib/support/cmdline.cc b/src/core/lib/support/cmdline.cc index d2785d2f30..da9f10a496 100644 --- a/src/core/lib/support/cmdline.cc +++ b/src/core/lib/support/cmdline.cc @@ -169,7 +169,7 @@ char* gpr_cmdline_usage_string(gpr_cmdline* cl, const char* argv0) { } gpr_strvec_add(&s, gpr_strdup("\n")); - tmp = gpr_strvec_flatten(&s, NULL); + tmp = gpr_strvec_flatten(&s, nullptr); gpr_strvec_destroy(&s); return tmp; } @@ -203,7 +203,7 @@ static arg* find_arg(gpr_cmdline* cl, char* name) { if (!a) { fprintf(stderr, "Unknown argument: %s\n", name); - return NULL; + return nullptr; } return a; @@ -246,9 +246,9 @@ static int value_state(gpr_cmdline* cl, char* str) { } static int normal_state(gpr_cmdline* cl, char* str) { - char* eq = NULL; - char* tmp = NULL; - char* arg_name = NULL; + char* eq = nullptr; + char* tmp = nullptr; + char* arg_name = nullptr; int r = 1; if (0 == strcmp(str, "-help") || 0 == strcmp(str, "--help") || @@ -256,7 +256,7 @@ static int normal_state(gpr_cmdline* cl, char* str) { return print_usage_and_die(cl); } - cl->cur_arg = NULL; + cl->cur_arg = nullptr; if (str[0] == '-') { if (str[1] == '-') { @@ -274,7 +274,7 @@ static int normal_state(gpr_cmdline* cl, char* str) { /* str is of the form '--no-foo' - it's a flag disable */ str += 3; cl->cur_arg = find_arg(cl, str); - if (cl->cur_arg == NULL) { + if (cl->cur_arg == nullptr) { return print_usage_and_die(cl); } if (cl->cur_arg->type != ARGTYPE_BOOL) { @@ -285,7 +285,7 @@ static int normal_state(gpr_cmdline* cl, char* str) { return 1; /* early out */ } eq = strchr(str, '='); - if (eq != NULL) { + if (eq != nullptr) { /* copy the string into a temp buffer and extract the name */ tmp = arg_name = (char*)gpr_malloc((size_t)(eq - str + 1)); memcpy(arg_name, str, (size_t)(eq - str)); @@ -294,10 +294,10 @@ static int normal_state(gpr_cmdline* cl, char* str) { arg_name = str; } cl->cur_arg = find_arg(cl, arg_name); - if (cl->cur_arg == NULL) { + if (cl->cur_arg == nullptr) { return print_usage_and_die(cl); } - if (eq != NULL) { + if (eq != nullptr) { /* str was of the type --foo=value, parse the value */ r = value_state(cl, eq + 1); } else if (cl->cur_arg->type != ARGTYPE_BOOL) { diff --git a/src/core/lib/support/env_linux.cc b/src/core/lib/support/env_linux.cc index 012ef63eff..0af2de9f7e 100644 --- a/src/core/lib/support/env_linux.cc +++ b/src/core/lib/support/env_linux.cc @@ -39,8 +39,8 @@ #include "src/core/lib/support/string.h" const char* gpr_getenv_silent(const char* name, char** dst) { - const char* insecure_func_used = NULL; - char* result = NULL; + const char* insecure_func_used = nullptr; + char* result = nullptr; #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE) typedef char* (*getenv_type)(const char*); static getenv_type getenv_func = NULL; @@ -60,14 +60,14 @@ const char* gpr_getenv_silent(const char* name, char** dst) { result = getenv(name); insecure_func_used = "getenv"; #endif - *dst = result == NULL ? result : gpr_strdup(result); + *dst = result == nullptr ? result : gpr_strdup(result); return insecure_func_used; } char* gpr_getenv(const char* name) { - char* result = NULL; + char* result = nullptr; const char* insecure_func_used = gpr_getenv_silent(name, &result); - if (insecure_func_used != NULL) { + if (insecure_func_used != nullptr) { gpr_log(GPR_DEBUG, "Warning: insecure environment read function '%s' used", insecure_func_used); } diff --git a/src/core/lib/support/host_port.cc b/src/core/lib/support/host_port.cc index 1927d5507d..cb8e3d4479 100644 --- a/src/core/lib/support/host_port.cc +++ b/src/core/lib/support/host_port.cc @@ -26,7 +26,7 @@ #include "src/core/lib/support/string.h" int gpr_join_host_port(char** out, const char* host, int port) { - if (host[0] != '[' && strchr(host, ':') != NULL) { + if (host[0] != '[' && strchr(host, ':') != nullptr) { /* IPv6 literals must be enclosed in brackets. */ return gpr_asprintf(out, "[%s]:%d", host, port); } else { @@ -40,19 +40,19 @@ int gpr_split_host_port(const char* name, char** host, char** port) { size_t host_len; const char* port_start; - *host = NULL; - *port = NULL; + *host = nullptr; + *port = nullptr; if (name[0] == '[') { /* Parse a bracketed host, typically an IPv6 literal. */ const char* rbracket = strchr(name, ']'); - if (rbracket == NULL) { + if (rbracket == nullptr) { /* Unmatched [ */ return 0; } if (rbracket[1] == '\0') { /* ]<end> */ - port_start = NULL; + port_start = nullptr; } else if (rbracket[1] == ':') { /* ]:<port?> */ port_start = rbracket + 2; @@ -62,14 +62,14 @@ int gpr_split_host_port(const char* name, char** host, char** port) { } host_start = name + 1; host_len = (size_t)(rbracket - host_start); - if (memchr(host_start, ':', host_len) == NULL) { + if (memchr(host_start, ':', host_len) == nullptr) { /* Require all bracketed hosts to contain a colon, because a hostname or IPv4 address should never use brackets. */ return 0; } } else { const char* colon = strchr(name, ':'); - if (colon != NULL && strchr(colon + 1, ':') == NULL) { + if (colon != nullptr && strchr(colon + 1, ':') == nullptr) { /* Exactly 1 colon. Split into host:port. */ host_start = name; host_len = (size_t)(colon - name); @@ -78,7 +78,7 @@ int gpr_split_host_port(const char* name, char** host, char** port) { /* 0 or 2+ colons. Bare hostname or IPv6 litearal. */ host_start = name; host_len = strlen(name); - port_start = NULL; + port_start = nullptr; } } @@ -87,7 +87,7 @@ int gpr_split_host_port(const char* name, char** host, char** port) { memcpy(*host, host_start, host_len); (*host)[host_len] = '\0'; - if (port_start != NULL) { + if (port_start != nullptr) { *port = gpr_strdup(port_start); } diff --git a/src/core/lib/support/log.cc b/src/core/lib/support/log.cc index 2140e4bd69..e9adc6c349 100644 --- a/src/core/lib/support/log.cc +++ b/src/core/lib/support/log.cc @@ -64,11 +64,11 @@ void gpr_set_log_verbosity(gpr_log_severity min_severity_to_print) { } void gpr_log_verbosity_init() { - char* verbosity = NULL; + char* verbosity = nullptr; const char* insecure_getenv = gpr_getenv_silent("GRPC_VERBOSITY", &verbosity); gpr_atm min_severity_to_print = GPR_LOG_SEVERITY_ERROR; - if (verbosity != NULL) { + if (verbosity != nullptr) { if (gpr_stricmp(verbosity, "DEBUG") == 0) { min_severity_to_print = (gpr_atm)GPR_LOG_SEVERITY_DEBUG; } else if (gpr_stricmp(verbosity, "INFO") == 0) { @@ -83,7 +83,7 @@ void gpr_log_verbosity_init() { gpr_atm_no_barrier_store(&g_min_severity_to_print, min_severity_to_print); } - if (insecure_getenv != NULL) { + if (insecure_getenv != nullptr) { gpr_log(GPR_DEBUG, "Warning: insecure environment read function '%s' used", insecure_getenv); } diff --git a/src/core/lib/support/log_linux.cc b/src/core/lib/support/log_linux.cc index e9be970305..e0e277fe87 100644 --- a/src/core/lib/support/log_linux.cc +++ b/src/core/lib/support/log_linux.cc @@ -43,7 +43,7 @@ static long gettid(void) { return syscall(__NR_gettid); } void gpr_log(const char* file, int line, gpr_log_severity severity, const char* format, ...) { - char* message = NULL; + char* message = nullptr; va_list args; va_start(args, format); if (vasprintf(&message, format, args) == -1) { @@ -69,7 +69,7 @@ extern "C" void gpr_default_log(gpr_log_func_args* args) { timer = (time_t)now.tv_sec; final_slash = strrchr(args->file, '/'); - if (final_slash == NULL) + if (final_slash == nullptr) display_file = args->file; else display_file = final_slash + 1; diff --git a/src/core/lib/support/mpscq.cc b/src/core/lib/support/mpscq.cc index b270777d5c..47e896d2df 100644 --- a/src/core/lib/support/mpscq.cc +++ b/src/core/lib/support/mpscq.cc @@ -49,15 +49,15 @@ gpr_mpscq_node* gpr_mpscq_pop_and_check_end(gpr_mpscq* q, bool* empty) { gpr_mpscq_node* next = (gpr_mpscq_node*)gpr_atm_acq_load(&tail->next); if (tail == &q->stub) { // indicates the list is actually (ephemerally) empty - if (next == NULL) { + if (next == nullptr) { *empty = true; - return NULL; + return nullptr; } q->tail = next; tail = next; next = (gpr_mpscq_node*)gpr_atm_acq_load(&tail->next); } - if (next != NULL) { + if (next != nullptr) { *empty = false; q->tail = next; return tail; @@ -66,17 +66,17 @@ gpr_mpscq_node* gpr_mpscq_pop_and_check_end(gpr_mpscq* q, bool* empty) { if (tail != head) { *empty = false; // indicates a retry is in order: we're still adding - return NULL; + return nullptr; } gpr_mpscq_push(q, &q->stub); next = (gpr_mpscq_node*)gpr_atm_acq_load(&tail->next); - if (next != NULL) { + if (next != nullptr) { q->tail = next; return tail; } // indicates a retry is in order: we're still adding *empty = false; - return NULL; + return nullptr; } void gpr_locked_mpscq_init(gpr_locked_mpscq* q) { @@ -99,7 +99,7 @@ gpr_mpscq_node* gpr_locked_mpscq_try_pop(gpr_locked_mpscq* q) { gpr_mu_unlock(&q->mu); return n; } - return NULL; + return nullptr; } gpr_mpscq_node* gpr_locked_mpscq_pop(gpr_locked_mpscq* q) { @@ -108,7 +108,7 @@ gpr_mpscq_node* gpr_locked_mpscq_pop(gpr_locked_mpscq* q) { gpr_mpscq_node* n; do { n = gpr_mpscq_pop_and_check_end(&q->queue, &empty); - } while (n == NULL && !empty); + } while (n == nullptr && !empty); gpr_mu_unlock(&q->mu); return n; } diff --git a/src/core/lib/support/string.cc b/src/core/lib/support/string.cc index 6dc4fbc921..e31ad72c68 100644 --- a/src/core/lib/support/string.cc +++ b/src/core/lib/support/string.cc @@ -35,7 +35,7 @@ char* gpr_strdup(const char* src) { size_t len; if (!src) { - return NULL; + return nullptr; } len = strlen(src) + 1; @@ -53,7 +53,7 @@ typedef struct { } dump_out; static dump_out dump_out_create(void) { - dump_out r = {0, 0, NULL}; + dump_out r = {0, 0, nullptr}; return r; } @@ -223,7 +223,7 @@ char* gpr_strjoin_sep(const char** strs, size_t nstrs, const char* sep, out_length += slen; } out[out_length] = 0; - if (final_length != NULL) { + if (final_length != nullptr) { *final_length = out_length; } return out; @@ -278,7 +278,7 @@ static void add_string_to_split(const char* beg, const char* end, char*** strs, void gpr_string_split(const char* input, const char* sep, char*** strs, size_t* nstrs) { const char* next; - *strs = NULL; + *strs = nullptr; *nstrs = 0; size_t capstrs = 0; while ((next = strstr(input, sep))) { @@ -289,7 +289,7 @@ void gpr_string_split(const char* input, const char* sep, char*** strs, } void* gpr_memrchr(const void* s, int c, size_t n) { - if (s == NULL) return NULL; + if (s == nullptr) return nullptr; char* b = (char*)s; size_t i; for (i = 0; i < n; i++) { @@ -297,12 +297,12 @@ void* gpr_memrchr(const void* s, int c, size_t n) { return &b[n - i - 1]; } } - return NULL; + return nullptr; } bool gpr_is_true(const char* s) { size_t i; - if (s == NULL) { + if (s == nullptr) { return false; } static const char* truthy[] = {"yes", "true", "1"}; diff --git a/src/core/lib/support/string_posix.cc b/src/core/lib/support/string_posix.cc index 79c81656cc..8b818e39b9 100644 --- a/src/core/lib/support/string_posix.cc +++ b/src/core/lib/support/string_posix.cc @@ -38,13 +38,13 @@ int gpr_asprintf(char** strp, const char* format, ...) { ret = vsnprintf(buf, sizeof(buf), format, args); va_end(args); if (ret < 0) { - *strp = NULL; + *strp = nullptr; return -1; } /* Allocate a new buffer, with space for the NUL terminator. */ strp_buflen = (size_t)ret + 1; - if ((*strp = (char*)gpr_malloc(strp_buflen)) == NULL) { + if ((*strp = (char*)gpr_malloc(strp_buflen)) == nullptr) { /* This shouldn't happen, because gpr_malloc() calls abort(). */ return -1; } @@ -65,7 +65,7 @@ int gpr_asprintf(char** strp, const char* format, ...) { /* This should never happen. */ gpr_free(*strp); - *strp = NULL; + *strp = nullptr; return -1; } diff --git a/src/core/lib/support/subprocess_posix.cc b/src/core/lib/support/subprocess_posix.cc index 4d6972a0c4..dc046b6499 100644 --- a/src/core/lib/support/subprocess_posix.cc +++ b/src/core/lib/support/subprocess_posix.cc @@ -50,16 +50,16 @@ gpr_subprocess* gpr_subprocess_create(int argc, const char** argv) { pid = fork(); if (pid == -1) { - return NULL; + return nullptr; } else if (pid == 0) { exec_args = (char**)gpr_malloc(((size_t)argc + 1) * sizeof(char*)); memcpy(exec_args, argv, (size_t)argc * sizeof(char*)); - exec_args[argc] = NULL; + exec_args[argc] = nullptr; execv(exec_args[0], exec_args); /* if we reach here, an error has occurred */ gpr_log(GPR_ERROR, "execv '%s' failed: %s", exec_args[0], strerror(errno)); _exit(1); - return NULL; + return nullptr; } else { r = (gpr_subprocess*)gpr_zalloc(sizeof(gpr_subprocess)); r->pid = pid; diff --git a/src/core/lib/support/sync.cc b/src/core/lib/support/sync.cc index 1c051a1ca4..347ffcd00e 100644 --- a/src/core/lib/support/sync.cc +++ b/src/core/lib/support/sync.cc @@ -61,7 +61,7 @@ void gpr_event_set(gpr_event* ev, void* value) { gpr_atm_rel_store(&ev->state, (gpr_atm)value); gpr_cv_broadcast(&s->cv); gpr_mu_unlock(&s->mu); - GPR_ASSERT(value != NULL); + GPR_ASSERT(value != nullptr); } void* gpr_event_get(gpr_event* ev) { @@ -70,12 +70,12 @@ void* gpr_event_get(gpr_event* ev) { void* gpr_event_wait(gpr_event* ev, gpr_timespec abs_deadline) { void* result = (void*)gpr_atm_acq_load(&ev->state); - if (result == NULL) { + if (result == nullptr) { struct sync_array_s* s = hash(ev); gpr_mu_lock(&s->mu); do { result = (void*)gpr_atm_acq_load(&ev->state); - } while (result == NULL && !gpr_cv_wait(&s->cv, &s->mu, abs_deadline)); + } while (result == nullptr && !gpr_cv_wait(&s->cv, &s->mu, abs_deadline)); gpr_mu_unlock(&s->mu); } return result; diff --git a/src/core/lib/support/sync_posix.cc b/src/core/lib/support/sync_posix.cc index 62d800b18c..d306d43cb4 100644 --- a/src/core/lib/support/sync_posix.cc +++ b/src/core/lib/support/sync_posix.cc @@ -33,7 +33,7 @@ gpr_atm gpr_counter_atm_cas = 0; gpr_atm gpr_counter_atm_add = 0; #endif -void gpr_mu_init(gpr_mu* mu) { GPR_ASSERT(pthread_mutex_init(mu, NULL) == 0); } +void gpr_mu_init(gpr_mu* mu) { GPR_ASSERT(pthread_mutex_init(mu, nullptr) == 0); } void gpr_mu_destroy(gpr_mu* mu) { GPR_ASSERT(pthread_mutex_destroy(mu) == 0); } @@ -63,7 +63,7 @@ int gpr_mu_trylock(gpr_mu* mu) { /*----------------------------------------*/ -void gpr_cv_init(gpr_cv* cv) { GPR_ASSERT(pthread_cond_init(cv, NULL) == 0); } +void gpr_cv_init(gpr_cv* cv) { GPR_ASSERT(pthread_cond_init(cv, nullptr) == 0); } void gpr_cv_destroy(gpr_cv* cv) { GPR_ASSERT(pthread_cond_destroy(cv) == 0); } diff --git a/src/core/lib/support/thd_posix.cc b/src/core/lib/support/thd_posix.cc index 297714e659..02e3846be1 100644 --- a/src/core/lib/support/thd_posix.cc +++ b/src/core/lib/support/thd_posix.cc @@ -40,7 +40,7 @@ static void* thread_body(void* v) { struct thd_arg a = *(struct thd_arg*)v; free(v); (*a.body)(a.arg); - return NULL; + return nullptr; } int gpr_thd_new(gpr_thd_id* t, void (*thd_body)(void* arg), void* arg, @@ -51,7 +51,7 @@ int gpr_thd_new(gpr_thd_id* t, void (*thd_body)(void* arg), void* arg, /* don't use gpr_malloc as we may cause an infinite recursion with * the profiling code */ struct thd_arg* a = (struct thd_arg*)malloc(sizeof(*a)); - GPR_ASSERT(a != NULL); + GPR_ASSERT(a != nullptr); a->body = thd_body; a->arg = arg; @@ -75,6 +75,6 @@ int gpr_thd_new(gpr_thd_id* t, void (*thd_body)(void* arg), void* arg, gpr_thd_id gpr_thd_currentid(void) { return (gpr_thd_id)pthread_self(); } -void gpr_thd_join(gpr_thd_id t) { pthread_join((pthread_t)t, NULL); } +void gpr_thd_join(gpr_thd_id t) { pthread_join((pthread_t)t, nullptr); } #endif /* GPR_POSIX_SYNC */ diff --git a/src/core/lib/support/time_posix.cc b/src/core/lib/support/time_posix.cc index 3674ef7184..7f65205800 100644 --- a/src/core/lib/support/time_posix.cc +++ b/src/core/lib/support/time_posix.cc @@ -158,7 +158,7 @@ void gpr_sleep_until(gpr_timespec until) { delta = gpr_time_sub(until, now); delta_ts = timespec_from_gpr(delta); - ns_result = nanosleep(&delta_ts, NULL); + ns_result = nanosleep(&delta_ts, nullptr); if (ns_result == 0) { break; } diff --git a/src/core/lib/support/tmpfile_posix.cc b/src/core/lib/support/tmpfile_posix.cc index 2e14d28598..79c5c68874 100644 --- a/src/core/lib/support/tmpfile_posix.cc +++ b/src/core/lib/support/tmpfile_posix.cc @@ -34,14 +34,14 @@ #include "src/core/lib/support/string.h" FILE* gpr_tmpfile(const char* prefix, char** tmp_filename) { - FILE* result = NULL; + FILE* result = nullptr; char* filename_template; int fd; - if (tmp_filename != NULL) *tmp_filename = NULL; + if (tmp_filename != nullptr) *tmp_filename = nullptr; gpr_asprintf(&filename_template, "/tmp/%s_XXXXXX", prefix); - GPR_ASSERT(filename_template != NULL); + GPR_ASSERT(filename_template != nullptr); fd = mkstemp(filename_template); if (fd == -1) { @@ -50,7 +50,7 @@ FILE* gpr_tmpfile(const char* prefix, char** tmp_filename) { goto end; } result = fdopen(fd, "w+"); - if (result == NULL) { + if (result == nullptr) { gpr_log(GPR_ERROR, "Could not open file %s from fd %d (error = %s).", filename_template, fd, strerror(errno)); unlink(filename_template); @@ -59,7 +59,7 @@ FILE* gpr_tmpfile(const char* prefix, char** tmp_filename) { } end: - if (result != NULL && tmp_filename != NULL) { + if (result != nullptr && tmp_filename != nullptr) { *tmp_filename = filename_template; } else { gpr_free(filename_template); diff --git a/src/core/lib/surface/alarm.cc b/src/core/lib/surface/alarm.cc index bc38692ec8..d8b1f18065 100644 --- a/src/core/lib/surface/alarm.cc +++ b/src/core/lib/surface/alarm.cc @@ -48,7 +48,7 @@ static void alarm_ref(grpc_alarm* alarm) { gpr_ref(&alarm->refs); } static void alarm_unref(grpc_alarm* alarm) { if (gpr_unref(&alarm->refs)) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - if (alarm->cq != NULL) { + if (alarm->cq != nullptr) { GRPC_CQ_INTERNAL_UNREF(&exec_ctx, alarm->cq, "alarm"); } grpc_exec_ctx_finish(&exec_ctx); @@ -110,7 +110,7 @@ grpc_alarm* grpc_alarm_create(void* reserved) { gpr_ref_init(&alarm->refs, 1); grpc_timer_init_unset(&alarm->alarm); - alarm->cq = NULL; + alarm->cq = nullptr; GRPC_CLOSURE_INIT(&alarm->on_alarm, alarm_cb, alarm, grpc_schedule_on_exec_ctx); return alarm; diff --git a/src/core/lib/surface/byte_buffer.cc b/src/core/lib/surface/byte_buffer.cc index a640f782a7..9e0636b4ce 100644 --- a/src/core/lib/surface/byte_buffer.cc +++ b/src/core/lib/surface/byte_buffer.cc @@ -66,7 +66,7 @@ grpc_byte_buffer* grpc_byte_buffer_copy(grpc_byte_buffer* bb) { bb->data.raw.slice_buffer.slices, bb->data.raw.slice_buffer.count, bb->data.raw.compression); } - GPR_UNREACHABLE_CODE(return NULL); + GPR_UNREACHABLE_CODE(return nullptr); } void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) { diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 9fd4fdbef9..92e36284bd 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -308,7 +308,7 @@ void* grpc_call_arena_alloc(grpc_call* call, size_t size) { static parent_call* get_or_create_parent_call(grpc_call* call) { parent_call* p = (parent_call*)gpr_atm_acq_load(&call->parent_call_atm); - if (p == NULL) { + if (p == nullptr) { p = (parent_call*)gpr_arena_alloc(call->arena, sizeof(*p)); gpr_mu_init(&p->child_list_mu); if (!gpr_atm_rel_cas(&call->parent_call_atm, (gpr_atm)NULL, (gpr_atm)p)) { @@ -346,7 +346,7 @@ grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, call->start_time = gpr_now(GPR_CLOCK_MONOTONIC); /* Always support no compression */ GPR_BITSET(&call->encodings_accepted_by_peer, GRPC_COMPRESS_NONE); - call->is_client = args->server_transport_data == NULL; + call->is_client = args->server_transport_data == nullptr; if (call->is_client) { GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx); } else { @@ -379,7 +379,7 @@ grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, bool immediately_cancel = false; - if (args->parent != NULL) { + if (args->parent != nullptr) { child_call* cc = call->child = (child_call*)gpr_arena_alloc(arena, sizeof(child_call)); call->child->parent = args->parent; @@ -407,7 +407,7 @@ grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, } grpc_call_context_set(call, GRPC_CONTEXT_TRACING, args->parent->context[GRPC_CONTEXT_TRACING].value, - NULL); + nullptr); } else if (args->propagation_mask & GRPC_PROPAGATE_CENSUS_STATS_CONTEXT) { add_init_error(&error, GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Census context propagation requested " @@ -420,7 +420,7 @@ grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, } } - if (pc->first_child == NULL) { + if (pc->first_child == nullptr) { pc->first_child = call; cc->sibling_next = cc->sibling_prev = call; } else { @@ -455,15 +455,15 @@ grpc_error* grpc_call_create(grpc_exec_ctx* exec_ctx, cancel_with_error(exec_ctx, call, STATUS_FROM_API_OVERRIDE, GRPC_ERROR_CANCELLED); } - if (args->cq != NULL) { + if (args->cq != nullptr) { GPR_ASSERT( - args->pollset_set_alternative == NULL && + args->pollset_set_alternative == nullptr && "Only one of 'cq' and 'pollset_set_alternative' should be non-NULL."); GRPC_CQ_INTERNAL_REF(args->cq, "bind"); call->pollent = grpc_polling_entity_create_from_pollset(grpc_cq_pollset(args->cq)); } - if (args->pollset_set_alternative != NULL) { + if (args->pollset_set_alternative != nullptr) { call->pollent = grpc_polling_entity_create_from_pollset_set( args->pollset_set_alternative); } @@ -482,7 +482,7 @@ void grpc_call_set_completion_queue(grpc_exec_ctx* exec_ctx, grpc_call* call, grpc_completion_queue* cq) { GPR_ASSERT(cq); - if (grpc_polling_entity_pollset_set(&call->pollent) != NULL) { + if (grpc_polling_entity_pollset_set(&call->pollent) != nullptr) { gpr_log(GPR_ERROR, "A pollset_set is already registered for this call."); abort(); } @@ -528,11 +528,11 @@ static void destroy_call(grpc_exec_ctx* exec_ctx, void* call, grpc_metadata_batch_destroy( exec_ctx, &c->metadata_batch[1 /* is_receiving */][i /* is_initial */]); } - if (c->receiving_stream != NULL) { + if (c->receiving_stream != nullptr) { grpc_byte_stream_destroy(exec_ctx, c->receiving_stream); } parent_call* pc = get_parent_call(c); - if (pc != NULL) { + if (pc != nullptr) { gpr_mu_destroy(&pc->child_list_mu); } for (ii = 0; ii < c->send_extra_metadata_count; ii++) { @@ -548,7 +548,7 @@ static void destroy_call(grpc_exec_ctx* exec_ctx, void* call, } get_final_status(exec_ctx, c, set_status_value_directly, - &c->final_info.final_status, NULL); + &c->final_info.final_status, nullptr); c->final_info.stats.latency = gpr_time_sub(gpr_now(GPR_CLOCK_MONOTONIC), c->start_time); @@ -580,7 +580,7 @@ void grpc_call_unref(grpc_call* c) { if (c == pc->first_child) { pc->first_child = cc->sibling_next; if (c == pc->first_child) { - pc->first_child = NULL; + pc->first_child = nullptr; } } cc->sibling_prev->child->sibling_next = cc->sibling_next; @@ -601,7 +601,7 @@ void grpc_call_unref(grpc_call* c) { // effect of scheduling the previously set cancellation closure, if // any, so that it can release any internal references it may be // holding to the call stack. - grpc_call_combiner_set_notify_on_cancel(&exec_ctx, &c->call_combiner, NULL); + grpc_call_combiner_set_notify_on_cancel(&exec_ctx, &c->call_combiner, nullptr); } GRPC_CALL_INTERNAL_UNREF(&exec_ctx, c, "destroy"); grpc_exec_ctx_finish(&exec_ctx); @@ -645,9 +645,9 @@ static void execute_batch(grpc_exec_ctx* exec_ctx, grpc_call* call, char* grpc_call_get_peer(grpc_call* call) { char* peer_string = (char*)gpr_atm_acq_load(&call->peer_string); - if (peer_string != NULL) return gpr_strdup(peer_string); + if (peer_string != nullptr) return gpr_strdup(peer_string); peer_string = grpc_channel_get_target(call->channel); - if (peer_string != NULL) return peer_string; + if (peer_string != nullptr) return peer_string; return gpr_strdup("unknown"); } @@ -668,7 +668,7 @@ grpc_call_error grpc_call_cancel_with_status(grpc_call* c, "grpc_call_cancel_with_status(" "c=%p, status=%d, description=%s, reserved=%p)", 4, (c, (int)status, description, reserved)); - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); cancel_with_status(&exec_ctx, c, STATUS_FROM_API_OVERRIDE, status, description); grpc_exec_ctx_finish(&exec_ctx); @@ -743,13 +743,13 @@ static bool get_final_status_from(grpc_exec_ctx* exec_ctx, grpc_call* call, grpc_status_code code; grpc_slice slice = grpc_empty_slice(); grpc_error_get_status(exec_ctx, error, call->send_deadline, &code, &slice, - NULL); + nullptr); if (code == GRPC_STATUS_OK && !allow_ok_status) { return false; } set_value(code, set_value_user_data); - if (details != NULL) { + if (details != nullptr) { *details = grpc_slice_ref_internal(slice); } return true; @@ -869,7 +869,7 @@ static void set_encodings_accepted_by_peer(grpc_exec_ctx* exec_ctx, accepted_user_data = grpc_mdelem_get_user_data(mdel, destroy_encodings_accepted_by_peer); - if (accepted_user_data != NULL) { + if (accepted_user_data != nullptr) { call->encodings_accepted_by_peer = (uint32_t)(((uintptr_t)accepted_user_data) - 1); return; @@ -916,7 +916,7 @@ static void set_stream_encodings_accepted_by_peer(grpc_exec_ctx* exec_ctx, accepted_user_data = grpc_mdelem_get_user_data(mdel, destroy_encodings_accepted_by_peer); - if (accepted_user_data != NULL) { + if (accepted_user_data != nullptr) { call->stream_encodings_accepted_by_peer = (uint32_t)(((uintptr_t)accepted_user_data) - 1); return; @@ -1053,7 +1053,7 @@ static uint32_t decode_status(grpc_mdelem md) { if (grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_1)) return 1; if (grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_2)) return 2; user_data = grpc_mdelem_get_user_data(md, destroy_status); - if (user_data != NULL) { + if (user_data != nullptr) { status = ((uint32_t)(intptr_t)user_data) - STATUS_OFFSET; } else { if (!grpc_parse_slice_to_uint32(GRPC_MDVALUE(md), &status)) { @@ -1109,7 +1109,7 @@ static void publish_app_metadata(grpc_call* call, grpc_metadata_batch* b, dest->metadata = (grpc_metadata*)gpr_realloc( dest->metadata, sizeof(grpc_metadata) * dest->capacity); } - for (grpc_linked_mdelem* l = b->list.head; l != NULL; l = l->next) { + for (grpc_linked_mdelem* l = b->list.head; l != nullptr; l = l->next) { mdusr = &dest->metadata[dest->count++]; /* we pass back borrowed slices that are valid whilst the call is valid */ mdusr->key = GRPC_MDKEY(l->md); @@ -1120,8 +1120,8 @@ static void publish_app_metadata(grpc_call* call, grpc_metadata_batch* b, static void recv_initial_filter(grpc_exec_ctx* exec_ctx, grpc_call* call, grpc_metadata_batch* b) { - if (b->idx.named.content_encoding != NULL) { - if (b->idx.named.grpc_encoding != NULL) { + if (b->idx.named.content_encoding != nullptr) { + if (b->idx.named.grpc_encoding != nullptr) { gpr_log(GPR_ERROR, "Received both content-encoding and grpc-encoding header. " "Ignoring grpc-encoding."); @@ -1132,21 +1132,21 @@ static void recv_initial_filter(grpc_exec_ctx* exec_ctx, grpc_call* call, call, decode_stream_compression(b->idx.named.content_encoding->md)); GPR_TIMER_END("incoming_stream_compression_algorithm", 0); grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.content_encoding); - } else if (b->idx.named.grpc_encoding != NULL) { + } else if (b->idx.named.grpc_encoding != nullptr) { GPR_TIMER_BEGIN("incoming_compression_algorithm", 0); set_incoming_compression_algorithm( call, decode_compression(b->idx.named.grpc_encoding->md)); GPR_TIMER_END("incoming_compression_algorithm", 0); grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_encoding); } - if (b->idx.named.grpc_accept_encoding != NULL) { + if (b->idx.named.grpc_accept_encoding != nullptr) { GPR_TIMER_BEGIN("encodings_accepted_by_peer", 0); set_encodings_accepted_by_peer(exec_ctx, call, b->idx.named.grpc_accept_encoding->md); grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_accept_encoding); GPR_TIMER_END("encodings_accepted_by_peer", 0); } - if (b->idx.named.accept_encoding != NULL) { + if (b->idx.named.accept_encoding != nullptr) { GPR_TIMER_BEGIN("stream_encodings_accepted_by_peer", 0); set_stream_encodings_accepted_by_peer(exec_ctx, call, b->idx.named.accept_encoding->md); @@ -1159,7 +1159,7 @@ static void recv_initial_filter(grpc_exec_ctx* exec_ctx, grpc_call* call, static void recv_trailing_filter(grpc_exec_ctx* exec_ctx, void* args, grpc_metadata_batch* b) { grpc_call* call = (grpc_call*)args; - if (b->idx.named.grpc_status != NULL) { + if (b->idx.named.grpc_status != nullptr) { uint32_t status_code = decode_status(b->idx.named.grpc_status->md); grpc_error* error = status_code == GRPC_STATUS_OK @@ -1168,7 +1168,7 @@ static void recv_trailing_filter(grpc_exec_ctx* exec_ctx, void* args, "Error received from peer"), GRPC_ERROR_INT_GRPC_STATUS, (intptr_t)status_code); - if (b->idx.named.grpc_message != NULL) { + if (b->idx.named.grpc_message != nullptr) { error = grpc_error_set_str( error, GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_ref_internal(GRPC_MDVALUE(b->idx.named.grpc_message->md))); @@ -1241,13 +1241,13 @@ static batch_control* allocate_batch_control(grpc_call* call, size_t num_ops) { int slot = batch_slot_for_op(ops[0].op); batch_control** pslot = &call->active_batches[slot]; - if (*pslot == NULL) { + if (*pslot == nullptr) { *pslot = (batch_control*)gpr_arena_alloc(call->arena, sizeof(batch_control)); } batch_control* bctl = *pslot; - if (bctl->call != NULL) { - return NULL; + if (bctl->call != nullptr) { + return nullptr; } memset(bctl, 0, sizeof(*bctl)); bctl->call = call; @@ -1259,7 +1259,7 @@ static void finish_batch_completion(grpc_exec_ctx* exec_ctx, void* user_data, grpc_cq_completion* storage) { batch_control* bctl = (batch_control*)user_data; grpc_call* call = bctl->call; - bctl->call = NULL; + bctl->call = nullptr; GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, "completion"); } @@ -1271,14 +1271,14 @@ static grpc_error* consolidate_batch_errors(batch_control* bctl) { /* Skip creating a composite error in the case that only one error was logged */ grpc_error* e = bctl->errors[0]; - bctl->errors[0] = NULL; + bctl->errors[0] = nullptr; return e; } else { grpc_error* error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Call batch failed", bctl->errors, n); for (size_t i = 0; i < n; i++) { GRPC_ERROR_UNREF(bctl->errors[i]); - bctl->errors[i] = NULL; + bctl->errors[i] = nullptr; } return error; } @@ -1311,11 +1311,11 @@ static void post_batch_completion(grpc_exec_ctx* exec_ctx, /* propagate cancellation to any interested children */ gpr_atm_rel_store(&call->received_final_op_atm, 1); parent_call* pc = get_parent_call(call); - if (pc != NULL) { + if (pc != nullptr) { grpc_call* child; gpr_mu_lock(&pc->child_list_mu); child = pc->first_child; - if (child != NULL) { + if (child != nullptr) { do { next_child_call = child->child->sibling_next; if (child->cancellation_is_inherited) { @@ -1336,21 +1336,21 @@ static void post_batch_completion(grpc_exec_ctx* exec_ctx, call->final_op.client.status_details); } else { get_final_status(exec_ctx, call, set_cancelled_value, - call->final_op.server.cancelled, NULL); + call->final_op.server.cancelled, nullptr); } GRPC_ERROR_UNREF(error); error = GRPC_ERROR_NONE; } if (error != GRPC_ERROR_NONE && bctl->op.recv_message && - *call->receiving_buffer != NULL) { + *call->receiving_buffer != nullptr) { grpc_byte_buffer_destroy(*call->receiving_buffer); - *call->receiving_buffer = NULL; + *call->receiving_buffer = nullptr; } if (bctl->completion_data.notify_tag.is_closure) { /* unrefs bctl->error */ - bctl->call = NULL; + bctl->call = nullptr; GRPC_CLOSURE_RUN( exec_ctx, (grpc_closure*)bctl->completion_data.notify_tag.tag, error); GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, "completion"); @@ -1378,7 +1378,7 @@ static void continue_receiving_slices(grpc_exec_ctx* exec_ctx, if (remaining == 0) { call->receiving_message = 0; grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); - call->receiving_stream = NULL; + call->receiving_stream = nullptr; finish_batch_step(exec_ctx, bctl); return; } @@ -1391,9 +1391,9 @@ static void continue_receiving_slices(grpc_exec_ctx* exec_ctx, call->receiving_slice); } else { grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); - call->receiving_stream = NULL; + call->receiving_stream = nullptr; grpc_byte_buffer_destroy(*call->receiving_buffer); - *call->receiving_buffer = NULL; + *call->receiving_buffer = nullptr; call->receiving_message = 0; finish_batch_step(exec_ctx, bctl); return; @@ -1430,9 +1430,9 @@ static void receiving_slice_ready(grpc_exec_ctx* exec_ctx, void* bctlp, GRPC_LOG_IF_ERROR("receiving_slice_ready", GRPC_ERROR_REF(error)); } grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); - call->receiving_stream = NULL; + call->receiving_stream = nullptr; grpc_byte_buffer_destroy(*call->receiving_buffer); - *call->receiving_buffer = NULL; + *call->receiving_buffer = nullptr; call->receiving_message = 0; finish_batch_step(exec_ctx, bctl); if (release_error) { @@ -1444,8 +1444,8 @@ static void receiving_slice_ready(grpc_exec_ctx* exec_ctx, void* bctlp, static void process_data_after_md(grpc_exec_ctx* exec_ctx, batch_control* bctl) { grpc_call* call = bctl->call; - if (call->receiving_stream == NULL) { - *call->receiving_buffer = NULL; + if (call->receiving_stream == nullptr) { + *call->receiving_buffer = nullptr; call->receiving_message = 0; finish_batch_step(exec_ctx, bctl); } else { @@ -1453,9 +1453,9 @@ static void process_data_after_md(grpc_exec_ctx* exec_ctx, if ((call->receiving_stream->flags & GRPC_WRITE_INTERNAL_COMPRESS) && (call->incoming_compression_algorithm > GRPC_COMPRESS_NONE)) { *call->receiving_buffer = grpc_raw_compressed_byte_buffer_create( - NULL, 0, call->incoming_compression_algorithm); + nullptr, 0, call->incoming_compression_algorithm); } else { - *call->receiving_buffer = grpc_raw_byte_buffer_create(NULL, 0); + *call->receiving_buffer = grpc_raw_byte_buffer_create(nullptr, 0); } GRPC_CLOSURE_INIT(&call->receiving_slice_ready, receiving_slice_ready, bctl, grpc_schedule_on_exec_ctx); @@ -1468,9 +1468,9 @@ static void receiving_stream_ready(grpc_exec_ctx* exec_ctx, void* bctlp, batch_control* bctl = (batch_control*)bctlp; grpc_call* call = bctl->call; if (error != GRPC_ERROR_NONE) { - if (call->receiving_stream != NULL) { + if (call->receiving_stream != nullptr) { grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); - call->receiving_stream = NULL; + call->receiving_stream = nullptr; } add_batch_error(exec_ctx, bctl, GRPC_ERROR_REF(error), true); cancel_with_error(exec_ctx, call, STATUS_FROM_SURFACE, @@ -1479,7 +1479,7 @@ static void receiving_stream_ready(grpc_exec_ctx* exec_ctx, void* bctlp, /* If recv_state is RECV_NONE, we will save the batch_control * object with rel_cas, and will not use it after the cas. Its corresponding * acq_load is in receiving_initial_metadata_ready() */ - if (error != GRPC_ERROR_NONE || call->receiving_stream == NULL || + if (error != GRPC_ERROR_NONE || call->receiving_stream == nullptr || !gpr_atm_rel_cas(&call->recv_state, RECV_NONE, (gpr_atm)bctlp)) { process_data_after_md(exec_ctx, bctl); } @@ -1505,7 +1505,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, GRPC_STREAM_COMPRESS_NONE) { const grpc_stream_compression_algorithm algo = call->incoming_stream_compression_algorithm; - char* error_msg = NULL; + char* error_msg = nullptr; const grpc_compression_options compression_options = grpc_channel_compression_options(call->channel); if (algo >= GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT) { @@ -1517,7 +1517,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, } else if (grpc_compression_options_is_stream_compression_algorithm_enabled( &compression_options, algo) == 0) { /* check if algorithm is supported by current channel config */ - const char* algo_name = NULL; + const char* algo_name = nullptr; grpc_stream_compression_algorithm_name(algo, &algo_name); gpr_asprintf(&error_msg, "Stream compression algorithm '%s' is disabled.", algo_name); @@ -1531,7 +1531,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, if (!GPR_BITGET(call->stream_encodings_accepted_by_peer, call->incoming_stream_compression_algorithm)) { if (GRPC_TRACER_ON(grpc_compression_trace)) { - const char* algo_name = NULL; + const char* algo_name = nullptr; grpc_stream_compression_algorithm_name( call->incoming_stream_compression_algorithm, &algo_name); gpr_log( @@ -1545,7 +1545,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, } else if (call->incoming_compression_algorithm != GRPC_COMPRESS_NONE) { const grpc_compression_algorithm algo = call->incoming_compression_algorithm; - char* error_msg = NULL; + char* error_msg = nullptr; const grpc_compression_options compression_options = grpc_channel_compression_options(call->channel); /* check if algorithm is known */ @@ -1558,7 +1558,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, } else if (grpc_compression_options_is_algorithm_enabled( &compression_options, algo) == 0) { /* check if algorithm is supported by current channel config */ - const char* algo_name = NULL; + const char* algo_name = nullptr; grpc_compression_algorithm_name(algo, &algo_name); gpr_asprintf(&error_msg, "Compression algorithm '%s' is disabled.", algo_name); @@ -1574,7 +1574,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx, if (!GPR_BITGET(call->encodings_accepted_by_peer, call->incoming_compression_algorithm)) { if (GRPC_TRACER_ON(grpc_compression_trace)) { - const char* algo_name = NULL; + const char* algo_name = nullptr; grpc_compression_algorithm_name(call->incoming_compression_algorithm, &algo_name); gpr_log(GPR_ERROR, @@ -1622,7 +1622,7 @@ static void receiving_initial_metadata_ready(grpc_exec_ctx* exec_ctx, } } - grpc_closure* saved_rsr_closure = NULL; + grpc_closure* saved_rsr_closure = nullptr; while (true) { gpr_atm rsr_bctlp = gpr_atm_acq_load(&call->recv_state); /* Should only receive initial metadata once */ @@ -1646,7 +1646,7 @@ static void receiving_initial_metadata_ready(grpc_exec_ctx* exec_ctx, break; } } - if (saved_rsr_closure != NULL) { + if (saved_rsr_closure != nullptr) { GRPC_CLOSURE_RUN(exec_ctx, saved_rsr_closure, GRPC_ERROR_REF(error)); } @@ -1687,7 +1687,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, GPR_ASSERT(grpc_cq_begin_op(call->cq, notify_tag)); grpc_cq_end_op( exec_ctx, call->cq, notify_tag, GRPC_ERROR_NONE, - free_no_op_completion, NULL, + free_no_op_completion, nullptr, (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion))); } else { GRPC_CLOSURE_SCHED(exec_ctx, (grpc_closure*)notify_tag, GRPC_ERROR_NONE); @@ -1697,7 +1697,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, } bctl = allocate_batch_control(call, ops, nops); - if (bctl == NULL) { + if (bctl == nullptr) { return GRPC_CALL_ERROR_TOO_MANY_OPERATIONS; } bctl->completion_data.notify_tag.tag = notify_tag; @@ -1710,7 +1710,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, /* rewrite batch ops into a transport op */ for (i = 0; i < nops; i++) { op = &ops[i]; - if (op->reserved != NULL) { + if (op->reserved != nullptr) { error = GRPC_CALL_ERROR; goto done_with_error; } @@ -1815,7 +1815,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, error = GRPC_CALL_ERROR_INVALID_FLAGS; goto done_with_error; } - if (op->data.send_message.send_message == NULL) { + if (op->data.send_message.send_message == nullptr) { error = GRPC_CALL_ERROR_INVALID_MESSAGE; goto done_with_error; } @@ -1891,7 +1891,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, override_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( "Error from server send status"); } - if (op->data.send_status_from_server.status_details != NULL) { + if (op->data.send_status_from_server.status_details != nullptr) { call->send_extra_metadata[1].md = grpc_mdelem_from_slices( exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, grpc_slice_ref_internal( @@ -1910,7 +1910,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx* exec_ctx, if (!prepare_application_metadata( exec_ctx, call, (int)op->data.send_status_from_server.trailing_metadata_count, - op->data.send_status_from_server.trailing_metadata, 1, 1, NULL, + op->data.send_status_from_server.trailing_metadata, 1, 1, nullptr, 0)) { for (int n = 0; n < call->send_extra_metadata_count; n++) { GRPC_MDELEM_UNREF(exec_ctx, call->send_extra_metadata[n].md); @@ -2082,7 +2082,7 @@ grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops, "reserved=%p)", 5, (call, ops, (unsigned long)nops, tag, reserved)); - if (reserved != NULL) { + if (reserved != nullptr) { err = GRPC_CALL_ERROR; } else { err = call_start_batch(&exec_ctx, call, ops, nops, tag, 0); diff --git a/src/core/lib/surface/call_log_batch.cc b/src/core/lib/surface/call_log_batch.cc index 030964675d..535a3d3282 100644 --- a/src/core/lib/surface/call_log_batch.cc +++ b/src/core/lib/surface/call_log_batch.cc @@ -27,7 +27,7 @@ static void add_metadata(gpr_strvec* b, const grpc_metadata* md, size_t count) { size_t i; - if (md == NULL) { + if (md == nullptr) { gpr_strvec_add(b, gpr_strdup("(nil)")); return; } @@ -66,7 +66,7 @@ char* grpc_op_string(const grpc_op* op) { gpr_asprintf(&tmp, "SEND_STATUS_FROM_SERVER status=%d details=", op->data.send_status_from_server.status); gpr_strvec_add(&b, tmp); - if (op->data.send_status_from_server.status_details != NULL) { + if (op->data.send_status_from_server.status_details != nullptr) { gpr_strvec_add(&b, grpc_dump_slice( *op->data.send_status_from_server.status_details, GPR_DUMP_ASCII)); @@ -99,7 +99,7 @@ char* grpc_op_string(const grpc_op* op) { op->data.recv_close_on_server.cancelled); gpr_strvec_add(&b, tmp); } - out = gpr_strvec_flatten(&b, NULL); + out = gpr_strvec_flatten(&b, nullptr); gpr_strvec_destroy(&b); return out; diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index 832cc07858..72e0b8bfb7 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -85,7 +85,7 @@ grpc_channel* grpc_channel_create_with_builder( GRPC_STATS_INC_CLIENT_CHANNELS_CREATED(exec_ctx); } grpc_error* error = grpc_channel_stack_builder_finish( - exec_ctx, builder, sizeof(grpc_channel), 1, destroy_channel, NULL, + exec_ctx, builder, sizeof(grpc_channel), 1, destroy_channel, nullptr, (void**)&channel); if (error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "channel stack builder failed: %s", @@ -99,7 +99,7 @@ grpc_channel* grpc_channel_create_with_builder( channel->target = target; channel->is_client = grpc_channel_stack_type_is_client(channel_stack_type); gpr_mu_init(&channel->registered_call_mu); - channel->registered_calls = NULL; + channel->registered_calls = nullptr; gpr_atm_no_barrier_store( &channel->call_size_estimate, @@ -206,7 +206,7 @@ grpc_channel* grpc_channel_create(grpc_exec_ctx* exec_ctx, const char* target, grpc_channel_stack_builder_set_transport(builder, optional_transport); if (!grpc_channel_init_create_stack(exec_ctx, builder, channel_stack_type)) { grpc_channel_stack_builder_destroy(exec_ctx, builder); - return NULL; + return nullptr; } return grpc_channel_create_with_builder(exec_ctx, builder, channel_stack_type); @@ -267,7 +267,7 @@ static grpc_call* grpc_channel_create_call_internal( size_t num_metadata = 0; GPR_ASSERT(channel->is_client); - GPR_ASSERT(!(cq != NULL && pollset_set_alternative != NULL)); + GPR_ASSERT(!(cq != nullptr && pollset_set_alternative != nullptr)); send_metadata[num_metadata++] = path_mdelem; if (!GRPC_MDISNULL(authority_mdelem)) { @@ -283,7 +283,7 @@ static grpc_call* grpc_channel_create_call_internal( args.propagation_mask = propagation_mask; args.cq = cq; args.pollset_set_alternative = pollset_set_alternative; - args.server_transport_data = NULL; + args.server_transport_data = nullptr; args.add_initial_metadata = send_metadata; args.add_initial_metadata_count = num_metadata; args.send_deadline = deadline; @@ -372,7 +372,7 @@ grpc_call* grpc_channel_create_registered_call( GPR_ASSERT(!reserved); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_call* call = grpc_channel_create_call_internal( - &exec_ctx, channel, parent_call, propagation_mask, completion_queue, NULL, + &exec_ctx, channel, parent_call, propagation_mask, completion_queue, nullptr, GRPC_MDELEM_REF(rc->path), GRPC_MDELEM_REF(rc->authority), grpc_timespec_to_millis_round_up(deadline)); grpc_exec_ctx_finish(&exec_ctx); @@ -413,7 +413,7 @@ static void destroy_channel(grpc_exec_ctx* exec_ctx, void* arg, } void grpc_channel_destroy(grpc_channel* channel) { - grpc_transport_op* op = grpc_make_transport_op(NULL); + grpc_transport_op* op = grpc_make_transport_op(nullptr); grpc_channel_element* elem; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE("grpc_channel_destroy(channel=%p)", 1, (channel)); diff --git a/src/core/lib/surface/channel_init.cc b/src/core/lib/surface/channel_init.cc index 17d8caf56f..b563537f35 100644 --- a/src/core/lib/surface/channel_init.cc +++ b/src/core/lib/surface/channel_init.cc @@ -39,7 +39,7 @@ static bool g_finalized; void grpc_channel_init_init(void) { for (int i = 0; i < GRPC_NUM_CHANNEL_STACK_TYPES; i++) { - g_slots[i].slots = NULL; + g_slots[i].slots = nullptr; g_slots[i].num_slots = 0; g_slots[i].cap_slots = 0; } diff --git a/src/core/lib/surface/channel_ping.cc b/src/core/lib/surface/channel_ping.cc index 5660bb812e..e8f47f01cf 100644 --- a/src/core/lib/surface/channel_ping.cc +++ b/src/core/lib/surface/channel_ping.cc @@ -48,12 +48,12 @@ void grpc_channel_ping(grpc_channel* channel, grpc_completion_queue* cq, void* tag, void* reserved) { GRPC_API_TRACE("grpc_channel_ping(channel=%p, cq=%p, tag=%p, reserved=%p)", 4, (channel, cq, tag, reserved)); - grpc_transport_op* op = grpc_make_transport_op(NULL); + grpc_transport_op* op = grpc_make_transport_op(nullptr); ping_result* pr = (ping_result*)gpr_malloc(sizeof(*pr)); grpc_channel_element* top_elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(reserved == NULL); + GPR_ASSERT(reserved == nullptr); pr->tag = tag; pr->cq = cq; GRPC_CLOSURE_INIT(&pr->closure, ping_done, pr, grpc_schedule_on_exec_ctx); diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 922df923ae..e90bbfccc2 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -113,8 +113,8 @@ static grpc_error* non_polling_poller_work(grpc_exec_ctx* exec_ctx, if (npp->shutdown) return GRPC_ERROR_NONE; non_polling_worker w; gpr_cv_init(&w.cv); - if (worker != NULL) *worker = (grpc_pollset_worker*)&w; - if (npp->root == NULL) { + if (worker != nullptr) *worker = (grpc_pollset_worker*)&w; + if (npp->root == nullptr) { npp->root = w.next = w.prev = &w; } else { w.next = npp->root; @@ -134,13 +134,13 @@ static grpc_error* non_polling_poller_work(grpc_exec_ctx* exec_ctx, if (npp->shutdown) { GRPC_CLOSURE_SCHED(exec_ctx, npp->shutdown, GRPC_ERROR_NONE); } - npp->root = NULL; + npp->root = nullptr; } } w.next->prev = w.prev; w.prev->next = w.next; gpr_cv_destroy(&w.cv); - if (worker != NULL) *worker = NULL; + if (worker != nullptr) *worker = nullptr; return GRPC_ERROR_NONE; } @@ -148,8 +148,8 @@ static grpc_error* non_polling_poller_kick( grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_pollset_worker* specific_worker) { non_polling_poller* p = (non_polling_poller*)pollset; - if (specific_worker == NULL) specific_worker = (grpc_pollset_worker*)p->root; - if (specific_worker != NULL) { + if (specific_worker == nullptr) specific_worker = (grpc_pollset_worker*)p->root; + if (specific_worker != nullptr) { non_polling_worker* w = (non_polling_worker*)specific_worker; if (!w->kicked) { w->kicked = true; @@ -163,9 +163,9 @@ static void non_polling_poller_shutdown(grpc_exec_ctx* exec_ctx, grpc_pollset* pollset, grpc_closure* closure) { non_polling_poller* p = (non_polling_poller*)pollset; - GPR_ASSERT(closure != NULL); + GPR_ASSERT(closure != nullptr); p->shutdown = closure; - if (p->root == NULL) { + if (p->root == nullptr) { GRPC_CLOSURE_SCHED(exec_ctx, closure, GRPC_ERROR_NONE); } else { non_polling_worker* w = p->root; @@ -327,10 +327,10 @@ static void cq_destroy_pluck(void* data); static const cq_vtable g_cq_vtable[] = { /* GRPC_CQ_NEXT */ {GRPC_CQ_NEXT, sizeof(cq_next_data), cq_init_next, cq_shutdown_next, - cq_destroy_next, cq_begin_op_for_next, cq_end_op_for_next, cq_next, NULL}, + cq_destroy_next, cq_begin_op_for_next, cq_end_op_for_next, cq_next, nullptr}, /* GRPC_CQ_PLUCK */ {GRPC_CQ_PLUCK, sizeof(cq_pluck_data), cq_init_pluck, cq_shutdown_pluck, - cq_destroy_pluck, cq_begin_op_for_pluck, cq_end_op_for_pluck, NULL, + cq_destroy_pluck, cq_begin_op_for_pluck, cq_end_op_for_pluck, nullptr, cq_pluck}, }; @@ -372,7 +372,7 @@ int grpc_completion_queue_thread_local_cache_flush(grpc_completion_queue* cq, grpc_cq_completion* storage = (grpc_cq_completion*)gpr_tls_get(&g_cached_event); int ret = 0; - if (storage != NULL && + if (storage != nullptr && (grpc_completion_queue*)gpr_tls_get(&g_cached_cq) == cq) { *tag = storage->tag; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; @@ -411,7 +411,7 @@ static bool cq_event_queue_push(grpc_cq_event_queue* q, grpc_cq_completion* c) { } static grpc_cq_completion* cq_event_queue_pop(grpc_cq_event_queue* q) { - grpc_cq_completion* c = NULL; + grpc_cq_completion* c = nullptr; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; if (gpr_spinlock_trylock(&q->queue_lock)) { @@ -421,7 +421,7 @@ static grpc_cq_completion* cq_event_queue_pop(grpc_cq_event_queue* q) { c = (grpc_cq_completion*)gpr_mpscq_pop_and_check_end(&q->queue, &is_empty); gpr_spinlock_unlock(&q->queue_lock); - if (c == NULL && !is_empty) { + if (c == nullptr && !is_empty) { GRPC_STATS_INC_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES(&exec_ctx); } } else { @@ -697,7 +697,7 @@ static void cq_end_op_for_next(grpc_exec_ctx* exec_ctx, if (is_first) { gpr_mu_lock(cq->mu); grpc_error* kick_error = - cq->poller_vtable->kick(exec_ctx, POLLSET_FROM_CQ(cq), NULL); + cq->poller_vtable->kick(exec_ctx, POLLSET_FROM_CQ(cq), nullptr); gpr_mu_unlock(cq->mu); if (kick_error != GRPC_ERROR_NONE) { @@ -775,7 +775,7 @@ static void cq_end_op_for_pluck(grpc_exec_ctx* exec_ctx, cq_finish_shutdown_pluck(exec_ctx, cq); gpr_mu_unlock(cq->mu); } else { - grpc_pollset_worker* pluck_worker = NULL; + grpc_pollset_worker* pluck_worker = nullptr; for (int i = 0; i < cqd->num_pluckers; i++) { if (cqd->pluckers[i].tag == tag) { pluck_worker = *cqd->pluckers[i].worker; @@ -822,7 +822,7 @@ static bool cq_is_next_finished(grpc_exec_ctx* exec_ctx, void* arg) { cq_is_finished_arg* a = (cq_is_finished_arg*)arg; grpc_completion_queue* cq = a->cq; cq_next_data* cqd = (cq_next_data*)DATA_FROM_CQ(cq); - GPR_ASSERT(a->stolen_completion == NULL); + GPR_ASSERT(a->stolen_completion == nullptr); gpr_atm current_last_seen_things_queued_ever = gpr_atm_no_barrier_load(&cqd->things_queued_ever); @@ -837,7 +837,7 @@ static bool cq_is_next_finished(grpc_exec_ctx* exec_ctx, void* arg) { * is ok and doesn't affect correctness. Might effect the tail latencies a * bit) */ a->stolen_completion = cq_event_queue_pop(&cqd->queue); - if (a->stolen_completion != NULL) { + if (a->stolen_completion != nullptr) { return true; } } @@ -858,7 +858,7 @@ static void dump_pending_tags(grpc_completion_queue* cq) { gpr_strvec_add(&v, s); } gpr_mu_unlock(cq->mu); - char* out = gpr_strvec_flatten(&v, NULL); + char* out = gpr_strvec_flatten(&v, nullptr); gpr_strvec_destroy(&v); gpr_log(GPR_DEBUG, "%s", out); gpr_free(out); @@ -894,17 +894,17 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, gpr_atm_no_barrier_load(&cqd->things_queued_ever), cq, deadline_millis, - NULL, - NULL, + nullptr, + nullptr, true}; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INITIALIZER(0, cq_is_next_finished, &is_finished_arg); for (;;) { grpc_millis iteration_deadline = deadline_millis; - if (is_finished_arg.stolen_completion != NULL) { + if (is_finished_arg.stolen_completion != nullptr) { grpc_cq_completion* c = is_finished_arg.stolen_completion; - is_finished_arg.stolen_completion = NULL; + is_finished_arg.stolen_completion = nullptr; ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; @@ -914,7 +914,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, grpc_cq_completion* c = cq_event_queue_pop(&cqd->queue); - if (c != NULL) { + if (c != nullptr) { ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; @@ -960,7 +960,7 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, gpr_mu_lock(cq->mu); cq->num_polls++; grpc_error* err = cq->poller_vtable->work(&exec_ctx, POLLSET_FROM_CQ(cq), - NULL, iteration_deadline); + nullptr, iteration_deadline); gpr_mu_unlock(cq->mu); if (err != GRPC_ERROR_NONE) { @@ -979,14 +979,14 @@ static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, if (cq_event_queue_num_items(&cqd->queue) > 0 && gpr_atm_acq_load(&cqd->pending_events) > 0) { gpr_mu_lock(cq->mu); - cq->poller_vtable->kick(&exec_ctx, POLLSET_FROM_CQ(cq), NULL); + cq->poller_vtable->kick(&exec_ctx, POLLSET_FROM_CQ(cq), nullptr); gpr_mu_unlock(cq->mu); } GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, &ret); GRPC_CQ_INTERNAL_UNREF(&exec_ctx, cq, "next"); grpc_exec_ctx_finish(&exec_ctx); - GPR_ASSERT(is_finished_arg.stolen_completion == NULL); + GPR_ASSERT(is_finished_arg.stolen_completion == nullptr); GPR_TIMER_END("grpc_completion_queue_next", 0); @@ -1073,7 +1073,7 @@ static bool cq_is_pluck_finished(grpc_exec_ctx* exec_ctx, void* arg) { grpc_completion_queue* cq = a->cq; cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); - GPR_ASSERT(a->stolen_completion == NULL); + GPR_ASSERT(a->stolen_completion == nullptr); gpr_atm current_last_seen_things_queued_ever = gpr_atm_no_barrier_load(&cqd->things_queued_ever); if (current_last_seen_things_queued_ever != a->last_seen_things_queued_ever) { @@ -1105,7 +1105,7 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, grpc_event ret; grpc_cq_completion* c; grpc_cq_completion* prev; - grpc_pollset_worker* worker = NULL; + grpc_pollset_worker* worker = nullptr; cq_pluck_data* cqd = (cq_pluck_data*)DATA_FROM_CQ(cq); GPR_TIMER_BEGIN("grpc_completion_queue_pluck", 0); @@ -1132,16 +1132,16 @@ static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, gpr_atm_no_barrier_load(&cqd->things_queued_ever), cq, deadline_millis, - NULL, + nullptr, tag, true}; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INITIALIZER(0, cq_is_pluck_finished, &is_finished_arg); for (;;) { - if (is_finished_arg.stolen_completion != NULL) { + if (is_finished_arg.stolen_completion != nullptr) { gpr_mu_unlock(cq->mu); c = is_finished_arg.stolen_completion; - is_finished_arg.stolen_completion = NULL; + is_finished_arg.stolen_completion = nullptr; ret.type = GRPC_OP_COMPLETE; ret.success = c->next & 1u; ret.tag = c->tag; @@ -1214,7 +1214,7 @@ done: GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, &ret); GRPC_CQ_INTERNAL_UNREF(&exec_ctx, cq, "pluck"); grpc_exec_ctx_finish(&exec_ctx); - GPR_ASSERT(is_finished_arg.stolen_completion == NULL); + GPR_ASSERT(is_finished_arg.stolen_completion == nullptr); GPR_TIMER_END("grpc_completion_queue_pluck", 0); @@ -1288,7 +1288,7 @@ void grpc_completion_queue_destroy(grpc_completion_queue* cq) { } grpc_pollset* grpc_cq_pollset(grpc_completion_queue* cq) { - return cq->poller_vtable->can_get_pollset ? POLLSET_FROM_CQ(cq) : NULL; + return cq->poller_vtable->can_get_pollset ? POLLSET_FROM_CQ(cq) : nullptr; } bool grpc_cq_can_listen(grpc_completion_queue* cq) { diff --git a/src/core/lib/surface/completion_queue_factory.cc b/src/core/lib/surface/completion_queue_factory.cc index aeecff5306..d0bb065c8f 100644 --- a/src/core/lib/surface/completion_queue_factory.cc +++ b/src/core/lib/surface/completion_queue_factory.cc @@ -35,7 +35,7 @@ static grpc_completion_queue* default_create( static grpc_completion_queue_factory_vtable default_vtable = {default_create}; static const grpc_completion_queue_factory g_default_cq_factory = { - "Default Factory", NULL, &default_vtable}; + "Default Factory", nullptr, &default_vtable}; /* * == Completion queue factory APIs diff --git a/src/core/lib/surface/event_string.cc b/src/core/lib/surface/event_string.cc index b92ee6ad07..5168edc9b5 100644 --- a/src/core/lib/surface/event_string.cc +++ b/src/core/lib/surface/event_string.cc @@ -42,7 +42,7 @@ char* grpc_event_string(grpc_event* ev) { char* out; gpr_strvec buf; - if (ev == NULL) return gpr_strdup("null"); + if (ev == nullptr) return gpr_strdup("null"); gpr_strvec_init(&buf); @@ -60,7 +60,7 @@ char* grpc_event_string(grpc_event* ev) { break; } - out = gpr_strvec_flatten(&buf, NULL); + out = gpr_strvec_flatten(&buf, nullptr); gpr_strvec_destroy(&buf); return out; } diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 233bd7a6b8..673e13ce6e 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -71,25 +71,25 @@ static void do_basic_init(void) { static bool append_filter(grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_append_filter( - builder, (const grpc_channel_filter*)arg, NULL, NULL); + builder, (const grpc_channel_filter*)arg, nullptr, nullptr); } static bool prepend_filter(grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) { return grpc_channel_stack_builder_prepend_filter( - builder, (const grpc_channel_filter*)arg, NULL, NULL); + builder, (const grpc_channel_filter*)arg, nullptr, nullptr); } static void register_builtin_channel_init() { grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - grpc_add_connected_filter, NULL); + grpc_add_connected_filter, nullptr); grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - grpc_add_connected_filter, NULL); + grpc_add_connected_filter, nullptr); grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, - grpc_add_connected_filter, NULL); + grpc_add_connected_filter, nullptr); grpc_channel_init_register_stage(GRPC_CLIENT_LAME_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter, (void*)&grpc_lame_filter); @@ -156,7 +156,7 @@ void grpc_init(void) { grpc_handshaker_factory_registry_init(); grpc_security_init(); for (i = 0; i < g_number_of_plugins; i++) { - if (g_all_of_the_plugins[i].init != NULL) { + if (g_all_of_the_plugins[i].init != nullptr) { g_all_of_the_plugins[i].init(); } } @@ -178,13 +178,13 @@ void grpc_shutdown(void) { int i; GRPC_API_TRACE("grpc_shutdown(void)", 0, ()); grpc_exec_ctx exec_ctx = - GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, NULL); + GRPC_EXEC_CTX_INITIALIZER(0, grpc_never_ready_to_finish, nullptr); gpr_mu_lock(&g_init_mu); if (--g_initializations == 0) { grpc_executor_shutdown(&exec_ctx); grpc_timer_manager_set_threading(false); // shutdown timer_manager thread for (i = g_number_of_plugins; i >= 0; i--) { - if (g_all_of_the_plugins[i].destroy != NULL) { + if (g_all_of_the_plugins[i].destroy != nullptr) { g_all_of_the_plugins[i].destroy(); } } diff --git a/src/core/lib/surface/init_secure.cc b/src/core/lib/surface/init_secure.cc index bcb91d7df8..deb9a8e9e5 100644 --- a/src/core/lib/surface/init_secure.cc +++ b/src/core/lib/surface/init_secure.cc @@ -54,7 +54,7 @@ static bool maybe_prepend_client_auth_filter( for (size_t i = 0; i < args->num_args; i++) { if (0 == strcmp(GRPC_ARG_SECURITY_CONNECTOR, args->args[i].key)) { return grpc_channel_stack_builder_prepend_filter( - builder, &grpc_client_auth_filter, NULL, NULL); + builder, &grpc_client_auth_filter, nullptr, nullptr); } } } @@ -69,7 +69,7 @@ static bool maybe_prepend_server_auth_filter( for (size_t i = 0; i < args->num_args; i++) { if (0 == strcmp(GRPC_SERVER_CREDENTIALS_ARG, args->args[i].key)) { return grpc_channel_stack_builder_prepend_filter( - builder, &grpc_server_auth_filter, NULL, NULL); + builder, &grpc_server_auth_filter, nullptr, nullptr); } } } @@ -78,11 +78,11 @@ static bool maybe_prepend_server_auth_filter( void grpc_register_security_filters(void) { grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX, - maybe_prepend_client_auth_filter, NULL); + maybe_prepend_client_auth_filter, nullptr); grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX, - maybe_prepend_client_auth_filter, NULL); + maybe_prepend_client_auth_filter, nullptr); grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, - maybe_prepend_server_auth_filter, NULL); + maybe_prepend_server_auth_filter, nullptr); } void grpc_security_init() { diff --git a/src/core/lib/surface/lame_client.cc b/src/core/lib/surface/lame_client.cc index add7be2e08..b9e2b58262 100644 --- a/src/core/lib/surface/lame_client.cc +++ b/src/core/lib/surface/lame_client.cc @@ -68,7 +68,7 @@ static void fill_metadata(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, calld->details.md = grpc_mdelem_from_slices( exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, grpc_slice_from_copied_string(chand->error_message)); - calld->status.prev = calld->details.next = NULL; + calld->status.prev = calld->details.next = nullptr; calld->status.next = &calld->details; calld->details.prev = &calld->status; mdb->list.head = &calld->status; @@ -106,13 +106,13 @@ static void lame_start_transport_op(grpc_exec_ctx* exec_ctx, GRPC_CLOSURE_SCHED(exec_ctx, op->on_connectivity_state_change, GRPC_ERROR_NONE); } - if (op->send_ping != NULL) { + if (op->send_ping != nullptr) { GRPC_CLOSURE_SCHED( exec_ctx, op->send_ping, GRPC_ERROR_CREATE_FROM_STATIC_STRING("lame client channel")); } GRPC_ERROR_UNREF(op->disconnect_with_error); - if (op->on_consumed != NULL) { + if (op->on_consumed != nullptr) { GRPC_CLOSURE_SCHED(exec_ctx, op->on_consumed, GRPC_ERROR_NONE); } } @@ -167,8 +167,8 @@ grpc_channel* grpc_lame_client_channel_create(const char* target, const char* error_message) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_channel_element* elem; - grpc_channel* channel = grpc_channel_create(&exec_ctx, target, NULL, - GRPC_CLIENT_LAME_CHANNEL, NULL); + grpc_channel* channel = grpc_channel_create(&exec_ctx, target, nullptr, + GRPC_CLIENT_LAME_CHANNEL, nullptr); elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); GRPC_API_TRACE( "grpc_lame_client_channel_create(target=%s, error_code=%d, " diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc index da7ae17bef..bb48c8d900 100644 --- a/src/core/lib/surface/server.cc +++ b/src/core/lib/surface/server.cc @@ -319,7 +319,7 @@ static void request_matcher_init(request_matcher* rm, grpc_server* server) { static void request_matcher_destroy(request_matcher* rm) { for (size_t i = 0; i < rm->server->cq_count; i++) { - GPR_ASSERT(gpr_locked_mpscq_pop(&rm->requests_per_cq[i]) == NULL); + GPR_ASSERT(gpr_locked_mpscq_pop(&rm->requests_per_cq[i]) == nullptr); gpr_locked_mpscq_destroy(&rm->requests_per_cq[i]); } gpr_free(rm->requests_per_cq); @@ -357,7 +357,7 @@ static void request_matcher_kill_requests(grpc_exec_ctx* exec_ctx, So, we can ignore the queue lock and just pop, with the guarantee that a NULL returned here truly means that the queue is empty */ while ((rc = (requested_call*)gpr_mpscq_pop( - &rm->requests_per_cq[i].queue)) != NULL) { + &rm->requests_per_cq[i].queue)) != nullptr) { fail_call(exec_ctx, server, i, rc, GRPC_ERROR_REF(error)); } } @@ -379,7 +379,7 @@ static void server_delete(grpc_exec_ctx* exec_ctx, grpc_server* server) { gpr_mu_destroy(&server->mu_global); gpr_mu_destroy(&server->mu_call); gpr_cv_destroy(&server->starting_cv); - while ((rm = server->registered_methods) != NULL) { + while ((rm = server->registered_methods) != nullptr) { server->registered_methods = rm->next; if (server->started) { request_matcher_destroy(&rm->matcher); @@ -427,7 +427,7 @@ static void finish_destroy_channel(grpc_exec_ctx* exec_ctx, void* cd, static void destroy_channel(grpc_exec_ctx* exec_ctx, channel_data* chand, grpc_error* error) { if (is_channel_orphaned(chand)) return; - GPR_ASSERT(chand->server != NULL); + GPR_ASSERT(chand->server != nullptr); orphan_channel(chand); server_ref(chand->server); maybe_finish_shutdown(exec_ctx, chand->server); @@ -476,7 +476,7 @@ static void publish_call(grpc_exec_ctx* exec_ctx, grpc_server* server, grpc_millis_to_timespec(calld->deadline, GPR_CLOCK_MONOTONIC); if (rc->data.registered.optional_payload) { *rc->data.registered.optional_payload = calld->payload; - calld->payload = NULL; + calld->payload = nullptr; } break; default: @@ -510,7 +510,7 @@ static void publish_new_rpc(grpc_exec_ctx* exec_ctx, void* arg, size_t cq_idx = (chand->cq_idx + i) % server->cq_count; requested_call* rc = (requested_call*)gpr_locked_mpscq_try_pop(&rm->requests_per_cq[cq_idx]); - if (rc == NULL) { + if (rc == nullptr) { continue; } else { GRPC_STATS_INC_SERVER_CQS_CHECKED(exec_ctx, i); @@ -532,7 +532,7 @@ static void publish_new_rpc(grpc_exec_ctx* exec_ctx, void* arg, size_t cq_idx = (chand->cq_idx + i) % server->cq_count; requested_call* rc = (requested_call*)gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx]); - if (rc == NULL) { + if (rc == nullptr) { continue; } else { gpr_mu_unlock(&server->mu_call); @@ -544,13 +544,13 @@ static void publish_new_rpc(grpc_exec_ctx* exec_ctx, void* arg, } gpr_atm_no_barrier_store(&calld->state, PENDING); - if (rm->pending_head == NULL) { + if (rm->pending_head == nullptr) { rm->pending_tail = rm->pending_head = calld; } else { rm->pending_tail->pending_next = calld; rm->pending_tail = calld; } - calld->pending_next = NULL; + calld->pending_next = nullptr; gpr_mu_unlock(&server->mu_call); } @@ -727,8 +727,8 @@ static void server_on_recv_initial_metadata(grpc_exec_ctx* exec_ctx, void* ptr, grpc_millis op_deadline; if (error == GRPC_ERROR_NONE) { - GPR_ASSERT(calld->recv_initial_metadata->idx.named.path != NULL); - GPR_ASSERT(calld->recv_initial_metadata->idx.named.authority != NULL); + GPR_ASSERT(calld->recv_initial_metadata->idx.named.path != nullptr); + GPR_ASSERT(calld->recv_initial_metadata->idx.named.authority != nullptr); calld->path = grpc_slice_ref_internal( GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.path->md)); calld->host = grpc_slice_ref_internal( @@ -764,7 +764,7 @@ static void server_mutate_op(grpc_call_element* elem, call_data* calld = (call_data*)elem->call_data; if (op->recv_initial_metadata) { - GPR_ASSERT(op->payload->recv_initial_metadata.recv_flags == NULL); + GPR_ASSERT(op->payload->recv_initial_metadata.recv_flags == nullptr); calld->recv_initial_metadata = op->payload->recv_initial_metadata.recv_initial_metadata; calld->on_done_recv_initial_metadata = @@ -838,7 +838,7 @@ static void channel_connectivity_changed(grpc_exec_ctx* exec_ctx, void* cd, channel_data* chand = (channel_data*)cd; grpc_server* server = chand->server; if (chand->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { - grpc_transport_op* op = grpc_make_transport_op(NULL); + grpc_transport_op* op = grpc_make_transport_op(nullptr); op->on_connectivity_state_change = &chand->channel_connectivity_changed, op->connectivity_state = &chand->connectivity_state; grpc_channel_next_op(exec_ctx, @@ -896,10 +896,10 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, channel_data* chand = (channel_data*)elem->channel_data; GPR_ASSERT(args->is_first); GPR_ASSERT(!args->is_last); - chand->server = NULL; - chand->channel = NULL; + chand->server = nullptr; + chand->channel = nullptr; chand->next = chand->prev = chand; - chand->registered_methods = NULL; + chand->registered_methods = nullptr; chand->connectivity_state = GRPC_CHANNEL_IDLE; GRPC_CLOSURE_INIT(&chand->channel_connectivity_changed, channel_connectivity_changed, chand, @@ -999,9 +999,9 @@ grpc_server* grpc_server_create(const grpc_channel_args* args, void* reserved) { } static int streq(const char* a, const char* b) { - if (a == NULL && b == NULL) return 1; - if (a == NULL) return 0; - if (b == NULL) return 0; + if (a == nullptr && b == nullptr) return 1; + if (a == nullptr) return 0; + if (b == nullptr) return 0; return 0 == strcmp(a, b); } @@ -1017,19 +1017,19 @@ void* grpc_server_register_method( if (!method) { gpr_log(GPR_ERROR, "grpc_server_register_method method string cannot be NULL"); - return NULL; + return nullptr; } for (m = server->registered_methods; m; m = m->next) { if (streq(m->method, method) && streq(m->host, host)) { gpr_log(GPR_ERROR, "duplicate registration for %s@%s", method, host ? host : "*"); - return NULL; + return nullptr; } } if ((flags & ~GRPC_INITIAL_METADATA_USED_MASK) != 0) { gpr_log(GPR_ERROR, "grpc_server_register_method invalid flags 0x%08x", flags); - return NULL; + return nullptr; } m = (registered_method*)gpr_zalloc(sizeof(registered_method)); m->method = gpr_strdup(method); @@ -1108,10 +1108,10 @@ void grpc_server_setup_transport(grpc_exec_ctx* exec_ctx, grpc_server* s, size_t slots; uint32_t probes; uint32_t max_probes = 0; - grpc_transport_op* op = NULL; + grpc_transport_op* op = nullptr; channel = - grpc_channel_create(exec_ctx, NULL, args, GRPC_SERVER_CHANNEL, transport); + grpc_channel_create(exec_ctx, nullptr, args, GRPC_SERVER_CHANNEL, transport); chand = (channel_data*)grpc_channel_stack_element( grpc_channel_get_channel_stack(channel), 0) ->channel_data; @@ -1143,7 +1143,7 @@ void grpc_server_setup_transport(grpc_exec_ctx* exec_ctx, grpc_server* s, grpc_slice host; bool has_host; grpc_slice method; - if (rm->host != NULL) { + if (rm->host != nullptr) { host = grpc_slice_intern(grpc_slice_from_static_string(rm->host)); has_host = true; } else { @@ -1153,7 +1153,7 @@ void grpc_server_setup_transport(grpc_exec_ctx* exec_ctx, grpc_server* s, hash = GRPC_MDSTR_KV_HASH(has_host ? grpc_slice_hash(host) : 0, grpc_slice_hash(method)); for (probes = 0; chand->registered_methods[(hash + probes) % slots] - .server_registered_method != NULL; + .server_registered_method != nullptr; probes++) ; if (probes > max_probes) max_probes = probes; @@ -1178,7 +1178,7 @@ void grpc_server_setup_transport(grpc_exec_ctx* exec_ctx, grpc_server* s, gpr_mu_unlock(&s->mu_global); GRPC_CHANNEL_INTERNAL_REF(channel, "connectivity"); - op = grpc_make_transport_op(NULL); + op = grpc_make_transport_op(nullptr); op->set_accept_stream = true; op->set_accept_stream_fn = accept_stream; op->set_accept_stream_user_data = chand; @@ -1227,7 +1227,7 @@ void grpc_server_shutdown_and_notify(grpc_server* server, GPR_ASSERT(grpc_cq_begin_op(cq, tag)); if (server->shutdown_published) { grpc_cq_end_op(&exec_ctx, cq, tag, GRPC_ERROR_NONE, done_published_shutdown, - NULL, + nullptr, (grpc_cq_completion*)gpr_malloc(sizeof(grpc_cq_completion))); gpr_mu_unlock(&server->mu_global); goto done; @@ -1328,8 +1328,8 @@ void grpc_server_add_listener( static grpc_call_error queue_call_request(grpc_exec_ctx* exec_ctx, grpc_server* server, size_t cq_idx, requested_call* rc) { - call_data* calld = NULL; - request_matcher* rm = NULL; + call_data* calld = nullptr; + request_matcher* rm = nullptr; if (gpr_atm_acq_load(&server->shutdown_flag)) { fail_call(exec_ctx, server, cq_idx, rc, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server Shutdown")); @@ -1347,9 +1347,9 @@ static grpc_call_error queue_call_request(grpc_exec_ctx* exec_ctx, /* this was the first queued request: we need to lock and start matching calls */ gpr_mu_lock(&server->mu_call); - while ((calld = rm->pending_head) != NULL) { + while ((calld = rm->pending_head) != nullptr) { rc = (requested_call*)gpr_locked_mpscq_pop(&rm->requests_per_cq[cq_idx]); - if (rc == NULL) break; + if (rc == nullptr) break; rm->pending_head = calld->pending_next; gpr_mu_unlock(&server->mu_call); if (!gpr_atm_full_cas(&calld->state, PENDING, ACTIVATED)) { @@ -1402,7 +1402,7 @@ grpc_call_error grpc_server_request_call( error = GRPC_CALL_ERROR_COMPLETION_QUEUE_SHUTDOWN; goto done; } - details->reserved = NULL; + details->reserved = nullptr; rc->cq_idx = cq_idx; rc->type = BATCH_CALL; rc->server = server; @@ -1447,7 +1447,7 @@ grpc_call_error grpc_server_request_registered_call( error = GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE; goto done; } - if ((optional_payload == NULL) != + if ((optional_payload == nullptr) != (rm->payload_handling == GRPC_SRM_PAYLOAD_NONE)) { gpr_free(rc); error = GRPC_CALL_ERROR_PAYLOAD_TYPE_MISMATCH; @@ -1476,7 +1476,7 @@ done: static void fail_call(grpc_exec_ctx* exec_ctx, grpc_server* server, size_t cq_idx, requested_call* rc, grpc_error* error) { - *rc->call = NULL; + *rc->call = nullptr; rc->initial_metadata->count = 0; GPR_ASSERT(error != GRPC_ERROR_NONE); diff --git a/src/core/lib/transport/bdp_estimator.h b/src/core/lib/transport/bdp_estimator.h index f7b94a81d3..984ba88ecb 100644 --- a/src/core/lib/transport/bdp_estimator.h +++ b/src/core/lib/transport/bdp_estimator.h @@ -33,7 +33,7 @@ extern grpc_tracer_flag grpc_bdp_estimator_trace; -namespace grpc_core { +namespace grpc_core; { class BdpEstimator { public: diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc index bdaf0243f9..55f4236d57 100644 --- a/src/core/lib/transport/connectivity_state.cc +++ b/src/core/lib/transport/connectivity_state.cc @@ -48,7 +48,7 @@ void grpc_connectivity_state_init(grpc_connectivity_state_tracker* tracker, const char* name) { gpr_atm_no_barrier_store(&tracker->current_state_atm, init_state); tracker->current_error = GRPC_ERROR_NONE; - tracker->watchers = NULL; + tracker->watchers = nullptr; tracker->name = gpr_strdup(name); } @@ -94,7 +94,7 @@ grpc_connectivity_state grpc_connectivity_state_get( gpr_log(GPR_DEBUG, "CONWATCH: %p %s: get %s", tracker, tracker->name, grpc_connectivity_state_name(cur)); } - if (error != NULL) { + if (error != nullptr) { *error = GRPC_ERROR_REF(tracker->current_error); } return cur; @@ -102,7 +102,7 @@ grpc_connectivity_state grpc_connectivity_state_get( bool grpc_connectivity_state_has_watchers( grpc_connectivity_state_tracker* connectivity_state) { - return connectivity_state->watchers != NULL; + return connectivity_state->watchers != nullptr; } bool grpc_connectivity_state_notify_on_state_change( @@ -112,7 +112,7 @@ bool grpc_connectivity_state_notify_on_state_change( (grpc_connectivity_state)gpr_atm_no_barrier_load( &tracker->current_state_atm); if (GRPC_TRACER_ON(grpc_connectivity_state_trace)) { - if (current == NULL) { + if (current == nullptr) { gpr_log(GPR_DEBUG, "CONWATCH: %p %s: unsubscribe notify=%p", tracker, tracker->name, notify); } else { @@ -121,17 +121,17 @@ bool grpc_connectivity_state_notify_on_state_change( grpc_connectivity_state_name(cur), notify); } } - if (current == NULL) { + if (current == nullptr) { grpc_connectivity_state_watcher* w = tracker->watchers; - if (w != NULL && w->notify == notify) { + if (w != nullptr && w->notify == notify) { GRPC_CLOSURE_SCHED(exec_ctx, notify, GRPC_ERROR_CANCELLED); tracker->watchers = w->next; gpr_free(w); return false; } - while (w != NULL) { + while (w != nullptr) { grpc_connectivity_state_watcher* rm_candidate = w->next; - if (rm_candidate != NULL && rm_candidate->notify == notify) { + if (rm_candidate != nullptr && rm_candidate->notify == notify) { GRPC_CLOSURE_SCHED(exec_ctx, notify, GRPC_ERROR_CANCELLED); w->next = w->next->next; gpr_free(rm_candidate); @@ -189,7 +189,7 @@ void grpc_connectivity_state_set(grpc_exec_ctx* exec_ctx, } GPR_ASSERT(cur != GRPC_CHANNEL_SHUTDOWN); gpr_atm_no_barrier_store(&tracker->current_state_atm, state); - while ((w = tracker->watchers) != NULL) { + while ((w = tracker->watchers) != nullptr) { *w->current = state; tracker->watchers = w->next; if (GRPC_TRACER_ON(grpc_connectivity_state_trace)) { diff --git a/src/core/lib/transport/error_utils.cc b/src/core/lib/transport/error_utils.cc index d968b04fd8..9bcff9f284 100644 --- a/src/core/lib/transport/error_utils.cc +++ b/src/core/lib/transport/error_utils.cc @@ -24,10 +24,10 @@ static grpc_error* recursively_find_error_with_field(grpc_error* error, grpc_error_ints which) { // If the error itself has a status code, return it. - if (grpc_error_get_int(error, which, NULL)) { + if (grpc_error_get_int(error, which, nullptr)) { return error; } - if (grpc_error_is_special(error)) return NULL; + if (grpc_error_is_special(error)) return nullptr; // Otherwise, search through its children. uint8_t slot = error->first_err; while (slot != UINT8_MAX) { @@ -36,7 +36,7 @@ static grpc_error* recursively_find_error_with_field(grpc_error* error, if (result) return result; slot = lerr->next; } - return NULL; + return nullptr; } void grpc_error_get_status(grpc_exec_ctx* exec_ctx, grpc_error* error, @@ -47,7 +47,7 @@ void grpc_error_get_status(grpc_exec_ctx* exec_ctx, grpc_error* error, // until we find the first one that has a status code. grpc_error* found_error = recursively_find_error_with_field(error, GRPC_ERROR_INT_GRPC_STATUS); - if (found_error == NULL) { + if (found_error == nullptr) { /// If no grpc-status exists, retry through the tree to find a http2 error /// code found_error = @@ -56,7 +56,7 @@ void grpc_error_get_status(grpc_exec_ctx* exec_ctx, grpc_error* error, // If we found an error with a status code above, use that; otherwise, // fall back to using the parent error. - if (found_error == NULL) found_error = error; + if (found_error == nullptr) found_error = error; grpc_status_code status = GRPC_STATUS_UNKNOWN; intptr_t integer; @@ -67,9 +67,9 @@ void grpc_error_get_status(grpc_exec_ctx* exec_ctx, grpc_error* error, status = grpc_http2_error_to_grpc_status( exec_ctx, (grpc_http2_error_code)integer, deadline); } - if (code != NULL) *code = status; + if (code != nullptr) *code = status; - if (http_error != NULL) { + if (http_error != nullptr) { if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR, &integer)) { *http_error = (grpc_http2_error_code)integer; } else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_GRPC_STATUS, @@ -83,7 +83,7 @@ void grpc_error_get_status(grpc_exec_ctx* exec_ctx, grpc_error* error, // If the error has a status message, use it. Otherwise, fall back to // the error description. - if (slice != NULL) { + if (slice != nullptr) { if (!grpc_error_get_str(found_error, GRPC_ERROR_STR_GRPC_MESSAGE, slice)) { if (!grpc_error_get_str(found_error, GRPC_ERROR_STR_DESCRIPTION, slice)) { *slice = grpc_slice_from_static_string("unknown error"); @@ -91,11 +91,11 @@ void grpc_error_get_status(grpc_exec_ctx* exec_ctx, grpc_error* error, } } - if (found_error == NULL) found_error = error; + if (found_error == nullptr) found_error = error; } bool grpc_error_has_clear_grpc_status(grpc_error* error) { - if (grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, NULL)) { + if (grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, nullptr)) { return true; } uint8_t slot = error->first_err; diff --git a/src/core/lib/transport/metadata.cc b/src/core/lib/transport/metadata.cc index ff11ddec13..a16f0508f0 100644 --- a/src/core/lib/transport/metadata.cc +++ b/src/core/lib/transport/metadata.cc @@ -241,7 +241,7 @@ grpc_mdelem grpc_mdelem_create( grpc_exec_ctx* exec_ctx, grpc_slice key, grpc_slice value, grpc_mdelem_data* compatible_external_backing_store) { if (!grpc_slice_is_interned(key) || !grpc_slice_is_interned(value)) { - if (compatible_external_backing_store != NULL) { + if (compatible_external_backing_store != nullptr) { return GRPC_MAKE_MDELEM(compatible_external_backing_store, GRPC_MDELEM_STORAGE_EXTERNAL); } @@ -330,7 +330,7 @@ grpc_mdelem grpc_mdelem_create( grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx* exec_ctx, grpc_slice key, grpc_slice value) { - grpc_mdelem out = grpc_mdelem_create(exec_ctx, key, value, NULL); + grpc_mdelem out = grpc_mdelem_create(exec_ctx, key, value, nullptr); grpc_slice_unref_internal(exec_ctx, key); grpc_slice_unref_internal(exec_ctx, value); return out; @@ -344,7 +344,7 @@ grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_exec_ctx* exec_ctx, grpc_slice value_slice = grpc_slice_maybe_static_intern(metadata->value, &changed); return grpc_mdelem_create(exec_ctx, key_slice, value_slice, - changed ? NULL : (grpc_mdelem_data*)metadata); + changed ? nullptr : (grpc_mdelem_data*)metadata); } static size_t get_base64_encoded_size(size_t raw_length) { @@ -478,7 +478,7 @@ void* grpc_mdelem_get_user_data(grpc_mdelem md, void (*destroy_func)(void*)) { switch (GRPC_MDELEM_STORAGE(md)) { case GRPC_MDELEM_STORAGE_EXTERNAL: case GRPC_MDELEM_STORAGE_ALLOCATED: - return NULL; + return nullptr; case GRPC_MDELEM_STORAGE_STATIC: return (void*)grpc_static_mdelem_user_data[GRPC_MDELEM_DATA(md) - grpc_static_mdelem_table]; @@ -488,12 +488,12 @@ void* grpc_mdelem_get_user_data(grpc_mdelem md, void (*destroy_func)(void*)) { if (gpr_atm_acq_load(&im->destroy_user_data) == (gpr_atm)destroy_func) { return (void*)gpr_atm_no_barrier_load(&im->user_data); } else { - return NULL; + return nullptr; } return result; } } - GPR_UNREACHABLE_CODE(return NULL); + GPR_UNREACHABLE_CODE(return nullptr); } void* grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void*), @@ -502,7 +502,7 @@ void* grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void*), case GRPC_MDELEM_STORAGE_EXTERNAL: case GRPC_MDELEM_STORAGE_ALLOCATED: destroy_func(user_data); - return NULL; + return nullptr; case GRPC_MDELEM_STORAGE_STATIC: destroy_func(user_data); return (void*)grpc_static_mdelem_user_data[GRPC_MDELEM_DATA(md) - @@ -510,12 +510,12 @@ void* grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void*), case GRPC_MDELEM_STORAGE_INTERNED: { interned_metadata* im = (interned_metadata*)GRPC_MDELEM_DATA(md); GPR_ASSERT(!is_mdelem_static(md)); - GPR_ASSERT((user_data == NULL) == (destroy_func == NULL)); + GPR_ASSERT((user_data == nullptr) == (destroy_func == nullptr)); gpr_mu_lock(&im->mu_user_data); if (gpr_atm_no_barrier_load(&im->destroy_user_data)) { /* user data can only be set once */ gpr_mu_unlock(&im->mu_user_data); - if (destroy_func != NULL) { + if (destroy_func != nullptr) { destroy_func(user_data); } return (void*)gpr_atm_no_barrier_load(&im->user_data); @@ -526,7 +526,7 @@ void* grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void*), return user_data; } } - GPR_UNREACHABLE_CODE(return NULL); + GPR_UNREACHABLE_CODE(return nullptr); } bool grpc_mdelem_eq(grpc_mdelem a, grpc_mdelem b) { diff --git a/src/core/lib/transport/metadata_batch.cc b/src/core/lib/transport/metadata_batch.cc index 90e84cd1e2..480544c8a8 100644 --- a/src/core/lib/transport/metadata_batch.cc +++ b/src/core/lib/transport/metadata_batch.cc @@ -32,17 +32,17 @@ static void assert_valid_list(grpc_mdelem_list* list) { #ifndef NDEBUG grpc_linked_mdelem* l; - GPR_ASSERT((list->head == NULL) == (list->tail == NULL)); + GPR_ASSERT((list->head == nullptr) == (list->tail == nullptr)); if (!list->head) return; - GPR_ASSERT(list->head->prev == NULL); - GPR_ASSERT(list->tail->next == NULL); - GPR_ASSERT((list->head == list->tail) == (list->head->next == NULL)); + GPR_ASSERT(list->head->prev == nullptr); + GPR_ASSERT(list->tail->next == nullptr); + GPR_ASSERT((list->head == list->tail) == (list->head->next == nullptr)); size_t verified_count = 0; for (l = list->head; l; l = l->next) { GPR_ASSERT(!GRPC_MDISNULL(l->md)); - GPR_ASSERT((l->prev == NULL) == (l == list->head)); - GPR_ASSERT((l->next == NULL) == (l == list->tail)); + GPR_ASSERT((l->prev == nullptr) == (l == list->head)); + GPR_ASSERT((l->next == nullptr) == (l == list->tail)); if (l->next) GPR_ASSERT(l->next->prev == l); if (l->prev) GPR_ASSERT(l->prev->next == l); verified_count++; @@ -54,7 +54,7 @@ static void assert_valid_list(grpc_mdelem_list* list) { static void assert_valid_callouts(grpc_exec_ctx* exec_ctx, grpc_metadata_batch* batch) { #ifndef NDEBUG - for (grpc_linked_mdelem* l = batch->list.head; l != NULL; l = l->next) { + for (grpc_linked_mdelem* l = batch->list.head; l != nullptr; l = l->next) { grpc_slice key_interned = grpc_slice_intern(GRPC_MDKEY(l->md)); grpc_metadata_batch_callouts_index callout_idx = GRPC_BATCH_INDEX_OF(key_interned); @@ -104,7 +104,7 @@ static grpc_error* maybe_link_callout(grpc_metadata_batch* batch, if (idx == GRPC_BATCH_CALLOUTS_COUNT) { return GRPC_ERROR_NONE; } - if (batch->idx.array[idx] == NULL) { + if (batch->idx.array[idx] == nullptr) { if (grpc_static_callout_is_default[idx]) ++batch->list.default_count; batch->idx.array[idx] = storage; return GRPC_ERROR_NONE; @@ -122,8 +122,8 @@ static void maybe_unlink_callout(grpc_metadata_batch* batch, return; } if (grpc_static_callout_is_default[idx]) --batch->list.default_count; - GPR_ASSERT(batch->idx.array[idx] != NULL); - batch->idx.array[idx] = NULL; + GPR_ASSERT(batch->idx.array[idx] != nullptr); + batch->idx.array[idx] = nullptr; } grpc_error* grpc_metadata_batch_add_head(grpc_exec_ctx* exec_ctx, @@ -138,9 +138,9 @@ grpc_error* grpc_metadata_batch_add_head(grpc_exec_ctx* exec_ctx, static void link_head(grpc_mdelem_list* list, grpc_linked_mdelem* storage) { assert_valid_list(list); GPR_ASSERT(!GRPC_MDISNULL(storage->md)); - storage->prev = NULL; + storage->prev = nullptr; storage->next = list->head; - if (list->head != NULL) { + if (list->head != nullptr) { list->head->prev = storage; } else { list->tail = storage; @@ -177,9 +177,9 @@ static void link_tail(grpc_mdelem_list* list, grpc_linked_mdelem* storage) { assert_valid_list(list); GPR_ASSERT(!GRPC_MDISNULL(storage->md)); storage->prev = list->tail; - storage->next = NULL; - storage->reserved = NULL; - if (list->tail != NULL) { + storage->next = nullptr; + storage->reserved = nullptr; + if (list->tail != nullptr) { list->tail->next = storage; } else { list->head = storage; @@ -206,12 +206,12 @@ grpc_error* grpc_metadata_batch_link_tail(grpc_exec_ctx* exec_ctx, static void unlink_storage(grpc_mdelem_list* list, grpc_linked_mdelem* storage) { assert_valid_list(list); - if (storage->prev != NULL) { + if (storage->prev != nullptr) { storage->prev->next = storage->next; } else { list->head = storage->next; } - if (storage->next != NULL) { + if (storage->next != nullptr) { storage->next->prev = storage->prev; } else { list->tail = storage->prev; @@ -270,12 +270,12 @@ void grpc_metadata_batch_clear(grpc_exec_ctx* exec_ctx, } bool grpc_metadata_batch_is_empty(grpc_metadata_batch* batch) { - return batch->list.head == NULL && batch->deadline == GRPC_MILLIS_INF_FUTURE; + return batch->list.head == nullptr && batch->deadline == GRPC_MILLIS_INF_FUTURE; } size_t grpc_metadata_batch_size(grpc_metadata_batch* batch) { size_t size = 0; - for (grpc_linked_mdelem* elem = batch->list.head; elem != NULL; + for (grpc_linked_mdelem* elem = batch->list.head; elem != nullptr; elem = elem->next) { size += GRPC_MDELEM_LENGTH(elem->md); } diff --git a/src/core/lib/transport/service_config.cc b/src/core/lib/transport/service_config.cc index 05907de7d7..6faf5c272a 100644 --- a/src/core/lib/transport/service_config.cc +++ b/src/core/lib/transport/service_config.cc @@ -64,11 +64,11 @@ grpc_service_config* grpc_service_config_create(const char* json_string) { service_config->json_string = gpr_strdup(json_string); service_config->json_tree = grpc_json_parse_string(service_config->json_string); - if (service_config->json_tree == NULL) { + if (service_config->json_tree == nullptr) { gpr_log(GPR_INFO, "failed to parse JSON for service config"); gpr_free(service_config->json_string); gpr_free(service_config); - return NULL; + return nullptr; } return service_config; } @@ -83,9 +83,9 @@ void grpc_service_config_parse_global_params( const grpc_service_config* service_config, void (*process_json)(const grpc_json* json, void* arg), void* arg) { const grpc_json* json = service_config->json_tree; - if (json->type != GRPC_JSON_OBJECT || json->key != NULL) return; - for (grpc_json* field = json->child; field != NULL; field = field->next) { - if (field->key == NULL) return; + if (json->type != GRPC_JSON_OBJECT || json->key != nullptr) return; + for (grpc_json* field = json->child; field != nullptr; field = field->next) { + if (field->key == nullptr) return; if (strcmp(field->key, "methodConfig") == 0) continue; process_json(field, arg); } @@ -94,13 +94,13 @@ void grpc_service_config_parse_global_params( const char* grpc_service_config_get_lb_policy_name( const grpc_service_config* service_config) { const grpc_json* json = service_config->json_tree; - if (json->type != GRPC_JSON_OBJECT || json->key != NULL) return NULL; - const char* lb_policy_name = NULL; - for (grpc_json* field = json->child; field != NULL; field = field->next) { - if (field->key == NULL) return NULL; + if (json->type != GRPC_JSON_OBJECT || json->key != nullptr) return nullptr; + const char* lb_policy_name = nullptr; + for (grpc_json* field = json->child; field != nullptr; field = field->next) { + if (field->key == nullptr) return nullptr; if (strcmp(field->key, "loadBalancingPolicy") == 0) { - if (lb_policy_name != NULL) return NULL; // Duplicate. - if (field->type != GRPC_JSON_STRING) return NULL; + if (lb_policy_name != nullptr) return nullptr; // Duplicate. + if (field->type != GRPC_JSON_STRING) return nullptr; lb_policy_name = field->value; } } @@ -110,10 +110,10 @@ const char* grpc_service_config_get_lb_policy_name( // Returns the number of names specified in the method config \a json. static size_t count_names_in_method_config_json(grpc_json* json) { size_t num_names = 0; - for (grpc_json* field = json->child; field != NULL; field = field->next) { - if (field->key != NULL && strcmp(field->key, "name") == 0) { + for (grpc_json* field = json->child; field != nullptr; field = field->next) { + if (field->key != nullptr && strcmp(field->key, "name") == 0) { if (field->type != GRPC_JSON_ARRAY) return -1; - for (grpc_json* name = field->child; name != NULL; name = name->next) { + for (grpc_json* name = field->child; name != nullptr; name = name->next) { if (name->type != GRPC_JSON_OBJECT) return -1; ++num_names; } @@ -125,26 +125,26 @@ static size_t count_names_in_method_config_json(grpc_json* json) { // Returns a path string for the JSON name object specified by \a json. // Returns NULL on error. Caller takes ownership of result. static char* parse_json_method_name(grpc_json* json) { - if (json->type != GRPC_JSON_OBJECT) return NULL; - const char* service_name = NULL; - const char* method_name = NULL; - for (grpc_json* child = json->child; child != NULL; child = child->next) { - if (child->key == NULL) return NULL; - if (child->type != GRPC_JSON_STRING) return NULL; + if (json->type != GRPC_JSON_OBJECT) return nullptr; + const char* service_name = nullptr; + const char* method_name = nullptr; + for (grpc_json* child = json->child; child != nullptr; child = child->next) { + if (child->key == nullptr) return nullptr; + if (child->type != GRPC_JSON_STRING) return nullptr; if (strcmp(child->key, "service") == 0) { - if (service_name != NULL) return NULL; // Duplicate. - if (child->value == NULL) return NULL; + if (service_name != nullptr) return nullptr; // Duplicate. + if (child->value == nullptr) return nullptr; service_name = child->value; } else if (strcmp(child->key, "method") == 0) { - if (method_name != NULL) return NULL; // Duplicate. - if (child->value == NULL) return NULL; + if (method_name != nullptr) return nullptr; // Duplicate. + if (child->value == nullptr) return nullptr; method_name = child->value; } } - if (service_name == NULL) return NULL; // Required field. + if (service_name == nullptr) return nullptr; // Required field. char* path; gpr_asprintf(&path, "/%s/%s", service_name, - method_name == NULL ? "*" : method_name); + method_name == nullptr ? "*" : method_name); return path; } @@ -159,18 +159,18 @@ static bool parse_json_method_config( grpc_slice_hash_table_entry* entries, size_t* idx) { // Construct value. void* method_config = create_value(json); - if (method_config == NULL) return false; + if (method_config == nullptr) return false; // Construct list of paths. bool success = false; gpr_strvec paths; gpr_strvec_init(&paths); - for (grpc_json* child = json->child; child != NULL; child = child->next) { - if (child->key == NULL) continue; + for (grpc_json* child = json->child; child != nullptr; child = child->next) { + if (child->key == nullptr) continue; if (strcmp(child->key, "name") == 0) { if (child->type != GRPC_JSON_ARRAY) goto done; - for (grpc_json* name = child->child; name != NULL; name = name->next) { + for (grpc_json* name = child->child; name != nullptr; name = name->next) { char* path = parse_json_method_name(name); - if (path == NULL) goto done; + if (path == nullptr) goto done; gpr_strvec_add(&paths, path); } } @@ -196,26 +196,26 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table( void (*unref_value)(grpc_exec_ctx* exec_ctx, void* value)) { const grpc_json* json = service_config->json_tree; // Traverse parsed JSON tree. - if (json->type != GRPC_JSON_OBJECT || json->key != NULL) return NULL; + if (json->type != GRPC_JSON_OBJECT || json->key != nullptr) return nullptr; size_t num_entries = 0; - grpc_slice_hash_table_entry* entries = NULL; - for (grpc_json* field = json->child; field != NULL; field = field->next) { - if (field->key == NULL) return NULL; + grpc_slice_hash_table_entry* entries = nullptr; + for (grpc_json* field = json->child; field != nullptr; field = field->next) { + if (field->key == nullptr) return nullptr; if (strcmp(field->key, "methodConfig") == 0) { - if (entries != NULL) return NULL; // Duplicate. - if (field->type != GRPC_JSON_ARRAY) return NULL; + if (entries != nullptr) return nullptr; // Duplicate. + if (field->type != GRPC_JSON_ARRAY) return nullptr; // Find number of entries. - for (grpc_json* method = field->child; method != NULL; + for (grpc_json* method = field->child; method != nullptr; method = method->next) { size_t count = count_names_in_method_config_json(method); - if (count <= 0) return NULL; + if (count <= 0) return nullptr; num_entries += count; } // Populate method config table entries. entries = (grpc_slice_hash_table_entry*)gpr_malloc( num_entries * sizeof(grpc_slice_hash_table_entry)); size_t idx = 0; - for (grpc_json* method = field->child; method != NULL; + for (grpc_json* method = field->child; method != nullptr; method = method->next) { if (!parse_json_method_config(exec_ctx, method, create_value, ref_value, unref_value, entries, &idx)) { @@ -224,17 +224,17 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table( unref_value(exec_ctx, entries[i].value); } gpr_free(entries); - return NULL; + return nullptr; } } GPR_ASSERT(idx == num_entries); } } // Instantiate method config table. - grpc_slice_hash_table* method_config_table = NULL; - if (entries != NULL) { + grpc_slice_hash_table* method_config_table = nullptr; + if (entries != nullptr) { method_config_table = - grpc_slice_hash_table_create(num_entries, entries, unref_value, NULL); + grpc_slice_hash_table_create(num_entries, entries, unref_value, nullptr); gpr_free(entries); } return method_config_table; @@ -246,7 +246,7 @@ void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, void* value = grpc_slice_hash_table_get(table, path); // If we didn't find a match for the path, try looking for a wildcard // entry (i.e., change "/service/method" to "/service/*"). - if (value == NULL) { + if (value == nullptr) { char* path_str = grpc_slice_to_c_string(path); const char* sep = strrchr(path_str, '/') + 1; const size_t len = (size_t)(sep - path_str); diff --git a/src/core/lib/transport/transport.cc b/src/core/lib/transport/transport.cc index 021f1b799b..9392c16db3 100644 --- a/src/core/lib/transport/transport.cc +++ b/src/core/lib/transport/transport.cc @@ -184,9 +184,9 @@ void grpc_transport_set_pops(grpc_exec_ctx* exec_ctx, grpc_transport* transport, grpc_polling_entity* pollent) { grpc_pollset* pollset; grpc_pollset_set* pollset_set; - if ((pollset = grpc_polling_entity_pollset(pollent)) != NULL) { + if ((pollset = grpc_polling_entity_pollset(pollent)) != nullptr) { transport->vtable->set_pollset(exec_ctx, transport, stream, pollset); - } else if ((pollset_set = grpc_polling_entity_pollset_set(pollent)) != NULL) { + } else if ((pollset_set = grpc_polling_entity_pollset_set(pollent)) != nullptr) { transport->vtable->set_pollset_set(exec_ctx, transport, stream, pollset_set); } else { diff --git a/src/core/lib/transport/transport_op_string.cc b/src/core/lib/transport/transport_op_string.cc index 24e74c10c5..eb84391237 100644 --- a/src/core/lib/transport/transport_op_string.cc +++ b/src/core/lib/transport/transport_op_string.cc @@ -47,7 +47,7 @@ static void put_metadata(gpr_strvec* b, grpc_mdelem md) { static void put_metadata_list(gpr_strvec* b, grpc_metadata_batch md) { grpc_linked_mdelem* m; - for (m = md.list.head; m != NULL; m = m->next) { + for (m = md.list.head; m != nullptr; m = m->next) { if (m != md.list.head) gpr_strvec_add(b, gpr_strdup(", ")); put_metadata(b, m->md); } @@ -121,7 +121,7 @@ char* grpc_transport_stream_op_batch_string( gpr_strvec_add(&b, tmp); } - out = gpr_strvec_flatten(&b, NULL); + out = gpr_strvec_flatten(&b, nullptr); gpr_strvec_destroy(&b); return out; @@ -135,10 +135,10 @@ char* grpc_transport_op_string(grpc_transport_op* op) { gpr_strvec b; gpr_strvec_init(&b); - if (op->on_connectivity_state_change != NULL) { + if (op->on_connectivity_state_change != nullptr) { if (!first) gpr_strvec_add(&b, gpr_strdup(" ")); first = false; - if (op->connectivity_state != NULL) { + if (op->connectivity_state != nullptr) { gpr_asprintf(&tmp, "ON_CONNECTIVITY_STATE_CHANGE:p=%p:from=%s", op->on_connectivity_state_change, grpc_connectivity_state_name(*op->connectivity_state)); @@ -175,25 +175,25 @@ char* grpc_transport_op_string(grpc_transport_op* op) { gpr_strvec_add(&b, tmp); } - if (op->bind_pollset != NULL) { + if (op->bind_pollset != nullptr) { if (!first) gpr_strvec_add(&b, gpr_strdup(" ")); first = false; gpr_strvec_add(&b, gpr_strdup("BIND_POLLSET")); } - if (op->bind_pollset_set != NULL) { + if (op->bind_pollset_set != nullptr) { if (!first) gpr_strvec_add(&b, gpr_strdup(" ")); first = false; gpr_strvec_add(&b, gpr_strdup("BIND_POLLSET_SET")); } - if (op->send_ping != NULL) { + if (op->send_ping != nullptr) { if (!first) gpr_strvec_add(&b, gpr_strdup(" ")); first = false; gpr_strvec_add(&b, gpr_strdup("SEND_PING")); } - out = gpr_strvec_flatten(&b, NULL); + out = gpr_strvec_flatten(&b, nullptr); gpr_strvec_destroy(&b); return out; diff --git a/src/core/tsi/fake_transport_security.cc b/src/core/tsi/fake_transport_security.cc index b12dde31fb..cce6ad29b5 100644 --- a/src/core/tsi/fake_transport_security.cc +++ b/src/core/tsi/fake_transport_security.cc @@ -122,7 +122,7 @@ static void store32_little_endian(uint32_t value, unsigned char* buf) { } static uint32_t read_frame_size(const grpc_slice_buffer* sb) { - GPR_ASSERT(sb != NULL && sb->length >= TSI_FAKE_FRAME_HEADER_SIZE); + GPR_ASSERT(sb != nullptr && sb->length >= TSI_FAKE_FRAME_HEADER_SIZE); uint8_t frame_size_buffer[TSI_FAKE_FRAME_HEADER_SIZE]; uint8_t* buf = frame_size_buffer; /* Copies the first 4 bytes to a temporary buffer. */ @@ -152,7 +152,7 @@ static void tsi_fake_frame_reset(tsi_fake_frame* frame, int needs_draining) { /* Checks if the frame's allocated size is at least frame->size, and reallocs * more memory if necessary. */ static void tsi_fake_frame_ensure_size(tsi_fake_frame* frame) { - if (frame->data == NULL) { + if (frame->data == nullptr) { frame->allocated_size = frame->size; frame->data = (unsigned char*)gpr_malloc(frame->allocated_size); } else if (frame->size > frame->allocated_size) { @@ -174,7 +174,7 @@ static tsi_result tsi_fake_frame_decode(const unsigned char* incoming_bytes, const unsigned char* bytes_cursor = incoming_bytes; if (frame->needs_draining) return TSI_INTERNAL_ERROR; - if (frame->data == NULL) { + if (frame->data == nullptr) { frame->allocated_size = TSI_FAKE_FRAME_INITIAL_ALLOCATED_SIZE; frame->data = (unsigned char*)gpr_malloc(frame->allocated_size); } @@ -246,7 +246,7 @@ static tsi_result tsi_fake_frame_set_data(unsigned char* data, size_t data_size, /* Destroys the contents of a fake frame. */ static void tsi_fake_frame_destruct(tsi_fake_frame* frame) { - if (frame->data != NULL) gpr_free(frame->data); + if (frame->data != nullptr) gpr_free(frame->data); } /* --- tsi_frame_protector methods implementation. ---*/ @@ -402,7 +402,7 @@ static tsi_result fake_zero_copy_grpc_protector_protect( grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* unprotected_slices, grpc_slice_buffer* protected_slices) { - if (self == NULL || unprotected_slices == NULL || protected_slices == NULL) { + if (self == nullptr || unprotected_slices == nullptr || protected_slices == nullptr) { return TSI_INVALID_ARGUMENT; } tsi_fake_zero_copy_grpc_protector* impl = @@ -426,7 +426,7 @@ static tsi_result fake_zero_copy_grpc_protector_unprotect( grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* protected_slices, grpc_slice_buffer* unprotected_slices) { - if (self == NULL || unprotected_slices == NULL || protected_slices == NULL) { + if (self == nullptr || unprotected_slices == nullptr || protected_slices == nullptr) { return TSI_INVALID_ARGUMENT; } tsi_fake_zero_copy_grpc_protector* impl = @@ -459,7 +459,7 @@ static tsi_result fake_zero_copy_grpc_protector_unprotect( static void fake_zero_copy_grpc_protector_destroy( grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self) { - if (self == NULL) return; + if (self == nullptr) return; tsi_fake_zero_copy_grpc_protector* impl = (tsi_fake_zero_copy_grpc_protector*)self; grpc_slice_buffer_destroy_internal(exec_ctx, &impl->header_sb); @@ -536,8 +536,8 @@ static const tsi_handshaker_result_vtable handshaker_result_vtable = { static tsi_result fake_handshaker_result_create( const unsigned char* unused_bytes, size_t unused_bytes_size, tsi_handshaker_result** handshaker_result) { - if ((unused_bytes_size > 0 && unused_bytes == NULL) || - handshaker_result == NULL) { + if ((unused_bytes_size > 0 && unused_bytes == nullptr) || + handshaker_result == nullptr) { return TSI_INVALID_ARGUMENT; } fake_handshaker_result* result = @@ -658,9 +658,9 @@ static tsi_result fake_handshaker_next( size_t* bytes_to_send_size, tsi_handshaker_result** handshaker_result, tsi_handshaker_on_next_done_cb cb, void* user_data) { /* Sanity check the arguments. */ - if ((received_bytes_size > 0 && received_bytes == NULL) || - bytes_to_send == NULL || bytes_to_send_size == NULL || - handshaker_result == NULL) { + if ((received_bytes_size > 0 && received_bytes == nullptr) || + bytes_to_send == nullptr || bytes_to_send_size == nullptr || + handshaker_result == nullptr) { return TSI_INVALID_ARGUMENT; } tsi_fake_handshaker* handshaker = (tsi_fake_handshaker*)self; @@ -695,10 +695,10 @@ static tsi_result fake_handshaker_next( /* Check if the handshake was completed. */ if (fake_handshaker_get_result(self) == TSI_HANDSHAKE_IN_PROGRESS) { - *handshaker_result = NULL; + *handshaker_result = nullptr; } else { /* Calculate the unused bytes. */ - const unsigned char* unused_bytes = NULL; + const unsigned char* unused_bytes = nullptr; size_t unused_bytes_size = received_bytes_size - consumed_bytes_size; if (unused_bytes_size > 0) { unused_bytes = received_bytes + consumed_bytes_size; @@ -717,11 +717,11 @@ static tsi_result fake_handshaker_next( } static const tsi_handshaker_vtable handshaker_vtable = { - NULL, /* get_bytes_to_send_to_peer -- deprecated */ - NULL, /* process_bytes_from_peer -- deprecated */ - NULL, /* get_result -- deprecated */ - NULL, /* extract_peer -- deprecated */ - NULL, /* create_frame_protector -- deprecated */ + nullptr, /* get_bytes_to_send_to_peer -- deprecated */ + nullptr, /* process_bytes_from_peer -- deprecated */ + nullptr, /* get_result -- deprecated */ + nullptr, /* extract_peer -- deprecated */ + nullptr, /* create_frame_protector -- deprecated */ fake_handshaker_destroy, fake_handshaker_next, }; @@ -749,7 +749,7 @@ tsi_frame_protector* tsi_create_fake_frame_protector( size_t* max_protected_frame_size) { tsi_fake_frame_protector* impl = (tsi_fake_frame_protector*)gpr_zalloc(sizeof(*impl)); - impl->max_frame_size = (max_protected_frame_size == NULL) + impl->max_frame_size = (max_protected_frame_size == nullptr) ? TSI_FAKE_DEFAULT_FRAME_SIZE : *max_protected_frame_size; impl->base.vtable = &frame_protector_vtable; @@ -762,7 +762,7 @@ tsi_zero_copy_grpc_protector* tsi_create_fake_zero_copy_grpc_protector( (tsi_fake_zero_copy_grpc_protector*)gpr_zalloc(sizeof(*impl)); grpc_slice_buffer_init(&impl->header_sb); grpc_slice_buffer_init(&impl->protected_sb); - impl->max_frame_size = (max_protected_frame_size == NULL) + impl->max_frame_size = (max_protected_frame_size == nullptr) ? TSI_FAKE_DEFAULT_FRAME_SIZE : *max_protected_frame_size; impl->parsed_frame_size = 0; diff --git a/src/core/tsi/gts_transport_security.cc b/src/core/tsi/gts_transport_security.cc index 1dfd8c4df0..d5948c9516 100644 --- a/src/core/tsi/gts_transport_security.cc +++ b/src/core/tsi/gts_transport_security.cc @@ -31,7 +31,7 @@ extern "C" void grpc_tsi_gts_init() { extern "C" void grpc_tsi_gts_shutdown() { gpr_mu_destroy(&g_gts_resource.mu); - if (g_gts_resource.cq == NULL) { + if (g_gts_resource.cq == nullptr) { return; } grpc_completion_queue_destroy(g_gts_resource.cq); diff --git a/src/core/tsi/ssl_transport_security.cc b/src/core/tsi/ssl_transport_security.cc index c1c2de6ca9..2fe62f2f10 100644 --- a/src/core/tsi/ssl_transport_security.cc +++ b/src/core/tsi/ssl_transport_security.cc @@ -115,7 +115,7 @@ typedef struct { /* --- Library Initialization. ---*/ static gpr_once init_openssl_once = GPR_ONCE_INIT; -static gpr_mu* openssl_mutexes = NULL; +static gpr_mu* openssl_mutexes = nullptr; static void openssl_locking_cb(int mode, int type, const char* file, int line) { if (mode & CRYPTO_LOCK) { @@ -223,11 +223,11 @@ static int looks_like_ip_address(const char* name) { static tsi_result ssl_get_x509_common_name(X509* cert, unsigned char** utf8, size_t* utf8_size) { int common_name_index = -1; - X509_NAME_ENTRY* common_name_entry = NULL; - ASN1_STRING* common_name_asn1 = NULL; + X509_NAME_ENTRY* common_name_entry = nullptr; + ASN1_STRING* common_name_asn1 = nullptr; X509_NAME* subject_name = X509_get_subject_name(cert); int utf8_returned_size = 0; - if (subject_name == NULL) { + if (subject_name == nullptr) { gpr_log(GPR_ERROR, "Could not get subject name from certificate."); return TSI_NOT_FOUND; } @@ -239,12 +239,12 @@ static tsi_result ssl_get_x509_common_name(X509* cert, unsigned char** utf8, return TSI_NOT_FOUND; } common_name_entry = X509_NAME_get_entry(subject_name, common_name_index); - if (common_name_entry == NULL) { + if (common_name_entry == nullptr) { gpr_log(GPR_ERROR, "Could not get common name entry from certificate."); return TSI_INTERNAL_ERROR; } common_name_asn1 = X509_NAME_ENTRY_get_data(common_name_entry); - if (common_name_asn1 == NULL) { + if (common_name_asn1 == nullptr) { gpr_log(GPR_ERROR, "Could not get common name entry asn1 from certificate."); return TSI_INTERNAL_ERROR; @@ -267,7 +267,7 @@ static tsi_result peer_property_from_x509_common_name( ssl_get_x509_common_name(cert, &common_name, &common_name_size); if (result != TSI_OK) { if (result == TSI_NOT_FOUND) { - common_name = NULL; + common_name = nullptr; common_name_size = 0; } else { return result; @@ -275,7 +275,7 @@ static tsi_result peer_property_from_x509_common_name( } result = tsi_construct_string_peer_property( TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, - common_name == NULL ? "" : (const char*)common_name, common_name_size, + common_name == nullptr ? "" : (const char*)common_name, common_name_size, property); OPENSSL_free(common_name); return result; @@ -315,7 +315,7 @@ static tsi_result add_subject_alt_names_properties_to_peer( sk_GENERAL_NAME_value(subject_alt_names, TSI_SIZE_AS_SIZE(i)); /* Filter out the non-dns entries names. */ if (subject_alt_name->type == GEN_DNS) { - unsigned char* name = NULL; + unsigned char* name = nullptr; int name_size; name_size = ASN1_STRING_to_UTF8(&name, subject_alt_name->d.dNSName); if (name_size < 0) { @@ -342,7 +342,7 @@ static tsi_result add_subject_alt_names_properties_to_peer( } const char* name = inet_ntop(af, subject_alt_name->d.iPAddress->data, ntop_buf, INET6_ADDRSTRLEN); - if (name == NULL) { + if (name == nullptr) { gpr_log(GPR_ERROR, "Could not get IP string from asn1 octet."); result = TSI_INTERNAL_ERROR; break; @@ -362,8 +362,8 @@ static tsi_result peer_from_x509(X509* cert, int include_certificate_type, tsi_peer* peer) { /* TODO(jboeuf): Maybe add more properties. */ GENERAL_NAMES* subject_alt_names = - (GENERAL_NAMES*)X509_get_ext_d2i(cert, NID_subject_alt_name, 0, 0); - int subject_alt_name_count = (subject_alt_names != NULL) + (GENERAL_NAMES*)X509_get_ext_d2i(cert, NID_subject_alt_name, nullptr, nullptr); + int subject_alt_name_count = (subject_alt_names != nullptr) ? (int)sk_GENERAL_NAME_num(subject_alt_names) : 0; size_t property_count; @@ -396,7 +396,7 @@ static tsi_result peer_from_x509(X509* cert, int include_certificate_type, } } while (0); - if (subject_alt_names != NULL) { + if (subject_alt_names != nullptr) { sk_GENERAL_NAME_pop_free(subject_alt_names, GENERAL_NAME_free); } if (result != TSI_OK) tsi_peer_destruct(peer); @@ -473,15 +473,15 @@ static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX* context, const char* pem_cert_chain, size_t pem_cert_chain_size) { tsi_result result = TSI_OK; - X509* certificate = NULL; + X509* certificate = nullptr; 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; + if (pem == nullptr) return TSI_OUT_OF_RESOURCES; do { - certificate = PEM_read_bio_X509_AUX(pem, NULL, NULL, (void*)""); - if (certificate == NULL) { + certificate = PEM_read_bio_X509_AUX(pem, nullptr, nullptr, (void*)""); + if (certificate == nullptr) { result = TSI_INVALID_ARGUMENT; break; } @@ -491,8 +491,8 @@ static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX* context, } while (1) { X509* certificate_authority = - PEM_read_bio_X509(pem, NULL, NULL, (void*)""); - if (certificate_authority == NULL) { + PEM_read_bio_X509(pem, nullptr, nullptr, (void*)""); + if (certificate_authority == nullptr) { ERR_clear_error(); break; /* Done reading. */ } @@ -507,7 +507,7 @@ static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX* context, } } while (0); - if (certificate != NULL) X509_free(certificate); + if (certificate != nullptr) X509_free(certificate); BIO_free(pem); return result; } @@ -516,14 +516,14 @@ static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX* context, static tsi_result ssl_ctx_use_private_key(SSL_CTX* context, const char* pem_key, size_t pem_key_size) { tsi_result result = TSI_OK; - EVP_PKEY* private_key = NULL; + EVP_PKEY* private_key = nullptr; 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; + if (pem == nullptr) return TSI_OUT_OF_RESOURCES; do { - private_key = PEM_read_bio_PrivateKey(pem, NULL, NULL, (void*)""); - if (private_key == NULL) { + private_key = PEM_read_bio_PrivateKey(pem, nullptr, nullptr, (void*)""); + if (private_key == nullptr) { result = TSI_INVALID_ARGUMENT; break; } @@ -532,7 +532,7 @@ static tsi_result ssl_ctx_use_private_key(SSL_CTX* context, const char* pem_key, break; } } while (0); - if (private_key != NULL) EVP_PKEY_free(private_key); + if (private_key != nullptr) EVP_PKEY_free(private_key); BIO_free(pem); return result; } @@ -546,40 +546,40 @@ static tsi_result ssl_ctx_load_verification_certs(SSL_CTX* context, *root_names) { tsi_result result = TSI_OK; size_t num_roots = 0; - X509* root = NULL; - X509_NAME* root_name = NULL; + X509* root = nullptr; + X509_NAME* root_name = nullptr; 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) { + if (root_store == nullptr) return TSI_INVALID_ARGUMENT; + if (pem == nullptr) return TSI_OUT_OF_RESOURCES; + if (root_names != nullptr) { *root_names = sk_X509_NAME_new_null(); - if (*root_names == NULL) return TSI_OUT_OF_RESOURCES; + if (*root_names == nullptr) return TSI_OUT_OF_RESOURCES; } while (1) { - root = PEM_read_bio_X509_AUX(pem, NULL, NULL, (void*)""); - if (root == NULL) { + root = PEM_read_bio_X509_AUX(pem, nullptr, nullptr, (void*)""); + if (root == nullptr) { ERR_clear_error(); break; /* We're at the end of stream. */ } - if (root_names != NULL) { + if (root_names != nullptr) { root_name = X509_get_subject_name(root); - if (root_name == NULL) { + if (root_name == nullptr) { gpr_log(GPR_ERROR, "Could not get name from root certificate."); result = TSI_INVALID_ARGUMENT; break; } root_name = X509_NAME_dup(root_name); - if (root_name == NULL) { + if (root_name == nullptr) { result = TSI_OUT_OF_RESOURCES; break; } sk_X509_NAME_push(*root_names, root_name); - root_name = NULL; + root_name = nullptr; } if (!X509_STORE_add_cert(root_store, root)) { gpr_log(GPR_ERROR, "Could not add root certificate to ssl context."); @@ -596,11 +596,11 @@ static tsi_result ssl_ctx_load_verification_certs(SSL_CTX* context, } if (result != TSI_OK) { - if (root != NULL) X509_free(root); - if (root_names != NULL) { + if (root != nullptr) X509_free(root); + if (root_names != nullptr) { sk_X509_NAME_pop_free(*root_names, X509_NAME_free); - *root_names = NULL; - if (root_name != NULL) X509_NAME_free(root_name); + *root_names = nullptr; + if (root_name != nullptr) X509_NAME_free(root_name); } } BIO_free(pem); @@ -613,8 +613,8 @@ static tsi_result populate_ssl_context( SSL_CTX* context, const tsi_ssl_pem_key_cert_pair* key_cert_pair, const char* cipher_list) { tsi_result result = TSI_OK; - if (key_cert_pair != NULL) { - if (key_cert_pair->cert_chain != NULL) { + if (key_cert_pair != nullptr) { + if (key_cert_pair->cert_chain != nullptr) { result = ssl_ctx_use_certificate_chain(context, key_cert_pair->cert_chain, strlen(key_cert_pair->cert_chain)); if (result != TSI_OK) { @@ -622,7 +622,7 @@ static tsi_result populate_ssl_context( return result; } } - if (key_cert_pair->private_key != NULL) { + if (key_cert_pair->private_key != nullptr) { result = ssl_ctx_use_private_key(context, key_cert_pair->private_key, strlen(key_cert_pair->private_key)); if (result != TSI_OK || !SSL_CTX_check_private_key(context)) { @@ -631,7 +631,7 @@ static tsi_result populate_ssl_context( } } } - if ((cipher_list != NULL) && !SSL_CTX_set_cipher_list(context, cipher_list)) { + if ((cipher_list != nullptr) && !SSL_CTX_set_cipher_list(context, cipher_list)) { gpr_log(GPR_ERROR, "Invalid cipher list: %s.", cipher_list); return TSI_INVALID_ARGUMENT; } @@ -652,19 +652,19 @@ static tsi_result populate_ssl_context( static tsi_result extract_x509_subject_names_from_pem_cert(const char* pem_cert, tsi_peer* peer) { tsi_result result = TSI_OK; - X509* cert = NULL; + X509* cert = nullptr; BIO* pem; pem = BIO_new_mem_buf((void*)pem_cert, (int)strlen(pem_cert)); - if (pem == NULL) return TSI_OUT_OF_RESOURCES; + if (pem == nullptr) return TSI_OUT_OF_RESOURCES; - cert = PEM_read_bio_X509(pem, NULL, NULL, (void*)""); - if (cert == NULL) { + cert = PEM_read_bio_X509(pem, nullptr, nullptr, (void*)""); + if (cert == nullptr) { gpr_log(GPR_ERROR, "Invalid certificate"); result = TSI_INVALID_ARGUMENT; } else { result = peer_from_x509(cert, 0, peer); } - if (cert != NULL) X509_free(cert); + if (cert != nullptr) X509_free(cert); BIO_free(pem); return result; } @@ -675,11 +675,11 @@ static tsi_result build_alpn_protocol_name_list( unsigned char** protocol_name_list, size_t* protocol_name_list_length) { uint16_t i; unsigned char* current; - *protocol_name_list = NULL; + *protocol_name_list = nullptr; *protocol_name_list_length = 0; if (num_alpn_protocols == 0) return TSI_INVALID_ARGUMENT; for (i = 0; i < num_alpn_protocols; i++) { - size_t length = alpn_protocols[i] == NULL ? 0 : strlen(alpn_protocols[i]); + size_t length = alpn_protocols[i] == nullptr ? 0 : strlen(alpn_protocols[i]); if (length == 0 || length > 255) { gpr_log(GPR_ERROR, "Invalid protocol name length: %d.", (int)length); return TSI_INVALID_ARGUMENT; @@ -687,7 +687,7 @@ static tsi_result build_alpn_protocol_name_list( *protocol_name_list_length += length + 1; } *protocol_name_list = (unsigned char*)gpr_malloc(*protocol_name_list_length); - if (*protocol_name_list == NULL) return TSI_OUT_OF_RESOURCES; + if (*protocol_name_list == nullptr) return TSI_OUT_OF_RESOURCES; current = *protocol_name_list; for (i = 0; i < num_alpn_protocols; i++) { size_t length = strlen(alpn_protocols[i]); @@ -846,8 +846,8 @@ static tsi_result ssl_protector_unprotect( static void ssl_protector_destroy(tsi_frame_protector* self) { tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self; - if (impl->buffer != NULL) gpr_free(impl->buffer); - if (impl->ssl != NULL) SSL_free(impl->ssl); + if (impl->buffer != nullptr) gpr_free(impl->buffer); + if (impl->ssl != nullptr) SSL_free(impl->ssl); gpr_free(self); } @@ -862,9 +862,9 @@ static const tsi_frame_protector_vtable frame_protector_vtable = { static void tsi_ssl_handshaker_factory_destroy( tsi_ssl_handshaker_factory* self) { - if (self == NULL) return; + if (self == nullptr) return; - if (self->vtable != NULL && self->vtable->destroy != NULL) { + if (self->vtable != nullptr && self->vtable->destroy != nullptr) { self->vtable->destroy(self); } /* Note, we don't free(self) here because this object is always directly @@ -874,26 +874,26 @@ static void tsi_ssl_handshaker_factory_destroy( static tsi_ssl_handshaker_factory* tsi_ssl_handshaker_factory_ref( tsi_ssl_handshaker_factory* self) { - if (self == NULL) return NULL; + if (self == nullptr) return nullptr; gpr_refn(&self->refcount, 1); return self; } static void tsi_ssl_handshaker_factory_unref(tsi_ssl_handshaker_factory* self) { - if (self == NULL) return; + if (self == nullptr) return; if (gpr_unref(&self->refcount)) { tsi_ssl_handshaker_factory_destroy(self); } } -static tsi_ssl_handshaker_factory_vtable handshaker_factory_vtable = {NULL}; +static tsi_ssl_handshaker_factory_vtable handshaker_factory_vtable = {nullptr}; /* Initializes a tsi_ssl_handshaker_factory object. Caller is responsible for * allocating memory for the factory. */ static void tsi_ssl_handshaker_factory_init( tsi_ssl_handshaker_factory* factory) { - GPR_ASSERT(factory != NULL); + GPR_ASSERT(factory != nullptr); factory->vtable = &handshaker_factory_vtable; gpr_ref_init(&factory->refcount, 1); @@ -906,7 +906,7 @@ static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, size_t* bytes_size) { tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; int bytes_read_from_ssl = 0; - if (bytes == NULL || bytes_size == NULL || *bytes_size == 0 || + if (bytes == nullptr || bytes_size == nullptr || *bytes_size == 0 || *bytes_size > INT_MAX) { return TSI_INVALID_ARGUMENT; } @@ -938,7 +938,7 @@ static tsi_result ssl_handshaker_process_bytes_from_peer( tsi_handshaker* self, const unsigned char* bytes, size_t* bytes_size) { tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; int bytes_written_into_ssl_size = 0; - if (bytes == NULL || bytes_size == 0 || *bytes_size > INT_MAX) { + if (bytes == nullptr || bytes_size == nullptr || *bytes_size > INT_MAX) { return TSI_INVALID_ARGUMENT; } GPR_ASSERT(*bytes_size <= INT_MAX); @@ -983,11 +983,11 @@ static tsi_result ssl_handshaker_process_bytes_from_peer( static tsi_result ssl_handshaker_extract_peer(tsi_handshaker* self, tsi_peer* peer) { tsi_result result = TSI_OK; - const unsigned char* alpn_selected = NULL; + const unsigned char* alpn_selected = nullptr; unsigned int alpn_selected_len; tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; X509* peer_cert = SSL_get_peer_certificate(impl->ssl); - if (peer_cert != NULL) { + if (peer_cert != nullptr) { result = peer_from_x509(peer_cert, 1, peer); X509_free(peer_cert); if (result != TSI_OK) return result; @@ -995,12 +995,12 @@ static tsi_result ssl_handshaker_extract_peer(tsi_handshaker* self, #if TSI_OPENSSL_ALPN_SUPPORT SSL_get0_alpn_selected(impl->ssl, &alpn_selected, &alpn_selected_len); #endif /* TSI_OPENSSL_ALPN_SUPPORT */ - if (alpn_selected == NULL) { + if (alpn_selected == nullptr) { /* Try npn. */ SSL_get0_next_proto_negotiated(impl->ssl, &alpn_selected, &alpn_selected_len); } - if (alpn_selected != NULL) { + if (alpn_selected != nullptr) { size_t i; tsi_peer_property* new_properties = (tsi_peer_property*)gpr_zalloc( sizeof(*new_properties) * (peer->property_count + 1)); @@ -1014,7 +1014,7 @@ static tsi_result ssl_handshaker_extract_peer(tsi_handshaker* self, gpr_free(new_properties); return result; } - if (peer->properties != NULL) gpr_free(peer->properties); + if (peer->properties != nullptr) gpr_free(peer->properties); peer->property_count++; peer->properties = new_properties; } @@ -1030,7 +1030,7 @@ static tsi_result ssl_handshaker_create_frame_protector( tsi_ssl_frame_protector* protector_impl = (tsi_ssl_frame_protector*)gpr_zalloc(sizeof(*protector_impl)); - if (max_output_protected_frame_size != NULL) { + if (max_output_protected_frame_size != nullptr) { if (*max_output_protected_frame_size > TSI_SSL_MAX_PROTECTED_FRAME_SIZE_UPPER_BOUND) { *max_output_protected_frame_size = @@ -1046,7 +1046,7 @@ static tsi_result ssl_handshaker_create_frame_protector( actual_max_output_protected_frame_size - TSI_SSL_MAX_PROTECTION_OVERHEAD; protector_impl->buffer = (unsigned char*)gpr_malloc(protector_impl->buffer_size); - if (protector_impl->buffer == NULL) { + if (protector_impl->buffer == nullptr) { gpr_log(GPR_ERROR, "Could not allocated buffer for tsi_ssl_frame_protector."); gpr_free(protector_impl); @@ -1056,7 +1056,7 @@ static tsi_result ssl_handshaker_create_frame_protector( /* Transfer ownership of ssl to the frame protector. It is OK as the caller * cannot call anything else but destroy on the handshaker after this call. */ protector_impl->ssl = impl->ssl; - impl->ssl = NULL; + impl->ssl = nullptr; protector_impl->into_ssl = impl->into_ssl; protector_impl->from_ssl = impl->from_ssl; @@ -1079,7 +1079,7 @@ static const tsi_handshaker_vtable handshaker_vtable = { ssl_handshaker_extract_peer, ssl_handshaker_create_frame_protector, ssl_handshaker_destroy, - NULL, + nullptr, }; /* --- tsi_ssl_handshaker_factory common methods. --- */ @@ -1089,33 +1089,33 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client, tsi_ssl_handshaker_factory* factory, tsi_handshaker** handshaker) { SSL* ssl = SSL_new(ctx); - BIO* into_ssl = NULL; - BIO* from_ssl = NULL; - tsi_ssl_handshaker* impl = NULL; - *handshaker = NULL; - if (ctx == NULL) { + BIO* into_ssl = nullptr; + BIO* from_ssl = nullptr; + tsi_ssl_handshaker* impl = nullptr; + *handshaker = nullptr; + if (ctx == nullptr) { gpr_log(GPR_ERROR, "SSL Context is null. Should never happen."); return TSI_INTERNAL_ERROR; } - if (ssl == NULL) { + if (ssl == nullptr) { return TSI_OUT_OF_RESOURCES; } SSL_set_info_callback(ssl, ssl_info_callback); into_ssl = BIO_new(BIO_s_mem()); from_ssl = BIO_new(BIO_s_mem()); - if (into_ssl == NULL || from_ssl == NULL) { + if (into_ssl == nullptr || from_ssl == nullptr) { gpr_log(GPR_ERROR, "BIO_new failed."); SSL_free(ssl); - if (into_ssl != NULL) BIO_free(into_ssl); - if (from_ssl != NULL) BIO_free(into_ssl); + if (into_ssl != nullptr) BIO_free(into_ssl); + if (from_ssl != nullptr) BIO_free(into_ssl); return TSI_OUT_OF_RESOURCES; } SSL_set_bio(ssl, into_ssl, from_ssl); if (is_client) { int ssl_result; SSL_set_connect_state(ssl); - if (server_name_indication != NULL) { + if (server_name_indication != nullptr) { if (!SSL_set_tlsext_host_name(ssl, server_name_indication)) { gpr_log(GPR_ERROR, "Invalid server name indication %s.", server_name_indication); @@ -1185,17 +1185,17 @@ tsi_result tsi_ssl_client_handshaker_factory_create_handshaker( void tsi_ssl_client_handshaker_factory_unref( tsi_ssl_client_handshaker_factory* self) { - if (self == NULL) return; + if (self == nullptr) return; tsi_ssl_handshaker_factory_unref(&self->base); } static void tsi_ssl_client_handshaker_factory_destroy( tsi_ssl_handshaker_factory* factory) { - if (factory == NULL) return; + if (factory == nullptr) return; tsi_ssl_client_handshaker_factory* self = (tsi_ssl_client_handshaker_factory*)factory; - if (self->ssl_context != NULL) SSL_CTX_free(self->ssl_context); - if (self->alpn_protocol_list != NULL) gpr_free(self->alpn_protocol_list); + if (self->ssl_context != nullptr) SSL_CTX_free(self->ssl_context); + if (self->alpn_protocol_list != nullptr) gpr_free(self->alpn_protocol_list); gpr_free(self); } @@ -1218,40 +1218,40 @@ tsi_result tsi_ssl_server_handshaker_factory_create_handshaker( if (self->ssl_context_count == 0) return TSI_INVALID_ARGUMENT; /* Create the handshaker with the first context. We will switch if needed because of SNI in ssl_server_handshaker_factory_servername_callback. */ - return create_tsi_ssl_handshaker(self->ssl_contexts[0], 0, NULL, &self->base, + return create_tsi_ssl_handshaker(self->ssl_contexts[0], 0, nullptr, &self->base, handshaker); } void tsi_ssl_server_handshaker_factory_unref( tsi_ssl_server_handshaker_factory* self) { - if (self == NULL) return; + if (self == nullptr) return; tsi_ssl_handshaker_factory_unref(&self->base); } static void tsi_ssl_server_handshaker_factory_destroy( tsi_ssl_handshaker_factory* factory) { - if (factory == NULL) return; + if (factory == nullptr) return; tsi_ssl_server_handshaker_factory* self = (tsi_ssl_server_handshaker_factory*)factory; size_t i; for (i = 0; i < self->ssl_context_count; i++) { - if (self->ssl_contexts[i] != NULL) { + if (self->ssl_contexts[i] != nullptr) { SSL_CTX_free(self->ssl_contexts[i]); tsi_peer_destruct(&self->ssl_context_x509_subject_names[i]); } } - if (self->ssl_contexts != NULL) gpr_free(self->ssl_contexts); - if (self->ssl_context_x509_subject_names != NULL) { + if (self->ssl_contexts != nullptr) gpr_free(self->ssl_contexts); + if (self->ssl_context_x509_subject_names != nullptr) { gpr_free(self->ssl_context_x509_subject_names); } - if (self->alpn_protocol_list != NULL) gpr_free(self->alpn_protocol_list); + if (self->alpn_protocol_list != nullptr) gpr_free(self->alpn_protocol_list); gpr_free(self); } static int does_entry_match_name(const char* entry, size_t entry_length, const char* name) { const char* dot; - const char* name_subdomain = NULL; + const char* name_subdomain = nullptr; size_t name_length = strlen(name); size_t name_subdomain_length; if (entry_length == 0) return 0; @@ -1277,7 +1277,7 @@ static int does_entry_match_name(const char* entry, size_t entry_length, return 0; } name_subdomain = strchr(name, '.'); - if (name_subdomain == NULL) return 0; + if (name_subdomain == nullptr) return 0; name_subdomain_length = strlen(name_subdomain); if (name_subdomain_length < 2) return 0; name_subdomain++; /* Starts after the dot. */ @@ -1285,7 +1285,7 @@ static int does_entry_match_name(const char* entry, size_t entry_length, entry += 2; /* Remove *. */ entry_length -= 2; dot = strchr(name_subdomain, '.'); - if ((dot == NULL) || (dot == &name_subdomain[name_subdomain_length - 1])) { + if ((dot == nullptr) || (dot == &name_subdomain[name_subdomain_length - 1])) { gpr_log(GPR_ERROR, "Invalid toplevel subdomain: %s", name_subdomain); return 0; } @@ -1302,7 +1302,7 @@ static int ssl_server_handshaker_factory_servername_callback(SSL* ssl, int* ap, (tsi_ssl_server_handshaker_factory*)arg; size_t i = 0; const char* servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); - if (servername == NULL || strlen(servername) == 0) { + if (servername == nullptr || strlen(servername) == 0) { return SSL_TLSEXT_ERR_NOACK; } @@ -1349,18 +1349,18 @@ tsi_result tsi_create_ssl_client_handshaker_factory( const char* pem_root_certs, const char* cipher_suites, const char** alpn_protocols, uint16_t num_alpn_protocols, tsi_ssl_client_handshaker_factory** factory) { - SSL_CTX* ssl_context = NULL; - tsi_ssl_client_handshaker_factory* impl = NULL; + SSL_CTX* ssl_context = nullptr; + tsi_ssl_client_handshaker_factory* impl = nullptr; tsi_result result = TSI_OK; gpr_once_init(&init_openssl_once, init_openssl); - if (factory == NULL) return TSI_INVALID_ARGUMENT; - *factory = NULL; - if (pem_root_certs == NULL) return TSI_INVALID_ARGUMENT; + if (factory == nullptr) return TSI_INVALID_ARGUMENT; + *factory = nullptr; + if (pem_root_certs == nullptr) return TSI_INVALID_ARGUMENT; ssl_context = SSL_CTX_new(TLSv1_2_method()); - if (ssl_context == NULL) { + if (ssl_context == nullptr) { gpr_log(GPR_ERROR, "Could not create ssl context."); return TSI_INVALID_ARGUMENT; } @@ -1376,7 +1376,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory( populate_ssl_context(ssl_context, pem_key_cert_pair, cipher_suites); if (result != TSI_OK) break; result = ssl_ctx_load_verification_certs(ssl_context, pem_root_certs, - strlen(pem_root_certs), NULL); + strlen(pem_root_certs), nullptr); if (result != TSI_OK) { gpr_log(GPR_ERROR, "Cannot load server root certificates."); break; @@ -1409,7 +1409,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory( tsi_ssl_handshaker_factory_unref(&impl->base); return result; } - SSL_CTX_set_verify(ssl_context, SSL_VERIFY_PEER, NULL); + SSL_CTX_set_verify(ssl_context, SSL_VERIFY_PEER, nullptr); /* TODO(jboeuf): Add revocation verification. */ *factory = impl; @@ -1438,15 +1438,15 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex( tsi_client_certificate_request_type client_certificate_request, const char* cipher_suites, const char** alpn_protocols, uint16_t num_alpn_protocols, tsi_ssl_server_handshaker_factory** factory) { - tsi_ssl_server_handshaker_factory* impl = NULL; + tsi_ssl_server_handshaker_factory* impl = nullptr; tsi_result result = TSI_OK; size_t i = 0; gpr_once_init(&init_openssl_once, init_openssl); - if (factory == NULL) return TSI_INVALID_ARGUMENT; - *factory = NULL; - if (num_key_cert_pairs == 0 || pem_key_cert_pairs == NULL) { + if (factory == nullptr) return TSI_INVALID_ARGUMENT; + *factory = nullptr; + if (num_key_cert_pairs == 0 || pem_key_cert_pairs == nullptr) { return TSI_INVALID_ARGUMENT; } @@ -1458,8 +1458,8 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex( (SSL_CTX**)gpr_zalloc(num_key_cert_pairs * sizeof(SSL_CTX*)); impl->ssl_context_x509_subject_names = (tsi_peer*)gpr_zalloc(num_key_cert_pairs * sizeof(tsi_peer)); - if (impl->ssl_contexts == NULL || - impl->ssl_context_x509_subject_names == NULL) { + if (impl->ssl_contexts == nullptr || + impl->ssl_context_x509_subject_names == nullptr) { tsi_ssl_handshaker_factory_unref(&impl->base); return TSI_OUT_OF_RESOURCES; } @@ -1478,7 +1478,7 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex( for (i = 0; i < num_key_cert_pairs; i++) { do { impl->ssl_contexts[i] = SSL_CTX_new(TLSv1_2_method()); - if (impl->ssl_contexts[i] == NULL) { + if (impl->ssl_contexts[i] == nullptr) { gpr_log(GPR_ERROR, "Could not create ssl context."); result = TSI_OUT_OF_RESOURCES; break; @@ -1487,8 +1487,8 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex( &pem_key_cert_pairs[i], cipher_suites); if (result != TSI_OK) break; - if (pem_client_root_certs != NULL) { - STACK_OF(X509_NAME)* root_names = NULL; + if (pem_client_root_certs != nullptr) { + STACK_OF(X509_NAME)* root_names = nullptr; result = ssl_ctx_load_verification_certs( impl->ssl_contexts[i], pem_client_root_certs, strlen(pem_client_root_certs), &root_names); @@ -1499,14 +1499,14 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex( SSL_CTX_set_client_CA_list(impl->ssl_contexts[i], root_names); switch (client_certificate_request) { case TSI_DONT_REQUEST_CLIENT_CERTIFICATE: - SSL_CTX_set_verify(impl->ssl_contexts[i], SSL_VERIFY_NONE, NULL); + SSL_CTX_set_verify(impl->ssl_contexts[i], SSL_VERIFY_NONE, nullptr); break; case TSI_REQUEST_CLIENT_CERTIFICATE_BUT_DONT_VERIFY: SSL_CTX_set_verify(impl->ssl_contexts[i], SSL_VERIFY_PEER, NullVerifyCallback); break; case TSI_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY: - SSL_CTX_set_verify(impl->ssl_contexts[i], SSL_VERIFY_PEER, NULL); + SSL_CTX_set_verify(impl->ssl_contexts[i], SSL_VERIFY_PEER, nullptr); break; case TSI_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_BUT_DONT_VERIFY: SSL_CTX_set_verify( @@ -1517,7 +1517,7 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex( case TSI_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY: SSL_CTX_set_verify( impl->ssl_contexts[i], - SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); + SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, nullptr); break; } /* TODO(jboeuf): Add revocation verification. */ @@ -1556,13 +1556,13 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex( int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name) { size_t i = 0; size_t san_count = 0; - const tsi_peer_property* cn_property = NULL; + const tsi_peer_property* cn_property = nullptr; int like_ip = looks_like_ip_address(name); /* Check the SAN first. */ for (i = 0; i < peer->property_count; i++) { const tsi_peer_property* property = &peer->properties[i]; - if (property->name == NULL) continue; + if (property->name == nullptr) continue; if (strcmp(property->name, TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY) == 0) { san_count++; @@ -1584,7 +1584,7 @@ int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name) { } /* If there's no SAN, try the CN, but only if its not like an IP Address */ - if (san_count == 0 && cn_property != NULL && !like_ip) { + if (san_count == 0 && cn_property != nullptr && !like_ip) { if (does_entry_match_name(cn_property->value.data, cn_property->value.length, name)) { return 1; @@ -1598,8 +1598,8 @@ int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name) { const tsi_ssl_handshaker_factory_vtable* tsi_ssl_handshaker_factory_swap_vtable( tsi_ssl_handshaker_factory* factory, tsi_ssl_handshaker_factory_vtable* new_vtable) { - GPR_ASSERT(factory != NULL); - GPR_ASSERT(factory->vtable != NULL); + GPR_ASSERT(factory != nullptr); + GPR_ASSERT(factory->vtable != nullptr); const tsi_ssl_handshaker_factory_vtable* orig_vtable = factory->vtable; factory->vtable = new_vtable; diff --git a/src/core/tsi/transport_security.cc b/src/core/tsi/transport_security.cc index 78e7be249c..9f66492536 100644 --- a/src/core/tsi/transport_security.cc +++ b/src/core/tsi/transport_security.cc @@ -74,12 +74,12 @@ tsi_result tsi_frame_protector_protect(tsi_frame_protector* self, size_t* unprotected_bytes_size, unsigned char* protected_output_frames, size_t* protected_output_frames_size) { - if (self == NULL || self->vtable == NULL || unprotected_bytes == NULL || - unprotected_bytes_size == NULL || protected_output_frames == NULL || - protected_output_frames_size == NULL) { + if (self == nullptr || self->vtable == nullptr || unprotected_bytes == nullptr || + unprotected_bytes_size == nullptr || protected_output_frames == nullptr || + protected_output_frames_size == nullptr) { return TSI_INVALID_ARGUMENT; } - if (self->vtable->protect == NULL) return TSI_UNIMPLEMENTED; + if (self->vtable->protect == nullptr) return TSI_UNIMPLEMENTED; return self->vtable->protect(self, unprotected_bytes, unprotected_bytes_size, protected_output_frames, protected_output_frames_size); @@ -88,11 +88,11 @@ tsi_result tsi_frame_protector_protect(tsi_frame_protector* self, tsi_result tsi_frame_protector_protect_flush( tsi_frame_protector* self, unsigned char* protected_output_frames, size_t* protected_output_frames_size, size_t* still_pending_size) { - if (self == NULL || self->vtable == NULL || protected_output_frames == NULL || - protected_output_frames_size == NULL || still_pending_size == NULL) { + if (self == nullptr || self->vtable == nullptr || protected_output_frames == nullptr || + protected_output_frames_size == nullptr || still_pending_size == nullptr) { return TSI_INVALID_ARGUMENT; } - if (self->vtable->protect_flush == NULL) return TSI_UNIMPLEMENTED; + if (self->vtable->protect_flush == nullptr) return TSI_UNIMPLEMENTED; return self->vtable->protect_flush(self, protected_output_frames, protected_output_frames_size, still_pending_size); @@ -102,19 +102,19 @@ tsi_result tsi_frame_protector_unprotect( tsi_frame_protector* self, const unsigned char* protected_frames_bytes, size_t* protected_frames_bytes_size, unsigned char* unprotected_bytes, size_t* unprotected_bytes_size) { - if (self == NULL || self->vtable == NULL || protected_frames_bytes == NULL || - protected_frames_bytes_size == NULL || unprotected_bytes == NULL || - unprotected_bytes_size == NULL) { + if (self == nullptr || self->vtable == nullptr || protected_frames_bytes == nullptr || + protected_frames_bytes_size == nullptr || unprotected_bytes == nullptr || + unprotected_bytes_size == nullptr) { return TSI_INVALID_ARGUMENT; } - if (self->vtable->unprotect == NULL) return TSI_UNIMPLEMENTED; + if (self->vtable->unprotect == nullptr) return TSI_UNIMPLEMENTED; return self->vtable->unprotect(self, protected_frames_bytes, protected_frames_bytes_size, unprotected_bytes, unprotected_bytes_size); } void tsi_frame_protector_destroy(tsi_frame_protector* self) { - if (self == NULL) return; + if (self == nullptr) return; self->vtable->destroy(self); } @@ -125,36 +125,36 @@ void tsi_frame_protector_destroy(tsi_frame_protector* self) { tsi_result tsi_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, unsigned char* bytes, size_t* bytes_size) { - if (self == NULL || self->vtable == NULL || bytes == NULL || - bytes_size == NULL) { + if (self == nullptr || self->vtable == nullptr || bytes == nullptr || + bytes_size == nullptr) { return TSI_INVALID_ARGUMENT; } if (self->frame_protector_created) return TSI_FAILED_PRECONDITION; - if (self->vtable->get_bytes_to_send_to_peer == NULL) return TSI_UNIMPLEMENTED; + if (self->vtable->get_bytes_to_send_to_peer == nullptr) return TSI_UNIMPLEMENTED; return self->vtable->get_bytes_to_send_to_peer(self, bytes, bytes_size); } tsi_result tsi_handshaker_process_bytes_from_peer(tsi_handshaker* self, const unsigned char* bytes, size_t* bytes_size) { - if (self == NULL || self->vtable == NULL || bytes == NULL || - bytes_size == NULL) { + if (self == nullptr || self->vtable == nullptr || bytes == nullptr || + bytes_size == nullptr) { return TSI_INVALID_ARGUMENT; } if (self->frame_protector_created) return TSI_FAILED_PRECONDITION; - if (self->vtable->process_bytes_from_peer == NULL) return TSI_UNIMPLEMENTED; + if (self->vtable->process_bytes_from_peer == nullptr) return TSI_UNIMPLEMENTED; return self->vtable->process_bytes_from_peer(self, bytes, bytes_size); } tsi_result tsi_handshaker_get_result(tsi_handshaker* self) { - if (self == NULL || self->vtable == NULL) return TSI_INVALID_ARGUMENT; + if (self == nullptr || self->vtable == nullptr) return TSI_INVALID_ARGUMENT; if (self->frame_protector_created) return TSI_FAILED_PRECONDITION; - if (self->vtable->get_result == NULL) return TSI_UNIMPLEMENTED; + if (self->vtable->get_result == nullptr) return TSI_UNIMPLEMENTED; return self->vtable->get_result(self); } tsi_result tsi_handshaker_extract_peer(tsi_handshaker* self, tsi_peer* peer) { - if (self == NULL || self->vtable == NULL || peer == NULL) { + if (self == nullptr || self->vtable == nullptr || peer == nullptr) { return TSI_INVALID_ARGUMENT; } memset(peer, 0, sizeof(tsi_peer)); @@ -162,7 +162,7 @@ tsi_result tsi_handshaker_extract_peer(tsi_handshaker* self, tsi_peer* peer) { if (tsi_handshaker_get_result(self) != TSI_OK) { return TSI_FAILED_PRECONDITION; } - if (self->vtable->extract_peer == NULL) return TSI_UNIMPLEMENTED; + if (self->vtable->extract_peer == nullptr) return TSI_UNIMPLEMENTED; return self->vtable->extract_peer(self, peer); } @@ -170,12 +170,12 @@ tsi_result tsi_handshaker_create_frame_protector( tsi_handshaker* self, size_t* max_protected_frame_size, tsi_frame_protector** protector) { tsi_result result; - if (self == NULL || self->vtable == NULL || protector == NULL) { + if (self == nullptr || self->vtable == nullptr || protector == nullptr) { return TSI_INVALID_ARGUMENT; } if (self->frame_protector_created) return TSI_FAILED_PRECONDITION; if (tsi_handshaker_get_result(self) != TSI_OK) return TSI_FAILED_PRECONDITION; - if (self->vtable->create_frame_protector == NULL) return TSI_UNIMPLEMENTED; + if (self->vtable->create_frame_protector == nullptr) return TSI_UNIMPLEMENTED; result = self->vtable->create_frame_protector(self, max_protected_frame_size, protector); if (result == TSI_OK) { @@ -189,16 +189,16 @@ tsi_result tsi_handshaker_next( size_t received_bytes_size, const unsigned char** bytes_to_send, size_t* bytes_to_send_size, tsi_handshaker_result** handshaker_result, tsi_handshaker_on_next_done_cb cb, void* user_data) { - if (self == NULL || self->vtable == NULL) return TSI_INVALID_ARGUMENT; + if (self == nullptr || self->vtable == nullptr) return TSI_INVALID_ARGUMENT; if (self->handshaker_result_created) return TSI_FAILED_PRECONDITION; - if (self->vtable->next == NULL) return TSI_UNIMPLEMENTED; + if (self->vtable->next == nullptr) return TSI_UNIMPLEMENTED; return self->vtable->next(self, received_bytes, received_bytes_size, bytes_to_send, bytes_to_send_size, handshaker_result, cb, user_data); } void tsi_handshaker_destroy(tsi_handshaker* self) { - if (self == NULL) return; + if (self == nullptr) return; self->vtable->destroy(self); } @@ -206,21 +206,21 @@ void tsi_handshaker_destroy(tsi_handshaker* self) { tsi_result tsi_handshaker_result_extract_peer(const tsi_handshaker_result* self, tsi_peer* peer) { - if (self == NULL || self->vtable == NULL || peer == NULL) { + if (self == nullptr || self->vtable == nullptr || peer == nullptr) { return TSI_INVALID_ARGUMENT; } memset(peer, 0, sizeof(tsi_peer)); - if (self->vtable->extract_peer == NULL) return TSI_UNIMPLEMENTED; + if (self->vtable->extract_peer == nullptr) return TSI_UNIMPLEMENTED; return self->vtable->extract_peer(self, peer); } tsi_result tsi_handshaker_result_create_frame_protector( const tsi_handshaker_result* self, size_t* max_protected_frame_size, tsi_frame_protector** protector) { - if (self == NULL || self->vtable == NULL || protector == NULL) { + if (self == nullptr || self->vtable == nullptr || protector == nullptr) { return TSI_INVALID_ARGUMENT; } - if (self->vtable->create_frame_protector == NULL) return TSI_UNIMPLEMENTED; + if (self->vtable->create_frame_protector == nullptr) return TSI_UNIMPLEMENTED; return self->vtable->create_frame_protector(self, max_protected_frame_size, protector); } @@ -228,16 +228,16 @@ tsi_result tsi_handshaker_result_create_frame_protector( tsi_result tsi_handshaker_result_get_unused_bytes( const tsi_handshaker_result* self, const unsigned char** bytes, size_t* bytes_size) { - if (self == NULL || self->vtable == NULL || bytes == NULL || - bytes_size == NULL) { + if (self == nullptr || self->vtable == nullptr || bytes == nullptr || + bytes_size == nullptr) { return TSI_INVALID_ARGUMENT; } - if (self->vtable->get_unused_bytes == NULL) return TSI_UNIMPLEMENTED; + if (self->vtable->get_unused_bytes == nullptr) return TSI_UNIMPLEMENTED; return self->vtable->get_unused_bytes(self, bytes, bytes_size); } void tsi_handshaker_result_destroy(tsi_handshaker_result* self) { - if (self == NULL) return; + if (self == nullptr) return; self->vtable->destroy(self); } @@ -259,20 +259,20 @@ static void tsi_peer_destroy_list_property(tsi_peer_property* children, } void tsi_peer_property_destruct(tsi_peer_property* property) { - if (property->name != NULL) { + if (property->name != nullptr) { gpr_free(property->name); } - if (property->value.data != NULL) { + if (property->value.data != nullptr) { gpr_free(property->value.data); } *property = tsi_init_peer_property(); /* Reset everything to 0. */ } void tsi_peer_destruct(tsi_peer* self) { - if (self == NULL) return; - if (self->properties != NULL) { + if (self == nullptr) return; + if (self->properties != nullptr) { tsi_peer_destroy_list_property(self->properties, self->property_count); - self->properties = NULL; + self->properties = nullptr; } self->property_count = 0; } @@ -280,7 +280,7 @@ void tsi_peer_destruct(tsi_peer* self) { tsi_result tsi_construct_allocated_string_peer_property( const char* name, size_t value_length, tsi_peer_property* property) { *property = tsi_init_peer_property(); - if (name != NULL) property->name = gpr_strdup(name); + if (name != nullptr) property->name = gpr_strdup(name); if (value_length > 0) { property->value.data = (char*)gpr_zalloc(value_length); property->value.length = value_length; diff --git a/src/core/tsi/transport_security_adapter.cc b/src/core/tsi/transport_security_adapter.cc index ec4e7d8cef..137bf6bfdd 100644 --- a/src/core/tsi/transport_security_adapter.cc +++ b/src/core/tsi/transport_security_adapter.cc @@ -67,7 +67,7 @@ static void adapter_result_destroy(tsi_handshaker_result* self) { static const tsi_handshaker_result_vtable result_vtable = { adapter_result_extract_peer, - NULL, /* create_zero_copy_grpc_protector */ + nullptr, /* create_zero_copy_grpc_protector */ adapter_result_create_frame_protector, adapter_result_get_unused_bytes, adapter_result_destroy, @@ -77,7 +77,7 @@ static const tsi_handshaker_result_vtable result_vtable = { static tsi_result tsi_adapter_create_handshaker_result( tsi_handshaker* wrapped, const unsigned char* unused_bytes, size_t unused_bytes_size, tsi_handshaker_result** handshaker_result) { - if (wrapped == NULL || (unused_bytes_size > 0 && unused_bytes == NULL)) { + if (wrapped == nullptr || (unused_bytes_size > 0 && unused_bytes == nullptr)) { return TSI_INVALID_ARGUMENT; } tsi_adapter_handshaker_result* impl = @@ -89,7 +89,7 @@ static tsi_result tsi_adapter_create_handshaker_result( impl->unused_bytes = (unsigned char*)gpr_malloc(unused_bytes_size); memcpy(impl->unused_bytes, unused_bytes, unused_bytes_size); } else { - impl->unused_bytes = NULL; + impl->unused_bytes = nullptr; } *handshaker_result = &impl->base; return TSI_OK; @@ -148,9 +148,9 @@ static tsi_result adapter_next( size_t* bytes_to_send_size, tsi_handshaker_result** handshaker_result, tsi_handshaker_on_next_done_cb cb, void* user_data) { /* Input sanity check. */ - if ((received_bytes_size > 0 && received_bytes == NULL) || - bytes_to_send == NULL || bytes_to_send_size == NULL || - handshaker_result == NULL) { + if ((received_bytes_size > 0 && received_bytes == nullptr) || + bytes_to_send == nullptr || bytes_to_send_size == nullptr || + handshaker_result == nullptr) { return TSI_INVALID_ARGUMENT; } @@ -183,16 +183,16 @@ static tsi_result adapter_next( /* If handshake completes, create tsi_handshaker_result. */ if (tsi_handshaker_is_in_progress(impl->wrapped)) { - *handshaker_result = NULL; + *handshaker_result = nullptr; } else { size_t unused_bytes_size = received_bytes_size - bytes_consumed; const unsigned char* unused_bytes = - unused_bytes_size == 0 ? NULL : received_bytes + bytes_consumed; + unused_bytes_size == 0 ? nullptr : received_bytes + bytes_consumed; status = tsi_adapter_create_handshaker_result( impl->wrapped, unused_bytes, unused_bytes_size, handshaker_result); if (status == TSI_OK) { impl->base.handshaker_result_created = true; - impl->wrapped = NULL; + impl->wrapped = nullptr; } } return status; @@ -209,7 +209,7 @@ static const tsi_handshaker_vtable handshaker_vtable = { }; tsi_handshaker* tsi_create_adapter_handshaker(tsi_handshaker* wrapped) { - GPR_ASSERT(wrapped != NULL); + GPR_ASSERT(wrapped != nullptr); tsi_adapter_handshaker* impl = (tsi_adapter_handshaker*)gpr_zalloc(sizeof(*impl)); impl->base.vtable = &handshaker_vtable; @@ -220,7 +220,7 @@ tsi_handshaker* tsi_create_adapter_handshaker(tsi_handshaker* wrapped) { } tsi_handshaker* tsi_adapter_handshaker_get_wrapped(tsi_handshaker* adapter) { - if (adapter == NULL) return NULL; + if (adapter == nullptr) return nullptr; tsi_adapter_handshaker* impl = (tsi_adapter_handshaker*)adapter; return impl->wrapped; } diff --git a/src/core/tsi/transport_security_grpc.cc b/src/core/tsi/transport_security_grpc.cc index 3c986475c4..875d367218 100644 --- a/src/core/tsi/transport_security_grpc.cc +++ b/src/core/tsi/transport_security_grpc.cc @@ -23,11 +23,11 @@ tsi_result tsi_handshaker_result_create_zero_copy_grpc_protector( grpc_exec_ctx* exec_ctx, const tsi_handshaker_result* self, size_t* max_output_protected_frame_size, tsi_zero_copy_grpc_protector** protector) { - if (exec_ctx == NULL || self == NULL || self->vtable == NULL || - protector == NULL) { + if (exec_ctx == nullptr || self == nullptr || self->vtable == nullptr || + protector == nullptr) { return TSI_INVALID_ARGUMENT; } - if (self->vtable->create_zero_copy_grpc_protector == NULL) { + if (self->vtable->create_zero_copy_grpc_protector == nullptr) { return TSI_UNIMPLEMENTED; } return self->vtable->create_zero_copy_grpc_protector( @@ -42,11 +42,11 @@ tsi_result tsi_zero_copy_grpc_protector_protect( grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* unprotected_slices, grpc_slice_buffer* protected_slices) { - if (exec_ctx == NULL || self == NULL || self->vtable == NULL || - unprotected_slices == NULL || protected_slices == NULL) { + if (exec_ctx == nullptr || self == nullptr || self->vtable == nullptr || + unprotected_slices == nullptr || protected_slices == nullptr) { return TSI_INVALID_ARGUMENT; } - if (self->vtable->protect == NULL) return TSI_UNIMPLEMENTED; + if (self->vtable->protect == nullptr) return TSI_UNIMPLEMENTED; return self->vtable->protect(exec_ctx, self, unprotected_slices, protected_slices); } @@ -55,17 +55,17 @@ tsi_result tsi_zero_copy_grpc_protector_unprotect( grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self, grpc_slice_buffer* protected_slices, grpc_slice_buffer* unprotected_slices) { - if (exec_ctx == NULL || self == NULL || self->vtable == NULL || - protected_slices == NULL || unprotected_slices == NULL) { + if (exec_ctx == nullptr || self == nullptr || self->vtable == nullptr || + protected_slices == nullptr || unprotected_slices == nullptr) { return TSI_INVALID_ARGUMENT; } - if (self->vtable->unprotect == NULL) return TSI_UNIMPLEMENTED; + if (self->vtable->unprotect == nullptr) return TSI_UNIMPLEMENTED; return self->vtable->unprotect(exec_ctx, self, protected_slices, unprotected_slices); } void tsi_zero_copy_grpc_protector_destroy(grpc_exec_ctx* exec_ctx, tsi_zero_copy_grpc_protector* self) { - if (self == NULL) return; + if (self == nullptr) return; self->vtable->destroy(exec_ctx, self); } |