Skip to content

Commit 05a2c8a

Browse files
committed
gh-145633: drop runtime checks for floatting-point format in the array module
1 parent 91e1312 commit 05a2c8a

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

Modules/arraymodule.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "pycore_bytesobject.h" // _PyBytes_Repeat
1212
#include "pycore_call.h" // _PyObject_CallMethod()
1313
#include "pycore_ceval.h" // _PyEval_GetBuiltin()
14+
#include "pycore_floatobject.h" // _PY_FLOAT_BIG_ENDIAN
1415
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
1516
#include "pycore_moduleobject.h" // _PyModule_GetState()
1617
#include "pycore_weakref.h" // FT_CLEAR_WEAKREFS()
@@ -91,9 +92,6 @@ enum machine_format_code {
9192
* instead of using the memory content of the array directly. In that
9293
* case, the array_reconstructor mechanism is bypassed completely, and
9394
* the standard array constructor is used instead.
94-
*
95-
* This is will most likely occur when the machine doesn't use IEEE
96-
* floating-point numbers.
9795
*/
9896

9997
UNSIGNED_INT8 = 0,
@@ -2011,24 +2009,10 @@ typecode_to_mformat_code(char typecode)
20112009
return UTF32_LE + is_big_endian;
20122010

20132011
case 'f':
2014-
if (sizeof(float) == 4) {
2015-
const float y = 16711938.0;
2016-
if (memcmp(&y, "\x4b\x7f\x01\x02", 4) == 0)
2017-
return IEEE_754_FLOAT_BE;
2018-
if (memcmp(&y, "\x02\x01\x7f\x4b", 4) == 0)
2019-
return IEEE_754_FLOAT_LE;
2020-
}
2021-
return UNKNOWN_FORMAT;
2012+
return _PY_FLOAT_BIG_ENDIAN ? IEEE_754_FLOAT_BE : IEEE_754_FLOAT_LE;
20222013

20232014
case 'd':
2024-
if (sizeof(double) == 8) {
2025-
const double x = 9006104071832581.0;
2026-
if (memcmp(&x, "\x43\x3f\xff\x01\x02\x03\x04\x05", 8) == 0)
2027-
return IEEE_754_DOUBLE_BE;
2028-
if (memcmp(&x, "\x05\x04\x03\x02\x01\xff\x3f\x43", 8) == 0)
2029-
return IEEE_754_DOUBLE_LE;
2030-
}
2031-
return UNKNOWN_FORMAT;
2015+
return _PY_FLOAT_BIG_ENDIAN ? IEEE_754_DOUBLE_BE : IEEE_754_DOUBLE_LE;
20322016

20332017
/* Integers */
20342018
case 'h':

0 commit comments

Comments
 (0)