diff options
Diffstat (limited to 'src/core/lib/gpr')
-rw-r--r-- | src/core/lib/gpr/alloc.cc | 2 | ||||
-rw-r--r-- | src/core/lib/gpr/arena.cc | 20 | ||||
-rw-r--r-- | src/core/lib/gpr/cpu_linux.cc | 6 | ||||
-rw-r--r-- | src/core/lib/gpr/host_port.cc | 6 | ||||
-rw-r--r-- | src/core/lib/gpr/log.cc | 8 | ||||
-rw-r--r-- | src/core/lib/gpr/log_linux.cc | 2 | ||||
-rw-r--r-- | src/core/lib/gpr/murmur_hash.cc | 8 | ||||
-rw-r--r-- | src/core/lib/gpr/string.cc | 30 | ||||
-rw-r--r-- | src/core/lib/gpr/string_posix.cc | 6 | ||||
-rw-r--r-- | src/core/lib/gpr/sync_posix.cc | 2 | ||||
-rw-r--r-- | src/core/lib/gpr/thd_posix.cc | 10 | ||||
-rw-r--r-- | src/core/lib/gpr/time.cc | 6 | ||||
-rw-r--r-- | src/core/lib/gpr/time_posix.cc | 4 |
13 files changed, 55 insertions, 55 deletions
diff --git a/src/core/lib/gpr/alloc.cc b/src/core/lib/gpr/alloc.cc index b1d1550630..e0d25963ed 100644 --- a/src/core/lib/gpr/alloc.cc +++ b/src/core/lib/gpr/alloc.cc @@ -95,4 +95,4 @@ void* gpr_malloc_aligned(size_t size, size_t alignment) { return (void*)ret; } -void gpr_free_aligned(void* ptr) { gpr_free(((void**)ptr)[-1]); } +void gpr_free_aligned(void* ptr) { gpr_free((static_cast<void**>(ptr))[-1]); } diff --git a/src/core/lib/gpr/arena.cc b/src/core/lib/gpr/arena.cc index 5a8d7ff6ec..a1eefa56bc 100644 --- a/src/core/lib/gpr/arena.cc +++ b/src/core/lib/gpr/arena.cc @@ -51,8 +51,8 @@ static void* zalloc_aligned(size_t size) { gpr_arena* gpr_arena_create(size_t initial_size) { initial_size = ROUND_UP_TO_ALIGNMENT_SIZE(initial_size); - gpr_arena* a = (gpr_arena*)zalloc_aligned( - ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(gpr_arena)) + initial_size); + gpr_arena* a = static_cast<gpr_arena*>(zalloc_aligned( + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(gpr_arena)) + initial_size)); a->initial_zone.size_end = initial_size; return a; } @@ -66,23 +66,23 @@ size_t gpr_arena_destroy(gpr_arena* arena) { gpr_free_aligned(z); z = next_z; } - return (size_t)size; + return static_cast<size_t>(size); } void* gpr_arena_alloc(gpr_arena* arena, size_t size) { size = ROUND_UP_TO_ALIGNMENT_SIZE(size); size_t start = - (size_t)gpr_atm_no_barrier_fetch_add(&arena->size_so_far, size); + static_cast<size_t>(gpr_atm_no_barrier_fetch_add(&arena->size_so_far, 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 == nullptr) { - size_t next_z_size = (size_t)gpr_atm_no_barrier_load(&arena->size_so_far); - next_z = (zone*)zalloc_aligned(ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone)) + - next_z_size); + size_t next_z_size = static_cast<size_t>gpr_atm_no_barrier_load(&arena->size_so_far); + next_z = static_cast<zone*>(zalloc_aligned(ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone)) + + next_z_size)); next_z->size_begin = z->size_end; next_z->size_end = z->size_end + next_z_size; - if (!gpr_atm_rel_cas(&z->next_atm, (gpr_atm)NULL, (gpr_atm)next_z)) { + if (!gpr_atm_rel_cas(&z->next_atm, static_cast<gpr_atm>(NULL), (gpr_atm)next_z)) { gpr_free_aligned(next_z); next_z = (zone*)gpr_atm_acq_load(&z->next_atm); } @@ -95,7 +95,7 @@ void* gpr_arena_alloc(gpr_arena* arena, size_t size) { GPR_ASSERT(start >= z->size_begin); GPR_ASSERT(start + size <= z->size_end); char* ptr = (z == &arena->initial_zone) - ? (char*)arena + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(gpr_arena)) - : (char*)z + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone)); + ? reinterpret_cast<char*>(arena) + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(gpr_arena)) + : reinterpret_cast<char*>(z) + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(zone)); return ptr + start - z->size_begin; } diff --git a/src/core/lib/gpr/cpu_linux.cc b/src/core/lib/gpr/cpu_linux.cc index 21b1a71dc9..4782f9f742 100644 --- a/src/core/lib/gpr/cpu_linux.cc +++ b/src/core/lib/gpr/cpu_linux.cc @@ -45,7 +45,7 @@ static void init_num_cpus() { #endif /* This must be signed. sysconf returns -1 when the number cannot be determined */ - ncpus = (int)sysconf(_SC_NPROCESSORS_ONLN); + ncpus = static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN)); if (ncpus < 1) { gpr_log(GPR_ERROR, "Cannot determine number of CPUs: assuming 1"); ncpus = 1; @@ -55,7 +55,7 @@ static void init_num_cpus() { unsigned gpr_cpu_num_cores(void) { static gpr_once once = GPR_ONCE_INIT; gpr_once_init(&once, init_num_cpus); - return (unsigned)ncpus; + return static_cast<unsigned>(ncpus); } unsigned gpr_cpu_current_cpu(void) { @@ -71,7 +71,7 @@ unsigned gpr_cpu_current_cpu(void) { gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno)); return 0; } - return (unsigned)cpu; + return static_cast<unsigned>(cpu); #endif } diff --git a/src/core/lib/gpr/host_port.cc b/src/core/lib/gpr/host_port.cc index 0776727906..5a03a16296 100644 --- a/src/core/lib/gpr/host_port.cc +++ b/src/core/lib/gpr/host_port.cc @@ -62,7 +62,7 @@ int gpr_split_host_port(const char* name, char** host, char** port) { return 0; } host_start = name + 1; - host_len = (size_t)(rbracket - host_start); + host_len = static_cast<size_t>(rbracket - host_start); 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. */ @@ -73,7 +73,7 @@ int gpr_split_host_port(const char* name, char** host, char** port) { if (colon != nullptr && strchr(colon + 1, ':') == nullptr) { /* Exactly 1 colon. Split into host:port. */ host_start = name; - host_len = (size_t)(colon - name); + host_len = static_cast<size_t>(colon - name); port_start = colon + 1; } else { /* 0 or 2+ colons. Bare hostname or IPv6 litearal. */ @@ -84,7 +84,7 @@ int gpr_split_host_port(const char* name, char** host, char** port) { } /* Allocate return values. */ - *host = (char*)gpr_malloc(host_len + 1); + *host = static_cast<char*>(gpr_malloc(host_len + 1)); memcpy(*host, host_start, host_len); (*host)[host_len] = '\0'; diff --git a/src/core/lib/gpr/log.cc b/src/core/lib/gpr/log.cc index 19c0f6c34d..9211a00a69 100644 --- a/src/core/lib/gpr/log.cc +++ b/src/core/lib/gpr/log.cc @@ -45,7 +45,7 @@ const char* gpr_log_severity_string(gpr_log_severity severity) { void gpr_log_message(const char* file, int line, gpr_log_severity severity, const char* message) { - if ((gpr_atm)severity < gpr_atm_no_barrier_load(&g_min_severity_to_print)) { + if (static_cast<gpr_atm>(severity) < gpr_atm_no_barrier_load(&g_min_severity_to_print)) { return; } @@ -70,11 +70,11 @@ void gpr_log_verbosity_init() { gpr_atm min_severity_to_print = GPR_LOG_SEVERITY_ERROR; if (verbosity != nullptr) { if (gpr_stricmp(verbosity, "DEBUG") == 0) { - min_severity_to_print = (gpr_atm)GPR_LOG_SEVERITY_DEBUG; + min_severity_to_print = static_cast<gpr_atm>(GPR_LOG_SEVERITY_DEBUG); } else if (gpr_stricmp(verbosity, "INFO") == 0) { - min_severity_to_print = (gpr_atm)GPR_LOG_SEVERITY_INFO; + min_severity_to_print = static_cast<gpr_atm>(GPR_LOG_SEVERITY_INFO); } else if (gpr_stricmp(verbosity, "ERROR") == 0) { - min_severity_to_print = (gpr_atm)GPR_LOG_SEVERITY_ERROR; + min_severity_to_print = static_cast<gpr_atm>(GPR_LOG_SEVERITY_ERROR); } gpr_free(verbosity); } diff --git a/src/core/lib/gpr/log_linux.cc b/src/core/lib/gpr/log_linux.cc index 6b1f1c71e4..d743eedf38 100644 --- a/src/core/lib/gpr/log_linux.cc +++ b/src/core/lib/gpr/log_linux.cc @@ -67,7 +67,7 @@ void gpr_default_log(gpr_log_func_args* args) { static __thread long tid = 0; if (tid == 0) tid = gettid(); - timer = (time_t)now.tv_sec; + timer = static_cast<time_t>(now.tv_sec); final_slash = strrchr(args->file, '/'); if (final_slash == nullptr) display_file = args->file; diff --git a/src/core/lib/gpr/murmur_hash.cc b/src/core/lib/gpr/murmur_hash.cc index 3f5e04d211..01a7290c67 100644 --- a/src/core/lib/gpr/murmur_hash.cc +++ b/src/core/lib/gpr/murmur_hash.cc @@ -36,7 +36,7 @@ uint32_t gpr_murmur_hash3(const void* key, size_t len, uint32_t seed) { const uint32_t c1 = 0xcc9e2d51; const uint32_t c2 = 0x1b873593; - const uint8_t* keyptr = (const uint8_t*)key; + const uint8_t* keyptr = static_cast<const uint8_t*>(key); const size_t bsize = sizeof(k1); const size_t nblocks = len / bsize; @@ -58,10 +58,10 @@ uint32_t gpr_murmur_hash3(const void* key, size_t len, uint32_t seed) { /* tail */ switch (len & 3) { case 3: - k1 ^= ((uint32_t)keyptr[2]) << 16; + k1 ^= (static_cast<uint32_t>(keyptr[2])) << 16; /* fallthrough */ case 2: - k1 ^= ((uint32_t)keyptr[1]) << 8; + k1 ^= (static_cast<uint32_t>(keyptr[1])) << 8; /* fallthrough */ case 1: k1 ^= keyptr[0]; @@ -72,7 +72,7 @@ uint32_t gpr_murmur_hash3(const void* key, size_t len, uint32_t seed) { }; /* finalization */ - h1 ^= (uint32_t)len; + h1 ^= static_cast<uint32_t>(len); FMIX32(h1); return h1; } diff --git a/src/core/lib/gpr/string.cc b/src/core/lib/gpr/string.cc index 6b360e4013..9c07f43cae 100644 --- a/src/core/lib/gpr/string.cc +++ b/src/core/lib/gpr/string.cc @@ -40,7 +40,7 @@ char* gpr_strdup(const char* src) { } len = strlen(src) + 1; - dst = (char*)gpr_malloc(len); + dst = static_cast<char*>(gpr_malloc(len)); memcpy(dst, src, len); @@ -61,7 +61,7 @@ static dump_out dump_out_create(void) { static void dump_out_append(dump_out* out, char c) { if (out->length == out->capacity) { out->capacity = GPR_MAX(8, 2 * out->capacity); - out->data = (char*)gpr_realloc(out->data, out->capacity); + out->data = static_cast<char*>(gpr_realloc(out->data, out->capacity)); } out->data[out->length++] = c; } @@ -69,7 +69,7 @@ static void dump_out_append(dump_out* out, char c) { static void hexdump(dump_out* out, const char* buf, size_t len) { static const char* hex = "0123456789abcdef"; - const uint8_t* const beg = (const uint8_t*)buf; + const uint8_t* const beg = reinterpret_cast<const uint8_t*>(buf); const uint8_t* const end = beg + len; const uint8_t* cur; @@ -81,7 +81,7 @@ static void hexdump(dump_out* out, const char* buf, size_t len) { } static void asciidump(dump_out* out, const char* buf, size_t len) { - const uint8_t* const beg = (const uint8_t*)buf; + const uint8_t* const beg = reinterpret_cast<const uint8_t*>(buf); const uint8_t* const end = beg + len; const uint8_t* cur; int out_was_empty = (out->length == 0); @@ -90,7 +90,7 @@ static void asciidump(dump_out* out, const char* buf, size_t len) { dump_out_append(out, '\''); } for (cur = beg; cur != end; ++cur) { - dump_out_append(out, (char)(isprint(*cur) ? *(char*)cur : '.')); + dump_out_append(out, (isprint(*cur) ? *(char*)cur : '.')); } if (!out_was_empty) { dump_out_append(out, '\''); @@ -118,7 +118,7 @@ int gpr_parse_bytes_to_uint32(const char* buf, size_t len, uint32_t* result) { for (i = 0; i < len; i++) { if (buf[i] < '0' || buf[i] > '9') return 0; /* bad char */ - new_val = 10 * out + (uint32_t)(buf[i] - '0'); + new_val = 10 * out + static_cast<uint32_t>(buf[i] - '0'); if (new_val < out) return 0; /* overflow */ out = new_val; } @@ -148,7 +148,7 @@ int gpr_ltoa(long value, char* string) { sign = value < 0 ? -1 : 1; while (value) { - string[i++] = (char)('0' + sign * (value % 10)); + string[i++] = static_cast<char>('0' + sign * (value % 10)); value /= 10; } if (sign < 0) string[i++] = '-'; @@ -169,7 +169,7 @@ int int64_ttoa(int64_t value, char* string) { sign = value < 0 ? -1 : 1; while (value) { - string[i++] = (char)('0' + sign * (value % 10)); + string[i++] = static_cast<char>('0' + sign * (value % 10)); value /= 10; } if (sign < 0) string[i++] = '-'; @@ -182,13 +182,13 @@ int gpr_parse_nonnegative_int(const char* value) { char* end; long result = strtol(value, &end, 0); if (*end != '\0' || result < 0 || result > INT_MAX) return -1; - return (int)result; + return static_cast<int>(result); } char* gpr_leftpad(const char* str, char flag, size_t length) { const size_t str_length = strlen(str); const size_t out_length = str_length > length ? str_length : length; - char* out = (char*)gpr_malloc(out_length + 1); + char* out = static_cast<char*>(gpr_malloc(out_length + 1)); memset(out, flag, out_length - str_length); memcpy(out + out_length - str_length, str, str_length); out[out_length] = 0; @@ -212,7 +212,7 @@ char* gpr_strjoin_sep(const char** strs, size_t nstrs, const char* sep, if (nstrs > 0) { out_length += sep_len * (nstrs - 1); /* separators */ } - out = (char*)gpr_malloc(out_length); + out = static_cast<char*>(gpr_malloc(out_length)); out_length = 0; for (i = 0; i < nstrs; i++) { const size_t slen = strlen(strs[i]); @@ -243,7 +243,7 @@ void gpr_strvec_destroy(gpr_strvec* sv) { void gpr_strvec_add(gpr_strvec* sv, char* str) { if (sv->count == sv->capacity) { sv->capacity = GPR_MAX(sv->capacity + 8, sv->capacity * 2); - sv->strs = (char**)gpr_realloc(sv->strs, sizeof(char*) * sv->capacity); + sv->strs = static_cast<char**>(gpr_realloc(sv->strs, sizeof(char*) * sv->capacity)); } sv->strs[sv->count++] = str; } @@ -265,12 +265,12 @@ int gpr_stricmp(const char* a, const char* b) { static void add_string_to_split(const char* beg, const char* end, char*** strs, size_t* nstrs, size_t* capstrs) { - char* out = (char*)gpr_malloc((size_t)(end - beg) + 1); - memcpy(out, beg, (size_t)(end - beg)); + char* out = static_cast<char*>(gpr_malloc(static_cast<size_t>(end - beg) + 1)); + memcpy(out, beg, static_cast<size_t>(end - beg)); out[end - beg] = 0; if (*nstrs == *capstrs) { *capstrs = GPR_MAX(8, 2 * *capstrs); - *strs = (char**)gpr_realloc(*strs, sizeof(*strs) * *capstrs); + *strs = static_cast<char**>(gpr_realloc(*strs, sizeof(*strs) * *capstrs)); } (*strs)[*nstrs] = out; ++*nstrs; diff --git a/src/core/lib/gpr/string_posix.cc b/src/core/lib/gpr/string_posix.cc index 8b818e39b9..d32775fb3b 100644 --- a/src/core/lib/gpr/string_posix.cc +++ b/src/core/lib/gpr/string_posix.cc @@ -43,8 +43,8 @@ int gpr_asprintf(char** strp, const char* format, ...) { } /* Allocate a new buffer, with space for the NUL terminator. */ - strp_buflen = (size_t)ret + 1; - if ((*strp = (char*)gpr_malloc(strp_buflen)) == nullptr) { + strp_buflen = static_cast<size_t>(ret) + 1; + if ((*strp = static_cast<char*>(gpr_malloc(strp_buflen))) == nullptr) { /* This shouldn't happen, because gpr_malloc() calls abort(). */ return -1; } @@ -59,7 +59,7 @@ int gpr_asprintf(char** strp, const char* format, ...) { va_start(args, format); ret = vsnprintf(*strp, strp_buflen, format, args); va_end(args); - if ((size_t)ret == strp_buflen - 1) { + if (static_cast<size_t>(ret) == strp_buflen - 1) { return ret; } diff --git a/src/core/lib/gpr/sync_posix.cc b/src/core/lib/gpr/sync_posix.cc index f23a8b2486..848d23730c 100644 --- a/src/core/lib/gpr/sync_posix.cc +++ b/src/core/lib/gpr/sync_posix.cc @@ -84,7 +84,7 @@ int gpr_cv_wait(gpr_cv* cv, gpr_mu* mu, gpr_timespec abs_deadline) { #else abs_deadline = gpr_convert_clock_type(abs_deadline, GPR_CLOCK_REALTIME); #endif // GPR_LINUX - abs_deadline_ts.tv_sec = (time_t)abs_deadline.tv_sec; + abs_deadline_ts.tv_sec = static_cast<time_t>(abs_deadline.tv_sec); abs_deadline_ts.tv_nsec = abs_deadline.tv_nsec; err = pthread_cond_timedwait(cv, mu, &abs_deadline_ts); } diff --git a/src/core/lib/gpr/thd_posix.cc b/src/core/lib/gpr/thd_posix.cc index 683fd4575e..e8e61ca396 100644 --- a/src/core/lib/gpr/thd_posix.cc +++ b/src/core/lib/gpr/thd_posix.cc @@ -49,7 +49,7 @@ static void dec_thd_count(); /* Body of every thread started via gpr_thd_new. */ static void* thread_body(void* v) { - struct thd_arg a = *(struct thd_arg*)v; + struct thd_arg a = *static_cast<struct thd_arg*>(v); free(v); if (a.name != nullptr) { #if GPR_APPLE_PTHREAD_NAME @@ -77,7 +77,7 @@ int gpr_thd_new(gpr_thd_id* t, const char* thd_name, pthread_t p; /* 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)); + struct thd_arg* a = static_cast<struct thd_arg*>(malloc(sizeof(*a))); GPR_ASSERT(a != nullptr); a->body = thd_body; a->arg = arg; @@ -99,13 +99,13 @@ int gpr_thd_new(gpr_thd_id* t, const char* thd_name, free(a); dec_thd_count(); } - *t = (gpr_thd_id)p; + *t = static_cast<gpr_thd_id>(p); return thread_started; } -gpr_thd_id gpr_thd_currentid(void) { return (gpr_thd_id)pthread_self(); } +gpr_thd_id gpr_thd_currentid(void) { return static_cast<gpr_thd_id>(pthread_self()); } -void gpr_thd_join(gpr_thd_id t) { pthread_join((pthread_t)t, nullptr); } +void gpr_thd_join(gpr_thd_id t) { pthread_join(static_cast<pthread_t>(t), nullptr); } /***************************************** * Only used when fork support is enabled diff --git a/src/core/lib/gpr/time.cc b/src/core/lib/gpr/time.cc index 6903674d75..9ebfaa7525 100644 --- a/src/core/lib/gpr/time.cc +++ b/src/core/lib/gpr/time.cc @@ -81,7 +81,7 @@ static gpr_timespec to_seconds_from_sub_second_time(int64_t time_in_units, units_per_sec) - 1; } - out.tv_nsec = (int32_t)((time_in_units - out.tv_sec * units_per_sec) * + out.tv_nsec = static_cast<int32_t>((time_in_units - out.tv_sec * units_per_sec) * GPR_NS_PER_SEC / units_per_sec); out.clock_type = type; } @@ -216,12 +216,12 @@ int32_t gpr_time_to_millis(gpr_timespec t) { care?) */ return -2147483647; } else { - return (int32_t)(t.tv_sec * GPR_MS_PER_SEC + t.tv_nsec / GPR_NS_PER_MS); + return static_cast<int32_t>(t.tv_sec * GPR_MS_PER_SEC + t.tv_nsec / GPR_NS_PER_MS); } } double gpr_timespec_to_micros(gpr_timespec t) { - return (double)t.tv_sec * GPR_US_PER_SEC + t.tv_nsec * 1e-3; + return static_cast<double>(t.tv_sec) * GPR_US_PER_SEC + t.tv_nsec * 1e-3; } gpr_timespec gpr_convert_clock_type(gpr_timespec t, gpr_clock_type clock_type) { diff --git a/src/core/lib/gpr/time_posix.cc b/src/core/lib/gpr/time_posix.cc index 9c7e86b080..09171c9c48 100644 --- a/src/core/lib/gpr/time_posix.cc +++ b/src/core/lib/gpr/time_posix.cc @@ -37,7 +37,7 @@ static struct timespec timespec_from_gpr(gpr_timespec gts) { /* fine to assert, as this is only used in gpr_sleep_until */ GPR_ASSERT(gts.tv_sec <= INT32_MAX && gts.tv_sec >= INT32_MIN); } - rv.tv_sec = (time_t)gts.tv_sec; + rv.tv_sec = static_cast<time_t>(gts.tv_sec); rv.tv_nsec = gts.tv_nsec; return rv; } @@ -52,7 +52,7 @@ static gpr_timespec gpr_from_timespec(struct timespec ts, */ gpr_timespec rv; rv.tv_sec = ts.tv_sec; - rv.tv_nsec = (int32_t)ts.tv_nsec; + rv.tv_nsec = static_cast<int32_t>(ts.tv_nsec); rv.clock_type = clock_type; return rv; } |