summaryrefslogtreecommitdiff
path: root/PC/winsound.c
diff options
context:
space:
mode:
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>2010-11-07 09:23:15 +0000
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>2010-11-07 09:23:15 +0000
commit76156625915b34e2223856399980fd99091b4393 (patch)
treed0171c6c39347658134977ba15a676994d24b952 /PC/winsound.c
parent979ce2f0aa42fe9face69cc9c7159a0d4a7cc088 (diff)
downloadcpython-76156625915b34e2223856399980fd99091b4393.tar.gz
Issue #6317: Now winsound.PlaySound can accept non ascii filename.
Diffstat (limited to 'PC/winsound.c')
-rw-r--r--PC/winsound.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/PC/winsound.c b/PC/winsound.c
index d61dde702b..0e82814f4d 100644
--- a/PC/winsound.c
+++ b/PC/winsound.c
@@ -72,30 +72,52 @@ PyDoc_STRVAR(sound_module_doc,
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;
}
-
+ /* Drop the argument parsing error as narrow strings
+ are also valid. */
+ 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");
+ Py_DECREF(osound);
return NULL;
}
-
+ Py_DECREF(osound);
Py_INCREF(Py_None);
return Py_None;
}