Clangify my stale code

reviewable/pr13883/r1
ncteisen 7 years ago
parent 9be168be0c
commit e78bd519ca
  1. 30
      src/core/lib/channel/channel_tracer.cc
  2. 8
      src/core/lib/json/json.cc
  3. 6
      src/core/lib/support/object_registry.cc
  4. 8
      src/core/lib/surface/channel.cc
  5. 15
      test/core/channel/channel_tracer_test.cc
  6. 13
      test/core/util/channel_tracing_utils.cc

@ -113,7 +113,7 @@ static void free_node(grpc_trace_node* node) {
static void grpc_channel_tracer_destroy(grpc_channel_tracer* tracer) {
grpc_trace_node* it = tracer->head_trace;
while (it != NULL) {
while (it != nullptr) {
grpc_trace_node* to_free = it;
it = it->next;
free_node(to_free);
@ -161,11 +161,11 @@ void grpc_channel_tracer_add_trace(grpc_channel_tracer* tracer, grpc_slice data,
new_trace_node->error = error;
new_trace_node->time_created = gpr_now(GPR_CLOCK_REALTIME);
new_trace_node->connectivity_state = connectivity_state;
new_trace_node->next = NULL;
new_trace_node->next = nullptr;
new_trace_node->referenced_tracer =
GRPC_CHANNEL_TRACER_REF(referenced_tracer);
// first node case
if (tracer->head_trace == NULL) {
if (tracer->head_trace == nullptr) {
tracer->head_trace = tracer->tail_trace = new_trace_node;
}
// regular node add case
@ -223,7 +223,7 @@ static void recursively_populate_json(grpc_channel_tracer* tracer,
static void populate_node_data(grpc_trace_node* node, seen_tracers* tracker,
grpc_json* json, grpc_json* children) {
grpc_json* child = NULL;
grpc_json* child = nullptr;
child = grpc_json_create_child(child, json, "data",
grpc_slice_to_c_string(node->data),
GRPC_JSON_STRING, true);
@ -239,14 +239,14 @@ static void populate_node_data(grpc_trace_node* node, seen_tracers* tracker,
child, json, "state",
grpc_connectivity_state_name(node->connectivity_state), GRPC_JSON_STRING,
false);
if (node->referenced_tracer != NULL) {
if (node->referenced_tracer != nullptr) {
char* uuid_str;
gpr_asprintf(&uuid_str, "%ld", node->referenced_tracer->channel_uuid);
child = grpc_json_create_child(child, json, "uuid", uuid_str,
GRPC_JSON_NUMBER, true);
if (children && !seen_tracers_check(tracker, node->referenced_tracer)) {
grpc_json* referenced_tracer = grpc_json_create_child(
NULL, children, NULL, NULL, GRPC_JSON_OBJECT, false);
nullptr, children, nullptr, nullptr, GRPC_JSON_OBJECT, false);
recursively_populate_json(node->referenced_tracer, tracker,
referenced_tracer, true);
}
@ -256,11 +256,11 @@ static void populate_node_data(grpc_trace_node* node, seen_tracers* tracker,
static void populate_node_list_data(grpc_channel_tracer* tracer,
seen_tracers* tracker, grpc_json* nodes,
grpc_json* children) {
grpc_json* child = NULL;
grpc_json* child = nullptr;
grpc_trace_node* it = tracer->head_trace;
while (it != NULL) {
child = grpc_json_create_child(child, nodes, NULL, NULL, GRPC_JSON_OBJECT,
false);
while (it != nullptr) {
child = grpc_json_create_child(child, nodes, nullptr, nullptr,
GRPC_JSON_OBJECT, false);
populate_node_data(it, tracker, child, children);
it = it->next;
}
@ -269,7 +269,7 @@ static void populate_node_list_data(grpc_channel_tracer* tracer,
static void populate_tracer_data(grpc_channel_tracer* tracer,
seen_tracers* tracker, grpc_json* channel_data,
grpc_json* children) {
grpc_json* child = NULL;
grpc_json* child = nullptr;
char* uuid_str;
gpr_asprintf(&uuid_str, "%ld", tracer->channel_uuid);
@ -282,7 +282,7 @@ static void populate_tracer_data(grpc_channel_tracer* tracer,
child = grpc_json_create_child(child, channel_data, "startTime",
fmt_time(tracer->time_created),
GRPC_JSON_STRING, true);
child = grpc_json_create_child(child, channel_data, "nodes", NULL,
child = grpc_json_create_child(child, channel_data, "nodes", nullptr,
GRPC_JSON_ARRAY, false);
populate_node_list_data(tracer, tracker, child, children);
}
@ -291,10 +291,10 @@ static void recursively_populate_json(grpc_channel_tracer* tracer,
seen_tracers* tracker, grpc_json* json,
bool recursive) {
grpc_json* channel_data = grpc_json_create_child(
NULL, json, "channelData", NULL, GRPC_JSON_OBJECT, false);
grpc_json* children = NULL;
nullptr, json, "channelData", nullptr, GRPC_JSON_OBJECT, false);
grpc_json* children = nullptr;
if (recursive) {
children = grpc_json_create_child(channel_data, json, "children", NULL,
children = grpc_json_create_child(channel_data, json, "children", nullptr,
GRPC_JSON_ARRAY, false);
}
seen_tracers_add(tracker, tracer);

@ -55,16 +55,16 @@ void grpc_json_destroy(grpc_json* json) {
grpc_json* grpc_json_link_child(grpc_json* parent, grpc_json* child,
grpc_json* sibling) {
// first child case.
if (parent->child == NULL) {
GPR_ASSERT(sibling == NULL);
if (parent->child == nullptr) {
GPR_ASSERT(sibling == nullptr);
parent->child = child;
return child;
}
if (sibling == NULL) {
if (sibling == nullptr) {
sibling = parent->child;
}
// always find the right most sibling.
while (sibling->next != NULL) {
while (sibling->next != nullptr) {
sibling = sibling->next;
}
sibling->next = child;

@ -73,7 +73,7 @@ intptr_t grpc_object_registry_register_object(void* object,
tracker->type = type;
intptr_t prior = gpr_atm_no_barrier_fetch_add(&g_uuid, 1);
gpr_mu_lock(&g_mu);
g_avl = gpr_avl_add(g_avl, (void*)prior, tracker, NULL);
g_avl = gpr_avl_add(g_avl, (void*)prior, tracker, nullptr);
gpr_mu_unlock(&g_mu);
return prior;
}
@ -91,8 +91,8 @@ grpc_object_registry_type grpc_object_registry_get_object(intptr_t uuid,
object_tracker* tracker =
static_cast<object_tracker*>(gpr_avl_get(g_avl, (void*)uuid, nullptr));
gpr_mu_unlock(&g_mu);
if (tracker == NULL) {
*object = NULL;
if (tracker == nullptr) {
*object = nullptr;
return GRPC_OBJECT_REGISTRY_UNKNOWN;
}
*object = tracker->object;

@ -104,7 +104,7 @@ grpc_channel* grpc_channel_create_with_builder(
channel->target = target;
channel->is_client = grpc_channel_stack_type_is_client(channel_stack_type);
channel->uuid = -1;
channel->tracer = NULL;
channel->tracer = nullptr;
gpr_mu_init(&channel->registered_call_mu);
channel->registered_calls = nullptr;
@ -196,7 +196,7 @@ grpc_channel* grpc_channel_create_with_builder(
0x1; /* always support no compression */
} else if (0 ==
strcmp(args->args[i].key, GRPC_ARG_CHANNEL_TRACING_MAX_NODES)) {
GPR_ASSERT(channel->tracer == NULL);
GPR_ASSERT(channel->tracer == nullptr);
// max_nodes defaults to 10, clamped between 0 and 100.
const grpc_integer_options options = {10, 0, 100};
size_t max_nodes =
@ -211,14 +211,14 @@ grpc_channel* grpc_channel_create_with_builder(
grpc_channel_args_destroy(args);
grpc_channel_tracer_add_trace(
channel->tracer, grpc_slice_from_static_string("Channel created"),
GRPC_ERROR_NONE, GRPC_CHANNEL_IDLE, NULL);
GRPC_ERROR_NONE, GRPC_CHANNEL_IDLE, nullptr);
return channel;
}
char* grpc_channel_get_trace(grpc_channel* channel, bool recursive) {
return channel->tracer
? grpc_channel_tracer_render_trace(channel->tracer, recursive)
: NULL;
: nullptr;
}
intptr_t grpc_channel_get_uuid(grpc_channel* channel) { return channel->uuid; }

@ -30,9 +30,10 @@
#include "test/core/util/test_config.h"
static void add_simple_trace(grpc_channel_tracer* tracer) {
grpc_channel_tracer_add_trace(
tracer, grpc_slice_from_static_string("simple trace"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"), GRPC_CHANNEL_READY, NULL);
grpc_channel_tracer_add_trace(tracer,
grpc_slice_from_static_string("simple trace"),
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"),
GRPC_CHANNEL_READY, nullptr);
}
// checks for the existence of all the required members of the tracer.
@ -66,10 +67,10 @@ static void test_basic_channel_tracing(size_t max_nodes) {
tracer, grpc_slice_from_static_string("trace three"),
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"),
GRPC_ERROR_INT_HTTP2_ERROR, 2),
GRPC_CHANNEL_IDLE, NULL);
grpc_channel_tracer_add_trace(tracer,
grpc_slice_from_static_string("trace four"),
GRPC_ERROR_NONE, GRPC_CHANNEL_SHUTDOWN, NULL);
GRPC_CHANNEL_IDLE, nullptr);
grpc_channel_tracer_add_trace(
tracer, grpc_slice_from_static_string("trace four"), GRPC_ERROR_NONE,
GRPC_CHANNEL_SHUTDOWN, nullptr);
validate_tracer(tracer, 4, max_nodes);
add_simple_trace(tracer);
add_simple_trace(tracer);

@ -25,11 +25,12 @@
#include "src/core/lib/json/json.h"
static grpc_json* get_json_child(grpc_json* parent, const char* key) {
GPR_ASSERT(parent != NULL);
for (grpc_json* child = parent->child; child != NULL; child = child->next) {
if (child->key != NULL && strcmp(child->key, key) == 0) return child;
GPR_ASSERT(parent != nullptr);
for (grpc_json* child = parent->child; child != nullptr;
child = child->next) {
if (child->key != nullptr && strcmp(child->key, key) == 0) return child;
}
return NULL;
return nullptr;
}
void validate_json_array_size(grpc_json* json, const char* key,
@ -38,7 +39,7 @@ void validate_json_array_size(grpc_json* json, const char* key,
GPR_ASSERT(arr);
GPR_ASSERT(arr->type == GRPC_JSON_ARRAY);
size_t count = 0;
for (grpc_json* child = arr->child; child != NULL; child = child->next) {
for (grpc_json* child = arr->child; child != nullptr; child = child->next) {
++count;
}
GPR_ASSERT(count == expected_size);
@ -54,7 +55,7 @@ void validate_channel_data(grpc_json* json, size_t num_nodes_logged_expected,
grpc_json* start_time = get_json_child(channel_data, "startTime");
GPR_ASSERT(start_time);
size_t num_nodes_logged =
(size_t)strtol(num_nodes_logged_json->value, NULL, 0);
(size_t)strtol(num_nodes_logged_json->value, nullptr, 0);
GPR_ASSERT(num_nodes_logged == num_nodes_logged_expected);
validate_json_array_size(channel_data, "nodes", actual_num_nodes_expected);
}

Loading…
Cancel
Save