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

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

`

50

50

` Py_UNICODE_ISDIGIT(ch) || \

`

51

51

` Py_UNICODE_ISNUMERIC(ch))

`

52

52

``

53

``

`-

#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

`+

}

`

55

57

``

56

``

`-

#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

`+

}

`

60

65

``

61

66

`/* macros to work with surrogates */

`

62

67

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

`

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

`

71

76

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

`

72

77

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

`

73

78

``

74

``

`-

/* 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

``

-

82

79

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

`

83

80

``

84

81

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

`

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

`

251

248

`int check_content);

`

252

249

``

253

250

`/* Fast access macros */

`

254

``

`-

#define PyUnicode_WSTR_LENGTH(op) \

`

255

``

`-

(PyUnicode_IS_COMPACT_ASCII(op) ? \

`

256

``

`-

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

`

257

``

`-

((PyCompactUnicodeObject*)op)->wstr_length)

`

258

251

``

259

252

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

`

260

253

` (this includes surrogate pairs as 2 units).

`

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

`

449

442

` (0xffffU) : \

`

450

443

` (0x10ffffU)))))

`

451

444

``

``

445

`+

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

+

452

453

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

`

453

454

``

454

455

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

`

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

`

547

548

` only allowed if u was set to NULL.

`

548

549

``

549

550

` 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(

`

551

552

`const Py_UNICODE u, / Unicode buffer */

`

552

553

` Py_ssize_t size /* size of buffer */

`

553

554

` );

`

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

`

576

577

` Py_UNICODE buffer.

`

577

578

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

`

578

579

` 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(

`

580

581

` PyObject unicode / Unicode object */

`

581

582

` );

`

582

583

``

583

584

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

`

584

585

` contains null characters. */

`

585

``

`-

PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode(

`

``

586

`+

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

`

586

587

` PyObject unicode / Unicode object */

`

587

588

` );

`

588

589

``

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

`

591

592

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

`

592

593

` function will calculate it. */

`

593

594

``

594

``

`-

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

`

``

595

`+

Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize(

`

595

596

` PyObject unicode, / Unicode object */

`

596

597

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

`

597

598

` );

`