Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 625cb37

Browse files
committed
Issue #25387: Check return value of winsound.MessageBeep
1 parent cefebf3 commit 625cb37

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

Doc/library/winsound.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ provided by Windows platforms. It includes functions and several constants.
4040
sound to play; possible values are ``-1``, ``MB_ICONASTERISK``,
4141
``MB_ICONEXCLAMATION``, ``MB_ICONHAND``, ``MB_ICONQUESTION``, and ``MB_OK``, all
4242
described below. The value ``-1`` produces a "simple beep"; this is the final
43-
fallback if a sound cannot be played otherwise.
43+
fallback if a sound cannot be played otherwise. If the system indicates an
44+
error, :exc:`RuntimeError` is raised.
4445

4546

4647
.. data:: SND_FILENAME

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ Core and Builtins
8080
Library
8181
-------
8282

83+
- Issue #25387: Check return value of winsound.MessageBeep.
84+
8385
- Issue #27866: Add SSLContext.get_ciphers() method to get a list of all
8486
enabled ciphers.
8587

PC/winsound.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,17 @@ static PyObject *
175175
winsound_MessageBeep_impl(PyObject *module, int x)
176176
/*[clinic end generated code: output=1ad89e4d8d30a957 input=a776c8a85c9853f6]*/
177177
{
178-
MessageBeep(x);
178+
BOOL ok;
179+
180+
Py_BEGIN_ALLOW_THREADS
181+
ok = MessageBeep(x);
182+
Py_END_ALLOW_THREADS
183+
184+
if (!ok) {
185+
PyErr_SetExcFromWindowsErr(PyExc_RuntimeError, 0);
186+
return NULL;
187+
}
188+
179189
Py_RETURN_NONE;
180190
}
181191

0 commit comments

Comments
 (0)