Use OverflowError exception type for overflows

Initially I used one of the existing exception raise functions, but it's
more correct and not much more code to raise OverflowError instead.
This commit is contained in:
Matt Wozniski 2019-05-09 03:20:15 -04:00
parent 095c844004
commit f325bd848b
3 changed files with 10 additions and 1 deletions

View File

@ -340,7 +340,7 @@ void mp_obj_int_buffer_overflow_check(mp_obj_t self_in, size_t nbytes, bool is_s
return; return;
raise: raise:
mp_raise_ValueError_varg(translate("value would overflow a %d byte buffer"), nbytes); mp_raise_OverflowError_varg(translate("value would overflow a %d byte buffer"), nbytes);
} }
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE

View File

@ -1598,6 +1598,14 @@ NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt,
nlr_raise(exception); nlr_raise(exception);
} }
NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...) {
va_list argptr;
va_start(argptr,fmt);
mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_OverflowError, fmt, argptr);
va_end(argptr);
nlr_raise(exception);
}
NORETURN void mp_raise_MpyError(const compressed_string_t *msg) { NORETURN void mp_raise_MpyError(const compressed_string_t *msg) {
mp_raise_msg(&mp_type_MpyError, msg); mp_raise_msg(&mp_type_MpyError, msg);
} }

View File

@ -163,6 +163,7 @@ NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg);
NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...); NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...);
NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg); NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg);
NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...); NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...);
NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...);
NORETURN void mp_raise_MpyError(const compressed_string_t *msg); NORETURN void mp_raise_MpyError(const compressed_string_t *msg);
NORETURN void mp_raise_recursion_depth(void); NORETURN void mp_raise_recursion_depth(void);