Skip to content

Commit f80014a

Browse files
authored
gh-103092: Isolate winsound (#103249)
1 parent 5ed2f19 commit f80014a

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Adapt the :mod:`winsound` extension module to :pep:`687`.

PC/winsound.c

+22-25
Original file line numberDiff line numberDiff line change
@@ -204,31 +204,13 @@ static struct PyMethodDef sound_methods[] =
204204

205205
#define ADD_DEFINE(CONST) do { \
206206
if (PyModule_AddIntConstant(module, #CONST, CONST) < 0) { \
207-
goto error; \
207+
return -1; \
208208
} \
209209
} while (0)
210210

211-
212-
static struct PyModuleDef winsoundmodule = {
213-
PyModuleDef_HEAD_INIT,
214-
"winsound",
215-
sound_module_doc,
216-
-1,
217-
sound_methods,
218-
NULL,
219-
NULL,
220-
NULL,
221-
NULL
222-
};
223-
224-
PyMODINIT_FUNC
225-
PyInit_winsound(void)
211+
static int
212+
exec_module(PyObject *module)
226213
{
227-
PyObject *module = PyModule_Create(&winsoundmodule);
228-
if (module == NULL) {
229-
return NULL;
230-
}
231-
232214
ADD_DEFINE(SND_ASYNC);
233215
ADD_DEFINE(SND_NODEFAULT);
234216
ADD_DEFINE(SND_NOSTOP);
@@ -248,9 +230,24 @@ PyInit_winsound(void)
248230

249231
#undef ADD_DEFINE
250232

251-
return module;
233+
return 0;
234+
}
235+
236+
static PyModuleDef_Slot sound_slots[] = {
237+
{Py_mod_exec, exec_module},
238+
{0, NULL}
239+
};
252240

253-
error:
254-
Py_DECREF(module);
255-
return NULL;
241+
static struct PyModuleDef winsoundmodule = {
242+
.m_base = PyModuleDef_HEAD_INIT,
243+
.m_name = "winsound",
244+
.m_doc = sound_module_doc,
245+
.m_methods = sound_methods,
246+
.m_slots = sound_slots,
247+
};
248+
249+
PyMODINIT_FUNC
250+
PyInit_winsound(void)
251+
{
252+
return PyModuleDef_Init(&winsoundmodule);
256253
}

0 commit comments

Comments
 (0)