Kaydet (Commit) 5efea043 authored tarafından Benjamin Peterson's avatar Benjamin Peterson

use floor division where needed #7681

üst ee5383da
from test.support import TESTFN, run_unittest from test.support import TESTFN, run_unittest
import os import os
import wave import wave
import struct
import unittest import unittest
nchannels = 2 nchannels = 2
...@@ -38,6 +39,16 @@ class TestWave(unittest.TestCase): ...@@ -38,6 +39,16 @@ class TestWave(unittest.TestCase):
self.assertEqual(nframes, self.f.getnframes()) self.assertEqual(nframes, self.f.getnframes())
self.assertEqual(self.f.readframes(nframes), output) self.assertEqual(self.f.readframes(nframes), output)
def test_issue7681(self):
self.f = wave.open(TESTFN, 'wb')
self.f.setnchannels(nchannels)
self.f.setsampwidth(sampwidth)
self.f.setframerate(framerate)
# Don't call setnframes, make _write_header divide to figure it out
output = b'\0' * nframes * nchannels * sampwidth
self.f.writeframes(output)
def test_main(): def test_main():
run_unittest(TestWave) run_unittest(TestWave)
......
...@@ -240,7 +240,7 @@ class Wave_read: ...@@ -240,7 +240,7 @@ class Wave_read:
data = array.array(_array_fmts[self._sampwidth]) data = array.array(_array_fmts[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
data.fromfile(chunk.file.file, nitems) data.fromfile(chunk.file.file, nitems)
# "tell" data chunk how much was read # "tell" data chunk how much was read
chunk.size_read = chunk.size_read + nitems * self._sampwidth chunk.size_read = chunk.size_read + nitems * self._sampwidth
...@@ -461,7 +461,7 @@ class Wave_write: ...@@ -461,7 +461,7 @@ class Wave_write:
def _write_header(self, initlength): def _write_header(self, initlength):
self._file.write(b'RIFF') self._file.write(b'RIFF')
if not self._nframes: if not self._nframes:
self._nframes = initlength / (self._nchannels * self._sampwidth) self._nframes = initlength // (self._nchannels * self._sampwidth)
self._datalength = self._nframes * self._nchannels * self._sampwidth self._datalength = self._nframes * self._nchannels * self._sampwidth
self._form_length_pos = self._file.tell() self._form_length_pos = self._file.tell()
self._file.write(struct.pack('<l4s4slhhllhh4s', self._file.write(struct.pack('<l4s4slhhllhh4s',
......
...@@ -209,6 +209,8 @@ C-API ...@@ -209,6 +209,8 @@ C-API
Library Library
------- -------
- Issue #7681: Use floor division in appropiate places in the wave module.
- Issue #5372: Drop the reuse of .o files in Distutils' ccompiler (since - Issue #5372: Drop the reuse of .o files in Distutils' ccompiler (since
Extension extra options may change the output without changing the .c Extension extra options may change the output without changing the .c
file). Initial patch by Collin Winter. file). Initial patch by Collin Winter.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment