classification
Title: Incorrect division in [wave.py]
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: alfps, benjamin.peterson, brian.curtin
Priority: normal Keywords: needs review, patch

Created on 2010-01-12 12:01 by alfps, last changed 2010-01-13 03:50 by benjamin.peterson. This issue is now closed.

Files
File name Uploaded Description Edit
error.py alfps, 2010-01-12 12:04
issue7681.diff brian.curtin, 2010-01-13 00:19 patch against release31-maint, r77454
Messages (6)
msg97629 - (view) Author: Alf P. Steinbach (alfps) Date: 2010-01-12 12:01
CPython 3.1.1 in Windows XP.

Traceback (most recent call last):
  File "C:\Documents and Settings\Alf\sound\error.py", line 6, in <module>
    writer.setframerate( framerate )
NameError: name 'framerate' is not defined
Exception wave.Error: Error('sampling rate not specified',) in <bound method Wave_write.__del__ of <wave.Wave_write obje
ct at 0x00FE87F0>> ignored

TO FIX:

"/" needs to be changed to "//" in lines and 243 464 of [wave.py]
msg97630 - (view) Author: Alf P. Steinbach (alfps) Date: 2010-01-12 12:04
Sorry, here's correct error message:

Traceback (most recent call last):
  File "C:\Documents and Settings\Alf\sound\error.py", line 8, in <module>
    writer.writeframes( b"\0"*2*4 )
  File "C:\Program Files\cpython\python31\lib\wave.py", line 432, in writeframes
    self.writeframesraw(data)
  File "C:\Program Files\cpython\python31\lib\wave.py", line 416, in writeframesraw
    self._ensure_header_written(len(data))
  File "C:\Program Files\cpython\python31\lib\wave.py", line 459, in _ensure_header_written
    self._write_header(datasize)
  File "C:\Program Files\cpython\python31\lib\wave.py", line 472, in _write_header
    self._sampwidth * 8, 'data'))
struct.error: required argument is not an integer
Exception struct.error: 'required argument is not an integer' in <bound method Wave_write.__del__ of <wave.Wave_write ob
ject at 0x00FE87F0>> ignored
msg97633 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-01-12 15:05
In your example, the "n_frames" name does not exist, which is causing the problem. In your first comment, "framerate" also did not exist.

I don't know what a proper frame rate value is, but I just put 10 in there and it worked fine. Can you confirm?
msg97668 - (view) Author: Alf P. Steinbach (alfps) Date: 2010-01-12 22:31
No, sorry, the bugs in [wave.py] have nothing to do with a name IN A COMMENT in the trivial code to exercise the bugs.

To reproduce the crash, just run the supplied code with Python 3.1.1 in Windows XP.

The cause of the crash is, as I pointed out, use of Python 2.x "/" division instead of Python 3.x "//" division. The author of [wave.py] had fixed that in some places. But he/she forgot two places.


Cheers & hth.,

- Alf
msg97673 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-01-13 00:19
There is no crash, but I see what you are saying now.
Patch to correct the two divisions and a test similar to your example.
msg97683 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-01-13 03:50
Thanks for the patch! Applied in r77459.
History
Date User Action Args
2010-01-13 03:50:27benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg97683

resolution: fixed
2010-01-13 00:19:44brian.curtinsetfiles: + issue7681.diff
title: Incorrect division in [wave.py] causing crash -> Incorrect division in [wave.py]
messages: + msg97673

keywords: + patch, needs review
type: behavior
stage: needs patch -> patch review
2010-01-12 22:31:16alfpssetmessages: + msg97668
2010-01-12 15:05:14brian.curtinsetpriority: normal

nosy: + brian.curtin
messages: + msg97633

type: crash -> (no value)
stage: needs patch
2010-01-12 12:04:02alfpssetfiles: + error.py

messages: + msg97630
2010-01-12 12:01:59alfpssetfiles: - error.py
2010-01-12 12:01:21alfpscreate