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

Skip to content

Commit a312c73

Browse files
committed
gh-85283: Build winsound extension with limited C API
Replace type->tp_name with PyType_GetQualName().
1 parent 054f496 commit a312c73

8 files changed

+31
-146
lines changed

Doc/whatsnew/3.13.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ Build Changes
932932
* Building CPython now requires a compiler with support for the C11 atomic
933933
library, GCC built-in atomic functions, or MSVC interlocked intrinsics.
934934

935-
* The ``errno``, ``md5``, ``_ctypes_test``, ``_stat`` and
935+
* The ``errno``, ``md5``, ``winsound``, ``_ctypes_test``, ``_stat`` and
936936
``_testimportmultiple`` C extensions are now built with the :ref:`limited C
937937
API <limited-c-api>`.
938938
(Contributed by Victor Stinner in :gh:`85283`.)

Include/internal/pycore_global_objects_fini_generated.h

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

-3
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ struct _Py_global_strings {
385385
STRUCT_FOR_ID(dont_inherit)
386386
STRUCT_FOR_ID(dst)
387387
STRUCT_FOR_ID(dst_dir_fd)
388-
STRUCT_FOR_ID(duration)
389388
STRUCT_FOR_ID(e)
390389
STRUCT_FOR_ID(eager_start)
391390
STRUCT_FOR_ID(effective_ids)
@@ -431,7 +430,6 @@ struct _Py_global_strings {
431430
STRUCT_FOR_ID(flush)
432431
STRUCT_FOR_ID(follow_symlinks)
433432
STRUCT_FOR_ID(format)
434-
STRUCT_FOR_ID(frequency)
435433
STRUCT_FOR_ID(from_param)
436434
STRUCT_FOR_ID(fromlist)
437435
STRUCT_FOR_ID(fromtimestamp)
@@ -675,7 +673,6 @@ struct _Py_global_strings {
675673
STRUCT_FOR_ID(sleep)
676674
STRUCT_FOR_ID(sock)
677675
STRUCT_FOR_ID(sort)
678-
STRUCT_FOR_ID(sound)
679676
STRUCT_FOR_ID(source)
680677
STRUCT_FOR_ID(source_traceback)
681678
STRUCT_FOR_ID(src)

Include/internal/pycore_runtime_init_generated.h

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
The ``errno``, ``md5``, ``_ctypes_test`` and ``_testimportmultiple`` C
2-
extensions are now built with the :ref:`limited C API <limited-c-api>`. Patch
3-
by Victor Stinner.
1+
The ``errno``, ``md5``, ``winsound``, ``_ctypes_test``, ``_stat`` and
2+
``_testimportmultiple`` C extensions are now built with the :ref:`limited C API
3+
<limited-c-api>`.
4+
Patch by Victor Stinner.

PC/clinic/winsound.c.h

+16-121
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PC/winsound.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
winsound.PlaySound(None, 0)
3636
*/
3737

38+
// Need limited C API version 3.13 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
39+
#define Py_LIMITED_API 0x030d0000
40+
3841
#include <Python.h>
3942
#include <windows.h>
4043
#include <mmsystem.h>
@@ -95,9 +98,13 @@ winsound_PlaySound_impl(PyObject *module, PyObject *sound, int flags)
9598
}
9699
wsound = (wchar_t *)view.buf;
97100
} else if (PyBytes_Check(sound)) {
98-
PyErr_Format(PyExc_TypeError,
99-
"'sound' must be str, os.PathLike, or None, not '%s'",
100-
Py_TYPE(sound)->tp_name);
101+
PyObject *type_name = PyType_GetQualName(Py_TYPE(sound));
102+
if (type_name != NULL) {
103+
PyErr_Format(PyExc_TypeError,
104+
"'sound' must be str, os.PathLike, or None, not %S",
105+
type_name);
106+
Py_DECREF(type_name);
107+
}
101108
return NULL;
102109
} else {
103110
PyObject *obj = PyOS_FSPath(sound);

0 commit comments

Comments
 (0)