Petr Viktorin <encu...@gmail.com> added the comment:
C compiler dev that it's indeed undefined behavior. > Quick and obvious fix: > > static PyObject * > nu_bool(const char *p, const formatdef *f) > { > char x; > memcpy((char *)&x, p, sizeof x); > return PyBool_FromLong(x != 0); > } > > Which is optimized to > > static PyObject * > nu_bool(const char *p, const formatdef *f) > { > return PyBool_FromLong(*p != 0); > } I'm left with a question for CPython's struct experts: The above would be my preferred fix, but the Python code is asking to convert a memory buffer to bool *using platform-specific semantics*. Is this fix OK if C treats a \xf0 _Bool as falsey? (Also, this assumes size of _Bool is the same as size of char. I guess we can add a build-time assertion for that, and say we don't support platforms where that's not the case.) ---------- nosy: +mark.dickinson, meador.inge _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39689> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com