[PATCH] D28515: [Support] - Introduce zlib::toString(zlib::Status)
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 11 07:42:17 PST 2017
This might be a reasonable early improvement, but maybe we should just
change the functions to return Error instead of Status?
Cheers,
Rafael
George Rimar via Phabricator <reviews at reviews.llvm.org> writes:
> grimar created this revision.
> grimar added reviewers: rafael, davide.
> grimar added subscribers: llvm-commits, grimar, evgeny777.
>
> Helper is useful for universal error messages
> when using zlib functionality.
> I plan to use it in https://reviews.llvm.org/D28105 or following patch for
> better uncompression errors diagnostic output.
>
>
> https://reviews.llvm.org/D28515
>
> Files:
> include/llvm/Support/Compression.h
> lib/Support/Compression.cpp
>
>
> Index: lib/Support/Compression.cpp
> ===================================================================
> --- lib/Support/Compression.cpp
> +++ lib/Support/Compression.cpp
> @@ -87,6 +87,25 @@
> return ::crc32(0, (const Bytef *)Buffer.data(), Buffer.size());
> }
>
> +StringRef zlib::toString(zlib::Status Stat) {
> + switch (Stat) {
> + case zlib::StatusOK:
> + return "";
> + case zlib::StatusUnsupported:
> + return "zlib is unavailable";
> + case zlib::StatusOutOfMemory:
> + return "there was not enough memory";
> + case zlib::StatusBufferTooShort:
> + return "there was not enough room in the output buffer";
> + case zlib::StatusInvalidArg:
> + return "invalid input parameter";
> + case zlib::StatusInvalidData:
> + return "data was corrupted or incomplete";
> + default:
> + llvm_unreachable("zlib status unknown");
> + }
> +}
> +
> #else
> bool zlib::isAvailable() { return false; }
> zlib::Status zlib::compress(StringRef InputBuffer,
> @@ -106,5 +125,8 @@
> uint32_t zlib::crc32(StringRef Buffer) {
> llvm_unreachable("zlib::crc32 is unavailable");
> }
> +StringRef zlib::toString(zlib::Status Stat) {
> + llvm_unreachable("zlib::toString is unavailable");
> +}
> #endif
>
> Index: include/llvm/Support/Compression.h
> ===================================================================
> --- include/llvm/Support/Compression.h
> +++ include/llvm/Support/Compression.h
> @@ -52,6 +52,8 @@
>
> uint32_t crc32(StringRef Buffer);
>
> +StringRef toString(Status Stat);
> +
> } // End of namespace zlib
>
> } // End of namespace llvm
>
>
> Index: lib/Support/Compression.cpp
> ===================================================================
> --- lib/Support/Compression.cpp
> +++ lib/Support/Compression.cpp
> @@ -87,6 +87,25 @@
> return ::crc32(0, (const Bytef *)Buffer.data(), Buffer.size());
> }
>
> +StringRef zlib::toString(zlib::Status Stat) {
> + switch (Stat) {
> + case zlib::StatusOK:
> + return "";
> + case zlib::StatusUnsupported:
> + return "zlib is unavailable";
> + case zlib::StatusOutOfMemory:
> + return "there was not enough memory";
> + case zlib::StatusBufferTooShort:
> + return "there was not enough room in the output buffer";
> + case zlib::StatusInvalidArg:
> + return "invalid input parameter";
> + case zlib::StatusInvalidData:
> + return "data was corrupted or incomplete";
> + default:
> + llvm_unreachable("zlib status unknown");
> + }
> +}
> +
> #else
> bool zlib::isAvailable() { return false; }
> zlib::Status zlib::compress(StringRef InputBuffer,
> @@ -106,5 +125,8 @@
> uint32_t zlib::crc32(StringRef Buffer) {
> llvm_unreachable("zlib::crc32 is unavailable");
> }
> +StringRef zlib::toString(zlib::Status Stat) {
> + llvm_unreachable("zlib::toString is unavailable");
> +}
> #endif
>
> Index: include/llvm/Support/Compression.h
> ===================================================================
> --- include/llvm/Support/Compression.h
> +++ include/llvm/Support/Compression.h
> @@ -52,6 +52,8 @@
>
> uint32_t crc32(StringRef Buffer);
>
> +StringRef toString(Status Stat);
> +
> } // End of namespace zlib
>
> } // End of namespace llvm
More information about the llvm-commits
mailing list