[Python-Dev] Re: Unpacking native bools in the struct module: Is Python relying on undefined behavior?

2020年2月27日 09:20:22 -0800

> 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);
 }
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/L6F66QMZHEG3TOIC2ERDFDUXHRSITUMZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to