Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

winsound.PlaySound() with SND_MEMORY should accept bytes instead of strings #55829

Closed
TomFelker mannequin opened this issue Mar 21, 2011 · 8 comments
Closed

winsound.PlaySound() with SND_MEMORY should accept bytes instead of strings #55829

TomFelker mannequin opened this issue Mar 21, 2011 · 8 comments
Assignees
Labels
extension-modules C modules in the Modules dir OS-windows type-bug An unexpected behavior, bug, or error

Comments

@TomFelker
Copy link
Mannequin

TomFelker mannequin commented Mar 21, 2011

BPO 11620
Nosy @pfmoore, @irmen, @tjguk, @briancurtin, @ericsnowcurrently, @zware, @zooba
Files
  • 11620-PlaySound.patch: Patch to fix SND_MEMORY flag for winsound.PlaySound
  • issue11620.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/zware'
    closed_at = <Date 2016-09-05.21:32:12.296>
    created_at = <Date 2011-03-21.00:34:40.499>
    labels = ['extension-modules', 'type-bug', 'OS-windows']
    title = 'winsound.PlaySound() with SND_MEMORY should accept bytes instead of strings'
    updated_at = <Date 2016-09-05.21:35:45.296>
    user = 'https://bugs.python.org/TomFelker'

    bugs.python.org fields:

    activity = <Date 2016-09-05.21:35:45.296>
    actor = 'zach.ware'
    assignee = 'zach.ware'
    closed = True
    closed_date = <Date 2016-09-05.21:32:12.296>
    closer = 'python-dev'
    components = ['Extension Modules', 'Windows']
    creation = <Date 2011-03-21.00:34:40.499>
    creator = 'Tom.Felker'
    dependencies = []
    files = ['24470', '44104']
    hgrepos = []
    issue_num = 11620
    keywords = ['patch']
    message_count = 8.0
    messages = ['131583', '152985', '198748', '260236', '271948', '272691', '274435', '274437']
    nosy_count = 11.0
    nosy_names = ['paul.moore', 'irmen', 'tim.golden', 'tlesher', 'brian.curtin', 'sijinjoseph', 'python-dev', 'Tom.Felker', 'eric.snow', 'zach.ware', 'steve.dower']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue11620'
    versions = ['Python 3.6']

    @TomFelker
    Copy link
    Mannequin Author

    TomFelker mannequin commented Mar 21, 2011

    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.

    @TomFelker TomFelker mannequin added the stdlib Python modules in the Lib dir label Mar 21, 2011
    @briancurtin briancurtin added extension-modules C modules in the Modules dir OS-windows type-bug An unexpected behavior, bug, or error and removed stdlib Python modules in the Lib dir labels Mar 22, 2011
    @tlesher
    Copy link
    Mannequin

    tlesher mannequin commented Feb 9, 2012

    This patch should both correct the incorrect acceptance of strings and the incorrect rejection of buffer objects when using SND_MEMORY.

    @briancurtin briancurtin self-assigned this Feb 9, 2012
    @ericsnowcurrently
    Copy link
    Member

    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.

    @irmen
    Copy link
    Mannequin

    irmen mannequin commented Feb 13, 2016

    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?

    @zware
    Copy link
    Member

    zware commented Aug 4, 2016

    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.

    @zware
    Copy link
    Member

    zware commented Aug 14, 2016

    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.

    @zware zware self-assigned this Aug 14, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 5, 2016

    New changeset 8fa615a2a896 by Zachary Ware in branch 'default':
    Closes bpo-11620: Fix support for SND_MEMORY in winsound.PlaySound.
    https://hg.python.org/cpython/rev/8fa615a2a896

    @python-dev python-dev mannequin closed this as completed Sep 5, 2016
    @zware
    Copy link
    Member

    zware commented Sep 5, 2016

    Thanks for the original patch, Tim!

    After discussion with Steve, we figured it's best to keep this to 3.6.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir OS-windows type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants