From f325bd848b183f9b111b44e2fab2a9e6a366af3c Mon Sep 17 00:00:00 2001 From: Matt Wozniski Date: Thu, 9 May 2019 03:20:15 -0400 Subject: [PATCH] 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. --- py/objint.c | 2 +- py/runtime.c | 8 ++++++++ py/runtime.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/py/objint.c b/py/objint.c index fc672b1123..029402a8db 100644 --- a/py/objint.c +++ b/py/objint.c @@ -340,7 +340,7 @@ void mp_obj_int_buffer_overflow_check(mp_obj_t self_in, size_t nbytes, bool is_s return; 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 diff --git a/py/runtime.c b/py/runtime.c index 1a75a3870b..9968f26e06 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1598,6 +1598,14 @@ NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, 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) { mp_raise_msg(&mp_type_MpyError, msg); } diff --git a/py/runtime.h b/py/runtime.h index c5a94b0b19..e8398cf0ea 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -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_NotImplementedError(const compressed_string_t *msg); 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_recursion_depth(void);