summaryrefslogtreecommitdiffstats
path: root/Modules/structmodule.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-04-08 23:39:38 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-04-08 23:39:38 (GMT)
commitf0e717bdb1729ba93f8f2524962ee95ab1d7d425 (patch)
treed68c784ba9420c2d65df8680156838d2f66c6292 /Modules/structmodule.c
parent9cec8fba06e66e92769e56130d581ea569399563 (diff)
downloadcpython-f0e717bdb1729ba93f8f2524962ee95ab1d7d425.zip
cpython-f0e717bdb1729ba93f8f2524962ee95ab1d7d425.tar.gz
cpython-f0e717bdb1729ba93f8f2524962ee95ab1d7d425.tar.bz2
Repair portability of sign extension when reading signed ints on boxes
where sizeof(long)==8. This *was* broken on boxes where signed right shifts didn't sign-extend, but not elsewhere. Unfortunately, apart from the Cray T3E I don't know of such a box, and Guido has so far refused to buy me any Cray machines for home Python testing <wink>. More immediately interesting would be if someone could please test this on *any* sizeof(long)==8 box, to make sure I didn't break it.
Diffstat (limited to 'Modules/structmodule.c')
-rw-r--r--Modules/structmodule.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/Modules/structmodule.c b/Modules/structmodule.c
index a28ca54..9d1c436 100644
--- a/Modules/structmodule.c
+++ b/Modules/structmodule.c
@@ -653,11 +653,9 @@ bu_int(const char *p, const formatdef *f)
do {
x = (x<<8) | (*p++ & 0xFF);
} while (--i > 0);
- i = 8*(sizeof(long) - f->size);
- if (i) {
- x <<= i;
- x >>= i;
- }
+ /* Extend the sign bit. */
+ if (SIZEOF_LONG > f->size)
+ x |= -(x & (1L << (8*f->size - 1)));
return PyInt_FromLong(x);
}
@@ -767,11 +765,9 @@ lu_int(const char *p, const formatdef *f)
do {
x = (x<<8) | (p[--i] & 0xFF);
} while (i > 0);
- i = 8*(sizeof(long) - f->size);
- if (i) {
- x <<= i;
- x >>= i;
- }
+ /* Extend the sign bit. */
+ if (SIZEOF_LONG > f->size)
+ x |= -(x & (1L << (8*f->size - 1)));
return PyInt_FromLong(x);
}