Skip to content

Commit 48d867b

Browse files
committed
all: Make more use of mp_raise_{msg,TypeError,ValueError} helpers.
1 parent 1e70fda commit 48d867b

File tree

17 files changed

+33
-37
lines changed

17 files changed

+33
-37
lines changed

esp8266/machine_uart.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ STATIC void pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const mp_o
104104
self->bits = 8;
105105
break;
106106
default:
107-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid data bits"));
107+
mp_raise_ValueError("invalid data bits");
108108
break;
109109
}
110110

@@ -140,7 +140,7 @@ STATIC void pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const mp_o
140140
self->stop = 2;
141141
break;
142142
default:
143-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid stop bits"));
143+
mp_raise_ValueError("invalid stop bits");
144144
break;
145145
}
146146

@@ -215,7 +215,7 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
215215
pyb_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
216216

217217
if (self->uart_id == 1) {
218-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "UART(1) can't read"));
218+
mp_raise_msg(&mp_type_OSError, "UART(1) can't read");
219219
}
220220

221221
// make sure we want at least 1 char

extmod/modframebuf.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size
244244
o->stride = (o->stride + 7) & ~7;
245245
break;
246246
default:
247-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
248-
"invalid format"));
247+
mp_raise_ValueError("invalid format");
249248
}
250249

251250
return MP_OBJ_FROM_PTR(o);

extmod/modubinascii.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
7575
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
7676

7777
if ((bufinfo.len & 1) != 0) {
78-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "odd-length string"));
78+
mp_raise_ValueError("odd-length string");
7979
}
8080
vstr_t vstr;
8181
vstr_init_len(&vstr, bufinfo.len / 2);
@@ -86,7 +86,7 @@ mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
8686
if (unichar_isxdigit(hex_ch)) {
8787
hex_byte += unichar_xdigit_value(hex_ch);
8888
} else {
89-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "non-hex digit found"));
89+
mp_raise_ValueError("non-hex digit found");
9090
}
9191
if (i & 1) {
9292
hex_byte <<= 4;

py/builtinimport.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
230230
#endif
231231

232232
// If we get here then the file was not frozen and we can't compile scripts.
233-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
234-
"script compilation not supported"));
233+
mp_raise_msg(&mp_type_ImportError, "script compilation not supported");
235234
}
236235

237236
STATIC void chop_component(const char *start, const char **end) {

py/modbuiltins.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,7 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
398398
#endif
399399

400400
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
401-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
402-
"ord expects a character"));
401+
mp_raise_TypeError("ord expects a character");
403402
} else {
404403
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
405404
"ord() expected a character, but string of length %d found", (int)len));

py/modmath.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
#include "py/builtin.h"
28-
#include "py/nlr.h"
28+
#include "py/runtime.h"
2929

3030
#if MICROPY_PY_BUILTINS_FLOAT && MICROPY_PY_MATH
3131

@@ -41,7 +41,7 @@
4141
/// working with floating-point numbers.
4242

4343
STATIC NORETURN void math_error(void) {
44-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "math domain error"));
44+
mp_raise_ValueError("math domain error");
4545
}
4646

4747
#define MATH_FUN_1(py_name, c_name) \

py/obj.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,7 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
460460
}
461461
} else if (value == MP_OBJ_SENTINEL) {
462462
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
463-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
464-
"object is not subscriptable"));
463+
mp_raise_TypeError("object is not subscriptable");
465464
} else {
466465
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
467466
"'%s' object is not subscriptable", mp_obj_get_type_str(base)));

py/objcomplex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t
196196
}
197197
case MP_BINARY_OP_FLOOR_DIVIDE:
198198
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE:
199-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "can't do truncated division of a complex number"));
199+
mp_raise_TypeError("can't do truncated division of a complex number");
200200

201201
case MP_BINARY_OP_TRUE_DIVIDE:
202202
case MP_BINARY_OP_INPLACE_TRUE_DIVIDE:

py/objint_longlong.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ mp_obj_t mp_obj_new_int_from_ll(long long val) {
247247
mp_obj_t mp_obj_new_int_from_ull(unsigned long long val) {
248248
// TODO raise an exception if the unsigned long long won't fit
249249
if (val >> (sizeof(unsigned long long) * 8 - 1) != 0) {
250-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OverflowError, "ulonglong too large"));
250+
mp_raise_msg(&mp_type_OverflowError, "ulonglong too large");
251251
}
252252
mp_obj_int_t *o = m_new_obj(mp_obj_int_t);
253253
o->base.type = &mp_type_int;

py/objstrunicode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s
142142
if (is_slice) {
143143
return self_data;
144144
}
145-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_IndexError, "string index out of range"));
145+
mp_raise_msg(&mp_type_IndexError, "string index out of range");
146146
}
147147
if (!UTF8_IS_CONT(*s)) {
148148
++i;
@@ -161,7 +161,7 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s
161161
if (is_slice) {
162162
return top;
163163
}
164-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_IndexError, "string index out of range"));
164+
mp_raise_msg(&mp_type_IndexError, "string index out of range");
165165
}
166166
// Then check completion
167167
if (i-- == 0) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy