Index: PC/winsound.c =================================================================== --- PC/winsound.c (revision 86280) +++ PC/winsound.c (working copy) @@ -72,31 +72,50 @@ static PyObject * sound_playsound(PyObject *s, PyObject *args) { + Py_UNICODE *wsound; + PyObject *osound; const char *sound; int flags; - int length; int ok; - if(!PyArg_ParseTuple(args,"z#i:PlaySound",&sound,&length,&flags)) { - return NULL; + 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; } - - 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; + PyErr_Clear(); + if (!PyArg_ParseTuple(args, "O&i:PlaySound", + PyUnicode_FSConverter, &osound, &flags)) + return NULL; + 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"); + Py_DECREF(osound); + return NULL; } - + sound = PyBytes_AsString(osound); Py_BEGIN_ALLOW_THREADS - ok = PlaySound(sound,NULL,flags); + ok = PlaySoundA(sound, NULL, flags); Py_END_ALLOW_THREADS - if(!ok) - { - PyErr_SetString(PyExc_RuntimeError,"Failed to play sound"); - return NULL; + if (!ok) { + PyErr_SetString(PyExc_RuntimeError, "Failed to play sound"); + Py_DECREF(osound); + return NULL; } - + Py_DECREF(osound); Py_INCREF(Py_None); return Py_None; }