Issue #19276: Fixed the wave module on 64-bit big-endian platforms.

This commit is contained in:
Serhiy Storchaka 2013-10-17 23:04:04 +03:00
parent 9ff06dcfad
commit d3b750516f
2 changed files with 5 additions and 1 deletions

View file

@ -80,7 +80,7 @@ class Error(Exception):
WAVE_FORMAT_PCM = 0x0001 WAVE_FORMAT_PCM = 0x0001
_array_fmts = None, 'b', 'h', None, 'l' _array_fmts = None, 'b', 'h', None, 'i'
# Determine endian-ness # Determine endian-ness
import struct import struct
@ -238,6 +238,7 @@ class Wave_read:
import array import array
chunk = self._data_chunk chunk = self._data_chunk
data = array.array(_array_fmts[self._sampwidth]) data = array.array(_array_fmts[self._sampwidth])
assert data.itemsize == self._sampwidth
nitems = nframes * self._nchannels nitems = nframes * self._nchannels
if nitems * self._sampwidth > chunk.chunksize - chunk.size_read: if nitems * self._sampwidth > chunk.chunksize - chunk.size_read:
nitems = (chunk.chunksize - chunk.size_read) // self._sampwidth nitems = (chunk.chunksize - chunk.size_read) // self._sampwidth
@ -421,6 +422,7 @@ class Wave_write:
if self._sampwidth > 1 and big_endian: if self._sampwidth > 1 and big_endian:
import array import array
data = array.array(_array_fmts[self._sampwidth], data) data = array.array(_array_fmts[self._sampwidth], data)
assert data.itemsize == self._sampwidth
data.byteswap() data.byteswap()
data.tofile(self._file) data.tofile(self._file)
self._datawritten = self._datawritten + len(data) * self._sampwidth self._datawritten = self._datawritten + len(data) * self._sampwidth

View file

@ -76,6 +76,8 @@ Core and Builtins
Library Library
------- -------
- Issue #19276: Fixed the wave module on 64-bit big-endian platforms.
- Issue #18776: atexit callbacks now display their full traceback when they - Issue #18776: atexit callbacks now display their full traceback when they
raise an exception. raise an exception.