[Python-checkins] cpython: Issue #25387: Check return value of winsound.MessageBeep

zach.ware python-checkins at python.org
Mon Sep 5 18:33:06 EDT 2016


https://hg.python.org/cpython/rev/4e5b3dc049cc
changeset: 103079:4e5b3dc049cc
user: Zachary Ware <zachary.ware at gmail.com>
date: Mon Sep 05 17:32:28 2016 -0500
summary:
 Issue #25387: Check return value of winsound.MessageBeep
files:
 Doc/library/winsound.rst | 3 ++-
 Misc/NEWS | 2 ++
 PC/winsound.c | 12 +++++++++++-
 3 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/Doc/library/winsound.rst b/Doc/library/winsound.rst
--- a/Doc/library/winsound.rst
+++ b/Doc/library/winsound.rst
@@ -40,7 +40,8 @@
 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
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -80,6 +80,8 @@
 Library
 -------
 
+- Issue #25387: Check return value of winsound.MessageBeep.
+
 - Issue #27866: Add SSLContext.get_ciphers() method to get a list of all
 enabled ciphers.
 
diff --git a/PC/winsound.c b/PC/winsound.c
--- a/PC/winsound.c
+++ b/PC/winsound.c
@@ -175,7 +175,17 @@
 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;
 }
 
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /