Skip to content

Commit fe3cc5b

Browse files
committed
py/modstruct: Use more compact mp_raise_ValueError function.
Saves a few bytes of code size.
1 parent 3b5affa commit fe3cc5b

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

py/modstruct.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) {
114114
mp_uint_t align;
115115
size_t sz = mp_binary_get_size(fmt_type, *fmt, &align);
116116
if (sz == 0) {
117-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "unsupported format"));
117+
mp_raise_ValueError("unsupported format");
118118
}
119119
while (cnt--) {
120120
// Apply alignment
@@ -149,7 +149,7 @@ STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) {
149149
// negative offsets are relative to the end of the buffer
150150
offset = bufinfo.len + offset;
151151
if (offset < 0) {
152-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "buffer too small"));
152+
mp_raise_ValueError("buffer too small");
153153
}
154154
}
155155
p += offset;
@@ -164,7 +164,7 @@ STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) {
164164
sz = get_fmt_num(&fmt);
165165
}
166166
if (p + sz > end_p) {
167-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "buffer too small"));
167+
mp_raise_ValueError("buffer too small");
168168
}
169169
mp_obj_t item;
170170
if (*fmt == 's') {
@@ -197,7 +197,7 @@ STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, byte* end_p, siz
197197
sz = get_fmt_num(&fmt);
198198
}
199199
if (p + sz > end_p) {
200-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "buffer too small"));
200+
mp_raise_ValueError("buffer too small");
201201
}
202202

203203
if (*fmt == 's') {
@@ -240,7 +240,7 @@ STATIC mp_obj_t struct_pack_into(size_t n_args, const mp_obj_t *args) {
240240
// negative offsets are relative to the end of the buffer
241241
offset = (mp_int_t)bufinfo.len + offset;
242242
if (offset < 0) {
243-
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "buffer too small"));
243+
mp_raise_ValueError("buffer too small");
244244
}
245245
}
246246
byte *p = (byte *)bufinfo.buf;

0 commit comments

Comments
 (0)