This improves consistency with other places (e.g. llvm::compression::decompress,
llvm::object::Decompressor::decompress, llvm-objcopy).
Note: when zstd::uncompress was added, we noticed that the API `ZSTD_decompress`
is fine while the zlib API `uncompress` is a misnomer.
return error("Bad stri table: uncompress {0} -> {1} bytes is implausible",
R.rest().size(), UncompressedSize);
- if (llvm::Error E = llvm::compression::zlib::uncompress(
+ if (llvm::Error E = llvm::compression::zlib::decompress(
llvm::arrayRefFromStringRef(R.rest()), UncompressedStorage,
UncompressedSize))
return std::move(E);
return nullptr;
}
SmallVector<uint8_t, 0> Uncompressed;
- if (llvm::Error E = llvm::compression::zlib::uncompress(
+ if (llvm::Error E = llvm::compression::zlib::decompress(
llvm::arrayRefFromStringRef(Blob), Uncompressed, Record[0])) {
Error("could not decompress embedded file contents: " +
llvm::toString(std::move(E)));
auto *hdr = reinterpret_cast<const typename ELFT::Chdr *>(sec.rawData.data());
auto compressed = sec.rawData.slice(sizeof(typename ELFT::Chdr));
if (Error e = hdr->ch_type == ELFCOMPRESS_ZLIB
- ? compression::zlib::uncompress(compressed, out, size)
- : compression::zstd::uncompress(compressed, out, size))
+ ? compression::zlib::decompress(compressed, out, size)
+ : compression::zstd::decompress(compressed, out, size))
fatal(toString(&sec) +
": decompress failed: " + llvm::toString(std::move(e)));
}
auto compressed = rawData.slice(sizeof(typename ELFT::Chdr));
size_t size = uncompressedSize;
if (Error e = hdr->ch_type == ELFCOMPRESS_ZLIB
- ? compression::zlib::uncompress(compressed, buf, size)
- : compression::zstd::uncompress(compressed, buf, size))
+ ? compression::zlib::decompress(compressed, buf, size)
+ : compression::zstd::decompress(compressed, buf, size))
fatal(toString(this) +
": decompress failed: " + llvm::toString(std::move(e)));
uint8_t *bufEnd = buf + size;
//
//===----------------------------------------------------------------------===//
//
-// This file contains basic functions for compression/uncompression.
+// This file contains basic functions for compression/decompression.
//
//===----------------------------------------------------------------------===//
SmallVectorImpl<uint8_t> &CompressedBuffer,
int Level = DefaultCompression);
-Error uncompress(ArrayRef<uint8_t> Input, uint8_t *UncompressedBuffer,
+Error decompress(ArrayRef<uint8_t> Input, uint8_t *Output,
size_t &UncompressedSize);
-Error uncompress(ArrayRef<uint8_t> Input,
- SmallVectorImpl<uint8_t> &UncompressedBuffer,
+Error decompress(ArrayRef<uint8_t> Input, SmallVectorImpl<uint8_t> &Output,
size_t UncompressedSize);
} // End of namespace zlib
SmallVectorImpl<uint8_t> &CompressedBuffer,
int Level = DefaultCompression);
-Error uncompress(ArrayRef<uint8_t> Input, uint8_t *UncompressedBuffer,
+Error decompress(ArrayRef<uint8_t> Input, uint8_t *Output,
size_t &UncompressedSize);
-Error uncompress(ArrayRef<uint8_t> Input,
- SmallVectorImpl<uint8_t> &UncompressedBuffer,
+Error decompress(ArrayRef<uint8_t> Input, SmallVectorImpl<uint8_t> &Output,
size_t UncompressedSize);
} // End of namespace zstd
Error Decompressor::decompress(MutableArrayRef<uint8_t> Buffer) {
size_t Size = Buffer.size();
- return compression::zlib::uncompress(arrayRefFromStringRef(SectionData),
+ return compression::zlib::decompress(arrayRefFromStringRef(SectionData),
Buffer.data(), Size);
}
// Read compressed filenames.
StringRef CompressedFilenames = Data.substr(0, CompressedLen);
Data = Data.substr(CompressedLen);
- auto Err = compression::zlib::uncompress(
+ auto Err = compression::zlib::decompress(
arrayRefFromStringRef(CompressedFilenames), StorageBuf,
UncompressedLen);
if (Err) {
if (!llvm::compression::zlib::isAvailable())
return make_error<InstrProfError>(instrprof_error::zlib_unavailable);
- if (Error E = compression::zlib::uncompress(
+ if (Error E = compression::zlib::decompress(
makeArrayRef(P, CompressedSize), UncompressedNameStrings,
UncompressedSize)) {
consumeError(std::move(E));
uint8_t *Buffer = Allocator.Allocate<uint8_t>(DecompressBufSize);
size_t UCSize = DecompressBufSize;
- llvm::Error E = compression::zlib::uncompress(
+ llvm::Error E = compression::zlib::decompress(
makeArrayRef(Data, *CompressSize), Buffer, UCSize);
if (E)
return sampleprof_error::uncompress_failed;
size_t UncompressedSize) {
switch (F) {
case compression::Format::Zlib:
- return zlib::uncompress(Input, Output, UncompressedSize);
+ return zlib::decompress(Input, Output, UncompressedSize);
case compression::Format::Zstd:
- return zstd::uncompress(Input, Output, UncompressedSize);
+ return zstd::decompress(Input, Output, UncompressedSize);
}
llvm_unreachable("");
}
CompressedBuffer.truncate(CompressedSize);
}
-Error zlib::uncompress(ArrayRef<uint8_t> Input, uint8_t *UncompressedBuffer,
+Error zlib::decompress(ArrayRef<uint8_t> Input, uint8_t *Output,
size_t &UncompressedSize) {
- int Res =
- ::uncompress((Bytef *)UncompressedBuffer, (uLongf *)&UncompressedSize,
- (const Bytef *)Input.data(), Input.size());
+ int Res = ::uncompress((Bytef *)Output, (uLongf *)&UncompressedSize,
+ (const Bytef *)Input.data(), Input.size());
// Tell MemorySanitizer that zlib output buffer is fully initialized.
// This avoids a false report when running LLVM with uninstrumented ZLib.
- __msan_unpoison(UncompressedBuffer, UncompressedSize);
+ __msan_unpoison(Output, UncompressedSize);
return Res ? make_error<StringError>(convertZlibCodeToString(Res),
inconvertibleErrorCode())
: Error::success();
}
-Error zlib::uncompress(ArrayRef<uint8_t> Input,
- SmallVectorImpl<uint8_t> &UncompressedBuffer,
+Error zlib::decompress(ArrayRef<uint8_t> Input,
+ SmallVectorImpl<uint8_t> &Output,
size_t UncompressedSize) {
- UncompressedBuffer.resize_for_overwrite(UncompressedSize);
- Error E =
- zlib::uncompress(Input, UncompressedBuffer.data(), UncompressedSize);
- if (UncompressedSize < UncompressedBuffer.size())
- UncompressedBuffer.truncate(UncompressedSize);
+ Output.resize_for_overwrite(UncompressedSize);
+ Error E = zlib::decompress(Input, Output.data(), UncompressedSize);
+ if (UncompressedSize < Output.size())
+ Output.truncate(UncompressedSize);
return E;
}
SmallVectorImpl<uint8_t> &CompressedBuffer, int Level) {
llvm_unreachable("zlib::compress is unavailable");
}
-Error zlib::uncompress(ArrayRef<uint8_t> Input, uint8_t *UncompressedBuffer,
+Error zlib::decompress(ArrayRef<uint8_t> Input, uint8_t *UncompressedBuffer,
size_t &UncompressedSize) {
- llvm_unreachable("zlib::uncompress is unavailable");
+ llvm_unreachable("zlib::decompress is unavailable");
}
-Error zlib::uncompress(ArrayRef<uint8_t> Input,
+Error zlib::decompress(ArrayRef<uint8_t> Input,
SmallVectorImpl<uint8_t> &UncompressedBuffer,
size_t UncompressedSize) {
- llvm_unreachable("zlib::uncompress is unavailable");
+ llvm_unreachable("zlib::decompress is unavailable");
}
#endif
CompressedBuffer.truncate(CompressedSize);
}
-Error zstd::uncompress(ArrayRef<uint8_t> Input, uint8_t *UncompressedBuffer,
+Error zstd::decompress(ArrayRef<uint8_t> Input, uint8_t *Output,
size_t &UncompressedSize) {
- const size_t Res =
- ::ZSTD_decompress(UncompressedBuffer, UncompressedSize,
- (const uint8_t *)Input.data(), Input.size());
+ const size_t Res = ::ZSTD_decompress(
+ Output, UncompressedSize, (const uint8_t *)Input.data(), Input.size());
UncompressedSize = Res;
// Tell MemorySanitizer that zstd output buffer is fully initialized.
// This avoids a false report when running LLVM with uninstrumented ZLib.
- __msan_unpoison(UncompressedBuffer, UncompressedSize);
+ __msan_unpoison(Output, UncompressedSize);
return ZSTD_isError(Res) ? make_error<StringError>(ZSTD_getErrorName(Res),
inconvertibleErrorCode())
: Error::success();
}
-Error zstd::uncompress(ArrayRef<uint8_t> Input,
- SmallVectorImpl<uint8_t> &UncompressedBuffer,
+Error zstd::decompress(ArrayRef<uint8_t> Input,
+ SmallVectorImpl<uint8_t> &Output,
size_t UncompressedSize) {
- UncompressedBuffer.resize_for_overwrite(UncompressedSize);
- Error E =
- zstd::uncompress(Input, UncompressedBuffer.data(), UncompressedSize);
- if (UncompressedSize < UncompressedBuffer.size())
- UncompressedBuffer.truncate(UncompressedSize);
+ Output.resize_for_overwrite(UncompressedSize);
+ Error E = zstd::decompress(Input, Output.data(), UncompressedSize);
+ if (UncompressedSize < Output.size())
+ Output.truncate(UncompressedSize);
return E;
}
SmallVectorImpl<uint8_t> &CompressedBuffer, int Level) {
llvm_unreachable("zstd::compress is unavailable");
}
-Error zstd::uncompress(ArrayRef<uint8_t> Input, uint8_t *UncompressedBuffer,
+Error zstd::decompress(ArrayRef<uint8_t> Input, uint8_t *Output,
size_t &UncompressedSize) {
- llvm_unreachable("zstd::uncompress is unavailable");
+ llvm_unreachable("zstd::decompress is unavailable");
}
-Error zstd::uncompress(ArrayRef<uint8_t> Input,
- SmallVectorImpl<uint8_t> &UncompressedBuffer,
+Error zstd::decompress(ArrayRef<uint8_t> Input,
+ SmallVectorImpl<uint8_t> &Output,
size_t UncompressedSize) {
- llvm_unreachable("zstd::uncompress is unavailable");
+ llvm_unreachable("zstd::decompress is unavailable");
}
#endif
zlib::compress(arrayRefFromStringRef(Input), Compressed, Level);
// Check that uncompressed buffer is the same as original.
- Error E = zlib::uncompress(Compressed, Uncompressed, Input.size());
+ Error E = zlib::decompress(Compressed, Uncompressed, Input.size());
EXPECT_FALSE(std::move(E));
EXPECT_EQ(Input, toStringRef(Uncompressed));
- // decompress with Z dispatches to zlib::uncompress.
+ // decompress with Z dispatches to zlib::decompress.
E = compression::decompress(DebugCompressionType::Zlib, Compressed,
Uncompressed, Input.size());
EXPECT_FALSE(std::move(E));
EXPECT_EQ(Input, toStringRef(Uncompressed));
if (Input.size() > 0) {
- // Uncompression fails if expected length is too short.
- E = zlib::uncompress(Compressed, Uncompressed, Input.size() - 1);
+ // Decompression fails if expected length is too short.
+ E = zlib::decompress(Compressed, Uncompressed, Input.size() - 1);
EXPECT_EQ("zlib error: Z_BUF_ERROR", llvm::toString(std::move(E)));
}
}
zstd::compress(arrayRefFromStringRef(Input), Compressed, Level);
// Check that uncompressed buffer is the same as original.
- Error E = zstd::uncompress(Compressed, Uncompressed, Input.size());
+ Error E = zstd::decompress(Compressed, Uncompressed, Input.size());
EXPECT_FALSE(std::move(E));
EXPECT_EQ(Input, toStringRef(Uncompressed));
- // uncompress with Zstd dispatches to zstd::uncompress.
+ // decompress with Zstd dispatches to zstd::decompress.
E = compression::decompress(DebugCompressionType::Zstd, Compressed,
Uncompressed, Input.size());
EXPECT_FALSE(std::move(E));
EXPECT_EQ(Input, toStringRef(Uncompressed));
if (Input.size() > 0) {
- // Uncompression fails if expected length is too short.
- E = zstd::uncompress(Compressed, Uncompressed, Input.size() - 1);
+ // Decompression fails if expected length is too short.
+ E = zstd::decompress(Compressed, Uncompressed, Input.size() - 1);
EXPECT_EQ("Destination buffer is too small", llvm::toString(std::move(E)));
}
}