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

`@@ -46,13 +46,17 @@

`

46

46

` Py_UNICODE_ISDIGIT(ch) || \

`

47

47

` Py_UNICODE_ISNUMERIC(ch))

`

48

48

``

49

``

`-

#define Py_UNICODE_COPY(target, source, length) \

`

50

``

`-

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

`

51

``

-

52

``

`-

#define Py_UNICODE_FILL(target, value, length) \

`

53

``

`-

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

`

54

``

`-

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

`

55

``

`-

} while (0)

`

``

49

`+

Py_DEPRECATED(3.3) static inline void

`

``

50

`+

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

`

``

51

`+

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

`

``

52

`+

}

`

``

53

+

``

54

`+

Py_DEPRECATED(3.3) static inline void

`

``

55

`+

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

`

``

56

`+

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

`

``

57

`+

target[i] = value;

`

``

58

`+

}

`

``

59

`+

}

`

56

60

``

57

61

`/* macros to work with surrogates */

`

58

62

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

`

`@@ -67,14 +71,6 @@

`

67

71

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

`

68

72

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

`

69

73

``

70

``

`-

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

`

71

``

`-

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

`

72

``

-

73

``

`-

#define Py_UNICODE_MATCH(string, offset, substring) \

`

74

``

`-

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

`

75

``

`-

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

`

76

``

`-

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

`

77

``

-

78

74

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

`

79

75

``

80

76

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

`

`@@ -247,10 +243,6 @@ PyAPI_FUNC(int) _PyUnicode_CheckConsistency(

`

247

243

`int check_content);

`

248

244

``

249

245

`/* Fast access macros */

`

250

``

`-

#define PyUnicode_WSTR_LENGTH(op) \

`

251

``

`-

(PyUnicode_IS_COMPACT_ASCII(op) ? \

`

252

``

`-

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

`

253

``

`-

((PyCompactUnicodeObject*)op)->wstr_length)

`

254

246

``

255

247

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

`

256

248

` (this includes surrogate pairs as 2 units).

`

`@@ -445,6 +437,14 @@ enum PyUnicode_Kind {

`

445

437

` (0xffffU) : \

`

446

438

` (0x10ffffU)))))

`

447

439

``

``

440

`+

Py_DEPRECATED(3.3)

`

``

441

`+

static inline Py_ssize_t _PyUnicode_get_wstr_length(PyObject *op) {

`

``

442

`+

return PyUnicode_IS_COMPACT_ASCII(op) ?

`

``

443

`+

((PyASCIIObject*)op)->length :

`

``

444

`+

((PyCompactUnicodeObject*)op)->wstr_length;

`

``

445

`+

}

`

``

446

`+

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

`

``

447

+

448

448

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

`

449

449

``

450

450

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

`

`@@ -543,7 +543,7 @@ PyAPI_FUNC(void) _PyUnicode_FastFill(

`

543

543

` only allowed if u was set to NULL.

`

544

544

``

545

545

` The buffer is copied into the new object. */

`

546

``

`-

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

`

``

546

`+

Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(

`

547

547

`const Py_UNICODE u, / Unicode buffer */

`

548

548

` Py_ssize_t size /* size of buffer */

`

549

549

` );

`

`@@ -572,13 +572,13 @@ PyAPI_FUNC(Py_UCS4) _PyUnicode_FindMaxChar (

`

572

572

` Py_UNICODE buffer.

`

573

573

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

`

574

574

` function will calculate it. */

`

575

``

`-

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

`

``

575

`+

Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode(

`

576

576

` PyObject unicode / Unicode object */

`

577

577

` );

`

578

578

``

579

579

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

`

580

580

` contains null characters. */

`

581

``

`-

PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode(

`

``

581

`+

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

`

582

582

` PyObject unicode / Unicode object */

`

583

583

` );

`

584

584

``

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

`

587

587

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

`

588

588

` function will calculate it. */

`

589

589

``

590

``

`-

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

`

``

590

`+

Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize(

`

591

591

` PyObject unicode, / Unicode object */

`

592

592

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

`

593

593

` );

`