summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAN Long <aisk@users.noreply.github.com>2023-04-10 21:01:05 (GMT)
committerGitHub <noreply@github.com>2023-04-10 21:01:05 (GMT)
commitf80014a9b0e8d00df3e65379070be1dfd2721682 (patch)
tree8f095b3fd6a023603a72b6b1231e4e31ac521bf5
parent5ed2f19b3985a0a94c16d8a0285c13e1fbde9e69 (diff)
downloadcpython-f80014a9b0e8d00df3e65379070be1dfd2721682.zip
cpython-f80014a9b0e8d00df3e65379070be1dfd2721682.tar.gz
cpython-f80014a9b0e8d00df3e65379070be1dfd2721682.tar.bz2
gh-103092: Isolate winsound (#103249)
-rw-r--r--Misc/NEWS.d/next/Library/2023-04-04-21-27-51.gh-issue-103092.7s7Bzf.rst1
-rw-r--r--PC/winsound.c47
2 files changed, 23 insertions, 25 deletions
diff --git a/Misc/NEWS.d/next/Library/2023-04-04-21-27-51.gh-issue-103092.7s7Bzf.rst b/Misc/NEWS.d/next/Library/2023-04-04-21-27-51.gh-issue-103092.7s7Bzf.rst
new file mode 100644
index 0000000..39c62ff
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-04-04-21-27-51.gh-issue-103092.7s7Bzf.rst
@@ -0,0 +1 @@
+Adapt the :mod:`winsound` extension module to :pep:`687`.
diff --git a/PC/winsound.c b/PC/winsound.c
index bae8e44..17ce2ef 100644
--- a/PC/winsound.c
+++ b/PC/winsound.c
@@ -204,31 +204,13 @@ static struct PyMethodDef sound_methods[] =
#define ADD_DEFINE(CONST) do { \
if (PyModule_AddIntConstant(module, #CONST, CONST) < 0) { \
- goto error; \
+ return -1; \
} \
} while (0)
-
-static struct PyModuleDef winsoundmodule = {
- PyModuleDef_HEAD_INIT,
- "winsound",
- sound_module_doc,
- -1,
- sound_methods,
- NULL,
- NULL,
- NULL,
- NULL
-};
-
-PyMODINIT_FUNC
-PyInit_winsound(void)
+static int
+exec_module(PyObject *module)
{
- PyObject *module = PyModule_Create(&winsoundmodule);
- if (module == NULL) {
- return NULL;
- }
-
ADD_DEFINE(SND_ASYNC);
ADD_DEFINE(SND_NODEFAULT);
ADD_DEFINE(SND_NOSTOP);
@@ -248,9 +230,24 @@ PyInit_winsound(void)
#undef ADD_DEFINE
- return module;
+ return 0;
+}
+
+static PyModuleDef_Slot sound_slots[] = {
+ {Py_mod_exec, exec_module},
+ {0, NULL}
+};
-error:
- Py_DECREF(module);
- return NULL;
+static struct PyModuleDef winsoundmodule = {
+ .m_base = PyModuleDef_HEAD_INIT,
+ .m_name = "winsound",
+ .m_doc = sound_module_doc,
+ .m_methods = sound_methods,
+ .m_slots = sound_slots,
+};
+
+PyMODINIT_FUNC
+PyInit_winsound(void)
+{
+ return PyModuleDef_Init(&winsoundmodule);
}