@@ -769,7 +769,6 @@ DEFINE_COMPAREITEMS(QQ, unsigned long long)
769769static const struct arraydescr descriptors [] = {
770770 {"b" , 1 , b_getitem , b_setitem , b_compareitems , 1 , 1 },
771771 {"B" , 1 , BB_getitem , BB_setitem , BB_compareitems , 1 , 0 },
772- {"u" , sizeof (wchar_t ), u_getitem , u_setitem , u_compareitems , 0 , 0 },
773772 {"w" , sizeof (Py_UCS4 ), w_getitem , w_setitem , w_compareitems , 0 , 0 ,},
774773 {"h" , sizeof (short ), h_getitem , h_setitem , h_compareitems , 1 , 1 },
775774 {"H" , sizeof (short ), HH_getitem , HH_setitem , HH_compareitems , 1 , 0 },
@@ -1985,47 +1984,30 @@ array_array_fromunicode_impl(arrayobject *self, PyObject *ustr)
19851984/*[clinic end generated code: output=24359f5e001a7f2b input=158d47c302f27ca1]*/
19861985{
19871986 const char * typecode = self -> ob_descr -> typecode ;
1988- if (strcmp (typecode , "u" ) != 0 && strcmp ( typecode , " w" ) != 0 ) {
1987+ if (strcmp (typecode , "w" ) != 0 ) {
19891988 PyErr_SetString (PyExc_ValueError ,
19901989 "fromunicode() may only be called on "
1991- "unicode type arrays ('u' or ' w')" );
1990+ "unicode type (' w') arrays " );
19921991 return NULL ;
19931992 }
19941993
1995- if (strcmp (typecode , "u" ) == 0 ) {
1996- Py_ssize_t ustr_length = PyUnicode_AsWideChar (ustr , NULL , 0 );
1997- assert (ustr_length > 0 );
1998- if (ustr_length > 1 ) {
1999- ustr_length -- ; /* trim trailing NUL character */
2000- Py_ssize_t old_size = Py_SIZE (self );
2001- if (array_resize (self , old_size + ustr_length ) == -1 ) {
2002- return NULL ;
2003- }
1994+ Py_ssize_t ustr_length = PyUnicode_GetLength (ustr );
1995+ Py_ssize_t old_size = Py_SIZE (self );
1996+ Py_ssize_t new_size = old_size + ustr_length ;
20041997
2005- // must not fail
2006- PyUnicode_AsWideChar (
2007- ustr , ((wchar_t * )self -> ob_item ) + old_size , ustr_length );
2008- }
1998+ if (new_size < 0 || (size_t )new_size > PY_SSIZE_T_MAX / sizeof (Py_UCS4 )) {
1999+ return PyErr_NoMemory ();
20092000 }
2010- else { // typecode == "w"
2011- Py_ssize_t ustr_length = PyUnicode_GetLength (ustr );
2012- Py_ssize_t old_size = Py_SIZE (self );
2013- Py_ssize_t new_size = old_size + ustr_length ;
2014-
2015- if (new_size < 0 || (size_t )new_size > PY_SSIZE_T_MAX / sizeof (Py_UCS4 )) {
2016- return PyErr_NoMemory ();
2017- }
2018- if (array_resize (self , new_size ) == -1 ) {
2019- return NULL ;
2020- }
2021-
2022- // must not fail
2023- Py_UCS4 * u = PyUnicode_AsUCS4 (ustr , ((Py_UCS4 * )self -> ob_item ) + old_size ,
2024- ustr_length , 0 );
2025- assert (u != NULL );
2026- (void )u ; // Suppress unused_variable warning.
2001+ if (array_resize (self , new_size ) == -1 ) {
2002+ return NULL ;
20272003 }
20282004
2005+ // must not fail
2006+ Py_UCS4 * u = PyUnicode_AsUCS4 (ustr , ((Py_UCS4 * )self -> ob_item ) + old_size ,
2007+ ustr_length , 0 );
2008+ assert (u != NULL );
2009+ (void )u ; // Suppress unused_variable warning.
2010+
20292011 Py_RETURN_NONE ;
20302012}
20312013
@@ -2045,19 +2027,14 @@ array_array_tounicode_impl(arrayobject *self)
20452027/*[clinic end generated code: output=08e442378336e1ef input=6690997213d219db]*/
20462028{
20472029 const char * typecode = self -> ob_descr -> typecode ;
2048- if (strcmp (typecode , "u" ) != 0 && strcmp ( typecode , " w" ) != 0 ) {
2030+ if (strcmp (typecode , "w" ) != 0 ) {
20492031 PyErr_SetString (PyExc_ValueError ,
2050- "tounicode() may only be called on unicode type arrays ('u' or ' w')" );
2032+ "tounicode() may only be called on unicode type (' w') arrays " );
20512033 return NULL ;
20522034 }
2053- if (strcmp (typecode , "u" ) == 0 ) {
2054- return PyUnicode_FromWideChar ((wchar_t * ) self -> ob_item , Py_SIZE (self ));
2055- }
2056- else { // typecode == "w"
2057- int byteorder = 0 ; // native byteorder
2058- return PyUnicode_DecodeUTF32 ((const char * ) self -> ob_item , Py_SIZE (self ) * 4 ,
2059- NULL , & byteorder );
2060- }
2035+ int byteorder = 0 ; // native byteorder
2036+ return PyUnicode_DecodeUTF32 ((const char * ) self -> ob_item , Py_SIZE (self ) * 4 ,
2037+ NULL , & byteorder );
20612038}
20622039
20632040/*[clinic input]
@@ -2133,15 +2110,6 @@ typecode_to_mformat_code(const char *typecode)
21332110 case 'B' :
21342111 return UNSIGNED_INT8 ;
21352112
2136- case 'u' :
2137- if (sizeof (wchar_t ) == 2 ) {
2138- return UTF16_LE + is_big_endian ;
2139- }
2140- if (sizeof (wchar_t ) == 4 ) {
2141- return UTF32_LE + is_big_endian ;
2142- }
2143- return UNKNOWN_FORMAT ;
2144-
21452113 case 'w' :
21462114 return UTF32_LE + is_big_endian ;
21472115
@@ -2696,7 +2664,7 @@ array_repr(PyObject *op)
26962664 return PyUnicode_FromFormat ("%s('%s')" ,
26972665 _PyType_Name (Py_TYPE (a )), typecode );
26982666 }
2699- if (strcmp (typecode , "u" ) == 0 || strcmp ( typecode , " w" ) == 0 ) {
2667+ if (strcmp (typecode , "w" ) == 0 ) {
27002668 v = array_array_tounicode_impl (a );
27012669 } else {
27022670 v = array_array_tolist_impl (a );
@@ -2966,9 +2934,6 @@ array_buffer_getbuf(PyObject *op, Py_buffer *view, int flags)
29662934 view -> internal = NULL ;
29672935 if ((flags & PyBUF_FORMAT ) == PyBUF_FORMAT ) {
29682936 view -> format = (char * )self -> ob_descr -> typecode ;
2969- if (sizeof (wchar_t ) >= 4 && strcmp (self -> ob_descr -> typecode , "u" ) == 0 ) {
2970- view -> format = "w" ;
2971- }
29722937 }
29732938
29742939 self -> ob_exports ++ ;
@@ -3003,16 +2968,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
30032968 return NULL ;
30042969 }
30052970
3006- if (strcmp (s , "u" ) == 0 ) {
3007- if (PyErr_WarnEx (PyExc_DeprecationWarning ,
3008- "The 'u' type code is deprecated and "
3009- "will be removed in Python 3.16" ,
3010- 1 )) {
3011- return NULL ;
3012- }
3013- }
3014-
3015- bool is_unicode = (strcmp (s , "u" ) == 0 || strcmp (s , "w" ) == 0 );
2971+ bool is_unicode = (strcmp (s , "w" ) == 0 );
30162972
30172973 if (initial && !is_unicode ) {
30182974 if (PyUnicode_Check (initial )) {
@@ -3022,7 +2978,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
30222978 }
30232979 else if (array_Check (initial , state )) {
30242980 const char * is = ((arrayobject * )initial )-> ob_descr -> typecode ;
3025- if (strcmp (is , "u" ) == 0 || strcmp ( is , " w" ) == 0 ) {
2981+ if (strcmp (is , "w" ) == 0 ) {
30262982 PyErr_Format (PyExc_TypeError , "cannot use a unicode array to "
30272983 "initialize an array with typecode '%s'" , s );
30282984 return NULL ;
@@ -3098,43 +3054,20 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
30983054 Py_DECREF (v );
30993055 }
31003056 else if (initial != NULL && PyUnicode_Check (initial )) {
3101- if (strcmp (s , "u" ) == 0 ) {
3102- Py_ssize_t n ;
3103- wchar_t * ustr = PyUnicode_AsWideCharString (initial , & n );
3104- if (ustr == NULL ) {
3105- Py_DECREF (a );
3106- Py_XDECREF (it );
3107- return NULL ;
3108- }
3109-
3110- if (n > 0 ) {
3111- arrayobject * self = (arrayobject * )a ;
3112- // self->ob_item may be NULL but it is safe.
3113- PyMem_Free (self -> ob_item );
3114- self -> ob_item = (char * )ustr ;
3115- Py_SET_SIZE (self , n );
3116- self -> allocated = n ;
3117- }
3118- else {
3119- PyMem_Free (ustr );
3120- }
3057+ Py_ssize_t n = PyUnicode_GET_LENGTH (initial );
3058+ Py_UCS4 * ustr = PyUnicode_AsUCS4Copy (initial );
3059+ if (ustr == NULL ) {
3060+ Py_DECREF (a );
3061+ Py_XDECREF (it );
3062+ return NULL ;
31213063 }
3122- else { // s == "w"
3123- Py_ssize_t n = PyUnicode_GET_LENGTH (initial );
3124- Py_UCS4 * ustr = PyUnicode_AsUCS4Copy (initial );
3125- if (ustr == NULL ) {
3126- Py_DECREF (a );
3127- Py_XDECREF (it );
3128- return NULL ;
3129- }
31303064
3131- arrayobject * self = (arrayobject * )a ;
3132- // self->ob_item may be NULL but it is safe.
3133- PyMem_Free (self -> ob_item );
3134- self -> ob_item = (char * )ustr ;
3135- Py_SET_SIZE (self , n );
3136- self -> allocated = n ;
3137- }
3065+ arrayobject * self = (arrayobject * )a ;
3066+ // self->ob_item may be NULL but it is safe.
3067+ PyMem_Free (self -> ob_item );
3068+ self -> ob_item = (char * )ustr ;
3069+ Py_SET_SIZE (self , n );
3070+ self -> allocated = n ;
31383071 }
31393072 else if (initial != NULL && array_Check (initial , state ) && len > 0 ) {
31403073 arrayobject * self = (arrayobject * )a ;
@@ -3180,7 +3113,6 @@ The following type codes are defined:\n\
31803113 Type code C Type Minimum size in bytes\n\
31813114 'b' signed integer 1\n\
31823115 'B' unsigned integer 1\n\
3183- 'u' Unicode character 2 (see note)\n\
31843116 'h' signed integer 2\n\
31853117 'H' unsigned integer 2\n\
31863118 'i' signed integer 2\n\
@@ -3195,9 +3127,6 @@ The following type codes are defined:\n\
31953127 'Zf' float complex 8\n\
31963128 'Zd' double complex 16\n\
31973129\n\
3198- NOTE: The 'u' typecode corresponds to Python's unicode character. On\n\
3199- narrow builds this is 2-bytes on wide builds this is 4-bytes.\n\
3200- \n\
32013130NOTE: The 'q' and 'Q' type codes are only available if the platform\n\
32023131C compiler used to build Python supports 'long long', or, on Windows,\n\
32033132'__int64'.\n\
0 commit comments