Skip to content

gh-105156: Deprecate the old Py_UNICODE type in C API #105157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Doc/c-api/unicode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Python:
whether you selected a "narrow" or "wide" Unicode version of Python at
build time.

.. deprecated-removed:: 3.13 3.15


.. c:type:: PyASCIIObject
PyCompactUnicodeObject
Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ Porting to Python 3.13
Deprecated
----------

* Deprecate the old ``Py_UNICODE`` and ``PY_UNICODE_TYPE`` types: use directly
the ``wchar_t`` type instead. Since Python 3.3, ``Py_UNICODE`` and
``PY_UNICODE_TYPE`` are just aliases to ``wchar_t``.
(Contributed by Victor Stinner in :gh:`105156`.)

Removed
-------

Expand Down
4 changes: 2 additions & 2 deletions Include/cpython/unicodeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
Python and represents a single Unicode element in the Unicode type.
With PEP 393, Py_UNICODE is deprecated and replaced with a
typedef to wchar_t. */
#define PY_UNICODE_TYPE wchar_t
/* Py_DEPRECATED(3.3) */ typedef wchar_t Py_UNICODE;
Py_DEPRECATED(3.13) typedef wchar_t PY_UNICODE_TYPE;
Py_DEPRECATED(3.13) typedef wchar_t Py_UNICODE;

/* --- Internal Unicode Operations ---------------------------------------- */

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Deprecate the old ``Py_UNICODE`` and ``PY_UNICODE_TYPE`` types: use directly
the ``wchar_t`` type instead. Since Python 3.3, ``Py_UNICODE`` and
``PY_UNICODE_TYPE`` are just aliases to ``wchar_t``. Patch by Victor
Stinner.
2 changes: 1 addition & 1 deletion Modules/_io/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
/*[clinic end generated code: output=23413f68e6484bbd input=588aac967e0ba74b]*/
{
#ifdef MS_WINDOWS
Py_UNICODE *widename = NULL;
wchar_t *widename = NULL;
#else
const char *name = NULL;
#endif
Expand Down
8 changes: 4 additions & 4 deletions Modules/_testcapi/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ getargs_y_hash(PyObject *self, PyObject *args)
static PyObject *
getargs_u(PyObject *self, PyObject *args)
{
Py_UNICODE *str;
wchar_t *str;
if (!PyArg_ParseTuple(args, "u", &str)) {
return NULL;
}
Expand All @@ -604,7 +604,7 @@ getargs_u(PyObject *self, PyObject *args)
static PyObject *
getargs_u_hash(PyObject *self, PyObject *args)
{
Py_UNICODE *str;
wchar_t *str;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "u#", &str, &size)) {
return NULL;
Expand All @@ -615,7 +615,7 @@ getargs_u_hash(PyObject *self, PyObject *args)
static PyObject *
getargs_Z(PyObject *self, PyObject *args)
{
Py_UNICODE *str;
wchar_t *str;
if (!PyArg_ParseTuple(args, "Z", &str)) {
return NULL;
}
Expand All @@ -628,7 +628,7 @@ getargs_Z(PyObject *self, PyObject *args)
static PyObject *
getargs_Z_hash(PyObject *self, PyObject *args)
{
Py_UNICODE *str;
wchar_t *str;
Py_ssize_t size;
if (!PyArg_ParseTuple(args, "Z#", &str, &size)) {
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1830,10 +1830,10 @@ typecode_to_mformat_code(char typecode)
return UNSIGNED_INT8;

case 'u':
if (sizeof(Py_UNICODE) == 2) {
if (sizeof(wchar_t) == 2) {
return UTF16_LE + is_big_endian;
}
if (sizeof(Py_UNICODE) == 4) {
if (sizeof(wchar_t) == 4) {
return UTF32_LE + is_big_endian;
}
return UNKNOWN_FORMAT;
Expand Down
8 changes: 4 additions & 4 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1800,14 +1800,14 @@ PyUnicode_FromWideChar(const wchar_t *u, Py_ssize_t size)

switch (PyUnicode_KIND(unicode)) {
case PyUnicode_1BYTE_KIND:
_PyUnicode_CONVERT_BYTES(Py_UNICODE, unsigned char,
_PyUnicode_CONVERT_BYTES(wchar_t, unsigned char,
u, u + size, PyUnicode_1BYTE_DATA(unicode));
break;
case PyUnicode_2BYTE_KIND:
#if Py_UNICODE_SIZE == 2
memcpy(PyUnicode_2BYTE_DATA(unicode), u, size * 2);
#else
_PyUnicode_CONVERT_BYTES(Py_UNICODE, Py_UCS2,
_PyUnicode_CONVERT_BYTES(wchar_t, Py_UCS2,
u, u + size, PyUnicode_2BYTE_DATA(unicode));
#endif
break;
Expand Down Expand Up @@ -3809,9 +3809,9 @@ PyUnicode_AsUTF8(PyObject *unicode)
PyUnicode_GetSize() has been deprecated since Python 3.3
because it returned length of Py_UNICODE.

But this function is part of stable abi, because it don't
But this function is part of stable abi, because it doesn't
include Py_UNICODE in signature and it was not excluded from
stable abi in PEP 384.
stable ABI in PEP 384.
*/
PyAPI_FUNC(Py_ssize_t)
PyUnicode_GetSize(PyObject *unicode)
Expand Down
2 changes: 1 addition & 1 deletion Python/modsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ do_mkvalue(const char **p_format, va_list *p_va)
case 'u':
{
PyObject *v;
Py_UNICODE *u = va_arg(*p_va, Py_UNICODE *);
const wchar_t *u = va_arg(*p_va, wchar_t*);
Py_ssize_t n;
if (**p_format == '#') {
++*p_format;
Expand Down