[issue22012] struct.unpack('?', '\x02') returns (False,) on Mac OSX

Mark Dickinson report at bugs.python.org
Sun Jul 20 10:25:18 CEST 2014


Mark Dickinson added the comment:

For native struct packing / unpacking, it's not even clear to me that this should be considered a bug (though for standard unpacking it definitely is):  the primary use-case for native unpacking is unpacking a collection of bytes that was written (from Python, or C, or ...) on the same machine, and in that case we're only going to be unpacking 0s and 1s.

FWIW, the docs say: "Either 0 or 1 in the native or standard bool representation will be packed, and any non-zero value will be True when unpacking.", so for native packing either the docs or the code need to be fixed.

The simplest solution would be to replace `nu_bool` with something identical to `bu_bool`.  In theory that would break on any platform where "sizeof(_Bool)" is greater than 1.  In practice, I doubt that Python's going to meet such platforms in a hurry.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22012>
_______________________________________


More information about the Python-bugs-list mailing list