This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author petr.viktorin
Recipients ammar2, benjamin.peterson, cstratak, gregory.p.smith, mark.dickinson, meador.inge, petr.viktorin, vstinner
Date 2020-03-11.14:41:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1583937709.13.0.269433347234.issue39689@roundup.psfhosted.org>
In-reply-to
Content
> our unittest assuming that b'\xf0' should be true when interpreted as a bool is wrong.
> just get rid of that value from the loop in the test?

That could be the proper thing to do, but it does make it easy to invoke C undefined behavior from Python code. AFAIK, it would be the only such place in the struct module.

So, I'd like to assume and assert/test that sizeof(_Bool) is 1 and the false bit-pattern is (char)0, and with that, just use `PyBool_FromLong((_Bool)*p != 0)`.


> maybe we should be raising an error if the bytes are not a valid platform _Bool pattern?

That's quite hard to test for.
Also, on all current supported platforms, the patterns for bool and char 0 and 1 are the same. I don't see this being different elsewhere, but if there ever is a such a platform, let the test catch the broken assumption.
History
Date User Action Args
2020-03-11 14:41:49petr.viktorinsetrecipients: + petr.viktorin, gregory.p.smith, mark.dickinson, vstinner, benjamin.peterson, meador.inge, cstratak, ammar2
2020-03-11 14:41:49petr.viktorinsetmessageid: <1583937709.13.0.269433347234.issue39689@roundup.psfhosted.org>
2020-03-11 14:41:49petr.viktorinlinkissue39689 messages
2020-03-11 14:41:49petr.viktorincreate