From d58a10965610eb6b338e411ce816b810d76ab59e Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Fri, 10 Aug 2012 13:27:08 -0700 Subject: windows: fix size_t<->int conversions in ninja.exe --- src/build_log.cc | 12 ++++++------ src/depfile_parser.cc | 4 ++-- src/depfile_parser.in.cc | 4 ++-- src/graph.h | 8 ++++---- src/hash_map.h | 2 +- src/lexer.cc | 2 +- src/lexer.in.cc | 2 +- src/string_piece.h | 4 ++-- src/util.cc | 6 +++--- src/util.h | 2 +- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/build_log.cc b/src/build_log.cc index 1b27be3..e72a93e 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -49,7 +49,7 @@ const int kCurrentVersion = 5; #define BIG_CONSTANT(x) (x##LLU) #endif // !defined(_MSC_VER) inline -uint64_t MurmurHash64A(const void* key, int len) { +uint64_t MurmurHash64A(const void* key, size_t len) { static const uint64_t seed = 0xDECAFBADDECAFBADull; const uint64_t m = BIG_CONSTANT(0xc6a4a7935bd1e995); const int r = 47; @@ -58,11 +58,11 @@ uint64_t MurmurHash64A(const void* key, int len) { const uint64_t * end = data + (len/8); while(data != end) { uint64_t k = *data++; - k *= m; - k ^= k >> r; - k *= m; + k *= m; + k ^= k >> r; + k *= m; h ^= k; - h *= m; + h *= m; } const unsigned char* data2 = (const unsigned char*)data; switch(len & 7) @@ -80,7 +80,7 @@ uint64_t MurmurHash64A(const void* key, int len) { h *= m; h ^= h >> r; return h; -} +} #undef BIG_CONSTANT diff --git a/src/depfile_parser.cc b/src/depfile_parser.cc index 03dad92..6887c91 100644 --- a/src/depfile_parser.cc +++ b/src/depfile_parser.cc @@ -149,7 +149,7 @@ yy4: yy5: { // Got a span of plain text. - int len = in - start; + int len = (int)(in - start); // Need to shift it over if we're overwriting backslashes. if (out < start) memmove(out, start, len); @@ -191,7 +191,7 @@ yy13: } - int len = out - filename; + int len = (int)(out - filename); const bool is_target = parsing_targets; if (len > 0 && filename[len - 1] == ':') { len--; // Strip off trailing colon, if any. diff --git a/src/depfile_parser.in.cc b/src/depfile_parser.in.cc index 68b6a95..1d4a177 100644 --- a/src/depfile_parser.in.cc +++ b/src/depfile_parser.in.cc @@ -70,7 +70,7 @@ bool DepfileParser::Parse(string* content, string* err) { } [a-zA-Z0-9+,/_:.~()@=-]+ { // Got a span of plain text. - int len = in - start; + int len = (int)(in - start); // Need to shift it over if we're overwriting backslashes. if (out < start) memmove(out, start, len); @@ -88,7 +88,7 @@ bool DepfileParser::Parse(string* content, string* err) { */ } - int len = out - filename; + int len = (int)(out - filename); const bool is_target = parsing_targets; if (len > 0 && filename[len - 1] == ':') { len--; // Strip off trailing colon, if any. diff --git a/src/graph.h b/src/graph.h index 0ef4f3f..f487a22 100644 --- a/src/graph.h +++ b/src/graph.h @@ -199,12 +199,12 @@ struct Edge { // pointer...) int implicit_deps_; int order_only_deps_; - bool is_implicit(int index) { - return index >= ((int)inputs_.size()) - order_only_deps_ - implicit_deps_ && + bool is_implicit(size_t index) { + return index >= inputs_.size() - order_only_deps_ - implicit_deps_ && !is_order_only(index); } - bool is_order_only(int index) { - return index >= ((int)inputs_.size()) - order_only_deps_; + bool is_order_only(size_t index) { + return index >= inputs_.size() - order_only_deps_; } bool is_phony() const; diff --git a/src/hash_map.h b/src/hash_map.h index 88c2681..9904fb8 100644 --- a/src/hash_map.h +++ b/src/hash_map.h @@ -19,7 +19,7 @@ // MurmurHash2, by Austin Appleby static inline -unsigned int MurmurHash2(const void* key, int len) { +unsigned int MurmurHash2(const void* key, size_t len) { static const unsigned int seed = 0xDECAFBAD; const unsigned int m = 0x5bd1e995; const int r = 24; diff --git a/src/lexer.cc b/src/lexer.cc index f4036d4..5d7d185 100644 --- a/src/lexer.cc +++ b/src/lexer.cc @@ -30,7 +30,7 @@ bool Lexer::Error(const string& message, string* err) { context = p + 1; } } - int col = last_token_ ? last_token_ - context : 0; + int col = last_token_ ? (int)(last_token_ - context) : 0; char buf[1024]; snprintf(buf, sizeof(buf), "%s:%d: ", filename_.AsString().c_str(), line); diff --git a/src/lexer.in.cc b/src/lexer.in.cc index ec3ad6b..7ae9c61 100644 --- a/src/lexer.in.cc +++ b/src/lexer.in.cc @@ -29,7 +29,7 @@ bool Lexer::Error(const string& message, string* err) { context = p + 1; } } - int col = last_token_ ? last_token_ - context : 0; + int col = last_token_ ? (int)(last_token_ - context) : 0; char buf[1024]; snprintf(buf, sizeof(buf), "%s:%d: ", filename_.AsString().c_str(), line); diff --git a/src/string_piece.h b/src/string_piece.h index ad1153e..b1bf105 100644 --- a/src/string_piece.h +++ b/src/string_piece.h @@ -31,7 +31,7 @@ struct StringPiece { StringPiece(const string& str) : str_(str.data()), len_(str.size()) {} StringPiece(const char* str) : str_(str), len_(strlen(str)) {} - StringPiece(const char* str, int len) : str_(str), len_(len) {} + StringPiece(const char* str, size_t len) : str_(str), len_(len) {} bool operator==(const StringPiece& other) const { return len_ == other.len_ && memcmp(str_, other.str_, len_) == 0; @@ -47,7 +47,7 @@ struct StringPiece { } const char* str_; - int len_; + size_t len_; }; #endif // NINJA_STRINGPIECE_H_ diff --git a/src/util.cc b/src/util.cc index 7c2f895..90a1d45 100644 --- a/src/util.cc +++ b/src/util.cc @@ -81,7 +81,7 @@ void Error(const char* msg, ...) { bool CanonicalizePath(string* path, string* err) { METRIC_RECORD("canonicalize str"); - int len = path->size(); + size_t len = path->size(); char* str = 0; if (len > 0) str = &(*path)[0]; @@ -91,7 +91,7 @@ bool CanonicalizePath(string* path, string* err) { return true; } -bool CanonicalizePath(char* path, int* len, string* err) { +bool CanonicalizePath(char* path, size_t* len, string* err) { // WARNING: this function is performance-critical; please benchmark // any changes you make to it. METRIC_RECORD("canonicalize path"); @@ -323,7 +323,7 @@ string ElideMiddle(const string& str, size_t width) { const int kMargin = 3; // Space for "...". string result = str; if (result.size() + kMargin > width) { - int elide_size = (width - kMargin) / 2; + size_t elide_size = (width - kMargin) / 2; result = result.substr(0, elide_size) + "..." + result.substr(result.size() - elide_size, elide_size); diff --git a/src/util.h b/src/util.h index bfcbfa8..ab1882b 100644 --- a/src/util.h +++ b/src/util.h @@ -39,7 +39,7 @@ void Error(const char* msg, ...); /// Canonicalize a path like "foo/../bar.h" into just "bar.h". bool CanonicalizePath(string* path, string* err); -bool CanonicalizePath(char* path, int* len, string* err); +bool CanonicalizePath(char* path, size_t* len, string* err); /// Read a file to a string. /// Returns -errno and fills in \a err on error. -- cgit v0.12