This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy, tests] Fix several llvm-objcopy tests
ClosedPublic

Authored by stella.stamenova on Jul 18 2018, 3:09 PM.

Details

Summary

In Python 3, sys.stdout.write expects a string rather than bytes. In order to be able to write the bytes to stdout, we need to use the buffer directly instead. This change is borrowing the implementation for writing to stdout that cat.py uses. Note that we cannot use cat.py directly because the file we are trying to open is a gzip file.

Diff Detail

Repository
rL LLVM

Event Timeline

thanks!
@stella.stamenova - do i understand correctly that the new version works correctly with both - python2 and python3 ? (just in case)

This revision is now accepted and ready to land.Jul 18 2018, 3:33 PM

@alexshap Yes! I tested it with Python2 and Python3 both.

What would the consequence be of just converting the bytes to a string and writing that out? I have neither a windows box nor python 3 installed.

What would the consequence be of just converting the bytes to a string and writing that out? I have neither a windows box nor python 3 installed.

I suppose we could try a conversion, but we would have to make a guess on the encoding and that could be a problem also. Do you see a benefit in doing a byte to string conversion over writing the bytes to the buffer?

jakehehrlich accepted this revision.Jul 19 2018, 10:44 AM

The reason for it was just that this all seemed too complicated to me for "something so simple" but now that I've looked into the problem I think what you've done makes perfect sense.

This revision was automatically updated to reflect the committed changes.