This is an archive of the discontinued LLVM Phabricator instance.

[Support] - Introduce zlib::toString(zlib::Status)
AbandonedPublic

Authored by grimar on Jan 10 2017, 5:52 AM.

Details

Reviewers
davide
rafael
Summary

Helper is useful for universal error messages
when using zlib functionality.
I plan to use it in D28105 or following patch for
better uncompression errors diagnostic output.

Diff Detail

Event Timeline

grimar updated this revision to Diff 83802.Jan 10 2017, 5:52 AM
grimar retitled this revision from to [Support] - Introduce zlib::toString(zlib::Status).
grimar updated this object.
grimar added reviewers: rafael, davide.
grimar added subscribers: llvm-commits, grimar, evgeny777.
davide edited edge metadata.Jan 10 2017, 8:25 AM

Can you add (unit)tests for this?

lib/Support/Compression.cpp
23–24

isAvailable() returns always true, so, how can this be ever hit?

grimar added inline comments.Jan 10 2017, 11:57 PM
lib/Support/Compression.cpp
23–24

I can imagine some code like next:

Status S = zlib::StatusUnsupported;
if (zlib::isAvailable() {
  S = ...; //Do something
}

if (S != zlib::StatusOK)
  printError(zlib::toString(S)

So it looks can be useful to cover this enum value too.

grimar added inline comments.Jan 11 2017, 12:05 AM
lib/Support/Compression.cpp
23–24

Ah, my example will not work currently, I see now.
I am thinking about making toString() to have single implementation for cases when HAVE_LIBZ and !HAVE_LIBZ.
That way example I showed will work and makes sence.

grimar updated this revision to Diff 83931.Jan 11 2017, 2:02 AM
grimar edited edge metadata.
  • Added unittest
  • Made toString() to be single implementation for cases when ZLib is available/NA
mgorny added a subscriber: mgorny.Jan 11 2017, 7:26 AM
mgorny added inline comments.
unittests/Support/CompressionTest.cpp
70

To be honest, I don't think this test takes makes a lot of sense since it's pretty much a duplicate of the function itself. As far as I can see, rather than catching bugs it's going to get people frustrated when they change one of the messages.

grimar added inline comments.Jan 11 2017, 7:31 AM
unittests/Support/CompressionTest.cpp
70

That is why I did not add it in inital diff.
I was and still unsure if we should or should not test string values like here.

davide requested changes to this revision.Jan 12 2017, 7:58 PM
davide edited edge metadata.
davide added inline comments.
unittests/Support/CompressionTest.cpp
70

What I actually meant is to create test scenarios triggering these errors, not copying the function itself.

This revision now requires changes to proceed.Jan 12 2017, 7:58 PM

As an alternative, you can merge the patch and the patch where you plan to use this code together (which would make more sense, IMHO).
In fact, I'm still confused why you splitted this in the first place.

As an alternative, you can merge the patch and the patch where you plan to use this code together (which would make more sense, IMHO).
In fact, I'm still confused why you splitted this in the first place.

I wanted to use it in LLD. That would mean 2 patches anyways, LLD and this one.

Previously Rafael suggested to return Error for methods of this API instead of status.
I think that is good idea, result will be single patch affecting users of this (Decomressor class, something else probably) and changing API itself in a single patch, just like you suggesting.

As an alternative, you can merge the patch and the patch where you plan to use this code together (which would make more sense, IMHO).
In fact, I'm still confused why you splitted this in the first place.

I wanted to use it in LLD. That would mean 2 patches anyways, LLD and this one.

Previously Rafael suggested to return Error for methods of this API instead of status.
I think that is good idea, result will be single patch affecting users of this (Decomressor class, something else probably) and changing API itself in a single patch, just like you suggesting.

Yes, that would be better.

grimar abandoned this revision.Jan 16 2017, 2:59 AM

D28684 posted instead.