]> granicus.if.org Git - python/commitdiff
_Stream.close(): Try to kill struct.pack() warnings when
authorTim Peters <tim.peters@gmail.com>
Wed, 2 Aug 2006 05:20:08 +0000 (05:20 +0000)
committerTim Peters <tim.peters@gmail.com>
Wed, 2 Aug 2006 05:20:08 +0000 (05:20 +0000)
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.

Lib/tarfile.py

index 47bc8719c3521ab3339cf8a24d62b53bb9a78aa9..c185fbd49eb0bc577c58fa46f60bd2d6f4652843 100644 (file)
@@ -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: