mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Try to squash struct.pack warnings on the "amd64 gentoo trunk"
buildbot (& possibly other 64-bit boxes) during test_gzip. The native zlib crc32 function returns an unsigned 32-bit integer, which the Python wrapper implicitly casts to C long. Therefore the same crc can "look negative" on a 32-bit box but "look positive" on a 64-bit box. This patch papers over that platform difference when writing the crc to file. It may be better to change the Python wrapper, either to make the result "look positive" on all platforms (which means it may have to return a Python long at times on a 32-bit box), or to keep the sign the same across boxes. But that would be a visible change in what users see, while the current hack changes no visible behavior (well, apart from stopping the struct deprecation warning). Note that the module-level write32() function is no longer used.
This commit is contained in:
parent
4edcba69f3
commit
62decc9f49
1 changed files with 7 additions and 1 deletions
|
@ -315,7 +315,13 @@ class GzipFile:
|
|||
def close(self):
|
||||
if self.mode == WRITE:
|
||||
self.fileobj.write(self.compress.flush())
|
||||
write32(self.fileobj, 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.
|
||||
write32u(self.fileobj, LOWU32(self.crc))
|
||||
# self.size may exceed 2GB, or even 4GB
|
||||
write32u(self.fileobj, LOWU32(self.size))
|
||||
self.fileobj = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue