kopia lustrzana https://github.com/pimoroni/pimoroni-pico
				
				
				
			Merge pull request #111 from pimoroni/patch-texthandling
Fix for MicroPython hard lock when passing in non-string object to text functionpull/112/head v0.1.0
						commit
						c3f609ebe0
					
				|  | @ -411,8 +411,9 @@ mp_obj_t BreakoutRoundLCD_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t | ||||||
|      |      | ||||||
|     breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_roundlcd_BreakoutRoundLCD_obj_t); |     breakout_roundlcd_BreakoutRoundLCD_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_roundlcd_BreakoutRoundLCD_obj_t); | ||||||
| 
 | 
 | ||||||
|     mp_check_self(mp_obj_is_str_or_bytes(args[ARG_text].u_obj)); |     mp_obj_t text_obj = args[ARG_text].u_obj; | ||||||
|     GET_STR_DATA_LEN(args[ARG_text].u_obj, str, str_len); |     if(mp_obj_is_str_or_bytes(text_obj)) { | ||||||
|  |         GET_STR_DATA_LEN(text_obj, str, str_len); | ||||||
| 
 | 
 | ||||||
|         std::string t((const char*)str); |         std::string t((const char*)str); | ||||||
| 
 | 
 | ||||||
|  | @ -427,6 +428,19 @@ mp_obj_t BreakoutRoundLCD_text(size_t n_args, const mp_obj_t *pos_args, mp_map_t | ||||||
|         } |         } | ||||||
|         else |         else | ||||||
|             self->breakout->text(t, p, wrap); |             self->breakout->text(t, p, wrap); | ||||||
|  |     } | ||||||
|  |     else if(mp_obj_is_float(text_obj)) { | ||||||
|  |         mp_raise_TypeError("can't convert 'float' object to str implicitly"); | ||||||
|  |     } | ||||||
|  |     else if(mp_obj_is_int(text_obj)) { | ||||||
|  |         mp_raise_TypeError("can't convert 'int' object to str implicitly"); | ||||||
|  |     } | ||||||
|  |     else if(mp_obj_is_bool(text_obj)) { | ||||||
|  |         mp_raise_TypeError("can't convert 'bool' object to str implicitly"); | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |         mp_raise_TypeError("can't convert object to str implicitly"); | ||||||
|  |     }         | ||||||
| 
 | 
 | ||||||
|     return mp_const_none; |     return mp_const_none; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -303,7 +303,7 @@ mp_obj_t picodisplay_character(mp_uint_t n_args, const mp_obj_t *args) { | ||||||
| 
 | 
 | ||||||
| mp_obj_t picodisplay_text(mp_uint_t n_args, const mp_obj_t *args) { | mp_obj_t picodisplay_text(mp_uint_t n_args, const mp_obj_t *args) { | ||||||
|     if(display != nullptr) { |     if(display != nullptr) { | ||||||
|         mp_check_self(mp_obj_is_str_or_bytes(args[0])); |         if(mp_obj_is_str_or_bytes(args[0])) { | ||||||
|             GET_STR_DATA_LEN(args[0], str, str_len); |             GET_STR_DATA_LEN(args[0], str, str_len); | ||||||
| 
 | 
 | ||||||
|             std::string t((const char*)str); |             std::string t((const char*)str); | ||||||
|  | @ -320,6 +320,19 @@ mp_obj_t picodisplay_text(mp_uint_t n_args, const mp_obj_t *args) { | ||||||
|             else |             else | ||||||
|                 display->text(t, p, wrap); |                 display->text(t, p, wrap); | ||||||
|         } |         } | ||||||
|  |         else if(mp_obj_is_float(args[0])) { | ||||||
|  |             mp_raise_TypeError("can't convert 'float' object to str implicitly"); | ||||||
|  |         } | ||||||
|  |         else if(mp_obj_is_int(args[0])) { | ||||||
|  |             mp_raise_TypeError("can't convert 'int' object to str implicitly"); | ||||||
|  |         } | ||||||
|  |         else if(mp_obj_is_bool(args[0])) { | ||||||
|  |             mp_raise_TypeError("can't convert 'bool' object to str implicitly"); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             mp_raise_TypeError("can't convert object to str implicitly"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|     else |     else | ||||||
|         mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG); |         mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -326,7 +326,7 @@ mp_obj_t picoexplorer_character(mp_uint_t n_args, const mp_obj_t *args) { | ||||||
| 
 | 
 | ||||||
| mp_obj_t picoexplorer_text(mp_uint_t n_args, const mp_obj_t *args) { | mp_obj_t picoexplorer_text(mp_uint_t n_args, const mp_obj_t *args) { | ||||||
|     if(explorer != nullptr) { |     if(explorer != nullptr) { | ||||||
|         mp_check_self(mp_obj_is_str_or_bytes(args[0])); |         if(mp_obj_is_str_or_bytes(args[0])) { | ||||||
|             GET_STR_DATA_LEN(args[0], str, str_len); |             GET_STR_DATA_LEN(args[0], str, str_len); | ||||||
| 
 | 
 | ||||||
|             std::string t((const char*)str); |             std::string t((const char*)str); | ||||||
|  | @ -343,6 +343,19 @@ mp_obj_t picoexplorer_text(mp_uint_t n_args, const mp_obj_t *args) { | ||||||
|             else |             else | ||||||
|                 explorer->text(t, p, wrap); |                 explorer->text(t, p, wrap); | ||||||
|         } |         } | ||||||
|  |         else if(mp_obj_is_float(args[0])) { | ||||||
|  |             mp_raise_TypeError("can't convert 'float' object to str implicitly"); | ||||||
|  |         } | ||||||
|  |         else if(mp_obj_is_int(args[0])) { | ||||||
|  |             mp_raise_TypeError("can't convert 'int' object to str implicitly"); | ||||||
|  |         } | ||||||
|  |         else if(mp_obj_is_bool(args[0])) { | ||||||
|  |             mp_raise_TypeError("can't convert 'bool' object to str implicitly"); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             mp_raise_TypeError("can't convert object to str implicitly"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|     else |     else | ||||||
|         mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG); |         mp_raise_msg(&mp_type_RuntimeError, NOT_INITIALISED_MSG); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Ładowanie…
	
		Reference in New Issue
	
	 Philip Howard
						Philip Howard