mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-130317: Fix strict aliasing in PyFloat_Pack8() (#133150)
* Fix strict aliasing in PyFloat_Pack8() and PyFloat_Pack4(). * Fix _testcapi.float_set_snan() on x86 (32-bit).
This commit is contained in:
parent
698c6e3a0c
commit
02cd6d7097
2 changed files with 12 additions and 9 deletions
|
@ -182,8 +182,11 @@ _testcapi_float_set_snan(PyObject *module, PyObject *obj)
|
|||
uint64_t v;
|
||||
memcpy(&v, &d, 8);
|
||||
v &= ~(1ULL << 51); /* make sNaN */
|
||||
memcpy(&d, &v, 8);
|
||||
return PyFloat_FromDouble(d);
|
||||
|
||||
// gh-130317: memcpy() is needed to preserve the sNaN flag on x86 (32-bit)
|
||||
PyObject *res = PyFloat_FromDouble(0.0);
|
||||
memcpy(&((PyFloatObject *)res)->ob_fval, &v, 8);
|
||||
return res;
|
||||
}
|
||||
|
||||
static PyMethodDef test_methods[] = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue