This is an archive of the discontinued LLVM Phabricator instance.

Fix TestSBData.py on Windows (which uses Python 3)
ClosedPublic

Authored by amccarth on Feb 20 2018, 3:18 PM.

Details

Summary

This test uses the SB API to set and read back bytes of data, and it works fine when Python 2 is the scripting language. On Windows, however, Python 3 is the default.

Note this line from the test:

addr_data = '\x11\x22\x33\x44\x55\x66\x77\x88'

The intent here is to create an array of eight bytes as a string literal. This works in Python 2, but Python 3 treats those as a series Unicode code points, and the CPython implementation happens to encode those code points as UTF-8. The first seven characters encode directly as single bytes of the same value. But the UTF-8 encoding of 0x88 is two bytes long: 0xC2 0x88. So the input array doesn't have the intended data at the end, so the test cases that use all eight bytes fail.

Adding the b prefix tells Python 3 that we want a byte array rather than a string. With this change, the test now passes on Windows. I believe this also works for Python 2 (Python 2.7 accepts the b-prefix and seems to do the right thing), but I'm not very familiar with the details of Python 2.

Diff Detail

Repository
rL LLVM

Event Timeline

amccarth created this revision.Feb 20 2018, 3:18 PM
zturner accepted this revision.Feb 22 2018, 2:10 PM
zturner added reviewers: asmith, stella.stamenova.
This revision is now accepted and ready to land.Feb 22 2018, 2:10 PM
This revision was automatically updated to reflect the committed changes.