From 1de00e6c42ee6beaaa490104888ef09be1d4a0d4 Mon Sep 17 00:00:00 2001 From: Kane York Date: Sat, 1 Aug 2020 17:17:44 -0700 Subject: chore(3p/nix): apply google-readability-casting Command run: jq Reviewed-by: tazjin --- third_party/nix/src/libstore/binary-cache-store.cc | 11 ++++---- third_party/nix/src/libstore/build.cc | 31 ++++++++++++---------- third_party/nix/src/libstore/crypto.cc | 11 +++++--- third_party/nix/src/libstore/download.cc | 25 ++++++++++------- third_party/nix/src/libstore/gc.cc | 5 ++-- third_party/nix/src/libstore/legacy-ssh-store.cc | 2 +- third_party/nix/src/libstore/local-fs-store.cc | 2 +- third_party/nix/src/libstore/local-store.cc | 18 ++++++++----- third_party/nix/src/libstore/nar-accessor.cc | 2 +- .../nix/src/libstore/nar-info-disk-cache.cc | 10 ++++--- third_party/nix/src/libstore/remote-fs-accessor.cc | 6 +++-- third_party/nix/src/libstore/remote-store.cc | 2 +- third_party/nix/src/libstore/sqlite.cc | 2 +- third_party/nix/src/libstore/ssh.cc | 2 +- third_party/nix/src/libstore/store-api.cc | 6 ++--- 15 files changed, 78 insertions(+), 57 deletions(-) (limited to 'third_party/nix/src/libstore') diff --git a/third_party/nix/src/libstore/binary-cache-store.cc b/third_party/nix/src/libstore/binary-cache-store.cc index fce4dc0e112c..d38db375edb9 100644 --- a/third_party/nix/src/libstore/binary-cache-store.cc +++ b/third_party/nix/src/libstore/binary-cache-store.cc @@ -88,7 +88,7 @@ void BinaryCacheStore::getFile(const std::string& path, Sink& sink) { } }}); auto data = promise.get_future().get(); - sink((unsigned char*)data->data(), data->size()); + sink(reinterpret_cast(data->data()), data->size()); } std::shared_ptr BinaryCacheStore::getFile( @@ -206,7 +206,9 @@ void BinaryCacheStore::addToStore(const ValidPathInfo& info, .count(); DLOG(INFO) << "copying path '" << narInfo->path << "' (" << narInfo->narSize << " bytes, compressed " - << ((1.0 - (double)narCompressed->size() / nar->size()) * 100.0) + << ((1.0 - + static_cast(narCompressed->size()) / nar->size()) * + 100.0) << "% in " << duration << "ms) to binary cache"; /* Atomically write the NAR file. */ @@ -288,9 +290,8 @@ void BinaryCacheStore::queryPathInfoUncached( stats.narInfoRead++; - (*callbackPtr)( - (std::shared_ptr)std::make_shared( - *this, *data, narInfoFile)); + (*callbackPtr)(std::shared_ptr( + std::make_shared(*this, *data, narInfoFile))); } catch (...) { callbackPtr->rethrow(); diff --git a/third_party/nix/src/libstore/build.cc b/third_party/nix/src/libstore/build.cc index 9bff3b8345df..c48e1abd722a 100644 --- a/third_party/nix/src/libstore/build.cc +++ b/third_party/nix/src/libstore/build.cc @@ -1589,11 +1589,13 @@ MakeError(NotDeterministic, BuildError) 8ULL * 1024 * 1024; // FIXME: make configurable struct statvfs st; if (statvfs(worker.store.realStoreDir.c_str(), &st) == 0 && - (unsigned long long)st.f_bavail * st.f_bsize < required) { + static_cast(st.f_bavail) * st.f_bsize < + required) { diskFull = true; } if (statvfs(tmpDir.c_str(), &st) == 0 && - (unsigned long long)st.f_bavail * st.f_bsize < required) { + static_cast(st.f_bavail) * st.f_bsize < + required) { diskFull = true; } #endif @@ -1832,7 +1834,7 @@ void chmod_(const Path& path, mode_t mode) { } int childEntry(void* arg) { - ((DerivationGoal*)arg)->runChild(); + (static_cast(arg))->runChild(); return 1; } @@ -2361,9 +2363,9 @@ void DerivationGoal::startBuilder() { } size_t stackSize = 1 * 1024 * 1024; - char* stack = - (char*)mmap(nullptr, stackSize, PROT_WRITE | PROT_READ, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0); + char* stack = static_cast( + mmap(nullptr, stackSize, PROT_WRITE | PROT_READ, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0)); if (stack == MAP_FAILED) { throw SysError("allocating stack"); } @@ -4483,9 +4485,9 @@ void Worker::waitForInput() { } if (nearest != steady_time_point::max()) { timeout.tv_sec = std::max( - 1L, - (long)std::chrono::duration_cast(nearest - before) - .count()); + 1L, static_cast(std::chrono::duration_cast( + nearest - before) + .count())); useTimeout = true; } @@ -4500,10 +4502,11 @@ void Worker::waitForInput() { lastWokenUp = before; } timeout.tv_sec = std::max( - 1L, - (long)std::chrono::duration_cast( - lastWokenUp + std::chrono::seconds(settings.pollInterval) - before) - .count()); + 1L, static_cast(std::chrono::duration_cast( + lastWokenUp + + std::chrono::seconds(settings.pollInterval) - + before) + .count())); } else { lastWokenUp = steady_time_point::min(); } @@ -4568,7 +4571,7 @@ void Worker::waitForInput() { } } else { DLOG(INFO) << goal->getName() << ": read " << rd << " bytes"; - std::string data((char*)buffer.data(), rd); + std::string data(reinterpret_cast(buffer.data()), rd); j->lastOutput = after; goal->handleChildOutput(k, data); } diff --git a/third_party/nix/src/libstore/crypto.cc b/third_party/nix/src/libstore/crypto.cc index 4661cbbb18fa..0a2795cb0a01 100644 --- a/third_party/nix/src/libstore/crypto.cc +++ b/third_party/nix/src/libstore/crypto.cc @@ -58,7 +58,8 @@ std::string SecretKey::signDetached(const std::string& data) const { unsigned long long sigLen; crypto_sign_detached(sig, &sigLen, (unsigned char*)data.data(), data.size(), (unsigned char*)key.data()); - return name + ":" + absl::Base64Escape(std::string((char*)sig, sigLen)); + return name + ":" + + absl::Base64Escape(std::string(reinterpret_cast(sig), sigLen)); #else noSodium(); #endif @@ -68,7 +69,8 @@ PublicKey SecretKey::toPublicKey() const { #if HAVE_SODIUM unsigned char pk[crypto_sign_PUBLICKEYBYTES]; crypto_sign_ed25519_sk_to_pk(pk, (unsigned char*)key.data()); - return PublicKey(name, std::string((char*)pk, crypto_sign_PUBLICKEYBYTES)); + return PublicKey(name, std::string(reinterpret_cast(pk), + crypto_sign_PUBLICKEYBYTES)); #else noSodium(); #endif @@ -102,8 +104,9 @@ bool verifyDetached(const std::string& data, const std::string& sig, } return crypto_sign_verify_detached( - (unsigned char*)sig2.data(), (unsigned char*)data.data(), - data.size(), (unsigned char*)key->second.key.data()) == 0; + reinterpret_cast(sig2.data()), + (unsigned char*)data.data(), data.size(), + (unsigned char*)key->second.key.data()) == 0; #else noSodium(); #endif diff --git a/third_party/nix/src/libstore/download.cc b/third_party/nix/src/libstore/download.cc index cf64a6bad722..60a409d0dc4f 100644 --- a/third_party/nix/src/libstore/download.cc +++ b/third_party/nix/src/libstore/download.cc @@ -160,7 +160,7 @@ struct CurlDownloader : public Downloader { decompressionSink = makeDecompressionSink(encoding, finalSink); } - (*decompressionSink)((unsigned char*)contents, realSize); + (*decompressionSink)(static_cast(contents), realSize); return realSize; } catch (...) { @@ -171,12 +171,13 @@ struct CurlDownloader : public Downloader { static size_t writeCallbackWrapper(void* contents, size_t size, size_t nmemb, void* userp) { - return ((DownloadItem*)userp)->writeCallback(contents, size, nmemb); + return (static_cast(userp)) + ->writeCallback(contents, size, nmemb); } size_t headerCallback(void* contents, size_t size, size_t nmemb) { size_t realSize = size * nmemb; - std::string line((char*)contents, realSize); + std::string line(static_cast(contents), realSize); DLOG(INFO) << "got header for '" << request.uri << "': " << absl::StripAsciiWhitespace(line); if (line.compare(0, 5, "HTTP/") == 0) { // new response starts @@ -219,7 +220,8 @@ struct CurlDownloader : public Downloader { static size_t headerCallbackWrapper(void* contents, size_t size, size_t nmemb, void* userp) { - return ((DownloadItem*)userp)->headerCallback(contents, size, nmemb); + return (static_cast(userp)) + ->headerCallback(contents, size, nmemb); } static int debugCallback(CURL* handle, curl_infotype type, char* data, @@ -246,7 +248,8 @@ struct CurlDownloader : public Downloader { static size_t readCallbackWrapper(char* buffer, size_t size, size_t nitems, void* userp) { - return ((DownloadItem*)userp)->readCallback(buffer, size, nitems); + return (static_cast(userp)) + ->readCallback(buffer, size, nitems); } void init() { @@ -580,9 +583,10 @@ struct CurlDownloader : public Downloader { nextWakeup != std::chrono::steady_clock::time_point() ? std::max( 0, - (int)std::chrono::duration_cast( - nextWakeup - std::chrono::steady_clock::now()) - .count()) + static_cast( + std::chrono::duration_cast( + nextWakeup - std::chrono::steady_clock::now()) + .count())) : maxSleepTimeMs; DLOG(INFO) << "download thread waiting for " << sleepTimeMs << " ms"; mc = curl_multi_wait(curlm, extraFDs, 1, sleepTimeMs, &numfds); @@ -846,7 +850,7 @@ void Downloader::download(DownloadRequest&& request, Sink& sink) { if it's blocked on a full buffer. We don't hold the state lock while doing this to prevent blocking the download thread if sink() takes a long time. */ - sink((unsigned char*)chunk.data(), chunk.size()); + sink(reinterpret_cast(chunk.data()), chunk.size()); } } @@ -902,7 +906,8 @@ CachedDownloadResult Downloader::downloadCached( if (ss.size() >= 3 && ss[0] == url) { time_t lastChecked; if (absl::SimpleAtoi(ss[2], &lastChecked) && - (uint64_t)lastChecked + request.ttl >= (uint64_t)time(nullptr)) { + static_cast(lastChecked) + request.ttl >= + static_cast(time(nullptr))) { skip = true; result.effectiveUri = request.uri; result.etag = ss[1]; diff --git a/third_party/nix/src/libstore/gc.cc b/third_party/nix/src/libstore/gc.cc index a491d7e32c48..596046e4f324 100644 --- a/third_party/nix/src/libstore/gc.cc +++ b/third_party/nix/src/libstore/gc.cc @@ -241,7 +241,8 @@ void LocalStore::findTempRoots(FDs& fds, Roots& tempRoots, bool censor) { std::string::size_type pos = 0; std::string::size_type end; - while ((end = contents.find((char)0, pos)) != std::string::npos) { + while ((end = contents.find(static_cast(0), pos)) != + std::string::npos) { Path root(contents, pos, end - pos); DLOG(INFO) << "got temporary root " << root; assertStorePath(root); @@ -916,7 +917,7 @@ void LocalStore::autoGC(bool sync) { throw SysError("getting filesystem info about '%s'", realStoreDir); } - return (uint64_t)st.f_bavail * st.f_bsize; + return static_cast(st.f_bavail) * st.f_bsize; }; std::shared_future future; diff --git a/third_party/nix/src/libstore/legacy-ssh-store.cc b/third_party/nix/src/libstore/legacy-ssh-store.cc index 02231aabcdba..343801870a96 100644 --- a/third_party/nix/src/libstore/legacy-ssh-store.cc +++ b/third_party/nix/src/libstore/legacy-ssh-store.cc @@ -214,7 +214,7 @@ struct LegacySSHStore : public Store { conn->to.flush(); BuildResult status; - status.status = (BuildResult::Status)readInt(conn->from); + status.status = static_cast(readInt(conn->from)); conn->from >> status.errorMsg; if (GET_PROTOCOL_MINOR(conn->remoteVersion) >= 3) { diff --git a/third_party/nix/src/libstore/local-fs-store.cc b/third_party/nix/src/libstore/local-fs-store.cc index 2dd09093d5f8..2ebf99a9b5a2 100644 --- a/third_party/nix/src/libstore/local-fs-store.cc +++ b/third_party/nix/src/libstore/local-fs-store.cc @@ -41,7 +41,7 @@ struct LocalStoreAccessor : public FSAccessor { return {S_ISREG(st.st_mode) ? Type::tRegular : S_ISLNK(st.st_mode) ? Type::tSymlink : Type::tDirectory, - S_ISREG(st.st_mode) ? (uint64_t)st.st_size : 0, + S_ISREG(st.st_mode) ? static_cast(st.st_size) : 0, S_ISREG(st.st_mode) && ((st.st_mode & S_IXUSR) != 0u)}; } diff --git a/third_party/nix/src/libstore/local-store.cc b/third_party/nix/src/libstore/local-store.cc index 9b19e078b86f..5e3271a5f3cc 100644 --- a/third_party/nix/src/libstore/local-store.cc +++ b/third_party/nix/src/libstore/local-store.cc @@ -350,7 +350,8 @@ void LocalStore::openDB(State& state, bool create) { if (sqlite3_step(stmt) != SQLITE_ROW) { throwSQLiteError(db, "querying journal mode"); } - prevMode = std::string((const char*)sqlite3_column_text(stmt, 0)); + prevMode = std::string( + reinterpret_cast(sqlite3_column_text(stmt, 0))); } if (prevMode != mode && sqlite3_exec(db, ("pragma main.journal_mode = " + mode + ";").c_str(), @@ -489,7 +490,7 @@ static void canonicalisePathMetaData_(const Path& path, uid_t fromUid, However, ignore files that we chown'ed ourselves previously to ensure that we don't fail on hard links within the same build (i.e. "touch $out/foo; ln $out/foo $out/bar"). */ - if (fromUid != (uid_t)-1 && st.st_uid != fromUid) { + if (fromUid != static_cast(-1) && st.st_uid != fromUid) { if (S_ISDIR(st.st_mode)) { throw BuildError(format("invalid file '%1%': is a directory") % path); } @@ -690,7 +691,8 @@ void LocalStore::queryPathInfoUncached( info->registrationTime = useQueryPathInfo.getInt(2); - auto s = (const char*)sqlite3_column_text(state->stmtQueryPathInfo, 3); + auto s = reinterpret_cast( + sqlite3_column_text(state->stmtQueryPathInfo, 3)); if (s != nullptr) { info->deriver = s; } @@ -700,12 +702,14 @@ void LocalStore::queryPathInfoUncached( info->ultimate = useQueryPathInfo.getInt(5) == 1; - s = (const char*)sqlite3_column_text(state->stmtQueryPathInfo, 6); + s = reinterpret_cast( + sqlite3_column_text(state->stmtQueryPathInfo, 6)); if (s != nullptr) { info->sigs = absl::StrSplit(s, absl::ByChar(' '), absl::SkipEmpty()); } - s = (const char*)sqlite3_column_text(state->stmtQueryPathInfo, 7); + s = reinterpret_cast( + sqlite3_column_text(state->stmtQueryPathInfo, 7)); if (s != nullptr) { info->ca = s; } @@ -860,8 +864,8 @@ Path LocalStore::queryPathFromHashPart(const std::string& hashPart) { return ""; } - const char* s = - (const char*)sqlite3_column_text(state->stmtQueryPathFromHashPart, 0); + const char* s = reinterpret_cast( + sqlite3_column_text(state->stmtQueryPathFromHashPart, 0)); return (s != nullptr) && prefix.compare(0, prefix.size(), s, prefix.size()) == 0 ? s diff --git a/third_party/nix/src/libstore/nar-accessor.cc b/third_party/nix/src/libstore/nar-accessor.cc index 49fa1bd1d61c..cfd3d50b32bc 100644 --- a/third_party/nix/src/libstore/nar-accessor.cc +++ b/third_party/nix/src/libstore/nar-accessor.cc @@ -76,7 +76,7 @@ struct NarAccessor : public FSAccessor { void preallocateContents(unsigned long long size) override { currentStart = std::string(s, pos, 16); assert(size <= std::numeric_limits::max()); - parents.top()->size = (size_t)size; + parents.top()->size = static_cast(size); parents.top()->start = pos; } diff --git a/third_party/nix/src/libstore/nar-info-disk-cache.cc b/third_party/nix/src/libstore/nar-info-disk-cache.cc index b284fc698dcc..90ea20a8936b 100644 --- a/third_party/nix/src/libstore/nar-info-disk-cache.cc +++ b/third_party/nix/src/libstore/nar-info-disk-cache.cc @@ -164,8 +164,9 @@ class NarInfoDiskCacheImpl final : public NarInfoDiskCache { static_cast(wantMassQuery))(priority) .exec(); assert(sqlite3_changes(state->db) == 1); - state->caches[uri] = Cache{(int)sqlite3_last_insert_rowid(state->db), - storeDir, wantMassQuery, priority}; + state->caches[uri] = + Cache{static_cast(sqlite3_last_insert_rowid(state->db)), + storeDir, wantMassQuery, priority}; }); } @@ -181,8 +182,9 @@ class NarInfoDiskCacheImpl final : public NarInfoDiskCache { return false; } state->caches.emplace( - uri, Cache{(int)queryCache.getInt(0), queryCache.getStr(1), - queryCache.getInt(2) != 0, (int)queryCache.getInt(3)}); + uri, Cache{static_cast(queryCache.getInt(0)), + queryCache.getStr(1), queryCache.getInt(2) != 0, + static_cast(queryCache.getInt(3))}); } auto& cache(getCache(*state, uri)); diff --git a/third_party/nix/src/libstore/remote-fs-accessor.cc b/third_party/nix/src/libstore/remote-fs-accessor.cc index 2917f01f7939..d5b20288479c 100644 --- a/third_party/nix/src/libstore/remote-fs-accessor.cc +++ b/third_party/nix/src/libstore/remote-fs-accessor.cc @@ -75,12 +75,14 @@ std::pair, Path> RemoteFSAccessor::fetch(const Path& path_) { throw SysError("opening NAR cache file '%s'", cacheFile); } - if (lseek(fd.get(), offset, SEEK_SET) != (off_t)offset) { + if (lseek(fd.get(), offset, SEEK_SET) != + static_cast(offset)) { throw SysError("seeking in '%s'", cacheFile); } std::string buf(length, 0); - readFull(fd.get(), (unsigned char*)buf.data(), length); + readFull(fd.get(), reinterpret_cast(buf.data()), + length); return buf; }); diff --git a/third_party/nix/src/libstore/remote-store.cc b/third_party/nix/src/libstore/remote-store.cc index 7c45c5ff515d..784a95d2e9f2 100644 --- a/third_party/nix/src/libstore/remote-store.cc +++ b/third_party/nix/src/libstore/remote-store.cc @@ -546,7 +546,7 @@ BuildResult RemoteStore::buildDerivation(const Path& drvPath, BuildResult res; unsigned int status; conn->from >> status >> res.errorMsg; - res.status = (BuildResult::Status)status; + res.status = static_cast(status); return res; } diff --git a/third_party/nix/src/libstore/sqlite.cc b/third_party/nix/src/libstore/sqlite.cc index b6ecfce924a1..0fb32326f5c5 100644 --- a/third_party/nix/src/libstore/sqlite.cc +++ b/third_party/nix/src/libstore/sqlite.cc @@ -133,7 +133,7 @@ bool SQLiteStmt::Use::next() { } std::string SQLiteStmt::Use::getStr(int col) { - auto s = (const char*)sqlite3_column_text(stmt, col); + auto s = reinterpret_cast(sqlite3_column_text(stmt, col)); assert(s); return s; } diff --git a/third_party/nix/src/libstore/ssh.cc b/third_party/nix/src/libstore/ssh.cc index 8f27f5eb2286..52fbe6425458 100644 --- a/third_party/nix/src/libstore/ssh.cc +++ b/third_party/nix/src/libstore/ssh.cc @@ -111,7 +111,7 @@ Path SSHMaster::startMaster() { state->tmpDir = std::make_unique(createTempDir("", "nix", true, true, 0700)); - state->socketPath = (Path)*state->tmpDir + "/ssh.sock"; + state->socketPath = Path(*state->tmpDir) + "/ssh.sock"; Pipe out; out.create(); diff --git a/third_party/nix/src/libstore/store-api.cc b/third_party/nix/src/libstore/store-api.cc index 4f4083f64f67..dba9c8f95ec6 100644 --- a/third_party/nix/src/libstore/store-api.cc +++ b/third_party/nix/src/libstore/store-api.cc @@ -304,8 +304,8 @@ Path Store::makeFixedOutputPath(bool recursive, const Hash& hash, "output:out", hashString( htSHA256, - "fixed:out:" + (recursive ? (std::string) "r:" : "") + - hash.to_string(Base16) + ":"), + absl::StrCat("fixed:out:", (recursive ? "r:" : ""), + hash.to_string(Base16), ":")), name); } @@ -926,7 +926,7 @@ Strings ValidPathInfo::shortRefs() const { } std::string makeFixedOutputCA(bool recursive, const Hash& hash) { - return "fixed:" + (recursive ? (std::string) "r:" : "") + hash.to_string(); + return "fixed:" + (recursive ? std::string("r:") : "") + hash.to_string(); } void Store::addToStore(const ValidPathInfo& info, Source& narSource, -- cgit 1.4.1