@@ -154,7 +154,8 @@ STATIC mp_obj_t str_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_
154154
155155// Convert an index into a pointer to its lead byte. Out of bounds indexing will raise IndexError or
156156// be capped to the first/last character of the string, depending on is_slice.
157- STATIC const char * str_index_to_ptr (const char * self_data , uint self_len , mp_obj_t index , bool is_slice ) {
157+ const byte * str_index_to_ptr (const mp_obj_type_t * type , const byte * self_data , uint self_len ,
158+ mp_obj_t index , bool is_slice ) {
158159 machine_int_t i ;
159160 // Copied from mp_get_index; I don't want bounds checking, just give me
160161 // the integer as-is. (I can't bounds-check without scanning the whole
@@ -164,7 +165,7 @@ STATIC const char *str_index_to_ptr(const char *self_data, uint self_len, mp_obj
164165 } else if (!mp_obj_get_int_maybe (index , & i )) {
165166 nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError , "string indices must be integers, not %s" , mp_obj_get_type_str (index )));
166167 }
167- const char * s , * top = self_data + self_len ;
168+ const byte * s , * top = self_data + self_len ;
168169 if (i < 0 )
169170 {
170171 // Negative indexing is performed by counting from the end of the string.
@@ -235,18 +236,18 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
235236 }
236237 return mp_obj_new_str_of_type (type , self_data + start , stop - start );
237238 }
238- const char * pstart , * pstop ;
239+ const byte * pstart , * pstop ;
239240 if (ostart != mp_const_none ) {
240- pstart = str_index_to_ptr (( const char * ) self_data , self_len , ostart , true);
241+ pstart = str_index_to_ptr (type , self_data , self_len , ostart , true);
241242 } else {
242- pstart = ( const char * ) self_data ;
243+ pstart = self_data ;
243244 }
244245 if (ostop != mp_const_none ) {
245246 // pstop will point just after the stop character. This depends on
246247 // the \0 at the end of the string.
247- pstop = str_index_to_ptr (( const char * ) self_data , self_len , ostop , true);
248+ pstop = str_index_to_ptr (type , self_data , self_len , ostop , true);
248249 } else {
249- pstop = ( const char * ) self_data + self_len ;
250+ pstop = self_data + self_len ;
250251 }
251252 if (pstop < pstart ) {
252253 return MP_OBJ_NEW_QSTR (MP_QSTR_ );
@@ -258,15 +259,15 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
258259 uint index_val = mp_get_index (type , self_len , index , false);
259260 return MP_OBJ_NEW_SMALL_INT ((mp_small_int_t )self_data [index_val ]);
260261 }
261- const char * s = str_index_to_ptr (( const char * ) self_data , self_len , index , false);
262+ const byte * s = str_index_to_ptr (type , self_data , self_len , index , false);
262263 int len = 1 ;
263264 if (UTF8_IS_NONASCII (* s )) {
264265 // Count the number of 1 bits (after the first)
265266 for (char mask = 0x40 ; * s & mask ; mask >>= 1 ) {
266267 ++ len ;
267268 }
268269 }
269- return mp_obj_new_str (s , len , true); // This will create a one-character string
270+ return mp_obj_new_str (( const char * ) s , len , true); // This will create a one-character string
270271 } else {
271272 return MP_OBJ_NULL ; // op not supported
272273 }
0 commit comments