@@ -351,7 +351,7 @@ static inline Py_ssize_t PyUnicode_GET_LENGTH(PyObject *op) {
351351 kind and data pointers obtained from other function calls.
352352 index is the index in the string (starts at 0) and value is the new
353353 code point value which should be written to that location. */
354- static inline void PyUnicode_WRITE (unsigned int kind, void *data,
354+ static inline void PyUnicode_WRITE (int kind, void *data,
355355 Py_ssize_t index, Py_UCS4 value)
356356{
357357 if (kind == PyUnicode_1BYTE_KIND) {
@@ -368,12 +368,15 @@ static inline void PyUnicode_WRITE(unsigned int kind, void *data,
368368 _Py_STATIC_CAST (Py_UCS4*, data)[index] = value;
369369 }
370370}
371+ #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
371372#define PyUnicode_WRITE (kind, data, index, value ) \
372- PyUnicode_WRITE ((unsigned int )(kind), (void *)(data), (index), (Py_UCS4)(value))
373+ PyUnicode_WRITE (_Py_STATIC_CAST(int , kind), _Py_CAST(void *, data), \
374+ (index), _Py_STATIC_CAST(Py_UCS4, value))
375+ #endif
373376
374377/* Read a code point from the string's canonical representation. No checks
375378 or ready calls are performed. */
376- static inline Py_UCS4 PyUnicode_READ(unsigned int kind,
379+ static inline Py_UCS4 PyUnicode_READ (int kind,
377380 const void *data, Py_ssize_t index)
378381{
379382 if (kind == PyUnicode_1BYTE_KIND) {
@@ -385,8 +388,11 @@ static inline Py_UCS4 PyUnicode_READ(unsigned int kind,
385388 assert (kind == PyUnicode_4BYTE_KIND);
386389 return _Py_STATIC_CAST (const Py_UCS4*, data)[index];
387390}
391+ #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
388392#define PyUnicode_READ (kind, data, index ) \
389- PyUnicode_READ ((unsigned int )(kind), (const void *)(data), (index))
393+ PyUnicode_READ (_Py_STATIC_CAST(int , kind), _Py_CAST(const void *, data), \
394+ (index))
395+ #endif
390396
391397/* PyUnicode_READ_CHAR() is less efficient than PyUnicode_READ() because it
392398 calls PyUnicode_KIND() and might call it twice. For single reads, use
@@ -395,7 +401,7 @@ static inline Py_UCS4 PyUnicode_READ(unsigned int kind,
395401static inline Py_UCS4 PyUnicode_READ_CHAR (PyObject *unicode, Py_ssize_t index)
396402{
397403 assert (PyUnicode_IS_READY (unicode));
398- unsigned int kind = PyUnicode_KIND (unicode);
404+ int kind = PyUnicode_KIND (unicode);
399405 if (kind == PyUnicode_1BYTE_KIND) {
400406 return PyUnicode_1BYTE_DATA (unicode)[index];
401407 }
@@ -420,7 +426,7 @@ static inline Py_UCS4 PyUnicode_MAX_CHAR_VALUE(PyObject *op)
420426 return 0x7fU ;
421427 }
422428
423- unsigned int kind = PyUnicode_KIND (op);
429+ int kind = PyUnicode_KIND (op);
424430 if (kind == PyUnicode_1BYTE_KIND) {
425431 return 0xffU ;
426432 }
0 commit comments