[Python-Dev] Re: Plan to remove Py_UNICODE APis except PEP 623.

2020年6月28日 07:34:39 -0700

Hi, Lamburg.
Thank you for quick response.
>
> We can't just remove access to one half of a codec (the decoding
> part) without at least providing an alternative for C extensions
> to use.
>
> Py_UNICODE can be removed from the API, but only if there are
> alternative APIs which C extensions can use to the same effect.
>
> Given PEP 393, this would be APIs which use wchar_t instead of
> Py_UNICODE.
>
Decoding part is implemented as `const char *` -> `PyObject*` (Unicode object).
I think this is reasonable since `const char *` is perfect to abstract
the encoded string,
In case of encoding part, `wchar_t *` is not perfect abstraction for
(decoded) unicode
string. Converting from Unicode object into `wchar_t *` is not zero-cost.
I think `PyObject *` (Unicode object) -> `PyObject *` (bytes object)
looks better signature than
`wchar_t *` -> `Pyobject *` (bytes object) because for encoders.
* Unicode object is more important than `wchar_t *` in Python.
* All PyUnicode_EncodeXXX APIs are implemented with PyUnicode_FromWideChar.
For example, we have these private encode APIs:
* PyObject* _PyUnicode_AsAsciiString(PyObject *unicode, const char *errors)
* PyObject* _PyUnicode_AsLatin1String(PyObject *unicode, const char *errors)
* PyObject* _PyUnicode_AsUTF8String(PyObject *unicode, const char *errors)
* PyObject* _PyUnicode_EncodeUTF16(PyObject *unicode, const char
*errors, int byteorder)
...
So how about making them public, instead of undeprecate Py_UNICODE* encode APIs?
1. Add PyUnicode_AsXXXBytes public APIs in Python 3.10.
 Current private APIs can become macro (e.g. #define
_PyUnicode_AsAsciiString PyUnicode_AsAsciiBytes),
 or deprecated static inline function.
2. Remove Py_UNICODE* encode APIs in Python 3.12.
Regards,
-- 
Inada Naoki <[email protected]>
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/Z4MT6IJBVWP2QOV3OMVJ32BZ5HLH5DG5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to