Skip to content

Commit

Permalink
windows: fix size_t<->int conversions in ninja.exe
Browse files Browse the repository at this point in the history
  • Loading branch information
evmar committed Aug 10, 2012
1 parent d98ba72 commit d58a109
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/build_log.cc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const int kCurrentVersion = 5;
#define BIG_CONSTANT(x) (x##LLU) #define BIG_CONSTANT(x) (x##LLU)
#endif // !defined(_MSC_VER) #endif // !defined(_MSC_VER)
inline inline
uint64_t MurmurHash64A(const void* key, int len) { uint64_t MurmurHash64A(const void* key, size_t len) {
static const uint64_t seed = 0xDECAFBADDECAFBADull; static const uint64_t seed = 0xDECAFBADDECAFBADull;
const uint64_t m = BIG_CONSTANT(0xc6a4a7935bd1e995); const uint64_t m = BIG_CONSTANT(0xc6a4a7935bd1e995);
const int r = 47; const int r = 47;
Expand All @@ -58,11 +58,11 @@ uint64_t MurmurHash64A(const void* key, int len) {
const uint64_t * end = data + (len/8); const uint64_t * end = data + (len/8);
while(data != end) { while(data != end) {
uint64_t k = *data++; uint64_t k = *data++;
k *= m; k *= m;
k ^= k >> r; k ^= k >> r;
k *= m; k *= m;
h ^= k; h ^= k;
h *= m; h *= m;
} }
const unsigned char* data2 = (const unsigned char*)data; const unsigned char* data2 = (const unsigned char*)data;
switch(len & 7) switch(len & 7)
Expand All @@ -80,7 +80,7 @@ uint64_t MurmurHash64A(const void* key, int len) {
h *= m; h *= m;
h ^= h >> r; h ^= h >> r;
return h; return h;
} }
#undef BIG_CONSTANT #undef BIG_CONSTANT




Expand Down
4 changes: 2 additions & 2 deletions src/depfile_parser.cc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ bool DepfileParser::Parse(string* content, string* err) {
yy5: yy5:
{ {
// Got a span of plain text. // 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. // Need to shift it over if we're overwriting backslashes.
if (out < start) if (out < start)
memmove(out, start, len); memmove(out, start, len);
Expand Down Expand Up @@ -191,7 +191,7 @@ bool DepfileParser::Parse(string* content, string* err) {


} }


int len = out - filename; int len = (int)(out - filename);
const bool is_target = parsing_targets; const bool is_target = parsing_targets;
if (len > 0 && filename[len - 1] == ':') { if (len > 0 && filename[len - 1] == ':') {
len--; // Strip off trailing colon, if any. len--; // Strip off trailing colon, if any.
Expand Down
4 changes: 2 additions & 2 deletions src/depfile_parser.in.cc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ bool DepfileParser::Parse(string* content, string* err) {
} }
[a-zA-Z0-9+,/_:.~()@=-]+ { [a-zA-Z0-9+,/_:.~()@=-]+ {
// Got a span of plain text. // 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. // Need to shift it over if we're overwriting backslashes.
if (out < start) if (out < start)
memmove(out, start, len); memmove(out, start, len);
Expand All @@ -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; const bool is_target = parsing_targets;
if (len > 0 && filename[len - 1] == ':') { if (len > 0 && filename[len - 1] == ':') {
len--; // Strip off trailing colon, if any. len--; // Strip off trailing colon, if any.
Expand Down
8 changes: 4 additions & 4 deletions src/graph.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ struct Edge {
// pointer...) // pointer...)
int implicit_deps_; int implicit_deps_;
int order_only_deps_; int order_only_deps_;
bool is_implicit(int index) { bool is_implicit(size_t index) {
return index >= ((int)inputs_.size()) - order_only_deps_ - implicit_deps_ && return index >= inputs_.size() - order_only_deps_ - implicit_deps_ &&
!is_order_only(index); !is_order_only(index);
} }
bool is_order_only(int index) { bool is_order_only(size_t index) {
return index >= ((int)inputs_.size()) - order_only_deps_; return index >= inputs_.size() - order_only_deps_;
} }


bool is_phony() const; bool is_phony() const;
Expand Down
2 changes: 1 addition & 1 deletion src/hash_map.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


// MurmurHash2, by Austin Appleby // MurmurHash2, by Austin Appleby
static inline 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; static const unsigned int seed = 0xDECAFBAD;
const unsigned int m = 0x5bd1e995; const unsigned int m = 0x5bd1e995;
const int r = 24; const int r = 24;
Expand Down
2 changes: 1 addition & 1 deletion src/lexer.cc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool Lexer::Error(const string& message, string* err) {
context = p + 1; context = p + 1;
} }
} }
int col = last_token_ ? last_token_ - context : 0; int col = last_token_ ? (int)(last_token_ - context) : 0;


char buf[1024]; char buf[1024];
snprintf(buf, sizeof(buf), "%s:%d: ", filename_.AsString().c_str(), line); snprintf(buf, sizeof(buf), "%s:%d: ", filename_.AsString().c_str(), line);
Expand Down
2 changes: 1 addition & 1 deletion src/lexer.in.cc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bool Lexer::Error(const string& message, string* err) {
context = p + 1; context = p + 1;
} }
} }
int col = last_token_ ? last_token_ - context : 0; int col = last_token_ ? (int)(last_token_ - context) : 0;


char buf[1024]; char buf[1024];
snprintf(buf, sizeof(buf), "%s:%d: ", filename_.AsString().c_str(), line); snprintf(buf, sizeof(buf), "%s:%d: ", filename_.AsString().c_str(), line);
Expand Down
4 changes: 2 additions & 2 deletions src/string_piece.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct StringPiece {
StringPiece(const string& str) : str_(str.data()), len_(str.size()) {} StringPiece(const string& str) : str_(str.data()), len_(str.size()) {}
StringPiece(const char* str) : str_(str), len_(strlen(str)) {} 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 { bool operator==(const StringPiece& other) const {
return len_ == other.len_ && memcmp(str_, other.str_, len_) == 0; return len_ == other.len_ && memcmp(str_, other.str_, len_) == 0;
Expand All @@ -47,7 +47,7 @@ struct StringPiece {
} }


const char* str_; const char* str_;
int len_; size_t len_;
}; };


#endif // NINJA_STRINGPIECE_H_ #endif // NINJA_STRINGPIECE_H_
6 changes: 3 additions & 3 deletions src/util.cc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void Error(const char* msg, ...) {


bool CanonicalizePath(string* path, string* err) { bool CanonicalizePath(string* path, string* err) {
METRIC_RECORD("canonicalize str"); METRIC_RECORD("canonicalize str");
int len = path->size(); size_t len = path->size();
char* str = 0; char* str = 0;
if (len > 0) if (len > 0)
str = &(*path)[0]; str = &(*path)[0];
Expand All @@ -91,7 +91,7 @@ bool CanonicalizePath(string* path, string* err) {
return true; 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 // WARNING: this function is performance-critical; please benchmark
// any changes you make to it. // any changes you make to it.
METRIC_RECORD("canonicalize path"); METRIC_RECORD("canonicalize path");
Expand Down Expand Up @@ -323,7 +323,7 @@ string ElideMiddle(const string& str, size_t width) {
const int kMargin = 3; // Space for "...". const int kMargin = 3; // Space for "...".
string result = str; string result = str;
if (result.size() + kMargin > width) { 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 = result.substr(0, elide_size)
+ "..." + "..."
+ result.substr(result.size() - elide_size, elide_size); + result.substr(result.size() - elide_size, elide_size);
Expand Down
2 changes: 1 addition & 1 deletion src/util.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void Error(const char* msg, ...);
/// Canonicalize a path like "foo/../bar.h" into just "bar.h". /// Canonicalize a path like "foo/../bar.h" into just "bar.h".
bool CanonicalizePath(string* path, string* err); 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. /// Read a file to a string.
/// Returns -errno and fills in \a err on error. /// Returns -errno and fills in \a err on error.
Expand Down

0 comments on commit d58a109

Please sign in to comment.