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

Mark Dickinson report at bugs.python.org
Sat Jul 19 23:22:45 CEST 2014


Mark Dickinson added the comment:

The relevant piece of code in the struct module looks like this:

static PyObject *
nu_bool(const char *p, const formatdef *f)
{
    BOOL_TYPE x;
    memcpy((char *)&x, p, sizeof x);
    return PyBool_FromLong(x != 0);
}

Is it possible that BOOL_TYPE is a bitfield of length 1, and that clang is somehow making use of that fact?

One thing I don't understand is that this shouldn't affect *standard* packing and unpacking (as opposed to native), but I still see the problem for a format of "<????".  However, it's fine for ">????".  Some debugging shows that we're calling 'nu_bool' even for "<????", which is a bit odd.

----------
nosy: +mark.dickinson

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


More information about the Python-bugs-list mailing list