mirror of https://github.com/python/cpython.git
Issue #6317: Now winsound.PlaySound can accept non ascii filename.
This commit is contained in:
parent
2e598faade
commit
c08c9bccfc
|
@ -251,6 +251,8 @@ Library
|
||||||
Extensions
|
Extensions
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
- Issue #6317: Now winsound.PlaySound can accept non ascii filename.
|
||||||
|
|
||||||
- Issue #9377: Use Unicode API for gethostname on Windows.
|
- Issue #9377: Use Unicode API for gethostname on Windows.
|
||||||
|
|
||||||
- Issue #10143: Update "os.pathconf" values.
|
- Issue #10143: Update "os.pathconf" values.
|
||||||
|
|
|
@ -72,30 +72,52 @@ PyDoc_STRVAR(sound_module_doc,
|
||||||
static PyObject *
|
static PyObject *
|
||||||
sound_playsound(PyObject *s, PyObject *args)
|
sound_playsound(PyObject *s, PyObject *args)
|
||||||
{
|
{
|
||||||
|
Py_UNICODE *wsound;
|
||||||
|
PyObject *osound;
|
||||||
const char *sound;
|
const char *sound;
|
||||||
int flags;
|
int flags;
|
||||||
int length;
|
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "z#i:PlaySound", &sound, &length, &flags)) {
|
if (PyArg_ParseTuple(args, "Zi:PlaySound", &wsound, &flags)) {
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & SND_ASYNC && flags & SND_MEMORY) {
|
if (flags & SND_ASYNC && flags & SND_MEMORY) {
|
||||||
/* Sidestep reference counting headache; unfortunately this also
|
/* Sidestep reference counting headache; unfortunately this also
|
||||||
prevent SND_LOOP from memory. */
|
prevent SND_LOOP from memory. */
|
||||||
PyErr_SetString(PyExc_RuntimeError, "Cannot play asynchronously from memory");
|
PyErr_SetString(PyExc_RuntimeError, "Cannot play asynchronously from memory");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
ok = PlaySound(sound, NULL, flags);
|
ok = PlaySoundW(wsound, NULL, flags);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "Failed to play sound");
|
PyErr_SetString(PyExc_RuntimeError, "Failed to play sound");
|
||||||
return NULL;
|
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 = 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);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue