Mercurial > cpython-lru_cache-weakref
diff Python/marshal.c @ 14678:94ca87a3e5ee legacy-trunk
Obscure marshal fixes:
When reading a short, sign-extend on platforms where shorts are
bigger than 16 bits.
When reading a long, repair the unportable sign extension that was
being done for 64-bit machines (it assumed that signed right shift
sign-extends).
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Tue, 19 Sep 2000 08:54:13 +0000 |
| parents | 6f6f965c5e2d |
| children | ddd903fb6a71 |
line wrap: on
line diff
--- a/Python/marshal.c Tue Sep 19 04:11:46 2000 +0000 +++ b/Python/marshal.c Tue Sep 19 08:54:13 2000 +0000 @@ -307,7 +307,8 @@ register short x; x = r_byte(p); x |= r_byte(p) << 8; - /* XXX If your short is > 16 bits, add sign-extension here!!! */ + /* Sign-extension, in case short greater than 16 bits */ + x |= -(x & 0x8000); return x; } @@ -330,8 +331,7 @@ } #if SIZEOF_LONG > 4 /* Sign extension for 64-bit machines */ - x <<= (8*sizeof(long) - 32); - x >>= (8*sizeof(long) - 32); + x |= -(x & 0x80000000L); #endif return x; } @@ -342,7 +342,7 @@ register long x; x = r_long(p); #if SIZEOF_LONG > 4 - x = (x & 0xFFFFFFFF) | (r_long(p) << 32); + x = (x & 0xFFFFFFFFL) | (r_long(p) << 32); #else if (r_long(p) != 0) { PyObject *f = PySys_GetObject("stderr");
