From afc2c0507ff117cc859b979af689ad691b1e319d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 21 Apr 2022 22:58:39 +0200 Subject: [PATCH 1/2] gh-80527: Deprecate PEP 623 Unicode functions Deprecate functions: * PyUnicode_AS_DATA() * PyUnicode_AS_UNICODE() * PyUnicode_GET_DATA_SIZE() * PyUnicode_GET_SIZE() Previously, these functions were macros and so it wasn't possible to decorate them with Py_DEPRECATED(). --- Include/cpython/unicodeobject.h | 16 +++++++++++----- ...2022-04-21-23-11-35.gh-issue-80527.Cx-95G.rst | 3 +++ 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/C API/2022-04-21-23-11-35.gh-issue-80527.Cx-95G.rst diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 8cc9885756037d2..80dbee39097f3e3 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -606,7 +606,7 @@ static inline Py_ssize_t PyUnicode_WSTR_LENGTH(PyObject *op) If the Py_UNICODE representation is not available, it will be computed on request. Use PyUnicode_GET_LENGTH() for the length in code points. */ -/* Py_DEPRECATED(3.3) */ +Py_DEPRECATED(3.3) static inline Py_ssize_t PyUnicode_GET_SIZE(PyObject *op) { _Py_COMP_DIAG_PUSH @@ -620,10 +620,13 @@ static inline Py_ssize_t PyUnicode_GET_SIZE(PyObject *op) } #define PyUnicode_GET_SIZE(op) PyUnicode_GET_SIZE(_PyObject_CAST(op)) - /* Py_DEPRECATED(3.3) */ - static inline Py_ssize_t PyUnicode_GET_DATA_SIZE(PyObject *op) +Py_DEPRECATED(3.3) +static inline Py_ssize_t PyUnicode_GET_DATA_SIZE(PyObject *op) { + _Py_COMP_DIAG_PUSH + _Py_COMP_DIAG_IGNORE_DEPR_DECLS return PyUnicode_GET_SIZE(op) * Py_UNICODE_SIZE; + _Py_COMP_DIAG_POP } #define PyUnicode_GET_DATA_SIZE(op) PyUnicode_GET_DATA_SIZE(_PyObject_CAST(op)) @@ -632,7 +635,7 @@ static inline Py_ssize_t PyUnicode_GET_SIZE(PyObject *op) try to port your code to use the new PyUnicode_*BYTE_DATA() macros or use PyUnicode_WRITE() and PyUnicode_READ(). */ -/* Py_DEPRECATED(3.3) */ +Py_DEPRECATED(3.3) static inline Py_UNICODE* PyUnicode_AS_UNICODE(PyObject *op) { wchar_t *wstr = _PyASCIIObject_CAST(op)->wstr; @@ -647,10 +650,13 @@ static inline Py_UNICODE* PyUnicode_AS_UNICODE(PyObject *op) } #define PyUnicode_AS_UNICODE(op) PyUnicode_AS_UNICODE(_PyObject_CAST(op)) -/* Py_DEPRECATED(3.3) */ +Py_DEPRECATED(3.3) static inline const char* PyUnicode_AS_DATA(PyObject *op) { + _Py_COMP_DIAG_PUSH + _Py_COMP_DIAG_IGNORE_DEPR_DECLS return (const char *)PyUnicode_AS_UNICODE(op); + _Py_COMP_DIAG_POP } #define PyUnicode_AS_DATA(op) PyUnicode_AS_DATA(_PyObject_CAST(op)) diff --git a/Misc/NEWS.d/next/C API/2022-04-21-23-11-35.gh-issue-80527.Cx-95G.rst b/Misc/NEWS.d/next/C API/2022-04-21-23-11-35.gh-issue-80527.Cx-95G.rst new file mode 100644 index 000000000000000..57283867f458852 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2022-04-21-23-11-35.gh-issue-80527.Cx-95G.rst @@ -0,0 +1,3 @@ +Mark functions as deprecated by :pep:`623:`: :c:func:`PyUnicode_AS_DATA`, +:c:func:`PyUnicode_AS_UNICODE`, :c:func:`PyUnicode_GET_DATA_SIZE`, +:c:func:`PyUnicode_GET_SIZE`. Patch by Victor Stinner. From da1302e27fc31bd4bf73cee574e76848132d23cc Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 21 Apr 2022 23:25:18 +0200 Subject: [PATCH 2/2] Fix typo --- .../next/C API/2022-04-21-23-11-35.gh-issue-80527.Cx-95G.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/C API/2022-04-21-23-11-35.gh-issue-80527.Cx-95G.rst b/Misc/NEWS.d/next/C API/2022-04-21-23-11-35.gh-issue-80527.Cx-95G.rst index 57283867f458852..45e92f1b9675915 100644 --- a/Misc/NEWS.d/next/C API/2022-04-21-23-11-35.gh-issue-80527.Cx-95G.rst +++ b/Misc/NEWS.d/next/C API/2022-04-21-23-11-35.gh-issue-80527.Cx-95G.rst @@ -1,3 +1,3 @@ -Mark functions as deprecated by :pep:`623:`: :c:func:`PyUnicode_AS_DATA`, +Mark functions as deprecated by :pep:`623`: :c:func:`PyUnicode_AS_DATA`, :c:func:`PyUnicode_AS_UNICODE`, :c:func:`PyUnicode_GET_DATA_SIZE`, :c:func:`PyUnicode_GET_SIZE`. Patch by Victor Stinner.