@@ -50,13 +50,17 @@ extern "C" {
5050 Py_UNICODE_ISDIGIT(ch) || \
5151 Py_UNICODE_ISNUMERIC(ch))
5252
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+ }
5557
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+ for (Py_ssize_t i = 0 ; i < length; i++) {
61+ target[i] = value;
62+ }
63+ }
6064
6165/* macros to work with surrogates */
6266#define Py_UNICODE_IS_SURROGATE (ch ) (0xD800 <= (ch) && (ch) <= 0xDFFF )
@@ -71,14 +75,6 @@ extern "C" {
7175/* low surrogate = bottom 10 bits added to DC00 */
7276#define Py_UNICODE_LOW_SURROGATE (ch ) (0xDC00 + ((ch) & 0x3FF ))
7377
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-
8278/* --- Unicode Type ------------------------------------------------------- */
8379
8480/* ASCII-only strings created through PyUnicode_New use the PyASCIIObject
@@ -251,10 +247,6 @@ PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
251247 int check_content);
252248
253249/* Fast access macros */
254- #define PyUnicode_WSTR_LENGTH (op ) \
255- (PyUnicode_IS_COMPACT_ASCII(op) ? \
256- ((PyASCIIObject*)op)->length : \
257- ((PyCompactUnicodeObject*)op)->wstr_length)
258250
259251/* Returns the deprecated Py_UNICODE representation's size in code units
260252 (this includes surrogate pairs as 2 units).
@@ -449,6 +441,14 @@ enum PyUnicode_Kind {
449441 (0xffffU ) : \
450442 (0x10ffffU )))))
451443
444+ Py_DEPRECATED (3.3 )
445+ static inline Py_ssize_t _PyUnicode_get_wstr_length(PyObject *op) {
446+ return PyUnicode_IS_COMPACT_ASCII (op) ?
447+ ((PyASCIIObject*)op)->length :
448+ ((PyCompactUnicodeObject*)op)->wstr_length ;
449+ }
450+ #define PyUnicode_WSTR_LENGTH (op ) _PyUnicode_get_wstr_length((PyObject*)op)
451+
452452/* === Public API ========================================================= */
453453
454454/* --- Plain Py_UNICODE --------------------------------------------------- */
@@ -547,7 +547,7 @@ PyAPI_FUNC(void) _PyUnicode_FastFill(
547547 only allowed if u was set to NULL.
548548
549549 The buffer is copied into the new object. */
550- /* Py_DEPRECATED(3.3) */ PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(
550+ Py_DEPRECATED (3.3 ) PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(
551551 const Py_UNICODE *u, /* Unicode buffer */
552552 Py_ssize_t size /* size of buffer */
553553 );
@@ -576,13 +576,13 @@ PyAPI_FUNC(Py_UCS4) _PyUnicode_FindMaxChar (
576576 Py_UNICODE buffer.
577577 If the wchar_t/Py_UNICODE representation is not yet available, this
578578 function will calculate it. */
579- /* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode(
579+ Py_DEPRECATED (3.3 ) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode(
580580 PyObject *unicode /* Unicode object */
581581 );
582582
583583/* Similar to PyUnicode_AsUnicode(), but raises a ValueError if the string
584584 contains null characters. */
585- PyAPI_FUNC (const Py_UNICODE *) _PyUnicode_AsUnicode(
585+ Py_DEPRECATED ( 3.3 ) PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode(
586586 PyObject *unicode /* Unicode object */
587587 );
588588
@@ -591,7 +591,7 @@ PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode(
591591 If the wchar_t/Py_UNICODE representation is not yet available, this
592592 function will calculate it. */
593593
594- /* Py_DEPRECATED(3.3) */ PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize(
594+ Py_DEPRECATED (3.3 ) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize(
595595 PyObject *unicode, /* Unicode object */
596596 Py_ssize_t *size /* location where to save the length */
597597 );
0 commit comments