]> granicus.if.org Git - python/commitdiff
Issue #25387: Check return value of winsound.MessageBeep
authorZachary Ware <zachary.ware@gmail.com>
Mon, 5 Sep 2016 22:32:28 +0000 (17:32 -0500)
committerZachary Ware <zachary.ware@gmail.com>
Mon, 5 Sep 2016 22:32:28 +0000 (17:32 -0500)
Doc/library/winsound.rst
Misc/NEWS
PC/winsound.c

index e72d025b99b48ab14a4f6f3fe561bcfe9be4b2db..372f792a0f938e17961fdee1a3ab72619f2e403a 100644 (file)
@@ -40,7 +40,8 @@ provided by Windows platforms.  It includes functions and several constants.
    sound to play; possible values are ``-1``, ``MB_ICONASTERISK``,
    ``MB_ICONEXCLAMATION``, ``MB_ICONHAND``, ``MB_ICONQUESTION``, and ``MB_OK``, all
    described below.  The value ``-1`` produces a "simple beep"; this is the final
-   fallback if a sound cannot be played otherwise.
+   fallback if a sound cannot be played otherwise.  If the system indicates an
+   error, :exc:`RuntimeError` is raised.
 
 
 .. data:: SND_FILENAME
index b13db4604fad55d2603a503a158bff1cf50936c2..f9abe29807b55fa641cc96c19ce9a713c9fec8df 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -80,6 +80,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #25387: Check return value of winsound.MessageBeep.
+
 - Issue #27866: Add SSLContext.get_ciphers() method to get a list of all
   enabled ciphers.
 
index 000ddd8475ef812f1138ad1920b0506b02ae32e2..7e06b7bd92b9e857b9d30c1d1ab30228157863cf 100644 (file)
@@ -175,7 +175,17 @@ static PyObject *
 winsound_MessageBeep_impl(PyObject *module, int x)
 /*[clinic end generated code: output=1ad89e4d8d30a957 input=a776c8a85c9853f6]*/
 {
-    MessageBeep(x);
+    BOOL ok;
+
+    Py_BEGIN_ALLOW_THREADS
+    ok = MessageBeep(x);
+    Py_END_ALLOW_THREADS
+
+    if (!ok) {
+        PyErr_SetExcFromWindowsErr(PyExc_RuntimeError, 0);
+        return NULL;
+    }
+
     Py_RETURN_NONE;
 }