@@ -231,7 +231,7 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size
231
231
mp_int_t val = mp_obj_get_int (item );
232
232
#if MICROPY_CPYTHON_COMPAT
233
233
if (val < 0 || val > 255 ) {
234
- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_ValueError , "bytes value out of range" ) );
234
+ mp_raise_ValueError ( "bytes value out of range" );
235
235
}
236
236
#endif
237
237
vstr_add_byte (& vstr , val );
@@ -240,7 +240,7 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size
240
240
return mp_obj_new_str_from_vstr (& mp_type_bytes , & vstr );
241
241
242
242
wrong_args :
243
- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_TypeError , "wrong number of arguments" ) );
243
+ mp_raise_TypeError ( "wrong number of arguments" );
244
244
}
245
245
246
246
// like strstr but with specified length and allows \0 bytes
@@ -436,8 +436,8 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) {
436
436
mp_uint_t required_len = 0 ;
437
437
for (mp_uint_t i = 0 ; i < seq_len ; i ++ ) {
438
438
if (mp_obj_get_type (seq_items [i ]) != self_type ) {
439
- nlr_raise ( mp_obj_new_exception_msg (& mp_type_TypeError ,
440
- "join expects a list of str/bytes objects consistent with self object" )) ;
439
+ mp_raise_msg (& mp_type_TypeError ,
440
+ "join expects a list of str/bytes objects consistent with self object" );
441
441
}
442
442
if (i > 0 ) {
443
443
required_len += sep_len ;
@@ -511,7 +511,7 @@ mp_obj_t mp_obj_str_split(size_t n_args, const mp_obj_t *args) {
511
511
const char * sep_str = mp_obj_str_get_data (sep , & sep_len );
512
512
513
513
if (sep_len == 0 ) {
514
- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_ValueError , "empty separator" ) );
514
+ mp_raise_ValueError ( "empty separator" );
515
515
}
516
516
517
517
for (;;) {
@@ -609,7 +609,7 @@ STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) {
609
609
const char * sep_str = mp_obj_str_get_data (sep , & sep_len );
610
610
611
611
if (sep_len == 0 ) {
612
- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_ValueError , "empty separator" ) );
612
+ mp_raise_ValueError ( "empty separator" );
613
613
}
614
614
615
615
const byte * beg = s ;
@@ -672,7 +672,7 @@ STATIC mp_obj_t str_finder(mp_uint_t n_args, const mp_obj_t *args, mp_int_t dire
672
672
if (p == NULL ) {
673
673
// not found
674
674
if (is_index ) {
675
- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_ValueError , "substring not found" ) );
675
+ mp_raise_ValueError ( "substring not found" );
676
676
} else {
677
677
return MP_OBJ_NEW_SMALL_INT (-1 );
678
678
}
@@ -878,7 +878,7 @@ STATIC mp_obj_t arg_as_int(mp_obj_t arg) {
878
878
}
879
879
880
880
STATIC NORETURN void terse_str_format_value_error (void ) {
881
- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_ValueError , "bad format string" ) );
881
+ mp_raise_ValueError ( "bad format string" );
882
882
}
883
883
884
884
STATIC vstr_t mp_obj_str_format_helper (const char * str , const char * top , int * arg_i , mp_uint_t n_args , const mp_obj_t * args , mp_map_t * kwargs ) {
@@ -896,8 +896,8 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
896
896
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
897
897
terse_str_format_value_error ();
898
898
} else {
899
- nlr_raise ( mp_obj_new_exception_msg (& mp_type_ValueError ,
900
- "single '}' encountered in format string" )) ;
899
+ mp_raise_msg (& mp_type_ValueError ,
900
+ "single '}' encountered in format string" );
901
901
}
902
902
}
903
903
if (* str != '{' ) {
@@ -936,12 +936,11 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
936
936
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
937
937
terse_str_format_value_error ();
938
938
} else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL ) {
939
- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
940
- "bad conversion specifier" ));
939
+ mp_raise_ValueError ("bad conversion specifier" );
941
940
} else {
942
941
if (str >= top ) {
943
- nlr_raise ( mp_obj_new_exception_msg (& mp_type_ValueError ,
944
- "end of format while looking for conversion specifier" )) ;
942
+ mp_raise_msg (& mp_type_ValueError ,
943
+ "end of format while looking for conversion specifier" );
945
944
} else {
946
945
nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_ValueError ,
947
946
"unknown conversion specifier %c" , * str ));
@@ -975,16 +974,14 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
975
974
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
976
975
terse_str_format_value_error ();
977
976
} else {
978
- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
979
- "unmatched '{' in format" ));
977
+ mp_raise_ValueError ("unmatched '{' in format" );
980
978
}
981
979
}
982
980
if (* str != '}' ) {
983
981
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
984
982
terse_str_format_value_error ();
985
983
} else {
986
- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
987
- "expected ':' after format specifier" ));
984
+ mp_raise_ValueError ("expected ':' after format specifier" );
988
985
}
989
986
}
990
987
@@ -997,13 +994,13 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
997
994
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
998
995
terse_str_format_value_error ();
999
996
} else {
1000
- nlr_raise ( mp_obj_new_exception_msg (& mp_type_ValueError ,
1001
- "can't switch from automatic field numbering to manual field specification" )) ;
997
+ mp_raise_msg (& mp_type_ValueError ,
998
+ "can't switch from automatic field numbering to manual field specification" );
1002
999
}
1003
1000
}
1004
1001
field_name = str_to_int (field_name , field_name_top , & index );
1005
1002
if ((uint )index >= n_args - 1 ) {
1006
- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_IndexError , "tuple index out of range" ) );
1003
+ mp_raise_msg ( & mp_type_IndexError , "tuple index out of range" );
1007
1004
}
1008
1005
arg = args [index + 1 ];
1009
1006
* arg_i = -1 ;
@@ -1026,12 +1023,12 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
1026
1023
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
1027
1024
terse_str_format_value_error ();
1028
1025
} else {
1029
- nlr_raise ( mp_obj_new_exception_msg (& mp_type_ValueError ,
1030
- "can't switch from manual field specification to automatic field numbering" )) ;
1026
+ mp_raise_msg (& mp_type_ValueError ,
1027
+ "can't switch from manual field specification to automatic field numbering" );
1031
1028
}
1032
1029
}
1033
1030
if ((uint )* arg_i >= n_args - 1 ) {
1034
- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_IndexError , "tuple index out of range" ) );
1031
+ mp_raise_msg ( & mp_type_IndexError , "tuple index out of range" );
1035
1032
}
1036
1033
arg = args [(* arg_i ) + 1 ];
1037
1034
(* arg_i )++ ;
@@ -1120,8 +1117,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
1120
1117
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
1121
1118
terse_str_format_value_error ();
1122
1119
} else {
1123
- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
1124
- "invalid format specifier" ));
1120
+ mp_raise_ValueError ("invalid format specifier" );
1125
1121
}
1126
1122
}
1127
1123
vstr_clear (& format_spec_vstr );
@@ -1142,16 +1138,16 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
1142
1138
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
1143
1139
terse_str_format_value_error ();
1144
1140
} else {
1145
- nlr_raise ( mp_obj_new_exception_msg (& mp_type_ValueError ,
1146
- "sign not allowed in string format specifier" )) ;
1141
+ mp_raise_msg (& mp_type_ValueError ,
1142
+ "sign not allowed in string format specifier" );
1147
1143
}
1148
1144
}
1149
1145
if (type == 'c' ) {
1150
1146
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
1151
1147
terse_str_format_value_error ();
1152
1148
} else {
1153
- nlr_raise ( mp_obj_new_exception_msg (& mp_type_ValueError ,
1154
- "sign not allowed with integer format specifier 'c'" )) ;
1149
+ mp_raise_msg (& mp_type_ValueError ,
1150
+ "sign not allowed with integer format specifier 'c'" );
1155
1151
}
1156
1152
}
1157
1153
} else {
@@ -1295,8 +1291,8 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
1295
1291
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
1296
1292
terse_str_format_value_error ();
1297
1293
} else {
1298
- nlr_raise ( mp_obj_new_exception_msg (& mp_type_ValueError ,
1299
- "'=' alignment not allowed in string format specifier" )) ;
1294
+ mp_raise_msg (& mp_type_ValueError ,
1295
+ "'=' alignment not allowed in string format specifier" );
1300
1296
}
1301
1297
}
1302
1298
@@ -1372,8 +1368,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
1372
1368
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
1373
1369
terse_str_format_value_error ();
1374
1370
} else {
1375
- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
1376
- "incomplete format key" ));
1371
+ mp_raise_ValueError ("incomplete format key" );
1377
1372
}
1378
1373
}
1379
1374
++ str ;
@@ -1431,16 +1426,15 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
1431
1426
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
1432
1427
terse_str_format_value_error ();
1433
1428
} else {
1434
- nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
1435
- "incomplete format" ));
1429
+ mp_raise_ValueError ("incomplete format" );
1436
1430
}
1437
1431
}
1438
1432
1439
1433
// Tuple value lookup
1440
1434
if (arg == MP_OBJ_NULL ) {
1441
1435
if ((uint )arg_i >= n_args ) {
1442
1436
not_enough_args :
1443
- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_TypeError , "not enough arguments for format string" ) );
1437
+ mp_raise_TypeError ( "not enough arguments for format string" );
1444
1438
}
1445
1439
arg = args [arg_i ++ ];
1446
1440
}
@@ -1450,16 +1444,14 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
1450
1444
mp_uint_t slen ;
1451
1445
const char * s = mp_obj_str_get_data (arg , & slen );
1452
1446
if (slen != 1 ) {
1453
- nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
1454
- "%%c requires int or char" ));
1447
+ mp_raise_TypeError ("%%c requires int or char" );
1455
1448
}
1456
1449
mp_print_strn (& print , s , 1 , flags , ' ' , width );
1457
1450
} else if (arg_looks_integer (arg )) {
1458
1451
char ch = mp_obj_get_int (arg );
1459
1452
mp_print_strn (& print , & ch , 1 , flags , ' ' , width );
1460
1453
} else {
1461
- nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
1462
- "integer required" ));
1454
+ mp_raise_TypeError ("integer required" );
1463
1455
}
1464
1456
break ;
1465
1457
@@ -1529,7 +1521,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
1529
1521
}
1530
1522
1531
1523
if ((uint )arg_i != n_args ) {
1532
- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_TypeError , "not all arguments converted during string formatting" ) );
1524
+ mp_raise_TypeError ( "not all arguments converted during string formatting" );
1533
1525
}
1534
1526
1535
1527
return mp_obj_new_str_from_vstr (is_bytes ? & mp_type_bytes : & mp_type_str , & vstr );
@@ -1695,7 +1687,7 @@ STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, mp_int_t directi
1695
1687
GET_STR_DATA_LEN (arg , sep , sep_len );
1696
1688
1697
1689
if (sep_len == 0 ) {
1698
- nlr_raise ( mp_obj_new_exception_msg ( & mp_type_ValueError , "empty separator" ) );
1690
+ mp_raise_ValueError ( "empty separator" );
1699
1691
}
1700
1692
1701
1693
mp_obj_t result [3 ];
@@ -2061,8 +2053,7 @@ bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2) {
2061
2053
2062
2054
STATIC void bad_implicit_conversion (mp_obj_t self_in ) {
2063
2055
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE ) {
2064
- nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
2065
- "can't convert to str implicitly" ));
2056
+ mp_raise_TypeError ("can't convert to str implicitly" );
2066
2057
} else {
2067
2058
nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_TypeError ,
2068
2059
"can't convert '%s' object to str implicitly" ,
0 commit comments