Skip to content

Commit

Permalink
[pzstd] Fixes for Windows build
Browse files Browse the repository at this point in the history
* `#include <algorithm>`
* Fix conversion warnings
* Assert that windowLog <= 23, which is currently always the case.
  This could be loosened, but we aren't looking to add new functionality.

Fixes on top of PR #3375 by @eli-schwartz, which added Windows CI for contrib & programs.
  • Loading branch information
terrelln committed Dec 19, 2022
1 parent 9ab1213 commit 5eb15ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion contrib/pzstd/Pzstd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "utils/ThreadPool.h"
#include "utils/WorkQueue.h"

#include <algorithm>
#include <chrono>
#include <cinttypes>
#include <cstddef>
Expand Down Expand Up @@ -336,6 +337,10 @@ static size_t calculateStep(
const ZSTD_parameters &params) {
(void)size;
(void)numThreads;
// Not validated to work correctly for window logs > 23.
// It will definitely fail if windowLog + 2 is >= 4GB because
// the skippable frame can only store sizes up to 4GB.
assert(params.cParams.windowLog <= 23);
return size_t{1} << (params.cParams.windowLog + 2);
}

Expand Down Expand Up @@ -587,7 +592,8 @@ std::uint64_t writeFile(
// start writing before compression is done because we need to know the
// compressed size.
// Wait for the compressed size to be available and write skippable frame
SkippableFrame frame(out->size());
assert(uint64_t(out->size()) < uint64_t(1) << 32);
SkippableFrame frame(uint32_t(out->size()));
if (!writeData(frame.data(), outputFd)) {
errorHolder.setError("Failed to write output");
return bytesWritten;
Expand Down
5 changes: 3 additions & 2 deletions contrib/pzstd/utils/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <sys/stat.h>
#include <cerrno>
#include <cstdint>
#include <limits>
#include <system_error>

// A small subset of `std::filesystem`.
Expand Down Expand Up @@ -82,11 +83,11 @@ inline std::uintmax_t file_size(
std::error_code& ec) noexcept {
auto stat = status(path, ec);
if (ec) {
return -1;
return std::numeric_limits<uintmax_t>::max();
}
if (!is_regular_file(stat)) {
ec.assign(ENOTSUP, std::generic_category());
return -1;
return std::numeric_limits<uintmax_t>::max();
}
ec.clear();
return stat.st_size;
Expand Down
1 change: 1 addition & 0 deletions contrib/pzstd/utils/Range.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "utils/Likely.h"

#include <algorithm>
#include <cstddef>
#include <cstring>
#include <stdexcept>
Expand Down

0 comments on commit 5eb15ee

Please sign in to comment.