]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-105156: Deprecate the old Py_UNICODE type in C API (#105157)
authorVictor Stinner <vstinner@python.org>
Thu, 1 Jun 2023 06:56:35 +0000 (08:56 +0200)
committerGitHub <noreply@github.com>
Thu, 1 Jun 2023 06:56:35 +0000 (08:56 +0200)
Deprecate the old Py_UNICODE and PY_UNICODE_TYPE types in the C API:
use wchar_t instead.

Replace Py_UNICODE with wchar_t in multiple C files.

Co-authored-by: Inada Naoki <songofacandy@gmail.com>
Doc/c-api/unicode.rst
Doc/whatsnew/3.13.rst
Include/cpython/unicodeobject.h
Misc/NEWS.d/next/C API/2023-05-31-18-37-57.gh-issue-105156.R4El5V.rst [new file with mode: 0644]
Modules/_io/fileio.c
Modules/_testcapi/getargs.c
Modules/arraymodule.c
Objects/unicodeobject.c
Python/modsupport.c

index 6771f378bfbc319be6243b44a62b0eddce0e73b3..e3c6ee42b469afe41c69d7cdbe174fdc1913640a 100644 (file)
@@ -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
index 441b3ab3f51f1a9b9b29193cc5655dcbd39148c4..e263d0bde484edb80da0ebd49e119ad5e2e6b5e3 100644 (file)
@@ -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
 -------
 
index 3394726dfffd72ea87b39511fcdfb2653f6c3492..92e7afde427bdccdf5087f40c7236edeb43d4030 100644 (file)
@@ -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 ---------------------------------------- */
 
diff --git a/Misc/NEWS.d/next/C API/2023-05-31-18-37-57.gh-issue-105156.R4El5V.rst b/Misc/NEWS.d/next/C API/2023-05-31-18-37-57.gh-issue-105156.R4El5V.rst
new file mode 100644 (file)
index 0000000..cbdb837
--- /dev/null
@@ -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.
index 30944fc56bf70eedcccd84e168128d6eff1b7648..005c9ffe56f71a8f82abba85c717bd420965bea8 100644 (file)
@@ -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
index 95ef2d2a546d310ba1d3710ba8669bddaaa23795..a473c41f60af3ccf06670a48dfcacc683ad7621e 100644 (file)
@@ -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;
     }
@@ -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;
@@ -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;
     }
@@ -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;
index f94bbec8e0bb3c131394fbf6ae861f7a899bbff0..999b848f9adbd7326f04e6a390fce96c9218b7b5 100644 (file)
@@ -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;
index 6f25f91c0ff28d5291005dec233e7870b8aff1c5..ffb4a87d4b926547950ea21078ba9881cf65749e 100644 (file)
@@ -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;
@@ -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)
index e2092ac2099d034ff8ce82d05a93f5c999518349..3db95f1f07284bbfc0f68dbfbb8ec4a0a30a6983 100644 (file)
@@ -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;