]> granicus.if.org Git - python/commitdiff
Merged revisions 86283 via svnmerge from
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Sun, 7 Nov 2010 11:53:57 +0000 (11:53 +0000)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Sun, 7 Nov 2010 11:53:57 +0000 (11:53 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r86283 | hirokazu.yamamoto | 2010-11-07 18:23:15 +0900 | 1 line

  Issue #6317: Now winsound.PlaySound can accept non ascii filename.
........

Misc/NEWS
PC/winsound.c

index a97d3dd2b9753bc543d490c88a16c6b60fd42de2..0638e2b29c4a6350b26ae5f07c74dce4d3c2310a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -616,6 +616,8 @@ Library
 Extension Modules
 -----------------
 
+- Issue #6317: Now winsound.PlaySound can accept non ascii filename.
+
 - Issue #9054: Fix a crash occurring when using the pyexpat module
   with expat version 2.0.1.
 
index 1e00e7a0a36eaba861b800faa524efe6c72b61bb..d45584868650678938db272736ee3f25b4183df2 100644 (file)
@@ -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;
 }