Index: Doc/tutorial/stdlib2.rst =================================================================== --- Doc/tutorial/stdlib2.rst (revision 60224) +++ Doc/tutorial/stdlib2.rst (working copy) @@ -133,9 +133,11 @@ ======================================= The :mod:`struct` module provides :func:`pack` and :func:`unpack` functions for -working with variable length binary record formats. The following example shows -how to loop through header information in a ZIP file (with pack codes ``"H"`` -and ``"L"`` representing two and four byte unsigned numbers respectively):: +working with variable length binary record formats. The following example +shows how to loop through header information in a ZIP file without using the +:mod:`zipfile` module. Pack codes ``"H"`` and ``"I"`` represent two and four +byte unsigned numbers respectively. The ``"<"`` indicates that they are all in +little-endian byte order:: import struct @@ -143,7 +145,7 @@ start = 0 for i in range(3): # show the first 3 file headers start += 14 - fields = struct.unpack('LLLHH', data[start:start+16]) + fields = struct.unpack('L", len(s)) + slen = struct.pack(">I", len(s)) return slen + s def handleError(self, record): Index: Lib/logging/config.py =================================================================== --- Lib/logging/config.py (revision 60224) +++ Lib/logging/config.py (working copy) @@ -284,7 +284,7 @@ Handle a request. Each request is expected to be a 4-byte length, packed using - struct.pack(">L", n), followed by the config file. + struct.pack(">I", n), followed by the config file. Uses fileConfig() to do the grunt work. """ import tempfile @@ -292,7 +292,7 @@ conn = self.connection chunk = conn.recv(4) if len(chunk) == 4: - slen = struct.unpack(">L", chunk)[0] + slen = struct.unpack(">I", chunk)[0] chunk = self.connection.recv(slen) while len(chunk) < slen: chunk = chunk + conn.recv(slen - len(chunk)) Index: Lib/posixfile.py =================================================================== --- Lib/posixfile.py (revision 60224) +++ Lib/posixfile.py (working copy) @@ -205,6 +205,12 @@ l_type, l_whence, l_start, l_len, l_sysid, l_pid, l_vfs = \ struct.unpack('hhlllii', flock) elif sys.platform == "linux2": + # XXX(gregory.p.smith): is this correct on 64bit + # platforms?? the fcntl struct is defined using off_t + # and pid_t which may not map to 'l' and 'h'. The + # Lib/test/test_fcntl.py code has some code to detect + # which size to use on BSD flavors. Does linux need + # that? l_type, l_whence, l_start, l_len, l_pid, l_sysid = \ struct.unpack('hhllhh', flock) else: Index: Lib/chunk.py =================================================================== --- Lib/chunk.py (revision 60224) +++ Lib/chunk.py (working copy) @@ -62,7 +62,7 @@ if len(self.chunkname) < 4: raise EOFError try: - self.chunksize = struct.unpack(strflag+'L', file.read(4))[0] + self.chunksize = struct.unpack(strflag+'I', file.read(4))[0] except struct.error: raise EOFError if inclheader: Index: Lib/aifc.py =================================================================== --- Lib/aifc.py (revision 60224) +++ Lib/aifc.py (working copy) @@ -149,13 +149,13 @@ def _read_long(file): try: - return struct.unpack('>l', file.read(4))[0] + return struct.unpack('>i', file.read(4))[0] except struct.error: raise EOFError def _read_ulong(file): try: - return struct.unpack('>L', file.read(4))[0] + return struct.unpack('>I', file.read(4))[0] except struct.error: raise EOFError @@ -198,7 +198,7 @@ f.write(struct.pack('>h', x)) def _write_long(f, x): - f.write(struct.pack('>L', x)) + f.write(struct.pack('>I', x)) def _write_string(f, s): if len(s) > 255: Index: Lib/platform.py =================================================================== --- Lib/platform.py (revision 60224) +++ Lib/platform.py (working copy) @@ -965,11 +965,7 @@ # else is given as default. if not bits: import struct - try: - size = struct.calcsize('P') - except struct.error: - # Older installations can only query longs - size = struct.calcsize('l') + size = struct.calcsize('P') bits = str(size*8) + 'bit' # Get data from the 'file' system command Index: Lib/tarfile.py =================================================================== --- Lib/tarfile.py (revision 60224) +++ Lib/tarfile.py (working copy) @@ -448,7 +448,7 @@ -self.zlib.MAX_WBITS, self.zlib.DEF_MEM_LEVEL, 0) - timestamp = struct.pack("L', x)) + self.__buf.write(struct.pack('>I', x)) pack_int = pack_uint pack_enum = pack_int @@ -142,7 +142,7 @@ data = self.__buf[i:j] if len(data) < 4: raise EOFError - x = struct.unpack('>L', data)[0] + x = struct.unpack('>I', data)[0] try: return int(x) except OverflowError: @@ -154,7 +154,7 @@ data = self.__buf[i:j] if len(data) < 4: raise EOFError - return struct.unpack('>l', data)[0] + return struct.unpack('>i', data)[0] unpack_enum = unpack_int Index: Lib/test/test_applesingle.py =================================================================== --- Lib/test/test_applesingle.py (revision 60224) +++ Lib/test/test_applesingle.py (working copy) @@ -15,8 +15,8 @@ dataforkdata = 'hello\r\0world\n' resourceforkdata = 'goodbye\ncruel\0world\r' -applesingledata = struct.pack(">ll16sh", AS_MAGIC, AS_VERSION, "foo", 2) + \ - struct.pack(">llllll", 1, 50, len(dataforkdata), +applesingledata = struct.pack(">ii16sh", AS_MAGIC, AS_VERSION, "foo", 2) + \ + struct.pack(">iiiiii", 1, 50, len(dataforkdata), 2, 50+len(dataforkdata), len(resourceforkdata)) + \ dataforkdata + \ resourceforkdata Index: Lib/test/test_logging.py =================================================================== --- Lib/test/test_logging.py (revision 60224) +++ Lib/test/test_logging.py (working copy) @@ -59,7 +59,7 @@ chunk = self.connection.recv(4) if len(chunk) < 4: break - slen = struct.unpack(">L", chunk)[0] + slen = struct.unpack(">I", chunk)[0] chunk = self.connection.recv(slen) while len(chunk) < slen: chunk = chunk + self.connection.recv(slen - len(chunk)) Index: Lib/test/test_largefile.py =================================================================== --- Lib/test/test_largefile.py (revision 60224) +++ Lib/test/test_largefile.py (working copy) @@ -6,7 +6,7 @@ #---------------------------------------------------------------------- from test import test_support -import os, struct, stat, sys +import os, stat, sys try: import signal Index: Lib/plat-mac/PixMapWrapper.py =================================================================== --- Lib/plat-mac/PixMapWrapper.py (revision 60224) +++ Lib/plat-mac/PixMapWrapper.py (working copy) @@ -14,7 +14,7 @@ # PixMap data structure element format (as used with struct) _pmElemFormat = { - 'baseAddr':'l', # address of pixel data + 'baseAddr':'i', # address of pixel data 'rowBytes':'H', # bytes per row, plus 0x8000 'bounds':'hhhh', # coordinates imposed over pixel data 'top':'h', @@ -23,16 +23,16 @@ 'right':'h', 'pmVersion':'h', # flags for Color QuickDraw 'packType':'h', # format of compression algorithm - 'packSize':'l', # size after compression - 'hRes':'l', # horizontal pixels per inch - 'vRes':'l', # vertical pixels per inch + 'packSize':'i', # size after compression + 'hRes':'i', # horizontal pixels per inch + 'vRes':'i', # vertical pixels per inch 'pixelType':'h', # pixel format 'pixelSize':'h', # bits per pixel 'cmpCount':'h', # color components per pixel 'cmpSize':'h', # bits per component - 'planeBytes':'l', # offset in bytes to next plane - 'pmTable':'l', # handle to color table - 'pmReserved':'l' # reserved for future use + 'planeBytes':'i', # offset in bytes to next plane + 'pmTable':'i', # handle to color table + 'pmReserved':'i' # reserved for future use } # PixMap data structure element offset @@ -65,7 +65,7 @@ def __init__(self): self.__dict__['data'] = '' - self._header = struct.pack("lhhhhhhhlllhhhhlll", + seif._header = struct.pack("ihhhhhhhiiihhhhiii", id(self.data)+MacOS.string_id_to_buffer, 0, # rowBytes 0, 0, 0, 0, # bounds Index: Lib/plat-mac/cfmfile.py =================================================================== --- Lib/plat-mac/cfmfile.py (revision 60224) +++ Lib/plat-mac/cfmfile.py (working copy) @@ -82,7 +82,7 @@ def parse(self, data): (res1, res2, self.version, res3, res4, res5, res6, - self.memberCount) = struct.unpack("8l", data[:32]) + self.memberCount) = struct.unpack("8i", data[:32]) data = data[32:] while data: frag = FragmentDescriptor(self.path, data) @@ -91,7 +91,7 @@ def build(self): self.memberCount = len(self.fragments) - data = struct.pack("8l", 0, 0, self.version, 0, 0, 0, 0, self.memberCount) + data = struct.pack("8i", 0, 0, self.version, 0, 0, 0, 0, self.memberCount) for frag in self.fragments: data = data + frag.build() return data @@ -119,13 +119,13 @@ self.offset, self.length, self.res1, self.res2, - self.memberSize,) = struct.unpack("4lhBB4lh", data[4:42]) + self.memberSize,) = struct.unpack("4ihBB4ih", data[4:42]) pname = data[42:self.memberSize] self.name = pname[1:1+ord(pname[0])] def build(self): data = self.architecture - data = data + struct.pack("4lhBB4l", + data = data + struct.pack("4ihBB4i", self.updatelevel, self.currentVersion, self.oldDefVersion, Index: Lib/plat-mac/Carbon/MediaDescr.py =================================================================== --- Lib/plat-mac/Carbon/MediaDescr.py (revision 60224) +++ Lib/plat-mac/Carbon/MediaDescr.py (working copy) @@ -61,7 +61,7 @@ 1, # May be longer, truncate 16, # size ('descSize', 'dataFormat', 'resvd1', 'resvd2', 'dataRefIndex'), # Attributes - "l4slhh" # Format + "i4sihh" # Format ) SoundDescription = _MediaDescriptionCodec( @@ -70,7 +70,7 @@ ('descSize', 'dataFormat', 'resvd1', 'resvd2', 'dataRefIndex', 'version', 'revlevel', 'vendor', 'numChannels', 'sampleSize', 'compressionID', 'packetSize', ('sampleRate', _tofixed, _fromfixed)), - "l4slhhhh4shhhhl" # Format + "i4sihhhh4shhhhi" # Format ) SoundDescriptionV1 = _MediaDescriptionCodec( @@ -80,7 +80,7 @@ 'version', 'revlevel', 'vendor', 'numChannels', 'sampleSize', 'compressionID', 'packetSize', ('sampleRate', _tofixed, _fromfixed), 'samplesPerPacket', 'bytesPerPacket', 'bytesPerFrame', 'bytesPerSample'), - "l4slhhhh4shhhhlllll" # Format + "i4sihhhh4shhhhiiiii" # Format ) ImageDescription = _MediaDescriptionCodec( @@ -91,7 +91,7 @@ 'width', 'height', ('hRes', _tofixed, _fromfixed), ('vRes', _tofixed, _fromfixed), 'dataSize', 'frameCount', ('name', _tostr31, _fromstr31), 'depth', 'clutID'), - 'l4slhhhh4sllhhlllh32shh', + 'i4sihhhh4siihhiiih32shh', ) # XXXX Others, like TextDescription and such, remain to be done. Index: Lib/plat-mac/Audio_mac.py =================================================================== --- Lib/plat-mac/Audio_mac.py (revision 60224) +++ Lib/plat-mac/Audio_mac.py (working copy) @@ -56,7 +56,7 @@ if self._sampwidth == 1: import audioop data = audioop.add(data, '\x80'*len(data), 1) - h1 = struct.pack('llHhllbbl', + h1 = struct.pack('iiHhiibbi', id(data)+MacOS.string_id_to_buffer, self._nchannels, self._outrate, 0, @@ -66,7 +66,7 @@ 60, nframes) h2 = 22*'\0' - h3 = struct.pack('hhlll', + h3 = struct.pack('hhiii', self._sampwidth*8, 0, 0, Index: Lib/plat-mac/aepack.py =================================================================== --- Lib/plat-mac/aepack.py (revision 60224) +++ Lib/plat-mac/aepack.py (working copy) @@ -93,7 +93,7 @@ if isinstance(x, AliasType): return AE.AECreateDesc('alis', x.data) if isinstance(x, IntType): - return AE.AECreateDesc('long', struct.pack('l', x)) + return AE.AECreateDesc('long', struct.pack('i', x)) if isinstance(x, FloatType): return AE.AECreateDesc('doub', struct.pack('d', x)) if isinstance(x, StringType): @@ -186,14 +186,13 @@ if t == typeKeyword: return mkkeyword(desc.data) if t == typeLongInteger: - return struct.unpack('l', desc.data)[0] + return struct.unpack('i', desc.data)[0] if t == typeLongDateTime: - a, b = struct.unpack('lL', desc.data) - return (long(a) << 32) + b + return struct.unpack('q', desc.data) if t == typeNull: return None if t == typeMagnitude: - v = struct.unpack('l', desc.data) + v = struct.unpack('i', desc.data) if v < 0: v = 0x100000000L + v return v Index: Lib/binhex.py =================================================================== --- Lib/binhex.py (revision 60224) +++ Lib/binhex.py (working copy) @@ -418,8 +418,8 @@ type = rest[1:5] creator = rest[5:9] flags = struct.unpack('>h', rest[9:11])[0] - self.dlen = struct.unpack('>l', rest[11:15])[0] - self.rlen = struct.unpack('>l', rest[15:19])[0] + self.dlen = struct.unpack('>i', rest[11:15])[0] + self.rlen = struct.unpack('>i', rest[15:19])[0] self.FName = fname self.FInfo = FInfo()