winsound.c fix to support python3
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; } ----------------------------------------------------------------------------
On 6/29/2013 11:59 AM, Tamir Friedman wrote:
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:
Thank you for tracking down the source of a problem. Please make an account at bugs.python.org and open a tracker issue. A post here will get lost. On the issue, either upload a patch file or describe the change. As near as I can tell, the description for your change might be: "winsound.c, line NN in sound_playsound function, is currently if (PyArg_ParseTuple(args, "Zi:PlaySound", &wsound, &flags)) { I think 'Zi' should be changed for 'z*i' because ..." -- Terry Jan Reedy
participants (2)
-
Tamir Friedman -
Terry Reedy