summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2006-08-02 05:20:08 (GMT)
committerTim Peters <tim.peters@gmail.com>2006-08-02 05:20:08 (GMT)
commita05f6e244a452a4a5ee647f6e1fc9ce01a13d696 (patch)
treea65e78bc7bf3606e4cb26d2ba42557ae6765bd13
parent99dfe3c411bdaa835075a27fdccefef13d88e214 (diff)
downloadcpython-a05f6e244a452a4a5ee647f6e1fc9ce01a13d696.zip
cpython-a05f6e244a452a4a5ee647f6e1fc9ce01a13d696.tar.gz
cpython-a05f6e244a452a4a5ee647f6e1fc9ce01a13d696.tar.bz2
_Stream.close(): Try to kill struct.pack() warnings when
writing the crc to file on the "PPC64 Debian trunk" buildbot when running test_tarfile. This is again a case where the native zlib crc is an unsigned 32-bit int, but the Python wrapper implicitly casts it to signed C long, so that "the sign bit looks different" on different platforms.
-rw-r--r--Lib/tarfile.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 47bc871..c185fbd 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -417,7 +417,13 @@ class _Stream:
self.fileobj.write(self.buf)
self.buf = ""
if self.comptype == "gz":
- self.fileobj.write(struct.pack("<l", self.crc))
+ # The native zlib crc is an unsigned 32-bit integer, but
+ # the Python wrapper implicitly casts that to a signed C
+ # long. So, on a 32-bit box self.crc may "look negative",
+ # while the same crc on a 64-bit box may "look positive".
+ # To avoid irksome warnings from the `struct` module, force
+ # it to look positive on all boxes.
+ self.fileobj.write(struct.pack("<L", self.crc & 0xffffffffL))
self.fileobj.write(struct.pack("<L", self.pos & 0xffffFFFFL))
if not self._extfileobj: