bpo-36346: Add Py_DEPRECATED to deprecated unicode APIs (GH-20878) · python/cpython@610a60c

@@ -50,13 +50,18 @@ extern "C" {

5050

Py_UNICODE_ISDIGIT(ch) || \

5151

Py_UNICODE_ISNUMERIC(ch))

525253-

#define Py_UNICODE_COPY(target, source, length) \

54-

memcpy((target), (source), (length)*sizeof(Py_UNICODE))

53+

Py_DEPRECATED(3.3) static inline void

54+

Py_UNICODE_COPY(Py_UNICODE *target, const Py_UNICODE *source, Py_ssize_t length) {

55+

memcpy(target, source, length * sizeof(Py_UNICODE));

56+

}

555756-

#define Py_UNICODE_FILL(target, value, length) \

57-

do {Py_ssize_t i_; Py_UNICODE *t_ = (target); Py_UNICODE v_ = (value);\

58-

for (i_ = 0; i_ < (length); i_++) t_[i_] = v_;\

59-

} while (0)

58+

Py_DEPRECATED(3.3) static inline void

59+

Py_UNICODE_FILL(Py_UNICODE *target, Py_UNICODE value, Py_ssize_t length) {

60+

Py_ssize_t i;

61+

for (i = 0; i < length; i++) {

62+

target[i] = value;

63+

}

64+

}

60656166

/* macros to work with surrogates */

6267

#define Py_UNICODE_IS_SURROGATE(ch) (0xD800 <= (ch) && (ch) <= 0xDFFF)

@@ -71,14 +76,6 @@ extern "C" {

7176

/* low surrogate = bottom 10 bits added to DC00 */

7277

#define Py_UNICODE_LOW_SURROGATE(ch) (0xDC00 + ((ch) & 0x3FF))

737874-

/* Check if substring matches at given offset. The offset must be

75-

valid, and the substring must not be empty. */

76-77-

#define Py_UNICODE_MATCH(string, offset, substring) \

78-

((*((string)->wstr + (offset)) == *((substring)->wstr)) && \

79-

((*((string)->wstr + (offset) + (substring)->wstr_length-1) == *((substring)->wstr + (substring)->wstr_length-1))) && \

80-

!memcmp((string)->wstr + (offset), (substring)->wstr, (substring)->wstr_length*sizeof(Py_UNICODE)))

81-8279

/* --- Unicode Type ------------------------------------------------------- */

83808481

/* ASCII-only strings created through PyUnicode_New use the PyASCIIObject

@@ -251,10 +248,6 @@ PyAPI_FUNC(int) _PyUnicode_CheckConsistency(

251248

int check_content);

252249253250

/* Fast access macros */

254-

#define PyUnicode_WSTR_LENGTH(op) \

255-

(PyUnicode_IS_COMPACT_ASCII(op) ? \

256-

((PyASCIIObject*)op)->length : \

257-

((PyCompactUnicodeObject*)op)->wstr_length)

258251259252

/* Returns the deprecated Py_UNICODE representation's size in code units

260253

(this includes surrogate pairs as 2 units).

@@ -449,6 +442,14 @@ enum PyUnicode_Kind {

449442

(0xffffU) : \

450443

(0x10ffffU)))))

451444445+

Py_DEPRECATED(3.3)

446+

static inline Py_ssize_t _PyUnicode_get_wstr_length(PyObject *op) {

447+

return PyUnicode_IS_COMPACT_ASCII(op) ?

448+

((PyASCIIObject*)op)->length :

449+

((PyCompactUnicodeObject*)op)->wstr_length;

450+

}

451+

#define PyUnicode_WSTR_LENGTH(op) _PyUnicode_get_wstr_length((PyObject*)op)

452+452453

/* === Public API ========================================================= */

453454454455

/* --- Plain Py_UNICODE --------------------------------------------------- */

@@ -547,7 +548,7 @@ PyAPI_FUNC(void) _PyUnicode_FastFill(

547548

only allowed if u was set to NULL.

548549549550

The buffer is copied into the new object. */

550-

/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(

551+

Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(

551552

const Py_UNICODE *u, /* Unicode buffer */

552553

Py_ssize_t size /* size of buffer */

553554

);

@@ -576,13 +577,13 @@ PyAPI_FUNC(Py_UCS4) _PyUnicode_FindMaxChar (

576577

Py_UNICODE buffer.

577578

If the wchar_t/Py_UNICODE representation is not yet available, this

578579

function will calculate it. */

579-

/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode(

580+

Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode(

580581

PyObject *unicode /* Unicode object */

581582

);

582583583584

/* Similar to PyUnicode_AsUnicode(), but raises a ValueError if the string

584585

contains null characters. */

585-

PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode(

586+

Py_DEPRECATED(3.3) PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode(

586587

PyObject *unicode /* Unicode object */

587588

);

588589

@@ -591,7 +592,7 @@ PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode(

591592

If the wchar_t/Py_UNICODE representation is not yet available, this

592593

function will calculate it. */

593594594-

/* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize(

595+

Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize(

595596

PyObject *unicode, /* Unicode object */

596597

Py_ssize_t *size /* location where to save the length */

597598

);