[Python-Dev] winsound.c fix to support python3
Tamir Friedman
tamir.fri at gmail.com
Sat Jun 29 17:59:13 CEST 2013
Hello,
My name is Tamir Friedman, and I suggest to fix a bug in PlaySound in
winsound library. It's doesn't support the SND_MEMORY feature because its
accepts only "str" and rejects "bytes" type.
therefore i include the fixed source file:
OLD:
----------------------------------------------------------------------------
static PyObject *
sound_playsound(PyObject *s, PyObject *args)
{
wchar_t *wsound;
int flags;
int ok;
if (PyArg_ParseTuple(args, "Zi:PlaySound", &wsound, &flags)) {
if (flags & SND_ASYNC && flags & SND_MEMORY) {
/* Sidestep reference counting headache; unfortunately this also
prevent SND_LOOP from memory. */
PyErr_SetString(PyExc_RuntimeError, "Cannot play asynchronously
from memory");
return NULL;
}
Py_BEGIN_ALLOW_THREADS
ok = PlaySoundW(wsound, NULL, flags);
Py_END_ALLOW_THREADS
if (!ok) {
PyErr_SetString(PyExc_RuntimeError, "Failed to play sound");
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
return NULL;
}
----------------------------------------------------------------------------
NEW:
----------------------------------------------------------------------------
static PyObject *
sound_playsound(PyObject *s, PyObject *args)
{
wchar_t *wsound;
int flags;
int ok;
if (PyArg_ParseTuple(args, "z*i:PlaySound", &wsound, &flags)) {
if (flags & SND_ASYNC && flags & SND_MEMORY) {
/* Sidestep reference counting headache; unfortunately this also
prevent SND_LOOP from memory. */
PyErr_SetString(PyExc_RuntimeError, "Cannot play asynchronously
from memory");
return NULL;
}
Py_BEGIN_ALLOW_THREADS
ok = PlaySoundW(wsound, NULL, flags);
Py_END_ALLOW_THREADS
if (!ok) {
PyErr_SetString(PyExc_RuntimeError, "Failed to play sound");
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
return NULL;
}
----------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130629/8eb5f988/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OLD_winsound_OLD.c
Type: text/x-csrc
Size: 5581 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130629/8eb5f988/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: winsound.c
Type: text/x-csrc
Size: 5637 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130629/8eb5f988/attachment-0001.c>
More information about the Python-Dev
mailing list