From 9d72bf8835f3012169aaa88ec608172d5a056b9e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 11 May 2006 02:19:43 +0000 Subject: [PATCH] * 64-bit compatibility fixes (for problems revealed by building on an Athlon 64 running 64-bit SUSE). A patched ATerm library is required to run Nix succesfully. --- src/libexpr/primops.cc | 4 ++-- src/libstore/gc.cc | 2 +- src/libstore/globals.cc | 2 +- src/libstore/references.cc | 2 +- src/libstore/store.cc | 4 ++-- src/libutil/aterm-map.cc | 15 ++++++++------- src/libutil/aterm-map.hh | 4 ++-- src/libutil/util.cc | 4 ++-- src/nix-env/main.cc | 2 +- src/nix-env/profiles.cc | 2 +- 10 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 262e3bec5..4cd180fd6 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -488,9 +488,9 @@ static string relativise(Path pivot, Path p) /* Otherwise, `p' is in a parent of `pivot'. Find up till which path component `p' and `pivot' match, and add an appropriate number of `..' components. */ - unsigned int i = 1; + string::size_type i = 1; while (1) { - unsigned int j = pivot.find('/', i); + string::size_type j = pivot.find('/', i); if (j == string::npos) break; j++; if (pivot.substr(0, j) != p.substr(0, j)) break; diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index c2bc5bdb1..dc0b078e5 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -212,7 +212,7 @@ static void readTempRoots(PathSet & tempRoots, FDs & fds) string contents = readFile(*fd); /* Extract the roots. */ - unsigned int pos = 0, end; + string::size_type pos = 0, end; while ((end = contents.find((char) 0, pos)) != string::npos) { Path root(contents, pos, end - pos); diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index fc338892f..194e1165f 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -46,7 +46,7 @@ static void readSettings() line += contents[pos++]; pos++; - unsigned int hash = line.find('#'); + string::size_type hash = line.find('#'); if (hash != string::npos) line = string(line, 0, hash); diff --git a/src/libstore/references.cc b/src/libstore/references.cc index 4e4bb7ad1..d67e5b9dc 100644 --- a/src/libstore/references.cc +++ b/src/libstore/references.cc @@ -99,7 +99,7 @@ PathSet scanForReferences(const string & path, const PathSet & paths) have the form `HASH-bla'). */ for (PathSet::const_iterator i = paths.begin(); i != paths.end(); i++) { string baseName = baseNameOf(*i); - unsigned int pos = baseName.find('-'); + string::size_type pos = baseName.find('-'); if (pos == string::npos) throw Error(format("bad reference `%1%'") % *i); string s = string(baseName, 0, pos); diff --git a/src/libstore/store.cc b/src/libstore/store.cc index 556ba8e62..4bf62570e 100644 --- a/src/libstore/store.cc +++ b/src/libstore/store.cc @@ -243,7 +243,7 @@ Path toStorePath(const Path & path) { if (!isInStore(path)) throw Error(format("path `%1%' is not in the Nix store") % path); - unsigned int slash = path.find('/', nixStore.size() + 1); + Path::size_type slash = path.find('/', nixStore.size() + 1); if (slash == Path::npos) return path; else @@ -563,7 +563,7 @@ static Hash queryHash(const Transaction & txn, const Path & storePath) { string s; nixDB.queryString(txn, dbValidPaths, storePath, s); - unsigned int colon = s.find(':'); + string::size_type colon = s.find(':'); if (colon == string::npos) throw Error(format("corrupt hash `%1%' in valid-path entry for `%2%'") % s % storePath); diff --git a/src/libutil/aterm-map.cc b/src/libutil/aterm-map.cc index f40046437..33388e148 100644 --- a/src/libutil/aterm-map.cc +++ b/src/libutil/aterm-map.cc @@ -111,34 +111,35 @@ void ATermMap::copy(KeyValue * elements, unsigned int capacity) } +/* !!! use a bigger shift for 64-bit platforms? */ static const unsigned int shift = 16; -static const unsigned int knuth = (unsigned int) (0.6180339887 * (1 << shift)); +static const unsigned long knuth = (unsigned long) (0.6180339887 * (1 << shift)); -unsigned int ATermMap::hash1(ATerm key) const +unsigned long ATermMap::hash1(ATerm key) const { /* Don't care about the least significant bits of the ATerm pointer since they're always 0. */ - unsigned int key2 = ((unsigned int) key) >> 2; + unsigned long key2 = ((unsigned long) key) >> 2; /* Approximately equal to: double d = key2 * 0.6180339887; unsigned int h = (int) (capacity * (d - floor(d))); */ - unsigned int h = (capacity * ((key2 * knuth) & ((1 << shift) - 1))) >> shift; + unsigned long h = (capacity * ((key2 * knuth) & ((1 << shift) - 1))) >> shift; return h; } -unsigned int ATermMap::hash2(ATerm key) const +unsigned long ATermMap::hash2(ATerm key) const { - unsigned int key2 = ((unsigned int) key) >> 2; + unsigned long key2 = ((unsigned long) key) >> 2; /* Note: the result must be relatively prime to `capacity' (which is a power of 2), so we make sure that the result is always odd. */ - unsigned int h = ((key2 * 134217689) & (capacity - 1)) | 1; + unsigned long h = ((key2 * 134217689) & (capacity - 1)) | 1; return h; } diff --git a/src/libutil/aterm-map.hh b/src/libutil/aterm-map.hh index 203b42934..115ed36cd 100644 --- a/src/libutil/aterm-map.hh +++ b/src/libutil/aterm-map.hh @@ -113,8 +113,8 @@ private: void copy(KeyValue * elements, unsigned int capacity); - inline unsigned int hash1(ATerm key) const; - inline unsigned int hash2(ATerm key) const; + inline unsigned long hash1(ATerm key) const; + inline unsigned long hash2(ATerm key) const; }; diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 0d970e69e..4e9346486 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -119,7 +119,7 @@ Path canonPath(const Path & path, bool resolveSymlinks) Path dirOf(const Path & path) { - unsigned int pos = path.rfind('/'); + Path::size_type pos = path.rfind('/'); if (pos == string::npos) throw Error(format("invalid file name: %1%") % path); return pos == 0 ? "/" : Path(path, 0, pos); @@ -128,7 +128,7 @@ Path dirOf(const Path & path) string baseNameOf(const Path & path) { - unsigned int pos = path.rfind('/'); + Path::size_type pos = path.rfind('/'); if (pos == string::npos) throw Error(format("invalid file name %1% ") % path); return string(path, pos + 1); diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc index e7f25c5ba..560612825 100644 --- a/src/nix-env/main.cc +++ b/src/nix-env/main.cc @@ -350,7 +350,7 @@ static void queryInstSources(EvalState & state, DrvInfo elem; elem.attrs = shared_ptr(new ATermMap(0)); /* ugh... */ string name = baseNameOf(*i); - unsigned int dash = name.find('-'); + string::size_type dash = name.find('-'); if (dash != string::npos) name = string(name, dash + 1); diff --git a/src/nix-env/profiles.cc b/src/nix-env/profiles.cc index 6db291b3d..6ec12e604 100644 --- a/src/nix-env/profiles.cc +++ b/src/nix-env/profiles.cc @@ -19,7 +19,7 @@ static int parseName(const string & profileName, const string & name) { if (string(name, 0, profileName.size() + 1) != profileName + "-") return -1; string s = string(name, profileName.size() + 1); - unsigned int p = s.find("-link"); + string::size_type p = s.find("-link"); if (p == string::npos) return -1; int n; if (string2Int(string(s, 0, p), n) && n >= 0)