From b7bb1693f4293a32d0382565db7f3365a3b42354 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Mon, 15 Jun 2020 09:55:04 +0900 Subject: [PATCH 01/17] bpo-36346: Uncomment Py_DEPRECATED for deprecated unicode APIs --- Include/cpython/unicodeobject.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 3b49ce7759037e..2d5bdd66b95174 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -543,7 +543,7 @@ PyAPI_FUNC(void) _PyUnicode_FastFill( only allowed if u was set to NULL. The buffer is copied into the new object. */ -/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode( +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode( const Py_UNICODE *u, /* Unicode buffer */ Py_ssize_t size /* size of buffer */ ); @@ -572,7 +572,7 @@ PyAPI_FUNC(Py_UCS4) _PyUnicode_FindMaxChar ( Py_UNICODE buffer. If the wchar_t/Py_UNICODE representation is not yet available, this function will calculate it. */ -/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode( +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode( PyObject *unicode /* Unicode object */ ); @@ -587,7 +587,7 @@ PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode( If the wchar_t/Py_UNICODE representation is not yet available, this function will calculate it. */ -/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize( +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize( PyObject *unicode, /* Unicode object */ Py_ssize_t *size /* location where to save the length */ ); @@ -974,7 +974,7 @@ Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS( */ -/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(int) PyUnicode_EncodeDecimal( +Py_DEPRECATED(3.3) PyAPI_FUNC(int) PyUnicode_EncodeDecimal( Py_UNICODE *s, /* Unicode buffer */ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ char *output, /* Output buffer; must have size >= length */ @@ -987,7 +987,7 @@ Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS( Returns a new Unicode string on success, NULL on failure. */ -/* Py_DEPRECATED(3.3) */ +Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_TransformDecimalToASCII( Py_UNICODE *s, /* Unicode buffer */ Py_ssize_t length /* Number of Py_UNICODE chars to transform */ @@ -1090,11 +1090,11 @@ PyAPI_FUNC(int) _PyUnicode_IsLinebreak( const Py_UCS4 ch /* Unicode character */ ); -/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UCS4) _PyUnicode_ToLowercase( +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UCS4) _PyUnicode_ToLowercase( Py_UCS4 ch /* Unicode character */ ); -/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UCS4) _PyUnicode_ToUppercase( +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UCS4) _PyUnicode_ToUppercase( Py_UCS4 ch /* Unicode character */ ); From 4e887186c63e5a1d626d1044eec7ab145a70cec2 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Mon, 15 Jun 2020 14:32:11 +0900 Subject: [PATCH 02/17] Deprecate _PyUnicode_AsUnicode --- Include/cpython/unicodeobject.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 2d5bdd66b95174..34943ed24023ca 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -46,9 +46,11 @@ Py_UNICODE_ISDIGIT(ch) || \ Py_UNICODE_ISNUMERIC(ch)) +/* Py_DEPRECATED(3.3) */ #define Py_UNICODE_COPY(target, source, length) \ memcpy((target), (source), (length)*sizeof(Py_UNICODE)) +/* Py_DEPRECATED(3.3) */ #define Py_UNICODE_FILL(target, value, length) \ do {Py_ssize_t i_; Py_UNICODE *t_ = (target); Py_UNICODE v_ = (value);\ for (i_ = 0; i_ < (length); i_++) t_[i_] = v_;\ @@ -70,6 +72,7 @@ /* Check if substring matches at given offset. The offset must be valid, and the substring must not be empty. */ +/* Py_DEPRECATED(3.3) */ #define Py_UNICODE_MATCH(string, offset, substring) \ ((*((string)->wstr + (offset)) == *((substring)->wstr)) && \ ((*((string)->wstr + (offset) + (substring)->wstr_length-1) == *((substring)->wstr + (substring)->wstr_length-1))) && \ @@ -247,6 +250,7 @@ PyAPI_FUNC(int) _PyUnicode_CheckConsistency( int check_content); /* Fast access macros */ +/* Py_DEPRECATED(3.3) */ #define PyUnicode_WSTR_LENGTH(op) \ (PyUnicode_IS_COMPACT_ASCII(op) ? \ ((PyASCIIObject*)op)->length : \ @@ -578,7 +582,7 @@ Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode( /* Similar to PyUnicode_AsUnicode(), but raises a ValueError if the string contains null characters. */ -PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode( +Py_DEPRECATED(3.3) PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode( PyObject *unicode /* Unicode object */ ); From 6b9d12cf7f8b025574393c958f7d7e47c0a32f47 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 16 Jun 2020 10:06:13 +0900 Subject: [PATCH 03/17] Supress deprecation warnings --- Modules/_testcapimodule.c | 3 +++ Objects/unicodeobject.c | 13 +++++++++++++ Python/getargs.c | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index e0457ae5dfa55d..d44775b4ec636b 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -36,6 +36,9 @@ # error "_testcapi must test the public Python C API, not CPython internal C API" #endif +/* Ignore use of deprecated APIs */ +_Py_COMP_DIAG_IGNORE_DEPR_DECLS + static struct PyModuleDef _testcapimodule; static PyObject *TestError; /* set to exception object in init */ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index c75eb077e0c80d..a41f6afaae772a 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -970,11 +970,14 @@ ensure_unicode(PyObject *obj) #include "stringlib/find_max_char.h" #include "stringlib/undef.h" +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS #include "stringlib/unicodedefs.h" #include "stringlib/fastsearch.h" #include "stringlib/count.h" #include "stringlib/find.h" #include "stringlib/undef.h" +_Py_COMP_DIAG_POP /* --- Unicode Object ----------------------------------------------------- */ @@ -4097,6 +4100,11 @@ PyUnicode_AsUnicodeAndSize(PyObject *unicode, Py_ssize_t *size) return w; } +/* Deprecated APIs */ + +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS + Py_UNICODE * PyUnicode_AsUnicode(PyObject *unicode) { @@ -4135,6 +4143,8 @@ PyUnicode_GetSize(PyObject *unicode) return -1; } +_Py_COMP_DIAG_POP + Py_ssize_t PyUnicode_GetLength(PyObject *unicode) { @@ -12364,6 +12374,8 @@ PyUnicode_IsIdentifier(PyObject *self) return len && i == len; } else { +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS Py_ssize_t i = 0, len = PyUnicode_GET_SIZE(self); if (len == 0) { /* an empty string is not a valid identifier */ @@ -12401,6 +12413,7 @@ PyUnicode_IsIdentifier(PyObject *self) } } return 1; +_Py_COMP_DIAG_POP } } diff --git a/Python/getargs.c b/Python/getargs.c index d2dba49966d47f..cf0cc0783687ae 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -1027,6 +1027,9 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, case 'u': /* raw unicode buffer (Py_UNICODE *) */ case 'Z': /* raw unicode buffer or None */ { + // TODO: Raise DeprecationWarning +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **); if (*format == '#') { @@ -1066,6 +1069,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, arg, msgbuf, bufsize); } break; +_Py_COMP_DIAG_POP } case 'e': {/* encoded string */ From 10e1b13e08a0d590cbeea68b5e55da95d36f7fac Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 16 Jun 2020 10:50:01 +0900 Subject: [PATCH 04/17] Use inline functions. Undeprecate some APIs. --- Include/cpython/unicodeobject.h | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 34943ed24023ca..8c9b41cbb55abd 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -46,15 +46,17 @@ Py_UNICODE_ISDIGIT(ch) || \ Py_UNICODE_ISNUMERIC(ch)) -/* Py_DEPRECATED(3.3) */ -#define Py_UNICODE_COPY(target, source, length) \ - memcpy((target), (source), (length)*sizeof(Py_UNICODE)) - -/* Py_DEPRECATED(3.3) */ -#define Py_UNICODE_FILL(target, value, length) \ - do {Py_ssize_t i_; Py_UNICODE *t_ = (target); Py_UNICODE v_ = (value);\ - for (i_ = 0; i_ < (length); i_++) t_[i_] = v_;\ - } while (0) +Py_DEPRECATED(3.3) static inline void +Py_UNICODE_COPY(Py_UNICODE *target, const Py_UNICODE *source, Py_ssize_t length) { + memcpy(target, source, length * sizeof(Py_UNICODE)); +} + +Py_DEPRECATED(3.3) static inline void +Py_UNICODE_FILL(Py_UNICODE *target, Py_UNICODE value, Py_ssize_t length) { + for (Py_ssize_t i = 0; i < length; i++) { + target[i] = value; + } +} /* macros to work with surrogates */ #define Py_UNICODE_IS_SURROGATE(ch) (0xD800 <= (ch) && (ch) <= 0xDFFF) @@ -1094,15 +1096,15 @@ PyAPI_FUNC(int) _PyUnicode_IsLinebreak( const Py_UCS4 ch /* Unicode character */ ); -Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UCS4) _PyUnicode_ToLowercase( +PyAPI_FUNC(Py_UCS4) _PyUnicode_ToLowercase( Py_UCS4 ch /* Unicode character */ ); -Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UCS4) _PyUnicode_ToUppercase( +PyAPI_FUNC(Py_UCS4) _PyUnicode_ToUppercase( Py_UCS4 ch /* Unicode character */ ); -Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UCS4) _PyUnicode_ToTitlecase( +PyAPI_FUNC(Py_UCS4) _PyUnicode_ToTitlecase( Py_UCS4 ch /* Unicode character */ ); From a703182b776ebcb7c92666827cafe6f80f5bb0fd Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 16 Jun 2020 22:09:30 +0900 Subject: [PATCH 05/17] Revive commented deprecation --- Include/cpython/unicodeobject.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 8c9b41cbb55abd..b4b31a7c77b597 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -1096,15 +1096,15 @@ PyAPI_FUNC(int) _PyUnicode_IsLinebreak( const Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(Py_UCS4) _PyUnicode_ToLowercase( +/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UCS4) _PyUnicode_ToLowercase( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(Py_UCS4) _PyUnicode_ToUppercase( +/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UCS4) _PyUnicode_ToUppercase( Py_UCS4 ch /* Unicode character */ ); -PyAPI_FUNC(Py_UCS4) _PyUnicode_ToTitlecase( +/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UCS4) _PyUnicode_ToTitlecase( Py_UCS4 ch /* Unicode character */ ); From 468a43b160856f192151454931d1a3dc07438eae Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 16 Jun 2020 22:12:01 +0900 Subject: [PATCH 06/17] supress one more warning --- Objects/unicodeobject.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index a41f6afaae772a..ed1d1a9ca30c56 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -15968,7 +15968,10 @@ PyUnicode_AsUnicodeCopy(PyObject *unicode) PyErr_BadArgument(); return NULL; } +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS u = PyUnicode_AsUnicodeAndSize(unicode, &len); +_Py_COMP_DIAG_POP if (u == NULL) return NULL; /* Ensure we won't overflow the size. */ From 52802fef557a3ab0f278abdc8113bf2c5dda38b9 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 16 Jun 2020 23:07:13 +0900 Subject: [PATCH 07/17] Remove Py_UNICODE_MATCH and deprecate PyUnicode_WSTR_LENGTH --- Include/cpython/unicodeobject.h | 24 ++++++++++-------------- Objects/unicodeobject.c | 7 +++++++ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index b4b31a7c77b597..61f4244e960784 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -71,15 +71,6 @@ Py_UNICODE_FILL(Py_UNICODE *target, Py_UNICODE value, Py_ssize_t length) { /* low surrogate = bottom 10 bits added to DC00 */ #define Py_UNICODE_LOW_SURROGATE(ch) (0xDC00 + ((ch) & 0x3FF)) -/* Check if substring matches at given offset. The offset must be - valid, and the substring must not be empty. */ - -/* Py_DEPRECATED(3.3) */ -#define Py_UNICODE_MATCH(string, offset, substring) \ - ((*((string)->wstr + (offset)) == *((substring)->wstr)) && \ - ((*((string)->wstr + (offset) + (substring)->wstr_length-1) == *((substring)->wstr + (substring)->wstr_length-1))) && \ - !memcmp((string)->wstr + (offset), (substring)->wstr, (substring)->wstr_length*sizeof(Py_UNICODE))) - /* --- Unicode Type ------------------------------------------------------- */ /* ASCII-only strings created through PyUnicode_New use the PyASCIIObject @@ -252,11 +243,6 @@ PyAPI_FUNC(int) _PyUnicode_CheckConsistency( int check_content); /* Fast access macros */ -/* Py_DEPRECATED(3.3) */ -#define PyUnicode_WSTR_LENGTH(op) \ - (PyUnicode_IS_COMPACT_ASCII(op) ? \ - ((PyASCIIObject*)op)->length : \ - ((PyCompactUnicodeObject*)op)->wstr_length) /* Returns the deprecated Py_UNICODE representation's size in code units (this includes surrogate pairs as 2 units). @@ -451,6 +437,16 @@ enum PyUnicode_Kind { (0xffffU) : \ (0x10ffffU))))) +/* Py_DEPRECATED(3.3) */ +#define PyUnicode_WSTR_LENGTH(op) _PyUnicode_WSTR_LENGTH_impl((PyObject*)op) + +Py_DEPRECATED(3.3) +static inline Py_ssize_t _PyUnicode_WSTR_LENGTH_impl(PyObject *op) { + return PyUnicode_IS_COMPACT_ASCII(op) ? + ((PyASCIIObject*)op)->length : + ((PyCompactUnicodeObject*)op)->wstr_length; +} + /* === Public API ========================================================= */ /* --- Plain Py_UNICODE --------------------------------------------------- */ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index ed1d1a9ca30c56..36f784f80f3bd0 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -120,6 +120,13 @@ extern "C" { _PyUnicode_UTF8_LENGTH(op)) #define _PyUnicode_WSTR(op) \ (((PyASCIIObject*)(op))->wstr) + +/* Don't use deprecated macro in unicodeobject.h */ +#undef PyUnicode_WSTR_LENGTH +#define PyUnicode_WSTR_LENGTH(op) \ + (PyUnicode_IS_COMPACT_ASCII(op) ? \ + ((PyASCIIObject*)op)->length : \ + ((PyCompactUnicodeObject*)op)->wstr_length) #define _PyUnicode_WSTR_LENGTH(op) \ (((PyCompactUnicodeObject*)(op))->wstr_length) #define _PyUnicode_LENGTH(op) \ From 6e862368b0d8b320b8e083618935eeca334fd416 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 16 Jun 2020 23:14:02 +0900 Subject: [PATCH 08/17] Undeprecate APIs that doesn't use wstr --- Include/cpython/unicodeobject.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 61f4244e960784..6f677a8549beaa 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -976,7 +976,7 @@ Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS( */ -Py_DEPRECATED(3.3) PyAPI_FUNC(int) PyUnicode_EncodeDecimal( +/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(int) PyUnicode_EncodeDecimal( Py_UNICODE *s, /* Unicode buffer */ Py_ssize_t length, /* Number of Py_UNICODE chars to encode */ char *output, /* Output buffer; must have size >= length */ @@ -989,7 +989,7 @@ Py_DEPRECATED(3.3) PyAPI_FUNC(int) PyUnicode_EncodeDecimal( Returns a new Unicode string on success, NULL on failure. */ -Py_DEPRECATED(3.3) +/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(PyObject*) PyUnicode_TransformDecimalToASCII( Py_UNICODE *s, /* Unicode buffer */ Py_ssize_t length /* Number of Py_UNICODE chars to transform */ From b9fa49a6734e5c9bd88955d722bd014197ca5854 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Tue, 16 Jun 2020 23:15:41 +0900 Subject: [PATCH 09/17] Update _testcapimodule --- Modules/_testcapimodule.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index d44775b4ec636b..0b2ebc7555fc64 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -36,9 +36,6 @@ # error "_testcapi must test the public Python C API, not CPython internal C API" #endif -/* Ignore use of deprecated APIs */ -_Py_COMP_DIAG_IGNORE_DEPR_DECLS - static struct PyModuleDef _testcapimodule; static PyObject *TestError; /* set to exception object in init */ @@ -1671,6 +1668,10 @@ parse_tuple_and_keywords(PyObject *self, PyObject *args) static volatile int x; +/* Ignore use of deprecated APIs */ +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS + /* Test the u and u# codes for PyArg_ParseTuple. May leak memory in case of an error. */ @@ -1847,6 +1848,7 @@ test_widechar(PyObject *self, PyObject *Py_UNUSED(ignored)) Py_RETURN_NONE; } +_Py_COMP_DIAG_POP static PyObject * unicode_aswidechar(PyObject *self, PyObject *args) From 30bed2d4e79ba116542709aa69b1efb410d31cd6 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 17 Jun 2020 11:24:04 +0900 Subject: [PATCH 10/17] Add news --- Doc/whatsnew/3.9.rst | 6 ++++++ .../next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst | 5 +++++ 2 files changed, 11 insertions(+) create mode 100644 Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index 67a83bc9584578..b586f0827e9f4b 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -1097,6 +1097,12 @@ Porting to Python 3.9 internal C API (``pycore_gc.h``). (Contributed by Victor Stinner in :issue:`40241`.) +* The ``Py_UNICODE_COPY``, ``Py_UNICODE_FILL``, ``PyUnicode_WSTR_LENGTH``, + ``PyUnicode_WSTR_LENGTH``, ``PyUnicode_FromUnicode``, + ``PyUnicode_AsUnicode``, ``_PyUnicode_AsUnicode``, and + ``PyUnicode_AsUnicodeAndSize`` deprecated in C. + Remove ``Py_UNICODE_MATCH`` + because it was broken since Python 3.3. Removed ------- diff --git a/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst b/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst new file mode 100644 index 00000000000000..b708d27055605c --- /dev/null +++ b/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst @@ -0,0 +1,5 @@ +Mark ``Py_UNICODE_COPY``, ``Py_UNICODE_FILL``, ``PyUnicode_WSTR_LENGTH``, +``PyUnicode_WSTR_LENGTH``, ``PyUnicode_FromUnicode``, +``PyUnicode_AsUnicode``, ``_PyUnicode_AsUnicode``, and +``PyUnicode_AsUnicodeAndSize`` deprecated in C. Remove ``Py_UNICODE_MATCH`` +because it was broken since Python 3.3. From 4490cc7a3726730521c7719bf41e541e50254668 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 17 Jun 2020 11:40:39 +0900 Subject: [PATCH 11/17] Add what's new entry --- Doc/whatsnew/3.9.rst | 14 +++++++++----- .../C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst | 5 ++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index b586f0827e9f4b..caa566b611f010 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -1098,11 +1098,11 @@ Porting to Python 3.9 (Contributed by Victor Stinner in :issue:`40241`.) * The ``Py_UNICODE_COPY``, ``Py_UNICODE_FILL``, ``PyUnicode_WSTR_LENGTH``, - ``PyUnicode_WSTR_LENGTH``, ``PyUnicode_FromUnicode``, - ``PyUnicode_AsUnicode``, ``_PyUnicode_AsUnicode``, and - ``PyUnicode_AsUnicodeAndSize`` deprecated in C. - Remove ``Py_UNICODE_MATCH`` - because it was broken since Python 3.3. + :c:func:`PyUnicode_FromUnicode`, :c:func:`PyUnicode_AsUnicode`, + ``_PyUnicode_AsUnicode``, and :c:func:`PyUnicode_AsUnicodeAndSize` are + marked as deprecated in C. They have been deprecated by :pep:`393` since + Python 3.3. + (Contributed by Inada Naoki in :issue:`36346`.) Removed ------- @@ -1171,3 +1171,7 @@ Removed * Remove ``_PyUnicode_ClearStaticStrings()`` function. (Contributed by Victor Stinner in :issue:`39465`.) + +* Remove ``Py_UNICODE_MATCH``. It has been deprecated by :pep:`393`, and + broken since Python 3.3. + (Contributed by Inada Naoki in :issue:`36346`.) diff --git a/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst b/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst index b708d27055605c..ba2033ebe82311 100644 --- a/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst +++ b/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst @@ -1,5 +1,4 @@ Mark ``Py_UNICODE_COPY``, ``Py_UNICODE_FILL``, ``PyUnicode_WSTR_LENGTH``, -``PyUnicode_WSTR_LENGTH``, ``PyUnicode_FromUnicode``, -``PyUnicode_AsUnicode``, ``_PyUnicode_AsUnicode``, and -``PyUnicode_AsUnicodeAndSize`` deprecated in C. Remove ``Py_UNICODE_MATCH`` +``PyUnicode_FromUnicode``, ``PyUnicode_AsUnicode``, ``_PyUnicode_AsUnicode``, +and ``PyUnicode_AsUnicodeAndSize`` deprecated in C. Remove ``Py_UNICODE_MATCH`` because it was broken since Python 3.3. From 8c2daaee9724e54a08095ae8f11b9624cf2c6436 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 17 Jun 2020 11:42:39 +0900 Subject: [PATCH 12/17] fixup --- Include/cpython/unicodeobject.h | 6 ++---- Modules/_testcapimodule.c | 5 +++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 6f677a8549beaa..d7c8c7db966674 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -437,15 +437,13 @@ enum PyUnicode_Kind { (0xffffU) : \ (0x10ffffU))))) -/* Py_DEPRECATED(3.3) */ -#define PyUnicode_WSTR_LENGTH(op) _PyUnicode_WSTR_LENGTH_impl((PyObject*)op) - Py_DEPRECATED(3.3) static inline Py_ssize_t _PyUnicode_WSTR_LENGTH_impl(PyObject *op) { return PyUnicode_IS_COMPACT_ASCII(op) ? ((PyASCIIObject*)op)->length : ((PyCompactUnicodeObject*)op)->wstr_length; } +#define PyUnicode_WSTR_LENGTH(op) _PyUnicode_WSTR_LENGTH_impl((PyObject*)op) /* === Public API ========================================================= */ @@ -1100,7 +1098,7 @@ PyAPI_FUNC(int) _PyUnicode_IsLinebreak( Py_UCS4 ch /* Unicode character */ ); -/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UCS4) _PyUnicode_ToTitlecase( +Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UCS4) _PyUnicode_ToTitlecase( Py_UCS4 ch /* Unicode character */ ); diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 0b2ebc7555fc64..5302641a9a37ef 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2069,6 +2069,10 @@ unicode_transformdecimaltoascii(PyObject *self, PyObject *args) return PyUnicode_TransformDecimalToASCII(unicode, length); } +/* Ignore use of deprecated APIs */ +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS + static PyObject * unicode_legacy_string(PyObject *self, PyObject *args) { @@ -2091,6 +2095,7 @@ unicode_legacy_string(PyObject *self, PyObject *args) return u; } +_Py_COMP_DIAG_POP static PyObject * getargs_w_star(PyObject *self, PyObject *args) From cae48046c123dcba9ca2f28e8e9c2c23f88b3eca Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 17 Jun 2020 12:13:09 +0900 Subject: [PATCH 13/17] Update Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst Co-authored-by: Kyle Stanley --- .../next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst b/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst index ba2033ebe82311..f26955e1c32311 100644 --- a/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst +++ b/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst @@ -1,4 +1,4 @@ Mark ``Py_UNICODE_COPY``, ``Py_UNICODE_FILL``, ``PyUnicode_WSTR_LENGTH``, ``PyUnicode_FromUnicode``, ``PyUnicode_AsUnicode``, ``_PyUnicode_AsUnicode``, -and ``PyUnicode_AsUnicodeAndSize`` deprecated in C. Remove ``Py_UNICODE_MATCH`` -because it was broken since Python 3.3. +and ``PyUnicode_AsUnicodeAndSize`` as deprecated in C. Remove ``Py_UNICODE_MATCH`` +because it has been broken since Python 3.3. From 26cb7891d32962c3448d55e8cccdf417d7ec674c Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 17 Jun 2020 17:27:33 +0900 Subject: [PATCH 14/17] Update Objects/unicodeobject.c Co-authored-by: Victor Stinner --- Objects/unicodeobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 36f784f80f3bd0..1433848c81f8e1 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -121,7 +121,7 @@ extern "C" { #define _PyUnicode_WSTR(op) \ (((PyASCIIObject*)(op))->wstr) -/* Don't use deprecated macro in unicodeobject.h */ +/* Don't use deprecated macro of unicodeobject.h */ #undef PyUnicode_WSTR_LENGTH #define PyUnicode_WSTR_LENGTH(op) \ (PyUnicode_IS_COMPACT_ASCII(op) ? \ From 439048953dcaf81ad1299427a415bbb4543751f6 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 17 Jun 2020 17:33:22 +0900 Subject: [PATCH 15/17] Update Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst Co-authored-by: Victor Stinner --- Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst b/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst index f26955e1c32311..902a0e60727e6a 100644 --- a/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst +++ b/Misc/NEWS.d/next/C API/2020-06-17-11-24-00.bpo-36346.fTMr3S.rst @@ -1,4 +1,4 @@ Mark ``Py_UNICODE_COPY``, ``Py_UNICODE_FILL``, ``PyUnicode_WSTR_LENGTH``, ``PyUnicode_FromUnicode``, ``PyUnicode_AsUnicode``, ``_PyUnicode_AsUnicode``, and ``PyUnicode_AsUnicodeAndSize`` as deprecated in C. Remove ``Py_UNICODE_MATCH`` -because it has been broken since Python 3.3. +which was deprecated and broken since Python 3.3. From 35d68db32d2d70560526d8e91804d3eb6eed9f00 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 17 Jun 2020 17:34:42 +0900 Subject: [PATCH 16/17] fixup --- Doc/whatsnew/3.9.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index caa566b611f010..15fca8fa9d4c98 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -1172,6 +1172,7 @@ Removed * Remove ``_PyUnicode_ClearStaticStrings()`` function. (Contributed by Victor Stinner in :issue:`39465`.) -* Remove ``Py_UNICODE_MATCH``. It has been deprecated by :pep:`393`, and - broken since Python 3.3. +* Remove ``Py_UNICODE_MATCH``. It has been deprecated by :pep:`393`, and + broken since Python 3.3. The :c:func:`PyUnicode_Tailmatch` function can be + used instead. (Contributed by Inada Naoki in :issue:`36346`.) From b3ee75124537449e73bb9a89a8c155fae0089c59 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Wed, 17 Jun 2020 19:36:06 +0900 Subject: [PATCH 17/17] avoid _impl suffix --- Include/cpython/unicodeobject.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index d7c8c7db966674..569bdb1e2a94ba 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -438,12 +438,12 @@ enum PyUnicode_Kind { (0x10ffffU))))) Py_DEPRECATED(3.3) -static inline Py_ssize_t _PyUnicode_WSTR_LENGTH_impl(PyObject *op) { +static inline Py_ssize_t _PyUnicode_get_wstr_length(PyObject *op) { return PyUnicode_IS_COMPACT_ASCII(op) ? ((PyASCIIObject*)op)->length : ((PyCompactUnicodeObject*)op)->wstr_length; } -#define PyUnicode_WSTR_LENGTH(op) _PyUnicode_WSTR_LENGTH_impl((PyObject*)op) +#define PyUnicode_WSTR_LENGTH(op) _PyUnicode_get_wstr_length((PyObject*)op) /* === Public API ========================================================= */