From e8d424c4b4542954918f98065b1e0e6bb438bd7f Mon Sep 17 00:00:00 2001 From: AN Long Date: Tue, 4 Apr 2023 21:22:44 +0800 Subject: [PATCH 1/4] gh-103092: isolate winsound --- ...-04-04-21-27-51.gh-issue-103092.7s7Bzf.rst | 1 + PC/winsound.c | 49 ++++++++++++------- 2 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2023-04-04-21-27-51.gh-issue-103092.7s7Bzf.rst 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 00000000000000..0ba6edb2163bf6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-04-04-21-27-51.gh-issue-103092.7s7Bzf.rst @@ -0,0 +1 @@ +Adapt :mod:`!winsound` to :pep:`687`. diff --git a/PC/winsound.c b/PC/winsound.c index 65025ddc5e1f51..d8a97099ad58a5 100644 --- a/PC/winsound.c +++ b/PC/winsound.c @@ -216,27 +216,14 @@ add_define(PyObject *dict, const char *key, long value) #define ADD_DEFINE(tok) add_define(dict,#tok,tok) - -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 *dict; - PyObject *module = PyModule_Create(&winsoundmodule); - if (module == NULL) - return NULL; dict = PyModule_GetDict(module); + if (dict == NULL) { + return -1; + } ADD_DEFINE(SND_ASYNC); ADD_DEFINE(SND_NODEFAULT); @@ -254,5 +241,29 @@ PyInit_winsound(void) ADD_DEFINE(MB_ICONEXCLAMATION); ADD_DEFINE(MB_ICONHAND); ADD_DEFINE(MB_ICONQUESTION); - return module; + + return 0; +} + +static PyModuleDef_Slot sound_slots[] = { + {Py_mod_exec, exec_module}, + {0, NULL} +}; + +static struct PyModuleDef winsoundmodule = { + PyModuleDef_HEAD_INIT, + "winsound", + sound_module_doc, + 0, + sound_methods, + sound_slots, + NULL, + NULL, + NULL +}; + +PyMODINIT_FUNC +PyInit_winsound(void) +{ + return PyModuleDef_Init(&winsoundmodule); } From 0a7e6f8ce4e788d8c21142c9ddc65a4e9455b2c5 Mon Sep 17 00:00:00 2001 From: AN Long Date: Thu, 6 Apr 2023 15:24:39 +0800 Subject: [PATCH 2/4] Update PC/winsound.c Co-authored-by: Oleg Iarygin --- PC/winsound.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/PC/winsound.c b/PC/winsound.c index d8a97099ad58a5..389d626a23733c 100644 --- a/PC/winsound.c +++ b/PC/winsound.c @@ -251,15 +251,11 @@ static PyModuleDef_Slot sound_slots[] = { }; static struct PyModuleDef winsoundmodule = { - PyModuleDef_HEAD_INIT, - "winsound", - sound_module_doc, - 0, - sound_methods, - sound_slots, - NULL, - NULL, - NULL + .m_base = PyModuleDef_HEAD_INIT, + .m_name = "winsound", + .m_doc = sound_module_doc, + .m_methods = sound_methods, + .m_slots = sound_slots }; PyMODINIT_FUNC From 4608cd7dcc25880f075eaca491ceac5786bcfd8f Mon Sep 17 00:00:00 2001 From: AN Long Date: Sun, 9 Apr 2023 13:03:14 +0800 Subject: [PATCH 3/4] Update Misc/NEWS.d/next/Library/2023-04-04-21-27-51.gh-issue-103092.7s7Bzf.rst Co-authored-by: Erlend E. Aasland --- .../next/Library/2023-04-04-21-27-51.gh-issue-103092.7s7Bzf.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 0ba6edb2163bf6..39c62ffbe8c659 100644 --- 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 @@ -1 +1 @@ -Adapt :mod:`!winsound` to :pep:`687`. +Adapt the :mod:`winsound` extension module to :pep:`687`. From d16e2cdd02c2a6efc04b5af4aef81e72eb77bc9a Mon Sep 17 00:00:00 2001 From: AN Long Date: Sun, 9 Apr 2023 13:03:21 +0800 Subject: [PATCH 4/4] Update PC/winsound.c Co-authored-by: Erlend E. Aasland --- PC/winsound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PC/winsound.c b/PC/winsound.c index 389d626a23733c..21d657edeada40 100644 --- a/PC/winsound.c +++ b/PC/winsound.c @@ -255,7 +255,7 @@ static struct PyModuleDef winsoundmodule = { .m_name = "winsound", .m_doc = sound_module_doc, .m_methods = sound_methods, - .m_slots = sound_slots + .m_slots = sound_slots, }; PyMODINIT_FUNC