8000 gh-85283: Build winsound extension with limited C API (#110978) · Glyphack/cpython@08b1645 · GitHub
[go: up one dir, main page]

Skip to content

Commit 08b1645

Browse files
vstinnerGlyphack
authored andcommitted
pythongh-85283: Build winsound extension with limited C API (python#110978)
Replace type->tp_name with PyType_GetQualName().
1 parent a132243 commit 08b1645

File tree

8 files changed

+30
-151
lines changed

8 files changed

+30
-151
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 0 additions & 3 deletions
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

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 3 deletions
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

Lines changed: 16 additions & 122 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PC/winsound.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@
3535
winsound.PlaySound(None, 0)
3636
*/
3737

38-
// clinic/winsound.c.h uses internal pycore_modsupport.h API
39-
#ifndef Py_BUILD_CORE_BUILTIN
40-
# define Py_BUILD_CORE_MODULE 1
41-
#endif
38+
// Need limited C API version 3.13 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
39+
#define Py_LIMITED_API 0x030d0000
4240

4341
#include <Python.h>
4442
#include <windows.h>
@@ -100,9 +98,13 @@ winsound_PlaySound_impl(PyObject *module, PyObject *sound, int flags)
10098
}
10199
wsound = (wchar_t *)view.buf;
102100
} else if (PyBytes_Check(sound)) {
103-
PyErr_Format(PyExc_TypeError,
104-
"'sound' must be str, os.PathLike, or None, not '%s'",
105-
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+
}
106108
return NULL;
107109
} else {
108110
PyObject *obj = PyOS_FSPath(sound);

0 commit comments

Comments
 (0)
0