aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib')
-rw-r--r--src/core/lib/channel/channel_args.cc32
-rw-r--r--src/core/lib/channel/channel_stack.cc2
-rw-r--r--src/core/lib/channel/channel_stack_builder.cc22
-rw-r--r--src/core/lib/channel/connected_channel.cc10
-rw-r--r--src/core/lib/channel/handshaker.cc10
-rw-r--r--src/core/lib/channel/handshaker_factory.cc8
-rw-r--r--src/core/lib/compression/stream_compression.cc2
-rw-r--r--src/core/lib/compression/stream_compression_gzip.cc14
-rw-r--r--src/core/lib/compression/stream_compression_identity.cc4
-rw-r--r--src/core/lib/debug/stats.cc4
-rw-r--r--src/core/lib/debug/trace.cc8
-rw-r--r--src/core/lib/http/httpcli.cc12
-rw-r--r--src/core/lib/http/httpcli_security_connector.cc32
-rw-r--r--src/core/lib/http/parser.cc12
-rw-r--r--src/core/lib/iomgr/call_combiner.cc2
-rw-r--r--src/core/lib/iomgr/closure.cc28
-rw-r--r--src/core/lib/iomgr/combiner.cc18
-rw-r--r--src/core/lib/iomgr/error.cc18
-rw-r--r--src/core/lib/iomgr/error.h9
-rw-r--r--src/core/lib/iomgr/error_internal.h3
-rw-r--r--src/core/lib/iomgr/ev_epoll1_linux.cc64
-rw-r--r--src/core/lib/iomgr/ev_epollex_linux.cc98
-rw-r--r--src/core/lib/iomgr/ev_epollsig_linux.cc120
-rw-r--r--src/core/lib/iomgr/ev_poll_posix.cc114
-rw-r--r--src/core/lib/iomgr/ev_posix.cc14
-rw-r--r--src/core/lib/iomgr/exec_ctx.cc8
-rw-r--r--src/core/lib/iomgr/executor.cc6
-rw-r--r--src/core/lib/iomgr/gethostname_host_name_max.cc2
-rw-r--r--src/core/lib/iomgr/iocp_windows.h6
-rw-r--r--src/core/lib/iomgr/iomgr.cc2
-rw-r--r--src/core/lib/iomgr/is_epollexclusive_available.cc2
-rw-r--r--src/core/lib/iomgr/load_file.cc6
-rw-r--r--src/core/lib/iomgr/polling_entity.cc12
-rw-r--r--src/core/lib/iomgr/pollset_windows.h5
-rw-r--r--src/core/lib/iomgr/resolve_address_posix.cc14
-rw-r--r--src/core/lib/iomgr/resource_quota.cc56
-rw-r--r--src/core/lib/iomgr/sockaddr_utils.cc26
-rw-r--r--src/core/lib/iomgr/sockaddr_windows.h6
-rw-r--r--src/core/lib/iomgr/socket_utils_common_posix.cc8
-rw-r--r--src/core/lib/iomgr/socket_windows.h5
-rw-r--r--src/core/lib/iomgr/tcp_client_posix.cc20
-rw-r--r--src/core/lib/iomgr/tcp_posix.cc39
-rw-r--r--src/core/lib/iomgr/tcp_server_posix.cc34
-rw-r--r--src/core/lib/iomgr/tcp_server_utils_posix_common.cc10
-rw-r--r--src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc24
-rw-r--r--src/core/lib/iomgr/tcp_uv.h6
-rw-r--r--src/core/lib/iomgr/tcp_windows.h5
-rw-r--r--src/core/lib/iomgr/timer_generic.cc30
-rw-r--r--src/core/lib/iomgr/timer_manager.cc10
-rw-r--r--src/core/lib/iomgr/udp_server.cc21
-rw-r--r--src/core/lib/iomgr/unix_sockets_posix.cc7
-rw-r--r--src/core/lib/iomgr/wakeup_fd_cv.cc4
-rw-r--r--src/core/lib/iomgr/wakeup_fd_posix.cc4
-rw-r--r--src/core/lib/json/json_string.cc14
-rw-r--r--src/core/lib/security/context/security_context.cc50
-rw-r--r--src/core/lib/security/credentials/composite/composite_credentials.cc26
-rw-r--r--src/core/lib/security/credentials/credentials.cc65
-rw-r--r--src/core/lib/security/credentials/fake/fake_credentials.cc8
-rw-r--r--src/core/lib/security/credentials/google_default/credentials_generic.cc6
-rw-r--r--src/core/lib/security/credentials/google_default/google_default_credentials.cc58
-rw-r--r--src/core/lib/security/credentials/iam/iam_credentials.cc6
-rw-r--r--src/core/lib/security/credentials/jwt/json_token.cc88
-rw-r--r--src/core/lib/security/credentials/jwt/jwt_credentials.cc16
-rw-r--r--src/core/lib/security/credentials/jwt/jwt_verifier.cc259
-rw-r--r--src/core/lib/security/credentials/oauth2/oauth2_credentials.cc76
-rw-r--r--src/core/lib/security/credentials/plugin/plugin_credentials.cc18
-rw-r--r--src/core/lib/security/credentials/ssl/ssl_credentials.cc64
-rw-r--r--src/core/lib/security/transport/client_auth_filter.cc48
-rw-r--r--src/core/lib/security/transport/lb_targets_info.cc4
-rw-r--r--src/core/lib/security/transport/secure_endpoint.cc8
-rw-r--r--src/core/lib/security/transport/security_connector.cc179
-rw-r--r--src/core/lib/security/transport/security_handshaker.cc42
-rw-r--r--src/core/lib/security/transport/server_auth_filter.cc16
-rw-r--r--src/core/lib/security/util/json_util.cc8
-rw-r--r--src/core/lib/slice/slice.cc24
-rw-r--r--src/core/lib/slice/slice_buffer.cc4
-rw-r--r--src/core/lib/slice/slice_hash_table.cc14
-rw-r--r--src/core/lib/slice/slice_intern.cc4
-rw-r--r--src/core/lib/support/alloc.cc14
-rw-r--r--src/core/lib/support/arena.cc2
-rw-r--r--src/core/lib/support/avl.cc40
-rw-r--r--src/core/lib/support/cmdline.cc20
-rw-r--r--src/core/lib/support/env_linux.cc10
-rw-r--r--src/core/lib/support/host_port.cc18
-rw-r--r--src/core/lib/support/log.cc6
-rw-r--r--src/core/lib/support/log_linux.cc4
-rw-r--r--src/core/lib/support/memory.h2
-rw-r--r--src/core/lib/support/mpscq.cc16
-rw-r--r--src/core/lib/support/string.cc14
-rw-r--r--src/core/lib/support/string_posix.cc6
-rw-r--r--src/core/lib/support/subprocess_posix.cc6
-rw-r--r--src/core/lib/support/sync.cc6
-rw-r--r--src/core/lib/support/sync_posix.cc8
-rw-r--r--src/core/lib/support/thd_posix.cc6
-rw-r--r--src/core/lib/support/time_posix.cc2
-rw-r--r--src/core/lib/support/tmpfile_posix.cc10
-rw-r--r--src/core/lib/surface/alarm.cc4
-rw-r--r--src/core/lib/surface/byte_buffer.cc2
-rw-r--r--src/core/lib/surface/call.cc136
-rw-r--r--src/core/lib/surface/call_log_batch.cc6
-rw-r--r--src/core/lib/surface/channel.cc32
-rw-r--r--src/core/lib/surface/channel_init.cc2
-rw-r--r--src/core/lib/surface/channel_ping.cc4
-rw-r--r--src/core/lib/surface/completion_queue.cc68
-rw-r--r--src/core/lib/surface/completion_queue_factory.cc2
-rw-r--r--src/core/lib/surface/event_string.cc4
-rw-r--r--src/core/lib/surface/init.cc16
-rw-r--r--src/core/lib/surface/init_secure.cc10
-rw-r--r--src/core/lib/surface/lame_client.cc10
-rw-r--r--src/core/lib/surface/server.cc72
-rw-r--r--src/core/lib/transport/connectivity_state.cc18
-rw-r--r--src/core/lib/transport/error_utils.cc20
-rw-r--r--src/core/lib/transport/metadata.cc20
-rw-r--r--src/core/lib/transport/metadata_batch.cc39
-rw-r--r--src/core/lib/transport/service_config.cc92
-rw-r--r--src/core/lib/transport/transport.cc5
-rw-r--r--src/core/lib/transport/transport_op_string.cc18
117 files changed, 1487 insertions, 1426 deletions
diff --git a/src/core/lib/channel/channel_args.cc b/src/core/lib/channel/channel_args.cc
index de4c2ac325..453e8cf6ed 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)) {
@@ -238,7 +238,7 @@ grpc_channel_args* grpc_channel_args_set_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 &&
@@ -256,14 +256,14 @@ static int find_compression_algorithm_states_bitset(const grpc_channel_args* a,
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 "
@@ -323,19 +323,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;
@@ -354,7 +354,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..73b484b06d 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);
@@ -136,8 +136,8 @@ static void on_read(grpc_exec_ctx* exec_ctx, void* user_data,
for (i = 0; i < req->incoming.count; i++) {
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_error* err = 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..581b903f1a 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,8 +767,8 @@ 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,
- 0),
+ grpc_slice_from_static_string("OS Error"),
+ nullptr, 0),
GRPC_ERROR_INT_ERRNO, err),
GRPC_ERROR_STR_OS_ERROR,
grpc_slice_from_static_string(strerror(err))),
diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h
index 36ba440c8a..8d7aea4872 100644
--- a/src/core/lib/iomgr/error.h
+++ b/src/core/lib/iomgr/error.h
@@ -24,6 +24,7 @@
#include <grpc/slice.h>
#include <grpc/status.h>
+#include <grpc/support/log.h>
#include <grpc/support/time.h>
#include "src/core/lib/debug/trace.h"
@@ -184,9 +185,15 @@ grpc_error* grpc_error_add_child(grpc_error* src,
grpc_error* child) GRPC_MUST_USE_RESULT;
grpc_error* grpc_os_error(const char* file, int line, int err,
const char* call_name) GRPC_MUST_USE_RESULT;
+
+inline grpc_error* grpc_assert_never_ok(grpc_error* error) {
+ GPR_ASSERT(error != GRPC_ERROR_NONE);
+ return error;
+}
+
/// create an error associated with errno!=0 (an 'operating system' error)
#define GRPC_OS_ERROR(err, call_name) \
- grpc_os_error(__FILE__, __LINE__, err, call_name)
+ grpc_assert_never_ok(grpc_os_error(__FILE__, __LINE__, err, call_name))
grpc_error* grpc_wsa_error(const char* file, int line, int err,
const char* call_name) GRPC_MUST_USE_RESULT;
/// windows only: create an error associated with WSAGetLastError()!=0
diff --git a/src/core/lib/iomgr/error_internal.h b/src/core/lib/iomgr/error_internal.h
index acf6e04e9c..d5ccbae9e7 100644
--- a/src/core/lib/iomgr/error_internal.h
+++ b/src/core/lib/iomgr/error_internal.h
@@ -23,6 +23,7 @@
#include <stdbool.h> // TODO, do we need this?
#include <grpc/support/sync.h>
+#include "src/core/lib/iomgr/error.h"
#ifdef __cplusplus
extern "C" {
@@ -59,7 +60,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 423e8d059f..27c769a7ed 100644
--- a/src/core/lib/iomgr/exec_ctx.cc
+++ b/src/core/lib/iomgr/exec_ctx.cc
@@ -50,7 +50,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);
}
@@ -85,8 +85,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;
@@ -97,7 +97,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/iocp_windows.h b/src/core/lib/iomgr/iocp_windows.h
index ff9b31efe2..d112c50538 100644
--- a/src/core/lib/iomgr/iocp_windows.h
+++ b/src/core/lib/iomgr/iocp_windows.h
@@ -21,6 +21,10 @@
#include <grpc/support/sync.h>
+#include "src/core/lib/iomgr/port.h"
+
+#ifdef GRPC_WINSOCK_SOCKET
+
#include "src/core/lib/iomgr/socket_windows.h"
#ifdef __cplusplus
@@ -45,4 +49,6 @@ void grpc_iocp_add_socket(grpc_winsocket*);
}
#endif
+#endif
+
#endif /* GRPC_CORE_LIB_IOMGR_IOCP_WINDOWS_H */
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/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/pollset_windows.h b/src/core/lib/iomgr/pollset_windows.h
index aaeb5f585f..f6da9da601 100644
--- a/src/core/lib/iomgr/pollset_windows.h
+++ b/src/core/lib/iomgr/pollset_windows.h
@@ -21,6 +21,9 @@
#include <grpc/support/sync.h>
+#include "src/core/lib/iomgr/port.h"
+
+#ifdef GRPC_WINSOCK_SOCKET
#include "src/core/lib/iomgr/socket_windows.h"
#ifdef __cplusplus
@@ -68,4 +71,6 @@ void grpc_pollset_global_shutdown(void);
}
#endif
+#endif
+
#endif /* GRPC_CORE_LIB_IOMGR_POLLSET_WINDOWS_H */
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..3477fb52cd 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/sockaddr_windows.h b/src/core/lib/iomgr/sockaddr_windows.h
index cf0f6b914d..20e37c9fc4 100644
--- a/src/core/lib/iomgr/sockaddr_windows.h
+++ b/src/core/lib/iomgr/sockaddr_windows.h
@@ -19,10 +19,16 @@
#ifndef GRPC_CORE_LIB_IOMGR_SOCKADDR_WINDOWS_H
#define GRPC_CORE_LIB_IOMGR_SOCKADDR_WINDOWS_H
+#include "src/core/lib/iomgr/port.h"
+
+#ifdef GRPC_WINSOCK_SOCKET
+
#include <winsock2.h>
#include <ws2tcpip.h>
// must be included after the above
#include <mswsock.h>
+#endif
+
#endif /* GRPC_CORE_LIB_IOMGR_SOCKADDR_WINDOWS_H */
diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc
index 88b757a4ae..2d4b8f0add 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,
- protocol, dsmode, newfd);
+ 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/socket_windows.h b/src/core/lib/iomgr/socket_windows.h
index 6f6c7a7024..c3ad99d82f 100644
--- a/src/core/lib/iomgr/socket_windows.h
+++ b/src/core/lib/iomgr/socket_windows.h
@@ -20,6 +20,9 @@
#define GRPC_CORE_LIB_IOMGR_SOCKET_WINDOWS_H
#include <grpc/support/port_platform.h>
+#include "src/core/lib/iomgr/port.h"
+
+#ifdef GRPC_WINSOCK_SOCKET
#include <winsock2.h>
#include <grpc/support/atm.h>
@@ -115,4 +118,6 @@ void grpc_socket_become_ready(grpc_exec_ctx* exec_ctx,
}
#endif
+#endif
+
#endif /* GRPC_CORE_LIB_IOMGR_SOCKET_WINDOWS_H */
diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc
index e72d70c027..cb0f627c94 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,8 +296,8 @@ 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 */,
- "tcp_client_connect_error");
+ 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..cb90933e31 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,8 @@ 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 +369,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 +390,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 +505,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 +553,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 +618,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 +631,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 +659,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 +746,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 +786,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/tcp_uv.h b/src/core/lib/iomgr/tcp_uv.h
index 8a4914935a..708e8469e6 100644
--- a/src/core/lib/iomgr/tcp_uv.h
+++ b/src/core/lib/iomgr/tcp_uv.h
@@ -32,6 +32,10 @@
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/iomgr/endpoint.h"
+#include "src/core/lib/iomgr/port.h"
+
+#ifdef GRPC_UV
+
#include <uv.h>
extern grpc_tracer_flag grpc_tcp_trace;
@@ -50,4 +54,6 @@ grpc_endpoint* grpc_tcp_create(uv_tcp_t* handle,
}
#endif
+#endif /* GRPC_UV */
+
#endif /* GRPC_CORE_LIB_IOMGR_TCP_UV_H */
diff --git a/src/core/lib/iomgr/tcp_windows.h b/src/core/lib/iomgr/tcp_windows.h
index aea5bab47d..9c7ccdf132 100644
--- a/src/core/lib/iomgr/tcp_windows.h
+++ b/src/core/lib/iomgr/tcp_windows.h
@@ -29,6 +29,9 @@
otherwise specified.
*/
+#include "src/core/lib/iomgr/port.h"
+
+#ifdef GRPC_WINSOCK_SOCKET
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/socket_windows.h"
@@ -49,4 +52,6 @@ grpc_error* grpc_tcp_prepare_socket(SOCKET sock);
}
#endif
+#endif
+
#endif /* GRPC_CORE_LIB_IOMGR_TCP_WINDOWS_H */
diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc
index 38ac66ea2f..a4bfbcb342 100644
--- a/src/core/lib/iomgr/timer_generic.cc
+++ b/src/core/lib/iomgr/timer_generic.cc
@@ -91,7 +91,7 @@ static timer_shard** g_shard_queue;
#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++) {
@@ -104,7 +104,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]);
@@ -118,7 +118,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;
}
@@ -146,9 +146,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;
}
@@ -169,7 +169,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
@@ -275,7 +275,7 @@ void grpc_timer_list_init(grpc_exec_ctx* exec_ctx) {
void grpc_timer_list_shutdown(grpc_exec_ctx* exec_ctx) {
size_t 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 < g_num_shards; i++) {
timer_shard* shard = &g_shards[i];
@@ -336,7 +336,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)) {
@@ -499,8 +499,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)) {
@@ -508,7 +508,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,
@@ -550,7 +550,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;
}
@@ -618,7 +618,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)) {
@@ -637,7 +637,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);
@@ -655,7 +655,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 bb2a0e0d44..acc40b6c9e 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);
@@ -280,7 +280,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);
@@ -304,7 +304,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..68ab9355ca 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;
@@ -508,6 +508,7 @@ int grpc_udp_server_get_fd(grpc_udp_server* s, unsigned port_index) {
for (sp = s->head; sp && port_index != 0; sp = sp->next) {
--port_index;
}
+ GPR_ASSERT(sp); // if this fails, our check earlier was bogus
return sp->fd;
}
@@ -522,7 +523,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..af862c00dc 100644
--- a/src/core/lib/iomgr/unix_sockets_posix.cc
+++ b/src/core/lib/iomgr/unix_sockets_posix.cc
@@ -39,7 +39,8 @@ 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,
@@ -56,7 +57,7 @@ grpc_error* grpc_resolve_unix_domain_address(const char* name,
(grpc_resolved_address*)gpr_malloc(sizeof(grpc_resolved_address));
un = (struct sockaddr_un*)(*addrs)->addrs->addr;
un->sun_family = AF_UNIX;
- strcpy(un->sun_path, name);
+ strncpy(un->sun_path, name, sizeof(un->sun_path));
(*addrs)->addrs->len = strlen(un->sun_path) + sizeof(un->sun_family) + 1;
return GRPC_ERROR_NONE;
}
@@ -84,7 +85,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..93dd721240 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,15 @@ 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 +254,8 @@ 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..90576e69b9 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,8 @@ 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 +128,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 +172,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 +184,31 @@ 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 +225,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 +239,9 @@ 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 +270,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 +282,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..f586c7b604 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;
@@ -80,8 +80,8 @@ static void on_compute_engine_detection_http_response(grpc_exec_ctx* exec_ctx,
detector->is_done = 1;
GRPC_LOG_IF_ERROR(
"Pollset kick",
- grpc_pollset_kick(exec_ctx,
- grpc_polling_entity_pollset(&detector->pollent), NULL));
+ grpc_pollset_kick(
+ exec_ctx, 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..a152ddcaaf 100644
--- a/src/core/lib/security/credentials/jwt/json_token.cc
+++ b/src/core/lib/security/credentials/jwt/json_token.cc
@@ -52,30 +52,31 @@ 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 +91,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 +100,16 @@ 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 +119,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 +161,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 +180,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];
@@ -192,9 +194,9 @@ static char* encoded_jwt_claim(const grpc_auth_json_key* json_key,
int64_ttoa(now.tv_sec, now_str);
int64_ttoa(expiration.tv_sec, expiration_str);
- child =
- create_child(NULL, json, "iss", json_key->client_email, GRPC_JSON_STRING);
- if (scope != NULL) {
+ child = 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 +239,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 +247,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 +267,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 +279,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 +297,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..3709b83c4e 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,30 @@ 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 +589,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 +597,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 +606,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 +636,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 +663,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 +681,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 +700,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 +721,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 +758,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 +776,22 @@ 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 +802,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 +824,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 +851,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 +861,34 @@ 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 +901,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 +920,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 +932,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..326f4d7773 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,15 +139,15 @@ 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,
- host_and_port, service);
+ 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;
auth_md_context->channel_auth_context =
@@ -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..b996cc8cdb 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,11 +596,11 @@ 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->target_name,
+ c->overridden_target_name != nullptr ? c->overridden_target_name
+ : c->target_name,
&tsi_hs);
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "Handshaker creation failed with error %s.",
@@ -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,8 @@ 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 +942,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 +950,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 +987,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 +1005,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 +1033,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 +1082,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 +1116,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..e8949135c0 100644
--- a/src/core/lib/slice/slice_intern.cc
+++ b/src/core/lib/slice/slice_intern.cc
@@ -171,8 +171,8 @@ 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)
- : s.refcount->vtable->hash(s);
+ return s.refcount == nullptr ? grpc_slice_default_hash_impl(s)
+ : s.refcount->vtable->hash(s);
}
grpc_slice grpc_slice_maybe_static_intern(grpc_slice slice,
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/avl.cc b/src/core/lib/support/avl.cc
index 4ba101b74a..0b67a21f2f 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
- : 1 + GPR_MAX(calculate_height(node->left),
- calculate_height(node->right));
+ 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/memory.h b/src/core/lib/support/memory.h
index 6b336681db..695418e3e1 100644
--- a/src/core/lib/support/memory.h
+++ b/src/core/lib/support/memory.h
@@ -76,7 +76,7 @@ class Allocator {
pointer address(reference x) const { return &x; }
const_pointer address(const_reference x) const { return &x; }
pointer allocate(std::size_t n,
- std::allocator<void>::const_pointer hint = 0) {
+ std::allocator<void>::const_pointer hint = nullptr) {
return static_cast<pointer>(gpr_malloc(n * sizeof(T)));
}
void deallocate(T* p, std::size_t n) { gpr_free(p); }
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..dfdd233bf4 100644
--- a/src/core/lib/support/sync_posix.cc
+++ b/src/core/lib/support/sync_posix.cc
@@ -33,7 +33,9 @@ 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 +65,9 @@ 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 e6597efa37..2ab7399e66 100644
--- a/src/core/lib/surface/call.cc
+++ b/src/core/lib/surface/call.cc
@@ -308,10 +308,10 @@ 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)) {
+ if (!gpr_atm_rel_cas(&call->parent_call_atm, (gpr_atm)nullptr, (gpr_atm)p)) {
gpr_mu_destroy(&p->child_list_mu);
p = (parent_call*)gpr_atm_acq_load(&call->parent_call_atm);
}
@@ -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_MESSAGE_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 &&
- "Only one of 'cq' and 'pollset_set_alternative' should be non-NULL.");
+ args->pollset_set_alternative == nullptr &&
+ "Only one of 'cq' and 'pollset_set_alternative' should be non-nullptr.");
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;
@@ -866,7 +866,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) {
*encodings_accepted_by_peer =
(uint32_t)(((uintptr_t)accepted_user_data) - 1);
return;
@@ -1006,7 +1006,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)) {
@@ -1063,7 +1063,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);
@@ -1074,14 +1074,14 @@ 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.content_encoding != nullptr) {
GPR_TIMER_BEGIN("incoming_stream_compression_algorithm", 0);
set_incoming_stream_compression_algorithm(
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);
}
- if (b->idx.named.grpc_encoding != NULL) {
+ if (b->idx.named.grpc_encoding != nullptr) {
GPR_TIMER_BEGIN("incoming_message_compression_algorithm", 0);
set_incoming_message_compression_algorithm(
call, decode_message_compression(b->idx.named.grpc_encoding->md));
@@ -1090,7 +1090,7 @@ static void recv_initial_filter(grpc_exec_ctx* exec_ctx, grpc_call* call,
}
uint32_t message_encodings_accepted_by_peer = 1u;
uint32_t stream_encodings_accepted_by_peer = 1u;
- 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,
@@ -1098,7 +1098,7 @@ static void recv_initial_filter(grpc_exec_ctx* exec_ctx, grpc_call* call,
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_encodings_accepted_by_peer(exec_ctx, call,
b->idx.named.accept_encoding->md,
@@ -1116,7 +1116,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
@@ -1125,7 +1125,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)));
@@ -1198,13 +1198,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;
@@ -1216,7 +1216,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");
}
@@ -1228,14 +1228,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;
}
@@ -1268,11 +1268,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) {
@@ -1293,21 +1293,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");
@@ -1335,7 +1335,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;
}
@@ -1348,9 +1348,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;
@@ -1387,9 +1387,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) {
@@ -1401,8 +1401,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 {
@@ -1416,9 +1416,9 @@ static void process_data_after_md(grpc_exec_ctx* exec_ctx,
&algo, call->incoming_message_compression_algorithm,
(grpc_stream_compression_algorithm)0));
*call->receiving_buffer =
- grpc_raw_compressed_byte_buffer_create(NULL, 0, algo);
+ grpc_raw_compressed_byte_buffer_create(nullptr, 0, algo);
} 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);
@@ -1431,9 +1431,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,
@@ -1442,7 +1442,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);
}
@@ -1468,7 +1468,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx,
GRPC_STREAM_COMPRESS_NONE &&
call->incoming_message_compression_algorithm !=
GRPC_MESSAGE_COMPRESS_NONE) {
- char* error_msg = NULL;
+ char* error_msg = nullptr;
gpr_asprintf(&error_msg,
"Incoming stream has both stream compression (%d) and message "
"compression (%d).",
@@ -1482,7 +1482,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx,
grpc_compression_algorithm_from_message_stream_compression_algorithm(
&compression_algorithm, call->incoming_message_compression_algorithm,
call->incoming_stream_compression_algorithm) == 0) {
- char* error_msg = NULL;
+ char* error_msg = nullptr;
gpr_asprintf(&error_msg,
"Error in incoming message compression (%d) or stream "
"compression (%d).",
@@ -1492,7 +1492,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx,
GRPC_STATUS_INTERNAL, error_msg);
gpr_free(error_msg);
} else {
- char* error_msg = NULL;
+ char* error_msg = nullptr;
const grpc_compression_options compression_options =
grpc_channel_compression_options(call->channel);
if (compression_algorithm >= GRPC_COMPRESS_ALGORITHMS_COUNT) {
@@ -1504,7 +1504,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx,
} else if (grpc_compression_options_is_algorithm_enabled(
&compression_options, compression_algorithm) == 0) {
/* check if algorithm is supported by current channel config */
- const char* algo_name = NULL;
+ const char* algo_name = nullptr;
grpc_compression_algorithm_name(compression_algorithm, &algo_name);
gpr_asprintf(&error_msg, "Compression algorithm '%s' is disabled.",
algo_name);
@@ -1517,7 +1517,7 @@ static void validate_filtered_metadata(grpc_exec_ctx* exec_ctx,
GPR_ASSERT(call->encodings_accepted_by_peer != 0);
if (!GPR_BITGET(call->encodings_accepted_by_peer, compression_algorithm)) {
if (GRPC_TRACER_ON(grpc_compression_trace)) {
- const char* algo_name = NULL;
+ const char* algo_name = nullptr;
grpc_compression_algorithm_name(compression_algorithm, &algo_name);
gpr_log(GPR_ERROR,
"Compression algorithm ('%s') not present in the bitset of "
@@ -1563,7 +1563,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 */
@@ -1587,7 +1587,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));
}
@@ -1628,7 +1628,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);
@@ -1638,7 +1638,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;
@@ -1651,7 +1651,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;
}
@@ -1728,7 +1728,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;
}
@@ -1804,7 +1804,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(
@@ -1823,7 +1823,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);
@@ -1995,7 +1995,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 160f1cd830..826006f9b6 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,
@@ -179,7 +179,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);
@@ -240,7 +240,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)) {
@@ -256,7 +256,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;
@@ -275,12 +275,12 @@ grpc_call* grpc_channel_create_call(grpc_channel* channel,
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, cq, NULL,
+ &exec_ctx, channel, parent_call, propagation_mask, cq, nullptr,
grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_PATH,
grpc_slice_ref_internal(method)),
- host != NULL ? grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_AUTHORITY,
- grpc_slice_ref_internal(*host))
- : GRPC_MDNULL,
+ host != nullptr ? grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_AUTHORITY,
+ grpc_slice_ref_internal(*host))
+ : GRPC_MDNULL,
grpc_timespec_to_millis_round_up(deadline));
grpc_exec_ctx_finish(&exec_ctx);
return call;
@@ -292,12 +292,12 @@ grpc_call* grpc_channel_create_pollset_set_call(
const grpc_slice* host, grpc_millis deadline, void* reserved) {
GPR_ASSERT(!reserved);
return grpc_channel_create_call_internal(
- exec_ctx, channel, parent_call, propagation_mask, NULL, pollset_set,
+ exec_ctx, channel, parent_call, propagation_mask, nullptr, pollset_set,
grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_PATH,
grpc_slice_ref_internal(method)),
- host != NULL ? grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY,
- grpc_slice_ref_internal(*host))
- : GRPC_MDNULL,
+ host != nullptr ? grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY,
+ grpc_slice_ref_internal(*host))
+ : GRPC_MDNULL,
deadline);
}
@@ -345,8 +345,8 @@ 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,
- GRPC_MDELEM_REF(rc->path), GRPC_MDELEM_REF(rc->authority),
+ &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);
return call;
@@ -386,7 +386,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..a171f90666 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,9 @@ 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 +164,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 +328,11 @@ 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 +374,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 +413,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 +423,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 +699,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 +777,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 +824,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 +839,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 +860,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 +896,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 +916,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 +962,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 +981,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 +1075,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 +1107,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 +1134,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 +1216,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 +1290,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..7114a9f545 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..b816439770 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);
+ channel = 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/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..19510b4c8d 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,19 +83,17 @@ 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");
}
}
}
-
- if (found_error == NULL) 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..5817765aa3 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,13 @@ 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..adcec8c444 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) {
- method_config_table =
- grpc_slice_hash_table_create(num_entries, entries, unref_value, 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, 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..b39e6ebc30 100644
--- a/src/core/lib/transport/transport.cc
+++ b/src/core/lib/transport/transport.cc
@@ -184,9 +184,10 @@ 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..e69ab02570 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;
+ // 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;