This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: winsound.PlaySound() with SND_MEMORY should accept bytes instead of strings
Type: behavior Stage: resolved
Components: Extension Modules, Windows Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: zach.ware Nosy List: Tom.Felker, brian.curtin, eric.snow, irmen, paul.moore, python-dev, sijinjoseph, steve.dower, tim.golden, tlesher, zach.ware
Priority: normal Keywords: patch

Created on 2011-03-21 00:34 by Tom.Felker, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
11620-PlaySound.patch tlesher, 2012-02-09 20:47 Patch to fix SND_MEMORY flag for winsound.PlaySound review
issue11620.diff zach.ware, 2016-08-14 20:19 review
Messages (8)
msg131583 - (view) Author: Tom Felker (Tom.Felker) Date: 2011-03-21 00:34
PlaySound supposedly lets you play a .WAV file whose contents are stored in a string, by passing the string and flags including winsound.SND_MEMORY.  I'm trying to use BytesIO object and the wave module to make a file in-memory, and pass this to winsound.  It's a TypeError if I pass the resultant bytes object directly, and if I pass a string object, I get

TypeError: must be str without null character or None, not str

Since wav files can contain zeros, for the feature to work at all, the C code would need to detect the SND_MEMORY flag and interpret the first argument as a bytes object, instead of a null-terminated string, in that case.
msg152985 - (view) Author: Tim Lesher (tlesher) * Date: 2012-02-09 20:47
This patch should both correct the incorrect acceptance of strings and the incorrect rejection of buffer objects when using SND_MEMORY.
msg198748 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2013-10-01 03:48
I ran into this today.  Can't we just change the "Z" to "z#" in the format string (or "z*")?  Other than that, Tim's patch makes sense.
msg260236 - (view) Author: Irmen de Jong (irmen) (Python triager) Date: 2016-02-13 12:11
Ran into this today when trying to provide a fallback sound output on windows when the user hasn't got pyaudio installed.
It seems that this module has been forgotten and didn't get fixed when the str/bytes change happened in Python 3.0?
msg271948 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2016-08-04 04:15
Irmen, you're probably correct that this was overlooked at the time of 3.0.

The patch is well out of date as well, winsound was Clinicized around the 3.4 timeframe.
msg272691 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2016-08-14 20:19
Here's an updated patch.  I'm a little wary of applying this on 3.5, because it is backward-incompatible: a str is no longer accepted with SND_MEMORY.  On the other hand, it's pretty much a fluke if that works at all currently.
msg274435 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-05 21:32
New changeset 8fa615a2a896 by Zachary Ware in branch 'default':
Closes #11620: Fix support for SND_MEMORY in winsound.PlaySound.
https://hg.python.org/cpython/rev/8fa615a2a896
msg274437 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2016-09-05 21:35
Thanks for the original patch, Tim!

After discussion with Steve, we figured it's best to keep this to 3.6.
History
Date User Action Args
2022-04-11 14:57:15adminsetgithub: 55829
2016-09-05 21:35:45zach.waresetmessages: + msg274437
versions: - Python 3.5
2016-09-05 21:32:12python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg274435

resolution: fixed
stage: patch review -> resolved
2016-08-14 20:19:28zach.waresetfiles: + issue11620.diff
assignee: zach.ware
messages: + msg272691

stage: needs patch -> patch review
2016-08-04 04:15:55zach.waresetassignee: brian.curtin -> (no value)
versions: + Python 3.6, - Python 3.3, Python 3.4
keywords: - needs review
nosy: + paul.moore, tim.golden, zach.ware, steve.dower

messages: + msg271948
stage: patch review -> needs patch
2016-02-13 12:12:28irmensetversions: + Python 3.5
2016-02-13 12:11:43irmensetnosy: + irmen
messages: + msg260236
2013-10-01 03:48:08eric.snowsetnosy: + eric.snow

messages: + msg198748
versions: + Python 3.3, Python 3.4, - Python 3.1
2012-02-09 20:49:21brian.curtinsetkeywords: + needs review
assignee: brian.curtin
stage: needs patch -> patch review
2012-02-09 20:47:09tleshersetfiles: + 11620-PlaySound.patch
keywords: + patch
messages: + msg152985
2011-06-03 20:14:52tleshersetnosy: + tlesher
2011-04-28 15:56:50sijinjosephsetnosy: + sijinjoseph
2011-03-22 20:12:00brian.curtinsetnosy: + brian.curtin

type: behavior
components: + Extension Modules, Windows, - Library (Lib)
stage: needs patch
2011-03-21 00:34:40Tom.Felkercreate