Skip to content

Commit 964e02a

Browse files
committed
fix test_float regression and 64-bit size mismatch issue
1 parent 955b64c commit 964e02a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Modules/_struct.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,14 +1486,28 @@ init_struct(void)
14861486
other = lilendian_table;
14871487
else
14881488
other = bigendian_table;
1489+
/* Scan through the native table, find a matching
1490+
entry in the endian table and swap in the
1491+
native implementations whenever possible
1492+
(64-bit platforms may not have "standard" sizes) */
14891493
while (native->format != '\0' && other->format != '\0') {
14901494
ptr = other;
14911495
while (ptr->format != '\0') {
14921496
if (ptr->format == native->format) {
1493-
ptr->pack = native->pack;
1494-
ptr->unpack = native->unpack;
1497+
/* Match faster when formats are
1498+
listed in the same order */
14951499
if (ptr == other)
14961500
other++;
1501+
/* Only use the trick if the
1502+
size matches */
1503+
if (ptr->size != native->size)
1504+
break;
1505+
/* Skip float and double, could be
1506+
"unknown" float format */
1507+
if (ptr->format == 'd' || ptr->format == 'f')
1508+
break;
1509+
ptr->pack = native->pack;
1510+
ptr->unpack = native->unpack;
14971511
break;
14981512
}
14991513
ptr++;

0 commit comments

Comments
 (0)