mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
gh-105156: Deprecate the old Py_UNICODE type in C API (#105157)
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>
This commit is contained in:
parent
f332594dd4
commit
8ed705c083
9 changed files with 25 additions and 14 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
-------
|
||||
|
||||
|
|
|
@ -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 ---------------------------------------- */
|
||||
|
||||
|
|
|
@ -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.
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue