diff options
-rw-r--r-- | src/main/cpp/blaze.cc | 15 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_darwin.cc | 4 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_linux.cc | 6 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_mingw.cc | 4 | ||||
-rw-r--r-- | src/main/cpp/blaze_util_platform.h | 9 | ||||
-rw-r--r-- | src/main/cpp/util/md5.cc | 51 | ||||
-rw-r--r-- | src/main/cpp/util/numbers.cc | 15 | ||||
-rw-r--r-- | src/main/cpp/util/numbers.h | 10 |
8 files changed, 54 insertions, 60 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc index 25712fa644..cd853bba3b 100644 --- a/src/main/cpp/blaze.cc +++ b/src/main/cpp/blaze.cc @@ -34,6 +34,7 @@ #include <sched.h> #include <signal.h> #include <stdarg.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -128,15 +129,15 @@ struct GlobalVariables { BlazeStartupOptions options; // The time in ms the launcher spends before sending the request to the Blaze - uint64 startup_time; + uint64_t startup_time; // The time spent on extracting the new blaze version // This is part of startup_time - uint64 extract_data_time; + uint64_t extract_data_time; // The time in ms if a command had to wait on a busy Blaze server process // This is part of startup_time - uint64 command_wait_time; + uint64_t command_wait_time; RestartReason restart_reason; @@ -889,14 +890,14 @@ static void ExtractData(const string &self_path) { // If the install dir doesn't exist, create it, if it does, we know it's good. struct stat buf; if (stat(globals->options.install_base.c_str(), &buf) == -1) { - uint64 st = MonotonicClock(); + uint64_t st = MonotonicClock(); // Work in a temp dir to avoid races. string tmp_install = globals->options.install_base + ".tmp." + std::to_string(getpid()); string tmp_binaries = tmp_install + "/_embedded_binaries"; ActuallyExtractData(self_path, tmp_binaries); - uint64 et = MonotonicClock(); + uint64_t et = MonotonicClock(); globals->extract_data_time = (et - st) / 1000000LL; // Now rename the completed installation to its final name. If this @@ -1459,7 +1460,7 @@ static void AcquireLock() { fflush(stderr); // Take a clock sample for that start of the waiting time - uint64 st = MonotonicClock(); + uint64_t st = MonotonicClock(); // Try to take the lock again (blocking). int r; do { @@ -1471,7 +1472,7 @@ static void AcquireLock() { "couldn't acquire file lock"); } // Take another clock sample, calculate elapsed - uint64 et = MonotonicClock(); + uint64_t et = MonotonicClock(); globals->command_wait_time = (et - st) / 1000000LL; } diff --git a/src/main/cpp/blaze_util_darwin.cc b/src/main/cpp/blaze_util_darwin.cc index 1e7da80935..82aec84384 100644 --- a/src/main/cpp/blaze_util_darwin.cc +++ b/src/main/cpp/blaze_util_darwin.cc @@ -60,7 +60,7 @@ string GetSelfPath() { return string(pathbuf, len); } -uint64 MonotonicClock() { +uint64_t MonotonicClock() { struct timeval ts = {}; if (gettimeofday(&ts, NULL) < 0) { pdie(blaze_exit_code::INTERNAL_ERROR, "error calling gettimeofday"); @@ -68,7 +68,7 @@ uint64 MonotonicClock() { return ts.tv_sec * 1000000000LL + ts.tv_usec * 1000; } -uint64 ProcessClock() { +uint64_t ProcessClock() { return clock() * (1000000000LL / CLOCKS_PER_SEC); } diff --git a/src/main/cpp/blaze_util_linux.cc b/src/main/cpp/blaze_util_linux.cc index b905963b35..6f05b467e9 100644 --- a/src/main/cpp/blaze_util_linux.cc +++ b/src/main/cpp/blaze_util_linux.cc @@ -15,9 +15,9 @@ #include <limits.h> #include <pwd.h> #include <string.h> // strerror +#include <sys/socket.h> #include <sys/statfs.h> #include <sys/types.h> -#include <sys/socket.h> #include <unistd.h> #include "src/main/cpp/blaze_util.h" @@ -87,13 +87,13 @@ pid_t GetPeerProcessId(int socket) { return creds.pid; } -uint64 MonotonicClock() { +uint64_t MonotonicClock() { struct timespec ts = {}; clock_gettime(CLOCK_MONOTONIC, &ts); return ts.tv_sec * 1000000000LL + ts.tv_nsec; } -uint64 ProcessClock() { +uint64_t ProcessClock() { struct timespec ts = {}; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts); return ts.tv_sec * 1000000000LL + ts.tv_nsec; diff --git a/src/main/cpp/blaze_util_mingw.cc b/src/main/cpp/blaze_util_mingw.cc index ff18d273d5..f9eab3c883 100644 --- a/src/main/cpp/blaze_util_mingw.cc +++ b/src/main/cpp/blaze_util_mingw.cc @@ -66,13 +66,13 @@ pid_t GetPeerProcessId(int socket) { return creds.pid; } -uint64 MonotonicClock() { +uint64_t MonotonicClock() { struct timespec ts = {}; clock_gettime(CLOCK_MONOTONIC, &ts); return ts.tv_sec * 1000000000LL + ts.tv_nsec; } -uint64 ProcessClock() { +uint64_t ProcessClock() { struct timespec ts = {}; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts); return ts.tv_sec * 1000000000LL + ts.tv_nsec; diff --git a/src/main/cpp/blaze_util_platform.h b/src/main/cpp/blaze_util_platform.h index d3c5add162..2d3101b60c 100644 --- a/src/main/cpp/blaze_util_platform.h +++ b/src/main/cpp/blaze_util_platform.h @@ -15,8 +15,9 @@ #ifndef DEVTOOLS_BLAZE_MAIN_BLAZE_UTIL_PLATFORM_H_ #define DEVTOOLS_BLAZE_MAIN_BLAZE_UTIL_PLATFORM_H_ +#include <stdint.h> + #include <string> -#include "src/main/cpp/util/numbers.h" namespace blaze { @@ -33,12 +34,12 @@ pid_t GetPeerProcessId(int socket); void WarnFilesystemType(const std::string& output_base); // Wrapper around clock_gettime(CLOCK_MONOTONIC) that returns the time -// as a uint64 nanoseconds since epoch. -uint64 MonotonicClock(); +// as a uint64_t nanoseconds since epoch. +uint64_t MonotonicClock(); // Wrapper around clock_gettime(CLOCK_PROCESS_CPUTIME_ID) that returns the // nanoseconds consumed by the current process since it started. -uint64 ProcessClock(); +uint64_t ProcessClock(); // Set cpu and IO scheduling properties. Note that this can take ~50ms // on Linux, so it should only be called when necessary. diff --git a/src/main/cpp/util/md5.cc b/src/main/cpp/util/md5.cc index 4427809939..cd8131a9e0 100644 --- a/src/main/cpp/util/md5.cc +++ b/src/main/cpp/util/md5.cc @@ -39,18 +39,17 @@ #include "src/main/cpp/util/md5.h" +#include <stdint.h> #include <string.h> // for memcpy #include <stddef.h> // for ofsetof -#include "src/main/cpp/util/numbers.h" - #if !_STRING_ARCH_unaligned # ifdef _LP64 -# define UNALIGNED_P(p) (reinterpret_cast<uint64>(p) % \ - __alignof__(uint32) != 0) // NOLINT +# define UNALIGNED_P(p) (reinterpret_cast<uint64_t>(p) % \ + __alignof__(uint32_t) != 0) // NOLINT # else -# define UNALIGNED_P(p) (reinterpret_cast<uint32>(p) % \ - __alignof__(uint32) != 0) // NOLINT +# define UNALIGNED_P(p) (reinterpret_cast<uint32_t>(p) % \ + __alignof__(uint32_t) != 0) // NOLINT # endif #else # define UNALIGNED_P(p) (0) @@ -157,15 +156,15 @@ void Md5Digest::Finish(unsigned char digest[16]) { /* Put the 64-bit file length in *bits* at the end of the buffer. */ unsigned int size = (ctx_buffer_len < 56 ? 64 : 128); - *(reinterpret_cast<uint32*>(ctx_buffer + size - 8)) = count[0] << 3; - *(reinterpret_cast<uint32*>(ctx_buffer + size - 4)) = + *(reinterpret_cast<uint32_t*>(ctx_buffer + size - 8)) = count[0] << 3; + *(reinterpret_cast<uint32_t*>(ctx_buffer + size - 4)) = (count[1] << 3) | (count[0] >> 29); memcpy(ctx_buffer + ctx_buffer_len, kPadding, size - 8 - ctx_buffer_len); Transform(ctx_buffer, size); - uint32* r = reinterpret_cast<uint32*>(digest); + uint32_t* r = reinterpret_cast<uint32_t*>(digest); r[0] = state[0]; r[1] = state[1]; r[2] = state[2]; @@ -209,23 +208,23 @@ void Md5Digest::Transform( // Rotation is separate from addition to prevent recomputation. #define FF(a, b, c, d, s, ac) { \ (a) += F((b), (c), (d)) + ((*x_pos++ = *cur_word++)) + \ - static_cast<uint32>(ac); \ + static_cast<uint32_t>(ac); \ (a) = ROTATE_LEFT((a), (s)); \ (a) += (b); \ } #define GG(a, b, c, d, x, s, ac) { \ - (a) += G((b), (c), (d)) + (x) + static_cast<uint32>(ac); \ + (a) += G((b), (c), (d)) + (x) + static_cast<uint32_t>(ac); \ (a) = ROTATE_LEFT((a), (s)); \ (a) += (b); \ } #define HH(a, b, c, d, x, s, ac) { \ - (a) += H((b), (c), (d)) + (x) + static_cast<uint32>(ac); \ + (a) += H((b), (c), (d)) + (x) + static_cast<uint32_t>(ac); \ (a) = ROTATE_LEFT((a), (s)); \ (a) += (b); \ } #define II(a, b, c, d, x, s, ac) { \ - (a) += I((b), (c), (d)) + (x) + static_cast<uint32>(ac); \ + (a) += I((b), (c), (d)) + (x) + static_cast<uint32_t>(ac); \ (a) = ROTATE_LEFT((a), (s)); \ (a) += (b); \ } @@ -235,21 +234,21 @@ void Md5Digest::Transform( ++count[1]; } - uint32 a = state[0]; - uint32 b = state[1]; - uint32 c = state[2]; - uint32 d = state[3]; - uint32 x[16]; + uint32_t a = state[0]; + uint32_t b = state[1]; + uint32_t c = state[2]; + uint32_t d = state[3]; + uint32_t x[16]; - const uint32 *cur_word = reinterpret_cast<const uint32*>(buffer); - const uint32 *end_word = cur_word + (len / sizeof(uint32)); + const uint32_t *cur_word = reinterpret_cast<const uint32_t*>(buffer); + const uint32_t *end_word = cur_word + (len / sizeof(uint32_t)); while (cur_word < end_word) { - uint32 *x_pos = x; - uint32 prev_a = a; - uint32 prev_b = b; - uint32 prev_c = c; - uint32 prev_d = d; + uint32_t *x_pos = x; + uint32_t prev_a = a; + uint32_t prev_b = b; + uint32_t prev_c = c; + uint32_t prev_d = d; // Round 1 FF(a, b, c, d, S11, 0xd76aa478); // 1 @@ -337,7 +336,7 @@ void Md5Digest::Transform( string Md5Digest::String() const { string result; - b2a_hex(reinterpret_cast<const uint8*>(state), &result, 16); + b2a_hex(reinterpret_cast<const uint8_t*>(state), &result, 16); return result; } diff --git a/src/main/cpp/util/numbers.cc b/src/main/cpp/util/numbers.cc index f825781a54..b9995bfb68 100644 --- a/src/main/cpp/util/numbers.cc +++ b/src/main/cpp/util/numbers.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "src/main/cpp/util/numbers.h" +#include <stdint.h> #include <errno.h> #include <limits.h> #include <cassert> @@ -23,13 +24,13 @@ namespace blaze_util { -static const int32 kint32min = static_cast<int32>(~0x7FFFFFFF); -static const int32 kint32max = static_cast<int32>(0x7FFFFFFF); +static const int32_t kint32min = static_cast<int32_t>(~0x7FFFFFFF); +static const int32_t kint32max = static_cast<int32_t>(0x7FFFFFFF); // Represents integer values of digits. // Uses 36 to indicate an invalid character since we support // bases up to 36. -static const int8 kAsciiToInt[256] = { +static const int8_t kAsciiToInt[256] = { 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, // 16 36s. 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, @@ -183,9 +184,9 @@ bool safe_strto32(const string &text, int *value_p) { } } -int32 strto32(const char *str, char **endptr, int base) { - if (sizeof(int32) == sizeof(long)) { // NOLINT - return static_cast<int32>(strtol(str, endptr, base)); // NOLINT +int32_t strto32(const char *str, char **endptr, int base) { + if (sizeof(int32_t) == sizeof(long)) { // NOLINT + return static_cast<int32_t>(strtol(str, endptr, base)); // NOLINT } const int saved_errno = errno; errno = 0; @@ -203,7 +204,7 @@ int32 strto32(const char *str, char **endptr, int base) { } if (errno == 0) errno = saved_errno; - return static_cast<int32>(result); + return static_cast<int32_t>(result); } } // namespace blaze_util diff --git a/src/main/cpp/util/numbers.h b/src/main/cpp/util/numbers.h index 3285a61219..3521775c11 100644 --- a/src/main/cpp/util/numbers.h +++ b/src/main/cpp/util/numbers.h @@ -16,21 +16,13 @@ #include <string> -typedef signed char int8; -typedef int int32; -typedef long long int64; // NOLINT - -typedef unsigned char uint8; -typedef unsigned int uint32; -typedef unsigned long long uint64; // NOLINT - namespace blaze_util { using std::string; bool safe_strto32(const string &text, int *value); -int32 strto32(const char *str, char **endptr, int base); +int32_t strto32(const char *str, char **endptr, int base); } // namespace blaze_util |